From 406642a1f069ebe3026be7fed39a3205a91dd3bc Mon Sep 17 00:00:00 2001 From: Ignotus Peverell Date: Wed, 18 Oct 2017 04:48:21 +0000 Subject: [PATCH] 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. --- chain/src/pipe.rs | 17 ++--------------- grin/src/adapters.rs | 5 +++-- grin/src/sync.rs | 3 +++ 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/chain/src/pipe.rs b/chain/src/pipe.rs index 2cc4f2893..b34f681bb 100644 --- a/chain/src/pipe.rs +++ b/chain/src/pipe.rs @@ -322,22 +322,9 @@ fn update_head(b: &Block, ctx: &mut BlockContext) -> Result, Error> // update the block height index 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)?; - } - // TODO if we're switching branch, make sure to backtrack the sum trees - + ctx.store.save_head(&tip).map_err(&Error::StoreErr)?; ctx.head = tip.clone(); - info!( - LOGGER, - "Updated head to {} at {}.", - b.hash(), - b.header.height - ); + info!(LOGGER, "Updated head to {} at {}.", b.hash(), b.header.height); Ok(Some(tip)) } else { Ok(None) diff --git a/grin/src/adapters.rs b/grin/src/adapters.rs index e80a50e6d..a6eaff884 100644 --- a/grin/src/adapters.rs +++ b/grin/src/adapters.rs @@ -60,8 +60,9 @@ impl NetAdapter for NetToChainAdapter { let bhash = b.hash(); debug!( LOGGER, - "Received block {} from network, going to process.", - bhash + "Received block {} at {} from network, going to process.", + bhash, + b.header.height, ); // pushing the new block through the chain pipeline diff --git a/grin/src/sync.rs b/grin/src/sync.rs index b66662a33..85c5ceac6 100644 --- a/grin/src/sync.rs +++ b/grin/src/sync.rs @@ -126,6 +126,9 @@ impl Syncer { let mut prev_h = header_head.last_block_h; while prev_h != full_head.last_block_h { let header = self.chain.get_block_header(&prev_h)?; + if header.height < full_head.height { + break; + } blocks_to_download.push(header.hash()); prev_h = header.previous; }