Skip to content

Enable all grandchild of the best block to become a best proposal block #1813

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 1 commit into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions core/src/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,16 @@ impl BlockChain {
let new_header = new_block.header_view();
let parent_hash_of_new_block = new_header.parent_hash();
let parent_details_of_new_block = self.block_details(&parent_hash_of_new_block).expect("Invalid parent hash");
let prev_best_proposal_hash = self.best_proposal_block_hash();
let grandparent_hash_of_new_block = parent_details_of_new_block.parent;
let prev_best_hash = self.best_block_hash();

if parent_details_of_new_block.total_score + new_header.score() > self.best_proposal_block_detail().total_score
&& engine.can_change_canon_chain(&new_header, prev_best_hash, prev_best_proposal_hash)
&& engine.can_change_canon_chain(
new_header.hash(),
parent_hash_of_new_block,
grandparent_hash_of_new_block,
prev_best_hash,
)
{
cinfo!(
BLOCKCHAIN,
Expand Down
9 changes: 7 additions & 2 deletions core/src/blockchain/headerchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,16 @@ impl HeaderChain {
fn best_header_changed(&self, new_header: &HeaderView, engine: &dyn CodeChainEngine) -> BestHeaderChanged {
let parent_hash_of_new_header = new_header.parent_hash();
let parent_details_of_new_header = self.block_details(&parent_hash_of_new_header).expect("Invalid parent hash");
let prev_best_proposal_hash = self.best_proposal_header_hash();
let grandparent_hash_of_new_header = parent_details_of_new_header.parent;
let prev_best_hash = self.best_header_hash();
let is_new_best = parent_details_of_new_header.total_score + new_header.score()
> self.best_proposal_header_detail().total_score
&& engine.can_change_canon_chain(&new_header, prev_best_hash, prev_best_proposal_hash);
&& engine.can_change_canon_chain(
new_header.hash(),
parent_hash_of_new_header,
grandparent_hash_of_new_header,
prev_best_hash,
);

if is_new_best {
ctrace!(
Expand Down
5 changes: 3 additions & 2 deletions core/src/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,10 @@ pub trait ConsensusEngine: Sync + Send {
/// Only the descendant of the current best block could be the next best block in Tendermint consensus.
fn can_change_canon_chain(
&self,
_new_header: &HeaderView,
_new_block_hash: H256,
_parent_hash_of_new_header: H256,
_grandparent_hash_of_new_header: H256,
_previous_best_hash: H256,
_previous_best_proposal_hash: H256,
) -> bool {
true
}
Expand Down
7 changes: 4 additions & 3 deletions core/src/consensus/tendermint/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,12 @@ impl ConsensusEngine for Tendermint {

fn can_change_canon_chain(
&self,
new_header: &HeaderView,
_new_header_hash: H256,
parent_hash_of_new_header: H256,
grandparent_hash_of_new_header: H256,
prev_best_hash: H256,
prev_best_proposal_hash: H256,
) -> bool {
new_header.parent_hash() == prev_best_hash || new_header.parent_hash() == prev_best_proposal_hash
parent_hash_of_new_header == prev_best_hash || grandparent_hash_of_new_header == prev_best_hash
}

fn action_handlers(&self) -> &[Arc<dyn ActionHandler>] {
Expand Down