fix: reset sync_head to header_head on initial transition to HeaderSync (#1531)

* fix for bug #1524, reset sync_head to header_head on initial transition to HeaderSync.
* using @antiochp fix solution in #1539
This commit is contained in:
Gary Yu
2018-09-20 07:29:24 +08:00
committed by GitHub
parent 56ffbee7e9
commit e1c8dc5a3a
3 changed files with 41 additions and 11 deletions
+8
View File
@@ -931,6 +931,14 @@ impl Chain {
.block_exists(&h)
.map_err(|e| ErrorKind::StoreErr(e, "chain block exists".to_owned()).into())
}
/// reset sync_head to header_head
pub fn init_sync_head(&self, header_head: &Tip) -> Result<(), Error> {
let batch = self.store.batch()?;
batch.init_sync_head(header_head)?;
batch.commit()?;
Ok(())
}
}
fn setup_head(
+8 -2
View File
@@ -215,9 +215,15 @@ pub fn sync_block_header(
validate_header(&bh, sync_ctx)?;
add_block_header(bh, batch)?;
// now update the header_head (if new header with most work) and the sync_head
// (always)
// Update header_head (but only if this header increases our total known work).
// i.e. Only if this header is now the head of the current "most work" chain.
update_header_head(bh, header_ctx, batch)?;
// Update sync_head regardless of total work.
// We may be syncing a long fork that will *eventually* increase the work
// and become the "most work" chain.
// header_head and sync_head will diverge in this situation until we switch to
// a single "most work" chain.
update_sync_head(bh, sync_ctx, batch)
}