From 7229a112e52cbcb158e4d3e3b14b03cd4188c962 Mon Sep 17 00:00:00 2001 From: Revertron Date: Thu, 15 Apr 2021 21:45:49 +0200 Subject: [PATCH] Improved new block handling. --- src/p2p/network.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/p2p/network.rs b/src/p2p/network.rs index 9f7cb3d..ba87d12 100644 --- a/src/p2p/network.rs +++ b/src/p2p/network.rs @@ -441,7 +441,7 @@ fn handle_message(context: Arc>, message: Message, peers: &mut Pe } } Message::Block { index, block } => { - debug!("Received block {}", index); + info!("Received block {}", index); let block: Block = match serde_json::from_str(&block) { Ok(block) => block, Err(_) => return State::Error @@ -479,6 +479,9 @@ fn handle_message(context: Arc>, message: Message, peers: &mut Pe BlockQuality::Bad => { // TODO save bad public keys to banned table debug!("Ignoring bad block {} with hash {:?}", block.index, block.hash); + let height = context.chain.height(); + context.chain.update_max_height(height); + context.bus.post(crate::event::Event::SyncFinished); } BlockQuality::Fork => { debug!("Got forked block {} with hash {:?}", block.index, block.hash); @@ -490,8 +493,9 @@ fn handle_message(context: Arc>, message: Message, peers: &mut Pe let index = context.chain.height(); context.bus.post(crate::event::Event::BlockchainChanged { index }); } - //let peer = peers.get_mut_peer(token).unwrap(); - //deal_with_fork(context, peer, block); + let height = context.chain.height(); + context.chain.update_max_height(height); + context.bus.post(crate::event::Event::SyncFinished); } } });