From 734529098c438805c09358b12d2d168c4bfa6e98 Mon Sep 17 00:00:00 2001 From: Revertron Date: Fri, 7 May 2021 22:14:30 +0200 Subject: [PATCH] Fixed lagging behind nodes with "better" last block. --- src/p2p/network.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/p2p/network.rs b/src/p2p/network.rs index a205471..b9466e0 100644 --- a/src/p2p/network.rs +++ b/src/p2p/network.rs @@ -564,17 +564,16 @@ fn handle_block(context: Arc>, peers: &mut Peers, token: &Token, } BlockQuality::Fork => { debug!("Got forked block {} with hash {:?}", block.index, block.hash); + // If we are very much behind of blockchain + let lagged = block.index == context.chain.get_height() && block.index + LIMITED_CONFIDENCE_DEPTH <= max_height; let last_block = context.chain.last_block().unwrap(); - if block.is_better_than(&last_block) { + if block.is_better_than(&last_block) || lagged { context.chain.replace_block(block).expect("Error replacing block with fork"); let index = context.chain.get_height(); context.bus.post(crate::event::Event::BlockchainChanged { index }); } else { debug!("Fork in not better than our block, dropping."); } - let height = context.chain.get_height(); - context.chain.update_max_height(height); - context.bus.post(crate::event::Event::SyncFinished); } } State::idle()