@liskhq/lisk-bft
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -37,5 +37,5 @@ /// <reference types="node" /> | ||
isBFTProtocolCompliant(blockHeader: BlockHeader, stateStore: StateStore): Promise<boolean>; | ||
getMaxHeightPrevoted(): Promise<number>; | ||
getMaxHeightPrevoted(lastMaxHeightPrevoted: number): Promise<number>; | ||
get finalizedHeight(): number; | ||
private _initFinalityManager; | ||
} |
@@ -107,4 +107,4 @@ "use strict"; | ||
} | ||
async getMaxHeightPrevoted() { | ||
return this.finalityManager.getMaxHeightPrevoted(); | ||
async getMaxHeightPrevoted(lastMaxHeightPrevoted) { | ||
return this.finalityManager.getMaxHeightPrevoted(lastMaxHeightPrevoted); | ||
} | ||
@@ -122,2 +122,3 @@ get finalizedHeight() { | ||
finalizedHeight, | ||
genesisHeight: this.constants.genesisHeight, | ||
threshold: this.constants.threshold, | ||
@@ -124,0 +125,0 @@ }); |
@@ -79,4 +79,6 @@ /// <reference types="node" /> | ||
private readonly _chain; | ||
constructor({ chain, finalizedHeight, threshold, }: { | ||
private readonly _genesisHeight; | ||
constructor({ chain, genesisHeight, finalizedHeight, threshold, }: { | ||
readonly chain: Chain; | ||
readonly genesisHeight: number; | ||
readonly finalizedHeight: number; | ||
@@ -89,3 +91,3 @@ readonly threshold: number; | ||
verifyBlockHeaders(blockHeader: BlockHeader, stateStore: StateStore): Promise<boolean>; | ||
getMaxHeightPrevoted(): Promise<number>; | ||
getMaxHeightPrevoted(lastMaxHeightPrevoted?: number): Promise<number>; | ||
private _calculateMaxHeightPrevoted; | ||
@@ -92,0 +94,0 @@ private _getMinValidHeightToPreCommit; |
@@ -71,6 +71,7 @@ "use strict"; | ||
class FinalityManager extends events_1.EventEmitter { | ||
constructor({ chain, finalizedHeight, threshold, }) { | ||
constructor({ chain, genesisHeight, finalizedHeight, threshold, }) { | ||
super(); | ||
assert(threshold > 0, 'Must provide a positive threshold'); | ||
this._chain = chain; | ||
this._genesisHeight = genesisHeight; | ||
this.preVoteThreshold = threshold; | ||
@@ -181,3 +182,6 @@ this.preCommitThreshold = threshold; | ||
const { ledger } = await this._getVotingLedger(stateStore); | ||
const chainMaxHeightPrevoted = this._calculateMaxHeightPrevoted(ledger); | ||
const lastMaxHeightPrevoted = bftBlockHeaders.length > 0 && bftBlockHeaders[0].asset.maxHeightPrevoted | ||
? bftBlockHeaders[0].asset.maxHeightPrevoted | ||
: this._genesisHeight; | ||
const chainMaxHeightPrevoted = this._calculateMaxHeightPrevoted(ledger, lastMaxHeightPrevoted); | ||
if (bftBlockHeaders.length >= this.processingThreshold && | ||
@@ -196,8 +200,8 @@ blockHeader.asset.maxHeightPrevoted !== chainMaxHeightPrevoted) { | ||
} | ||
async getMaxHeightPrevoted() { | ||
async getMaxHeightPrevoted(lastMaxHeightPrevoted) { | ||
const bftState = await this._chain.dataAccess.getConsensusState(exports.CONSENSUS_STATE_VALIDATOR_LEDGER_KEY); | ||
const { ledger } = this._decodeVotingLedger(bftState); | ||
return this._calculateMaxHeightPrevoted(ledger); | ||
return this._calculateMaxHeightPrevoted(ledger, lastMaxHeightPrevoted !== null && lastMaxHeightPrevoted !== void 0 ? lastMaxHeightPrevoted : this._genesisHeight); | ||
} | ||
_calculateMaxHeightPrevoted(ledger) { | ||
_calculateMaxHeightPrevoted(ledger, lastMaxHeightPrevoted) { | ||
debug('updatePreVotedAndFinalizedHeight invoked'); | ||
@@ -207,3 +211,3 @@ const maxHeightPreVoted = Object.keys(ledger) | ||
.find(key => ledger[key].prevotes >= this.preVoteThreshold); | ||
return maxHeightPreVoted ? parseInt(maxHeightPreVoted, 10) : this.finalizedHeight; | ||
return maxHeightPreVoted ? parseInt(maxHeightPreVoted, 10) : lastMaxHeightPrevoted; | ||
} | ||
@@ -210,0 +214,0 @@ _getMinValidHeightToPreCommit(header, bftApplicableBlocks) { |
{ | ||
"name": "@liskhq/lisk-bft", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Byzantine fault tolerance implementation according to the Lisk protocol", | ||
@@ -39,3 +39,3 @@ "author": "Lisk Foundation <admin@lisk.io>, lightcurve GmbH <admin@lightcurve.io>", | ||
"dependencies": { | ||
"@liskhq/lisk-chain": "^0.3.1", | ||
"@liskhq/lisk-chain": "^0.3.2", | ||
"@liskhq/lisk-codec": "^0.2.0", | ||
@@ -42,0 +42,0 @@ "@liskhq/lisk-cryptography": "^3.1.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53422
704
Updated@liskhq/lisk-chain@^0.3.2