mirror of
https://github.com/mimblewimble/grin.git
synced 2025-04-30 14:21:14 +03:00
* reset sync_head on restart (handle banned peers and sync against invalid chain) * reset both sync_head and header_head on restart
This commit is contained in:
parent
521678bd23
commit
2450ff376b
2 changed files with 8 additions and 10 deletions
|
@ -176,16 +176,13 @@ impl Chain {
|
|||
Err(e) => return Err(Error::StoreErr(e, "chain init load head".to_owned())),
|
||||
};
|
||||
|
||||
// make sure sync_head is available for later use
|
||||
let _ = match chain_store.get_sync_head() {
|
||||
Ok(tip) => tip,
|
||||
Err(NotFoundErr) => {
|
||||
let tip = chain_store.head().unwrap();
|
||||
chain_store.save_sync_head(&tip)?;
|
||||
tip
|
||||
},
|
||||
Err(e) => return Err(Error::StoreErr(e, "chain init sync head".to_owned())),
|
||||
};
|
||||
// Make sure we have a sync_head available for later use.
|
||||
// We may have been tracking an invalid chain on a now banned peer
|
||||
// so we want to reset the both sync_head and header_head on restart to handle this.
|
||||
// TODO - handle sync_head/header_head and peer banning in a more effective way.
|
||||
let tip = chain_store.head().unwrap();
|
||||
chain_store.save_header_head(&tip)?;
|
||||
chain_store.save_sync_head(&tip)?;
|
||||
|
||||
info!(
|
||||
LOGGER,
|
||||
|
|
|
@ -154,6 +154,7 @@ pub fn header_sync(peers: Peers, chain: Arc<chain::Chain>) {
|
|||
if let Some(peer) = peers.most_work_peer() {
|
||||
if let Ok(p) = peer.try_read() {
|
||||
let peer_difficulty = p.info.total_difficulty.clone();
|
||||
debug!(LOGGER, "sync: header_sync: {}, {}", difficulty, peer_difficulty);
|
||||
if peer_difficulty > difficulty {
|
||||
let _ = request_headers(
|
||||
peer.clone(),
|
||||
|
|
Loading…
Add table
Reference in a new issue