diff --git a/elements/lisk-chain/src/chain.ts b/elements/lisk-chain/src/chain.ts index 17a01fe2b2a..52b5c8b3785 100644 --- a/elements/lisk-chain/src/chain.ts +++ b/elements/lisk-chain/src/chain.ts @@ -109,6 +109,7 @@ export class Chain { }; private _lastBlock: Block; + private readonly _genesisHeight: number; private readonly _networkIdentifier: Buffer; private readonly _blockRewardArgs: BlockRewardOptions; private readonly _accountSchema: Schema; @@ -170,6 +171,7 @@ export class Chain { genesisBlockTimestamp: genesisBlock.header.timestamp, interval: blockTime, }); + this._genesisHeight = genesisBlock.header.height; this._blockRewardArgs = { distance: rewardDistance, rewardOffset, @@ -187,6 +189,10 @@ export class Chain { }; } + public get genesisHeight(): number { + return this._genesisHeight; + } + public get lastBlock(): Block { return this._lastBlock; } diff --git a/framework-plugins/lisk-framework-forger-plugin/src/forger_plugin.ts b/framework-plugins/lisk-framework-forger-plugin/src/forger_plugin.ts index 7e271a169b6..07968d607e1 100644 --- a/framework-plugins/lisk-framework-forger-plugin/src/forger_plugin.ts +++ b/framework-plugins/lisk-framework-forger-plugin/src/forger_plugin.ts @@ -60,6 +60,7 @@ interface ForgerPayloadInfo { } interface NodeInfo { + genesisHeight: number; genesisConfig: GenesisConfig; } @@ -187,20 +188,22 @@ export class ForgerPlugin extends BasePlugin { header: { height: lastBlockHeight }, } = this.codec.decodeBlock(await this._channel.invoke('app:getLastBlock')); const { syncUptoHeight } = await getForgerSyncInfo(this._forgerPluginDB); + const { genesisHeight } = await this._channel.invoke('app:getNodeInfo'); + const forgerPluginSyncedHeight = syncUptoHeight === 0 ? genesisHeight : syncUptoHeight; - if (syncUptoHeight === lastBlockHeight) { + if (forgerPluginSyncedHeight === lastBlockHeight) { // No need to sync return; } let needleHeight: number; - if (syncUptoHeight > lastBlockHeight) { + if (forgerPluginSyncedHeight > lastBlockHeight) { // Clear all forging information we have and sync again await this._forgerPluginDB.clear(); - needleHeight = 1; + needleHeight = genesisHeight + 1; } else { - needleHeight = syncUptoHeight + 1; + needleHeight = forgerPluginSyncedHeight + 1; } // Sync in batch of 1000 blocks diff --git a/framework-plugins/lisk-framework-http-api-plugin/test/functional/node.spec.ts b/framework-plugins/lisk-framework-http-api-plugin/test/functional/node.spec.ts index 3fe3f135d8c..64e75efebc4 100644 --- a/framework-plugins/lisk-framework-http-api-plugin/test/functional/node.spec.ts +++ b/framework-plugins/lisk-framework-http-api-plugin/test/functional/node.spec.ts @@ -47,6 +47,7 @@ describe('Node', () => { const nodeStatusAndConstantFixture = { version: appInstance._node._options.version, networkVersion: appInstance._node._options.networkVersion, + genesisHeight: appInstance._node._chain.genesisHeight, networkIdentifier: appInstance._node.networkIdentifier.toString('hex'), lastBlockID: appInstance._node._chain.lastBlock.header.id.toString('hex'), height: appInstance._node._chain.lastBlock.header.height, diff --git a/framework/src/node/node.ts b/framework/src/node/node.ts index 8a52bc20e14..085431e6eb5 100644 --- a/framework/src/node/node.ts +++ b/framework/src/node/node.ts @@ -503,6 +503,7 @@ export class Node { networkIdentifier: this._networkIdentifier.toString('hex'), lastBlockID: this._chain.lastBlock.header.id.toString('hex'), height: this._chain.lastBlock.header.height, + genesisHeight: this._chain.genesisHeight, finalizedHeight: this._bft.finalityManager.finalizedHeight, syncing: this._synchronizer.isActive, unconfirmedTransactions: this._transactionPool.getAll().length,