only load ancestry from chain closure in engine

This commit is contained in:
Robert Habermeier 2017-08-24 16:29:31 +02:00
parent b953f9b66a
commit c79ecee094
2 changed files with 12 additions and 7 deletions

View File

@ -411,8 +411,8 @@ impl HeaderChain {
self.live_epoch_proofs.write().insert(hash, transition); self.live_epoch_proofs.write().insert(hash, transition);
} }
let raw = ::rlp::encode(&header); let raw = header.encoded().into_inner();
transaction.put(self.col, &hash[..], &*raw); transaction.put_vec(self.col, &hash[..], raw);
let (best_num, is_new_best) = { let (best_num, is_new_best) = {
let cur_best = self.best_block.read(); let cur_best = self.best_block.read();

View File

@ -745,13 +745,18 @@ impl Engine for AuthorityRound {
{ {
if let Ok(finalized) = epoch_manager.finality_checker.push_hash(chain_head.hash(), *chain_head.author()) { if let Ok(finalized) = epoch_manager.finality_checker.push_hash(chain_head.hash(), *chain_head.author()) {
let mut finalized = finalized.into_iter(); let mut finalized = finalized.into_iter();
while let Some(hash) = finalized.next() { while let Some(finalized_hash) = finalized.next() {
if let Some(pending) = transition_store(hash) { if let Some(pending) = transition_store(finalized_hash) {
let finality_proof = ::std::iter::once(hash) let finality_proof = ::std::iter::once(finalized_hash)
.chain(finalized) .chain(finalized)
.chain(epoch_manager.finality_checker.unfinalized_hashes()) .chain(epoch_manager.finality_checker.unfinalized_hashes())
.map(|hash| chain(hash) .map(|h| if h == chain_head.hash() {
.expect("these headers fetched before when constructing finality checker; qed")) // 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::<Vec<Header>>(); .collect::<Vec<Header>>();
// this gives us the block number for `hash`, assuming it's ancestry. // this gives us the block number for `hash`, assuming it's ancestry.