mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 17:01:09 +03:00
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:
parent
56ffbee7e9
commit
e1c8dc5a3a
3 changed files with 41 additions and 11 deletions
|
@ -931,6 +931,14 @@ impl Chain {
|
||||||
.block_exists(&h)
|
.block_exists(&h)
|
||||||
.map_err(|e| ErrorKind::StoreErr(e, "chain block exists".to_owned()).into())
|
.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(
|
fn setup_head(
|
||||||
|
|
|
@ -215,9 +215,15 @@ pub fn sync_block_header(
|
||||||
validate_header(&bh, sync_ctx)?;
|
validate_header(&bh, sync_ctx)?;
|
||||||
add_block_header(bh, batch)?;
|
add_block_header(bh, batch)?;
|
||||||
|
|
||||||
// now update the header_head (if new header with most work) and the sync_head
|
// Update header_head (but only if this header increases our total known work).
|
||||||
// (always)
|
// i.e. Only if this header is now the head of the current "most work" chain.
|
||||||
update_header_head(bh, header_ctx, batch)?;
|
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)
|
update_sync_head(bh, sync_ctx, batch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -141,18 +141,34 @@ pub fn run_sync(
|
||||||
|
|
||||||
// run the header sync every 10s
|
// run the header sync every 10s
|
||||||
if si.header_sync_due(&header_head) {
|
if si.header_sync_due(&header_head) {
|
||||||
header_sync(peers.clone(), chain.clone(), &mut history_locators);
|
|
||||||
|
|
||||||
let status = sync_state.status();
|
let status = sync_state.status();
|
||||||
match status {
|
let update_sync_state = match status {
|
||||||
SyncStatus::TxHashsetDownload => (),
|
SyncStatus::TxHashsetDownload => false,
|
||||||
_ => {
|
SyncStatus::NoSync | SyncStatus::Initial => {
|
||||||
sync_state.update(SyncStatus::HeaderSync {
|
// Reset sync_head to header_head on transition to HeaderSync,
|
||||||
current_height: header_head.height,
|
// but ONLY on initial transition to HeaderSync state.
|
||||||
highest_height: si.highest_height,
|
let sync_head = chain.get_sync_head().unwrap();
|
||||||
});
|
debug!(
|
||||||
|
LOGGER,
|
||||||
|
"sync: initial transition to HeaderSync. sync_head: {} at {}, reset to: {} at {}",
|
||||||
|
sync_head.hash(),
|
||||||
|
sync_head.height,
|
||||||
|
header_head.hash(),
|
||||||
|
header_head.height,
|
||||||
|
);
|
||||||
|
chain.init_sync_head(&header_head).unwrap();
|
||||||
|
history_locators.clear();
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
_ => true,
|
||||||
};
|
};
|
||||||
|
if update_sync_state {
|
||||||
|
sync_state.update(SyncStatus::HeaderSync {
|
||||||
|
current_height: header_head.height,
|
||||||
|
highest_height: si.highest_height,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
header_sync(peers.clone(), chain.clone(), &mut history_locators);
|
||||||
}
|
}
|
||||||
|
|
||||||
if fast_sync_enabled {
|
if fast_sync_enabled {
|
||||||
|
|
Loading…
Reference in a new issue