diff --git a/framework/src/modules/chain/rounds/delegates.js b/framework/src/modules/chain/rounds/delegates.js index a2679e0ed20..1b0f1263fc3 100644 --- a/framework/src/modules/chain/rounds/delegates.js +++ b/framework/src/modules/chain/rounds/delegates.js @@ -217,7 +217,11 @@ class Delegates { cause, }; - await this.storage.entities.Account.insertFork(fork); + try { + await this.storage.entities.Account.insertFork(fork); + } catch (err) { + this.logger.warn(err, 'Failed to insert fork info'); + } this.channel.publish('chain:delegates:fork', fork); } diff --git a/framework/test/mocha/unit/modules/chain/submodules/delegates.js b/framework/test/mocha/unit/modules/chain/submodules/delegates.js index 0aebbad091a..9ac47add580 100644 --- a/framework/test/mocha/unit/modules/chain/submodules/delegates.js +++ b/framework/test/mocha/unit/modules/chain/submodules/delegates.js @@ -34,6 +34,7 @@ describe('delegates', () => { const mockLogger = { debug: sinonSandbox.stub(), info: sinonSandbox.stub(), + warn: sinonSandbox.stub(), error: sinonSandbox.stub(), }; const mockStorage = { @@ -112,6 +113,25 @@ describe('delegates', () => { fork, ); }); + + it('should not throw an error when the database fails', async () => { + const fork = { + delegatePublicKey: dummyBlock.generatorPublicKey, + blockTimestamp: dummyBlock.timestamp, + blockId: dummyBlock.id, + blockHeight: dummyBlock.height, + previousBlockId: dummyBlock.previousBlock, + cause, + }; + mockStorage.entities.Account.insertFork.rejects( + new Error('invalid DB state'), + ); + await delegatesModule.fork(dummyBlock, cause); + expect(mockChannel.publish).to.be.calledWithExactly( + 'chain:delegates:fork', + fork, + ); + }); }); describe('#generateDelegateList', () => {