Improved new block handling.

This commit is contained in:
Revertron
2021-04-15 21:45:49 +02:00
parent 0e153ae47e
commit 7229a112e5
+7 -3
View File
@@ -441,7 +441,7 @@ fn handle_message(context: Arc<Mutex<Context>>, message: Message, peers: &mut Pe
} }
} }
Message::Block { index, block } => { Message::Block { index, block } => {
debug!("Received block {}", index); info!("Received block {}", index);
let block: Block = match serde_json::from_str(&block) { let block: Block = match serde_json::from_str(&block) {
Ok(block) => block, Ok(block) => block,
Err(_) => return State::Error Err(_) => return State::Error
@@ -479,6 +479,9 @@ fn handle_message(context: Arc<Mutex<Context>>, message: Message, peers: &mut Pe
BlockQuality::Bad => { BlockQuality::Bad => {
// TODO save bad public keys to banned table // TODO save bad public keys to banned table
debug!("Ignoring bad block {} with hash {:?}", block.index, block.hash); 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 => { BlockQuality::Fork => {
debug!("Got forked block {} with hash {:?}", block.index, block.hash); debug!("Got forked block {} with hash {:?}", block.index, block.hash);
@@ -490,8 +493,9 @@ fn handle_message(context: Arc<Mutex<Context>>, message: Message, peers: &mut Pe
let index = context.chain.height(); let index = context.chain.height();
context.bus.post(crate::event::Event::BlockchainChanged { index }); context.bus.post(crate::event::Event::BlockchainChanged { index });
} }
//let peer = peers.get_mut_peer(token).unwrap(); let height = context.chain.height();
//deal_with_fork(context, peer, block); context.chain.update_max_height(height);
context.bus.post(crate::event::Event::SyncFinished);
} }
} }
}); });