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

Commit

Permalink
Merge pull request #6596 from LiskHQ/6582-fix_forger_plugin_with_testnet
Browse files Browse the repository at this point in the history
Update forger plugin to consider genesis height - #6582
  • Loading branch information
shuse2 authored Jul 22, 2021
2 parents cacfc87 + 0b23fc2 commit 2ec6fd5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
6 changes: 6 additions & 0 deletions elements/lisk-chain/src/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -170,6 +171,7 @@ export class Chain {
genesisBlockTimestamp: genesisBlock.header.timestamp,
interval: blockTime,
});
this._genesisHeight = genesisBlock.header.height;
this._blockRewardArgs = {
distance: rewardDistance,
rewardOffset,
Expand All @@ -187,6 +189,10 @@ export class Chain {
};
}

public get genesisHeight(): number {
return this._genesisHeight;
}

public get lastBlock(): Block {
return this._lastBlock;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ interface ForgerPayloadInfo {
}

interface NodeInfo {
genesisHeight: number;
genesisConfig: GenesisConfig;
}

Expand Down Expand Up @@ -187,20 +188,22 @@ export class ForgerPlugin extends BasePlugin {
header: { height: lastBlockHeight },
} = this.codec.decodeBlock(await this._channel.invoke<string>('app:getLastBlock'));
const { syncUptoHeight } = await getForgerSyncInfo(this._forgerPluginDB);
const { genesisHeight } = await this._channel.invoke<NodeInfo>('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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions framework/src/node/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2ec6fd5

Please sign in to comment.