Skip to content

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

Merged
merged 2 commits into from
Oct 11, 2019

Conversation

majecty
Copy link
Contributor

@majecty majecty commented Oct 10, 2019

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.

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
Copy link
Contributor Author

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.

@majecty majecty requested a review from ScarletBlue October 10, 2019 07:28
result,
}) => {
let allowed_height = if inner.step.is_commit() {
inner.height + 1
Copy link
Contributor Author

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.

@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

became -> becomes?

Copy link
Contributor Author

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.

@majecty majecty force-pushed the f/change-best-block branch from c8ef3dd to 91f30eb Compare October 10, 2019 08:54
…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.
@majecty majecty force-pushed the f/change-best-block branch from 91f30eb to e7d86fb Compare October 10, 2019 09:14
@majecty majecty requested a review from foriequal0 October 10, 2019 12:27
@majecty majecty changed the title [WIP] Fix the condition to check whether the new block could change the best block Fix the condition to check whether the new block could change the best block Oct 10, 2019
@majecty majecty merged commit 7c20fdd into CodeChain-io:master Oct 11, 2019
@majecty majecty deleted the f/change-best-block branch August 4, 2020 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants