Closed janhack closed 1 year ago
In this case, it should not make a difference, but generally it would be good to avoid floor and ceil on floating point numbers and instead only use integer arithmetic. Concretely, Math.floor((scenario.config.activeValidators * 2) / 3) + 1; could be replaced with integer division.
As far as the research by @AndreasKendziorra , the division is deterministic although there will be an rounding error when using floating number
I don't understand the cases expect(bftInfo?.prevoteWeight).toBeUndefined(); and expect(bftInfo?.precommitWeight).toBeUndefined();. I am not sure why why expect the weight to be undefined. Isn't it the case that the bftInfo array does not contain an object at that height in the first place.
This is because blockBFTInfo
will be removed with batch size * 3 while inserting a block. although it exists in the fixture, the below min height, the value should be undefined
areHeadersContradicting: These tests only cover the easy cases, but not the cases depending on maxHeightPrevoted and maxHeightGenerated. I guess we assume here those tests are covered by the function areDistinctHeadersContradicting.
yes. those should be covered in areDistinctHeadersContradicting
.
'should store BFT parameters with height maxHeightPrevoted + 1 if blockBFTInfo does not exist': The BFT parameters should be stored at genesisHeight + 1 in this case (note that only after processing the genesis block, blockBFTInfo should be empty and then we actually have maxHeightPrevoted == genesisHeight).
I think in the BFT, it is not considering genesis height. the logic is if the bft info is empty, store maxHeightPrevoted + 1 which only happens in genesis block case?
I think in the BFT, it is not considering genesis height. the logic is if the bft info is empty, store maxHeightPrevoted + 1 which only happens in genesis block case?
No, in this case the genesis height is used, see the function getCurrentHeight
in https://github.com/LiskHQ/lips/blob/main/proposals/lip-0058.md#getcurrentheight
No, in this case the genesis height is used, see the function getCurrentHeight in https://github.com/LiskHQ/lips/blob/main/proposals/lip-0058.md#getcurrentheight
I think we missed to update this, ill try to address it in different PR
I was double checking and currently we store genesis height as maxHeightPrevoted in https://github.com/LiskHQ/lisk-sdk/blob/development/framework/src/engine/bft/module.ts#L49-L60
Therefore, when we use in the empty case https://github.com/LiskHQ/lisk-sdk/blob/development/framework/src/engine/bft/method.ts#L222, the maxHeightPrevoted is genesis height
bft_processing.spec.ts
floor
andceil
on floating point numbers and instead only use integer arithmetic. Concretely,Math.floor((scenario.config.activeValidators * 2) / 3) + 1;
could be replaced with integer division.expect(bftInfo?.prevoteWeight).toBeUndefined();
andexpect(bftInfo?.precommitWeight).toBeUndefined();
. I am not sure why why expect the weight to be undefined. Isn't it the case that thebftInfo
array does not contain an object at that height in the first place.bft_votes.spec.ts
maxHeightPrevoted == 103
, but the block at height 149 has prevote weight 68. This can happen, of course, after callingupdatePrevotesPrecommits
and before then callingupdateMaxHeightPrevoted
. But in the BFT protocol no other function is called in between those two functions. Probably that does not create an issue with the test, but in principle it could have undesired side-effects and it would be best to test with a consistent state of BFT votes.maxHeightGenerated == 0
would not be added to the chain as it contradicts the block at height 149 by the same generator. Maybe this is still fine for the tests, but it could be better to have a valid block.prevoteThreshold: BigInt(69)
, i.e., exactly just increment the minimal amount to get a different result, instead of choosing an extreme.aggregateCommit.height == bftVotes.maxHeightCertified
. This validation is not defined in LIP 58, but part of the aggregate commit validation.method.spec.ts
areHeadersContradicting
: These tests only cover the easy cases, but not the cases depending onmaxHeightPrevoted
andmaxHeightGenerated
. I guess we assume here those tests are covered by the functionareDistinctHeadersContradicting
.isHeaderContradictingChain
: The initializationmaxHeightPrevoted: 10,
does not make sense. This probably does not affect the test.29
and30
.19
the function returns20
.genesisHeight + 1
in this case (note that only after processing the genesis block, blockBFTInfo should be empty and then we actually havemaxHeightPrevoted == genesisHeight
).utils.spec.ts
maxHeightGenerated
ormaxHeightPrevoted
for the block headers (I assume they are then just some random value). I think it would be better to also define those, to be sure that the headers are not considered contradicting for other reasons. Currently, it is also difficult to see that all cases in the function are covered.General comment
getGeneratorAtTimestamp
andgetSlotNumber
. They are maybe not directly part of the BFT protocol, but are defined in LIP 0058.