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:
Antioch Peverell 2018-10-31 10:29:23 +00:00 committed by GitHub
parent 5651fa7a8f
commit bc0128ab88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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(())