-
Notifications
You must be signed in to change notification settings - Fork 51
Fix the condition to check whether the new block could change the best block #1811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Tendermint consensus, only the child of the parent block could be the best block.
result, | ||
}) => { | ||
let allowed_height = if inner.step.is_commit() { | ||
inner.height + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.
core/src/consensus/mod.rs
Outdated
@@ -266,7 +266,10 @@ pub trait ConsensusEngine: Sync + Send { | |||
header.hash() | |||
} | |||
|
|||
fn can_change_canon_chain(&self, _header: &HeaderView) -> bool { | |||
/// In PoW consensus, the higher scored block became the best block. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
became -> becomes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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.