More small fixes and improvements to sync

This commit is contained in:
Ignotus Peverell 2017-10-18 07:19:44 +00:00
parent 406642a1f0
commit 6fc48dbae2
No known key found for this signature in database
GPG key ID: 99CD25F39F8F8211
2 changed files with 14 additions and 6 deletions

View file

@ -61,10 +61,7 @@ pub fn process_block(b: &Block, mut ctx: BlockContext) -> Result<Option<Tip>, 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<Option<Tip>, 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);

View file

@ -152,14 +152,16 @@ impl Syncer {
let too_old_pos = (0..blocks_downloading.len())
.filter(|p| blocks_downloading[*p].1 < twenty_sec_ago)
.collect::<Vec<_>>();
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