From 6fc48dbae26c2eef2bfa62e8e3e116d60c4c1d7a Mon Sep 17 00:00:00 2001 From: Ignotus Peverell Date: Wed, 18 Oct 2017 07:19:44 +0000 Subject: [PATCH] More small fixes and improvements to sync --- chain/src/pipe.rs | 14 ++++++++++---- grin/src/sync.rs | 6 ++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/chain/src/pipe.rs b/chain/src/pipe.rs index b34f681bb..8fd96044e 100644 --- a/chain/src/pipe.rs +++ b/chain/src/pipe.rs @@ -61,10 +61,7 @@ pub fn process_block(b: &Block, mut ctx: BlockContext) -> Result, Er ); check_known(b.hash(), &mut ctx)?; - if !ctx.opts.intersects(SYNC) { - // in sync mode, the header has already been validated - validate_header(&b.header, &mut ctx)?; - } + validate_header(&b.header, &mut ctx)?; // take the lock on the sum trees and start a chain extension unit of work // dependent on the success of the internal validation and saving operations @@ -322,6 +319,15 @@ 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", updating the header chain in sync resets + // all additional "future" headers we've received + 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)?; ctx.head = tip.clone(); info!(LOGGER, "Updated head to {} at {}.", b.hash(), b.header.height); diff --git a/grin/src/sync.rs b/grin/src/sync.rs index 85c5ceac6..2a5e45082 100644 --- a/grin/src/sync.rs +++ b/grin/src/sync.rs @@ -152,14 +152,16 @@ impl Syncer { let too_old_pos = (0..blocks_downloading.len()) .filter(|p| blocks_downloading[*p].1 < twenty_sec_ago) .collect::>(); + let mut offs = 0; for too_old in too_old_pos { - let block_h = blocks_downloading.remove(too_old); + let block_h = blocks_downloading.remove(too_oldi - offs); debug!( LOGGER, "Download request expired for {}, will re-issue.", block_h.0 ); - blocks_to_download.insert(0, block_h.0); + blocks_to_download.push(block_h.0); + offs += 1; } // consume hashes from blocks to download, place them in downloading and