Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Prevent crashing the application when a block is received and node is syncing or forging - Closes #3896 #3946

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion framework/src/modules/chain/blocks/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,12 @@ class Blocks extends EventEmitter {
// Process a block from the P2P
async receiveBlockFromNetwork(block) {
return this.sequence.add(async () => {
this._shouldNotBeActive();
if (this._isActive) {
this.logger.info(
'Ignoring received block from network, node is syncing or forging'
);
return;
}
this._isActive = true;
// set active to true
if (this.blocksVerify.isSaneBlock(block, this._lastBlock)) {
Expand Down
23 changes: 23 additions & 0 deletions framework/test/mocha/unit/modules/chain/blocks/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,29 @@ describe('blocks', () => {
});
});
});
describe('client not ready to receive block', () => {
beforeEach(async () => {
sinonSandbox.stub(blocksInstance.blocksVerify, 'isSaneBlock');
sequenceStub.add.callsFake(async fn => {
await fn();
});
});

it('should not process the received block and info log it', async () => {
blocksInstance._isActive = true;
await blocksInstance.receiveBlockFromNetwork({
id: '2',
previousBlock: '1',
height: 2,
});

expect(loggerStub.info).to.be.calledWith(
'Ignoring received block from network, node is syncing or forging'
);
expect(blocksInstance._isActive).to.be.true; // Value shouldn't be altered.
expect(blocksInstance.blocksVerify.isSaneBlock).to.not.be.called;
});
});
});

describe('_rebuildMode', () => {
Expand Down