From c79ecee094190dd70a57eb097aed0f17aab011f7 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 24 Aug 2017 16:29:31 +0200 Subject: [PATCH] only load ancestry from chain closure in engine --- ethcore/light/src/client/header_chain.rs | 4 ++-- ethcore/src/engines/authority_round/mod.rs | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ethcore/light/src/client/header_chain.rs b/ethcore/light/src/client/header_chain.rs index 1f97e281b..123eaf653 100644 --- a/ethcore/light/src/client/header_chain.rs +++ b/ethcore/light/src/client/header_chain.rs @@ -411,8 +411,8 @@ impl HeaderChain { self.live_epoch_proofs.write().insert(hash, transition); } - let raw = ::rlp::encode(&header); - transaction.put(self.col, &hash[..], &*raw); + let raw = header.encoded().into_inner(); + transaction.put_vec(self.col, &hash[..], raw); let (best_num, is_new_best) = { let cur_best = self.best_block.read(); diff --git a/ethcore/src/engines/authority_round/mod.rs b/ethcore/src/engines/authority_round/mod.rs index 33979e01c..44f3d801c 100644 --- a/ethcore/src/engines/authority_round/mod.rs +++ b/ethcore/src/engines/authority_round/mod.rs @@ -745,13 +745,18 @@ impl Engine for AuthorityRound { { if let Ok(finalized) = epoch_manager.finality_checker.push_hash(chain_head.hash(), *chain_head.author()) { let mut finalized = finalized.into_iter(); - while let Some(hash) = finalized.next() { - if let Some(pending) = transition_store(hash) { - let finality_proof = ::std::iter::once(hash) + while let Some(finalized_hash) = finalized.next() { + if let Some(pending) = transition_store(finalized_hash) { + let finality_proof = ::std::iter::once(finalized_hash) .chain(finalized) .chain(epoch_manager.finality_checker.unfinalized_hashes()) - .map(|hash| chain(hash) - .expect("these headers fetched before when constructing finality checker; qed")) + .map(|h| if h == chain_head.hash() { + // chain closure only stores ancestry, but the chain head is also + // unfinalized. + chain_head.clone() + } else { + chain(h).expect("these headers fetched before when constructing finality checker; qed") + }) .collect::>(); // this gives us the block number for `hash`, assuming it's ancestry.