mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
More small fixes and improvements to sync
This commit is contained in:
parent
406642a1f0
commit
6fc48dbae2
2 changed files with 14 additions and 6 deletions
|
@ -61,10 +61,7 @@ pub fn process_block(b: &Block, mut ctx: BlockContext) -> Result<Option<Tip>, Er
|
||||||
);
|
);
|
||||||
check_known(b.hash(), &mut ctx)?;
|
check_known(b.hash(), &mut ctx)?;
|
||||||
|
|
||||||
if !ctx.opts.intersects(SYNC) {
|
validate_header(&b.header, &mut ctx)?;
|
||||||
// in sync mode, the header has already been validated
|
|
||||||
validate_header(&b.header, &mut ctx)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
// take the lock on the sum trees and start a chain extension unit of work
|
// 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
|
// 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
|
// 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", 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.store.save_head(&tip).map_err(&Error::StoreErr)?;
|
||||||
ctx.head = tip.clone();
|
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);
|
||||||
|
|
|
@ -152,14 +152,16 @@ impl Syncer {
|
||||||
let too_old_pos = (0..blocks_downloading.len())
|
let too_old_pos = (0..blocks_downloading.len())
|
||||||
.filter(|p| blocks_downloading[*p].1 < twenty_sec_ago)
|
.filter(|p| blocks_downloading[*p].1 < twenty_sec_ago)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
let mut offs = 0;
|
||||||
for too_old in too_old_pos {
|
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!(
|
debug!(
|
||||||
LOGGER,
|
LOGGER,
|
||||||
"Download request expired for {}, will re-issue.",
|
"Download request expired for {}, will re-issue.",
|
||||||
block_h.0
|
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
|
// consume hashes from blocks to download, place them in downloading and
|
||||||
|
|
Loading…
Reference in a new issue