Fix the condition to check whether the new block could change the best block#1811
Merged
majecty merged 2 commits intoCodeChain-io:masterfrom Oct 11, 2019
Merged
Conversation
majecty
commented
Oct 10, 2019
| header.number() >= allowed_height | ||
|
|
||
| fn can_change_canon_chain(&self, new_header: &HeaderView, prev_best_hash: H256) -> bool { | ||
| new_header.parent_hash() == prev_best_hash |
Author
There was a problem hiding this comment.
In Tendermint consensus, only the child of the parent block could be the best block.
majecty
commented
Oct 10, 2019
| result, | ||
| }) => { | ||
| let allowed_height = if inner.step.is_commit() { | ||
| inner.height + 1 |
Author
There was a problem hiding this comment.
This was the cause of a bug.
If a proposal is not imported in Commit state yet, the code should return inner.height instead of inner.height + 1.
ScarletBlue
suggested changes
Oct 10, 2019
core/src/consensus/mod.rs
Outdated
| } | ||
|
|
||
| fn can_change_canon_chain(&self, _header: &HeaderView) -> bool { | ||
| /// In PoW consensus, the higher scored block became the best block. |
Author
There was a problem hiding this comment.
You're right. I'll change it to becomes.
c8ef3dd to
91f30eb
Compare
…t block When a new block is imported in Tendermint consensus, CodeChain checks the conditions below to judge whether it is safe to change the best block: First, whether the score is higher than before. Second, whether the height of a new block is higher than the finalized block's height. This commit fixes the code that is calculating the finalized block's height erroneously.
91f30eb to
e7d86fb
Compare
foriequal0
approved these changes
Oct 11, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a new block is imported in Tendermint consensus, CodeChain checks the conditions below to judge whether it is safe to change the best block:
First, whether the score is higher than before.
Second, whether the height of a new block is higher than the finalized block's height.
This commit fixes the code that is calculating the finalized block's height erroneously.