From ac974a180d56e58501aa502abac24cd5b13affa1 Mon Sep 17 00:00:00 2001 From: Nicolas Gotchac Date: Wed, 14 Nov 2018 13:05:49 +0100 Subject: [PATCH] Use block header for building finality (#9914) --- ethcore/src/client/client.rs | 2 +- ethcore/src/engines/authority_round/mod.rs | 12 +++++++----- ethcore/src/engines/mod.rs | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 348911424..ff09f7c72 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -481,7 +481,7 @@ impl Importer { let mut batch = DBTransaction::new(); - let ancestry_actions = self.engine.ancestry_actions(&block, &mut chain.ancestry_with_metadata_iter(*parent)); + let ancestry_actions = self.engine.ancestry_actions(&header, &mut chain.ancestry_with_metadata_iter(*parent)); let receipts = block.receipts; let traces = block.traces.drain(); diff --git a/ethcore/src/engines/authority_round/mod.rs b/ethcore/src/engines/authority_round/mod.rs index c6195d0b2..1a54ccec1 100644 --- a/ethcore/src/engines/authority_round/mod.rs +++ b/ethcore/src/engines/authority_round/mod.rs @@ -798,6 +798,7 @@ impl AuthorityRound { } }; + let epoch_transition_hash = epoch_manager.epoch_transition_hash; let ancestry_iter = ancestry.map(|header| { let mut signers = vec![*header.author()]; signers.extend(parent_empty_steps_signers.drain(..)); @@ -815,10 +816,11 @@ impl AuthorityRound { None } }) - .while_some(); + .while_some() + .take_while(|&(h, _)| h != epoch_transition_hash); - if let Err(_) = epoch_manager.finality_checker.build_ancestry_subchain(ancestry_iter) { - debug!(target: "engine", "inconsistent validator set within epoch"); + if let Err(e) = epoch_manager.finality_checker.build_ancestry_subchain(ancestry_iter) { + debug!(target: "engine", "inconsistent validator set within epoch: {:?}", e); return Vec::new(); } } @@ -1448,9 +1450,9 @@ impl Engine for AuthorityRound { super::total_difficulty_fork_choice(new, current) } - fn ancestry_actions(&self, block: &ExecutedBlock, ancestry: &mut Iterator) -> Vec { + fn ancestry_actions(&self, header: &Header, ancestry: &mut Iterator) -> Vec { let finalized = self.build_finality( - block.header(), + header, &mut ancestry.take_while(|e| !e.is_finalized).map(|e| e.header), ); diff --git a/ethcore/src/engines/mod.rs b/ethcore/src/engines/mod.rs index 9bf7fa92b..39f3ac204 100644 --- a/ethcore/src/engines/mod.rs +++ b/ethcore/src/engines/mod.rs @@ -429,7 +429,7 @@ pub trait Engine: Sync + Send { /// Gather all ancestry actions. Called at the last stage when a block is committed. The Engine must guarantee that /// the ancestry exists. - fn ancestry_actions(&self, _block: &M::LiveBlock, _ancestry: &mut Iterator) -> Vec { + fn ancestry_actions(&self, _header: &M::Header, _ancestry: &mut Iterator) -> Vec { Vec::new() }