mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
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:
parent
42ff6c2f6b
commit
406642a1f0
3 changed files with 8 additions and 17 deletions
|
@ -322,22 +322,9 @@ 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"
|
||||
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.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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue