@liskhq/lisk-bft
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -10,2 +10,3 @@ "use strict"; | ||
const types_1 = require("./types"); | ||
const constant_1 = require("./constant"); | ||
exports.EVENT_BFT_BLOCK_FINALIZED = 'EVENT_BFT_BLOCK_FINALIZED'; | ||
@@ -85,14 +86,19 @@ exports.BFTFinalizedHeightCodecSchema = { | ||
assert(blockHeader, 'No block was provided to be verified'); | ||
const roundsThreshold = 3; | ||
const validators = await lisk_chain_1.getValidators(stateStore); | ||
const numberOfVotingValidators = validators.filter(validator => validator.isConsensusParticipant).length; | ||
const heightThreshold = numberOfVotingValidators * roundsThreshold; | ||
const heightThreshold = numberOfVotingValidators * constant_1.BFT_ROUND_THRESHOLD; | ||
if (blockHeader.asset.maxHeightPreviouslyForged === 0) { | ||
return true; | ||
} | ||
if (blockHeader.height <= blockHeader.asset.maxHeightPreviouslyForged) { | ||
return false; | ||
} | ||
if (blockHeader.height - blockHeader.asset.maxHeightPreviouslyForged > heightThreshold) { | ||
return true; | ||
} | ||
const maxHeightPreviouslyForgedBlock = stateStore.chain.lastBlockHeaders.find(bftHeader => bftHeader.height === blockHeader.asset.maxHeightPreviouslyForged); | ||
if (!maxHeightPreviouslyForgedBlock || | ||
blockHeader.asset.maxHeightPreviouslyForged >= blockHeader.height || | ||
(blockHeader.height - blockHeader.asset.maxHeightPreviouslyForged <= heightThreshold && | ||
!blockHeader.generatorPublicKey.equals(maxHeightPreviouslyForgedBlock.generatorPublicKey))) { | ||
if (!maxHeightPreviouslyForgedBlock) { | ||
throw new Error(`Block at height ${blockHeader.asset.maxHeightPreviouslyForged} must be in the lastBlockHeaders.`); | ||
} | ||
if (!blockHeader.generatorPublicKey.equals(maxHeightPreviouslyForgedBlock.generatorPublicKey)) { | ||
return false; | ||
@@ -99,0 +105,0 @@ } |
{ | ||
"name": "@liskhq/lisk-bft", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Byzantine fault tolerance implementation according to the Lisk protocol", | ||
@@ -72,3 +72,4 @@ "author": "Lisk Foundation <admin@lisk.io>, lightcurve GmbH <admin@lightcurve.io>", | ||
"typescript": "3.8.3" | ||
} | ||
}, | ||
"gitHead": "4db44a150d38c5cf1e428f78922073b3d314b29f" | ||
} |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
61856
24
669
0