Fix for missing header head during sync

Addresses a corner case of sync. If we're still in sync mode but
just caught up to the head, a block could be added through normal
gossip. So we can't short-circuit some of the header handling
even though during sync the header should have already been
validated and saved, because we can still get a block from gossip.
This commit is contained in:
Ignotus Peverell 2017-10-18 04:48:21 +00:00
parent 42ff6c2f6b
commit 406642a1f0
No known key found for this signature in database
GPG key ID: 99CD25F39F8F8211
3 changed files with 8 additions and 17 deletions

View file

@ -322,22 +322,9 @@ fn update_head(b: &Block, ctx: &mut BlockContext) -> Result<Option<Tip>, Error>
// update the block height index // update the block height index
ctx.store.setup_height(&b.header).map_err(&Error::StoreErr)?; ctx.store.setup_height(&b.header).map_err(&Error::StoreErr)?;
// in sync mode, only update the "body chain", otherwise update both the
// "header chain" and "body chain"
if ctx.opts.intersects(SYNC) {
ctx.store.save_body_head(&tip).map_err(&Error::StoreErr)?;
} else {
ctx.store.save_head(&tip).map_err(&Error::StoreErr)?; ctx.store.save_head(&tip).map_err(&Error::StoreErr)?;
}
// TODO if we're switching branch, make sure to backtrack the sum trees
ctx.head = tip.clone(); ctx.head = tip.clone();
info!( info!(LOGGER, "Updated head to {} at {}.", b.hash(), b.header.height);
LOGGER,
"Updated head to {} at {}.",
b.hash(),
b.header.height
);
Ok(Some(tip)) Ok(Some(tip))
} else { } else {
Ok(None) Ok(None)

View file

@ -60,8 +60,9 @@ impl NetAdapter for NetToChainAdapter {
let bhash = b.hash(); let bhash = b.hash();
debug!( debug!(
LOGGER, LOGGER,
"Received block {} from network, going to process.", "Received block {} at {} from network, going to process.",
bhash bhash,
b.header.height,
); );
// pushing the new block through the chain pipeline // pushing the new block through the chain pipeline

View file

@ -126,6 +126,9 @@ impl Syncer {
let mut prev_h = header_head.last_block_h; let mut prev_h = header_head.last_block_h;
while prev_h != full_head.last_block_h { while prev_h != full_head.last_block_h {
let header = self.chain.get_block_header(&prev_h)?; let header = self.chain.get_block_header(&prev_h)?;
if header.height < full_head.height {
break;
}
blocks_to_download.push(header.hash()); blocks_to_download.push(header.hash());
prev_h = header.previous; prev_h = header.previous;
} }