From aea9020f8347a1b8339b59653e0832eb58d727b4 Mon Sep 17 00:00:00 2001 From: Ishan Date: Tue, 12 Mar 2024 18:53:30 +0530 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Unable=20CCU=20sending=20w?= =?UTF-8?q?hen=20receiving=20chain=20is=20syncing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/ccu_handler.ts | 4 ++++ .../test/unit/ccu_handler.spec.ts | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/framework-plugins/lisk-framework-chain-connector-plugin/src/ccu_handler.ts b/framework-plugins/lisk-framework-chain-connector-plugin/src/ccu_handler.ts index 661d1b818e..4c036c2bc6 100644 --- a/framework-plugins/lisk-framework-chain-connector-plugin/src/ccu_handler.ts +++ b/framework-plugins/lisk-framework-chain-connector-plugin/src/ccu_handler.ts @@ -277,6 +277,10 @@ export class CCUHandler { if (!this._db.privateKey) { throw new Error('There is no key enabled to submit CCU.'); } + const { syncing } = await this._receivingChainAPIClient.getNodeInfo(); + if (syncing) { + throw new Error('Receiving node is syncing.'); + } const relayerPublicKey = cryptography.ed.getPublicKeyFromPrivateKey(this._db.privateKey); const targetCommand = this._isReceivingChainMainchain ? COMMAND_NAME_SUBMIT_MAINCHAIN_CCU diff --git a/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/ccu_handler.spec.ts b/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/ccu_handler.spec.ts index 53ca01ff78..d116ecae8e 100644 --- a/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/ccu_handler.spec.ts +++ b/framework-plugins/lisk-framework-chain-connector-plugin/test/unit/ccu_handler.spec.ts @@ -813,6 +813,13 @@ describe('CCUHandler', () => { ); }); + it('should throw error when receiving chain is syncing', async () => { + receivingChainAPIClientMock.getNodeInfo.mockResolvedValue({ syncing: true }); + await expect(ccuHandler['submitCCU'](ccuParams, 'txID')).rejects.toThrow( + 'Receiving node is syncing.', + ); + }); + it('should return undefined when the tx id is equal to last sent CCU', async () => { ccuTx.sign(config.receivingChainID as Buffer, Buffer.from(privateKey, 'hex')); const result = await ccuHandler['submitCCU'](ccuParams, ccuTx.id.toString('hex'));