mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
be careful resetting sync_head (#1885)
* be careful resetting sync_head make sure we have the header corresponding to header_head and that nothing is corrupted from an earlier shutdown * add logging when resetting heads due to missing header
This commit is contained in:
parent
5651fa7a8f
commit
bc0128ab88
1 changed files with 20 additions and 2 deletions
|
@ -1095,8 +1095,26 @@ fn setup_head(
|
||||||
Err(e) => return Err(ErrorKind::StoreErr(e, "chain init load head".to_owned()))?,
|
Err(e) => return Err(ErrorKind::StoreErr(e, "chain init load head".to_owned()))?,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Reset sync_head to be consistent with current header_head.
|
// Check we have the header corresponding to the header_head.
|
||||||
batch.reset_sync_head()?;
|
// If not then something is corrupted and we should reset our header_head.
|
||||||
|
// Either way we want to reset sync_head to match header_head.
|
||||||
|
let head = batch.head()?;
|
||||||
|
let header_head = batch.header_head()?;
|
||||||
|
if batch.get_block_header(&header_head.last_block_h).is_ok() {
|
||||||
|
// Reset sync_head to be consistent with current header_head.
|
||||||
|
batch.reset_sync_head()?;
|
||||||
|
} else {
|
||||||
|
// Reset both header_head and sync_head to be consistent with current head.
|
||||||
|
warn!(
|
||||||
|
"setup_head: header missing for {}, {}, resetting header_head and sync_head to head: {}, {}",
|
||||||
|
header_head.last_block_h,
|
||||||
|
header_head.height,
|
||||||
|
head.last_block_h,
|
||||||
|
head.height,
|
||||||
|
);
|
||||||
|
batch.reset_head()?;
|
||||||
|
}
|
||||||
|
|
||||||
batch.commit()?;
|
batch.commit()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue