reset sync_head on restart () ()

* 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:
AntiochP 2017-12-27 19:09:11 -05:00 committed by GitHub
parent 521678bd23
commit 2450ff376b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 10 deletions
chain/src
grin/src

View file

@ -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,

View file

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