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

Commit

Permalink
Merge branch 'hotfix/5.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuGowda committed Jul 22, 2021
2 parents 2456c66 + 2ec6fd5 commit 89f6c74
Show file tree
Hide file tree
Showing 22 changed files with 98 additions and 51 deletions.
4 changes: 2 additions & 2 deletions commander/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lisk-commander",
"version": "5.1.3",
"version": "5.1.4-alpha.0",
"description": "A command line interface for Lisk",
"author": "Lisk Foundation <[email protected]>, lightcurve GmbH <[email protected]>",
"license": "Apache-2.0",
Expand Down Expand Up @@ -114,7 +114,7 @@
"cli-table3": "0.6.0",
"fs-extra": "9.1.0",
"inquirer": "8.0.0",
"lisk-framework": "^0.8.2",
"lisk-framework": "^0.8.3-alpha.0",
"listr": "0.14.3",
"progress": "2.0.3",
"semver": "7.3.5",
Expand Down
2 changes: 1 addition & 1 deletion elements/lisk-bft/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@liskhq/lisk-bft",
"version": "0.3.1",
"version": "0.3.2-alpha.0",
"description": "Byzantine fault tolerance implementation according to the Lisk protocol",
"author": "Lisk Foundation <[email protected]>, lightcurve GmbH <[email protected]>",
"license": "Apache-2.0",
Expand Down
5 changes: 3 additions & 2 deletions elements/lisk-bft/src/bft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ export class BFT extends EventEmitter {
return true;
}

public async getMaxHeightPrevoted(): Promise<number> {
return this.finalityManager.getMaxHeightPrevoted();
public async getMaxHeightPrevoted(lastMaxHeightPrevoted: number): Promise<number> {
return this.finalityManager.getMaxHeightPrevoted(lastMaxHeightPrevoted);
}

public get finalizedHeight(): number {
Expand All @@ -227,6 +227,7 @@ export class BFT extends EventEmitter {
const finalityManager = new FinalityManager({
chain: this._chain,
finalizedHeight,
genesisHeight: this.constants.genesisHeight,
threshold: this.constants.threshold,
});

Expand Down
19 changes: 14 additions & 5 deletions elements/lisk-bft/src/finality_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,24 @@ export class FinalityManager extends EventEmitter {

public finalizedHeight: number;
private readonly _chain: Chain;
private readonly _genesisHeight: number;

public constructor({
chain,
genesisHeight,
finalizedHeight,
threshold,
}: {
readonly chain: Chain;
readonly genesisHeight: number;
readonly finalizedHeight: number;
readonly threshold: number;
}) {
super();
assert(threshold > 0, 'Must provide a positive threshold');

this._chain = chain;
this._genesisHeight = genesisHeight;

// Threshold to consider a block pre-voted
this.preVoteThreshold = threshold;
Expand Down Expand Up @@ -339,7 +343,12 @@ export class FinalityManager extends EventEmitter {

const bftBlockHeaders = stateStore.chain.lastBlockHeaders;
const { ledger } = await this._getVotingLedger(stateStore);
const chainMaxHeightPrevoted = this._calculateMaxHeightPrevoted(ledger);
// lastBlockHeaders are sorted by height desc
const lastMaxHeightPrevoted =
bftBlockHeaders.length > 0 && bftBlockHeaders[0].asset.maxHeightPrevoted
? bftBlockHeaders[0].asset.maxHeightPrevoted
: this._genesisHeight;
const chainMaxHeightPrevoted = this._calculateMaxHeightPrevoted(ledger, lastMaxHeightPrevoted);
// We need minimum processingThreshold to decide
// If maxHeightPrevoted is correct
if (
Expand Down Expand Up @@ -367,22 +376,22 @@ export class FinalityManager extends EventEmitter {
return true;
}

public async getMaxHeightPrevoted(): Promise<number> {
public async getMaxHeightPrevoted(lastMaxHeightPrevoted?: number): Promise<number> {
const bftState = await this._chain.dataAccess.getConsensusState(
CONSENSUS_STATE_VALIDATOR_LEDGER_KEY,
);
const { ledger } = this._decodeVotingLedger(bftState);
return this._calculateMaxHeightPrevoted(ledger);
return this._calculateMaxHeightPrevoted(ledger, lastMaxHeightPrevoted ?? this._genesisHeight);
}

private _calculateMaxHeightPrevoted(ledger: LedgerMap): number {
private _calculateMaxHeightPrevoted(ledger: LedgerMap, lastMaxHeightPrevoted: number): number {
debug('updatePreVotedAndFinalizedHeight invoked');

const maxHeightPreVoted = Object.keys(ledger)
.reverse()
.find(key => ledger[key].prevotes >= this.preVoteThreshold);

return maxHeightPreVoted ? parseInt(maxHeightPreVoted, 10) : this.finalizedHeight;
return maxHeightPreVoted ? parseInt(maxHeightPreVoted, 10) : lastMaxHeightPrevoted;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ describe('FinalityManager', () => {

finalityManager = new FinalityManager({
chain: chainStub,
genesisHeight: 0,
finalizedHeight: scenario.config.finalizedHeight,
threshold: Math.floor((scenario.config.activeDelegates * 2) / 3) + 1,
});
Expand Down Expand Up @@ -168,7 +169,7 @@ describe('FinalityManager', () => {
CONSENSUS_STATE_VALIDATOR_LEDGER_KEY,
);
const { ledger } = finalityManager['_decodeVotingLedger'](updatedBftLedgers);
const preVoted = finalityManager['_calculateMaxHeightPrevoted'](ledger);
const preVoted = finalityManager['_calculateMaxHeightPrevoted'](ledger, 0);
expect(preVoted).toEqual(testCase.output.preVotedConfirmedHeight);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ describe('FinalityManager', () => {

const finalityManager = new FinalityManager({
chain: chainStub,
genesisHeight: 0,
finalizedHeight: invalidBlockHeaderSpec.config.finalizedHeight,
threshold: invalidBlockHeaderSpec.config.activeDelegates,
});
Expand Down
40 changes: 30 additions & 10 deletions elements/lisk-bft/test/unit/finality_manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ describe('finality_manager', () => {
finalityManager = new FinalityManager({
chain: chainStub,
finalizedHeight,
genesisHeight: 0,
threshold,
});
});
Expand All @@ -94,20 +95,39 @@ describe('finality_manager', () => {
new FinalityManager({
chain: chainStub,
finalizedHeight,
genesisHeight: 0,
threshold,
}),
).toThrow('Invalid number of validators for BFT property');
});

it('should initialize maxHeightPrevoted to the finalizedHeight', async () => {
const nonZeroFinalizedHeight = 10000000;
finalityManager = new FinalityManager({
chain: chainStub,
finalizedHeight: nonZeroFinalizedHeight,
threshold,
});
await expect(finalityManager.getMaxHeightPrevoted()).resolves.toEqual(
nonZeroFinalizedHeight,
it('should initialize maxHeightPrevoted to the the last maxHeightPrevoted', async () => {
const validatorLedger = {
validators: [],
ledger: [
{
height: 610,
prevotes: 67,
precommits: 0,
},
{
height: 611,
prevotes: 67,
precommits: 0,
},
{
height: 612,
prevotes: 66,
precommits: 0,
},
],
};
jest
.spyOn(chainStub.dataAccess, 'getConsensusState')
.mockResolvedValue(codec.encode(BFTVotingLedgerSchema, validatorLedger));
const lastMaxHeightPrevoted = 30;
await expect(finalityManager.getMaxHeightPrevoted(lastMaxHeightPrevoted)).resolves.toEqual(
lastMaxHeightPrevoted,
);
});
});
Expand All @@ -124,7 +144,7 @@ describe('finality_manager', () => {
}) as unknown) as StateStore;

const header = createFakeBlockHeader({
asset: { maxHeightPrevoted: 10 },
asset: { maxHeightPrevoted: 12 },
});

expect.assertions(1);
Expand Down
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
4 changes: 2 additions & 2 deletions elements/lisk-elements/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lisk-elements",
"version": "5.1.2",
"version": "5.1.3-alpha.0",
"description": "Elements for building blockchain applications in the Lisk network",
"author": "Lisk Foundation <[email protected]>, lightcurve GmbH <[email protected]>",
"license": "Apache-2.0",
Expand Down Expand Up @@ -37,7 +37,7 @@
},
"dependencies": {
"@liskhq/lisk-api-client": "^5.1.2",
"@liskhq/lisk-bft": "^0.3.1",
"@liskhq/lisk-bft": "^0.3.2-alpha.0",
"@liskhq/lisk-chain": "^0.3.1",
"@liskhq/lisk-codec": "^0.2.0",
"@liskhq/lisk-cryptography": "^3.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@liskhq/lisk-framework-dashboard-plugin",
"version": "0.1.2",
"version": "0.1.3-alpha.0",
"description": "A plugin for interacting with a newly developed blockchain application.",
"author": "Lisk Foundation <[email protected]>, lightcurve GmbH <[email protected]>",
"license": "Apache-2.0",
Expand Down Expand Up @@ -45,7 +45,7 @@
"@liskhq/lisk-utils": "^0.2.0",
"express": "4.17.1",
"json-format-highlight": "1.0.4",
"lisk-framework": "^0.8.2",
"lisk-framework": "^0.8.3-alpha.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0",
Expand Down
4 changes: 2 additions & 2 deletions framework-plugins/lisk-framework-faucet-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@liskhq/lisk-framework-faucet-plugin",
"version": "0.1.2",
"version": "0.1.3-alpha.0",
"description": "A plugin for distributing testnet tokens from a newly developed blockchain application.",
"author": "Lisk Foundation <[email protected]>, lightcurve GmbH <[email protected]>",
"license": "Apache-2.0",
Expand Down Expand Up @@ -49,7 +49,7 @@
"@liskhq/lisk-validator": "^0.6.0",
"axios": "0.21.1",
"express": "4.17.1",
"lisk-framework": "^0.8.2",
"lisk-framework": "^0.8.3-alpha.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0"
Expand Down
4 changes: 2 additions & 2 deletions framework-plugins/lisk-framework-forger-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@liskhq/lisk-framework-forger-plugin",
"version": "0.2.2",
"version": "0.2.3-alpha.0",
"description": "A plugin for lisk-framework that monitors configured delegates forging activity and voters information.",
"author": "Lisk Foundation <[email protected]>, lightcurve GmbH <[email protected]>",
"license": "Apache-2.0",
Expand Down Expand Up @@ -52,7 +52,7 @@
"express-rate-limit": "5.1.3",
"fs-extra": "9.1.0",
"ip": "1.1.5",
"lisk-framework": "^0.8.2"
"lisk-framework": "^0.8.3-alpha.0"
},
"devDependencies": {
"@liskhq/lisk-api-client": "^5.1.2",
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
4 changes: 2 additions & 2 deletions framework-plugins/lisk-framework-http-api-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@liskhq/lisk-framework-http-api-plugin",
"version": "0.2.2",
"version": "0.2.3-alpha.0",
"description": "A plugin for lisk-framework that provides basic HTTP API endpoints to get running node information.",
"author": "Lisk Foundation <[email protected]>, lightcurve GmbH <[email protected]>",
"license": "Apache-2.0",
Expand Down Expand Up @@ -44,7 +44,7 @@
"express": "4.17.1",
"express-rate-limit": "5.1.3",
"ip": "1.1.5",
"lisk-framework": "^0.8.2"
"lisk-framework": "^0.8.3-alpha.0"
},
"devDependencies": {
"@liskhq/lisk-cryptography": "^3.1.0",
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
4 changes: 2 additions & 2 deletions framework-plugins/lisk-framework-monitor-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@liskhq/lisk-framework-monitor-plugin",
"version": "0.2.2",
"version": "0.2.3-alpha.0",
"description": "A plugin for lisk-framework that provides network statistics of the running node",
"author": "Lisk Foundation <[email protected]>, lightcurve GmbH <[email protected]>",
"license": "Apache-2.0",
Expand Down Expand Up @@ -46,7 +46,7 @@
"express": "4.17.1",
"express-rate-limit": "5.1.3",
"ip": "1.1.5",
"lisk-framework": "^0.8.2"
"lisk-framework": "^0.8.3-alpha.0"
},
"devDependencies": {
"@types/cors": "2.8.6",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@liskhq/lisk-framework-report-misbehavior-plugin",
"version": "0.2.2",
"version": "0.2.3-alpha.0",
"description": "A plugin for lisk-framework that provides automatic detection of delegate misbehavior and sends a reportDelegateMisbehaviorTransaction to the running node",
"author": "Lisk Foundation <[email protected]>, lightcurve GmbH <[email protected]>",
"license": "Apache-2.0",
Expand Down Expand Up @@ -38,7 +38,7 @@
"prepublishOnly": "npm run lint && npm test && npm run build && npm run build:check"
},
"dependencies": {
"@liskhq/lisk-bft": "^0.3.1",
"@liskhq/lisk-bft": "^0.3.2-alpha.0",
"@liskhq/lisk-chain": "^0.3.1",
"@liskhq/lisk-codec": "^0.2.0",
"@liskhq/lisk-cryptography": "^3.1.0",
Expand All @@ -48,7 +48,7 @@
"@liskhq/lisk-validator": "^0.6.0",
"debug": "4.3.1",
"fs-extra": "9.1.0",
"lisk-framework": "^0.8.2"
"lisk-framework": "^0.8.3-alpha.0"
},
"devDependencies": {
"@types/cors": "2.8.6",
Expand Down
Loading

0 comments on commit 89f6c74

Please sign in to comment.