From 6d4dfb282fca68c43b6b7a56559a2525a51bf26c Mon Sep 17 00:00:00 2001 From: Revertron Date: Thu, 29 Apr 2021 19:27:45 +0200 Subject: [PATCH] Added additional material for consensus. --- src/blockchain/block.rs | 7 +++++-- src/p2p/network.rs | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/blockchain/block.rs b/src/blockchain/block.rs index b821996..9fde23a 100644 --- a/src/blockchain/block.rs +++ b/src/blockchain/block.rs @@ -73,8 +73,11 @@ impl Block { if self.transaction.is_some() && other.transaction.is_none() { return true; } - let my_diff = hash_difficulty(self.hash.as_slice()) + key_hash_difficulty(self.hash.as_slice()); - let it_diff = hash_difficulty(other.hash.as_slice()) + key_hash_difficulty(other.hash.as_slice()); + let hash_diff = hash_difficulty(self.hash.as_slice()) + key_hash_difficulty(self.hash.as_slice()); + let my_diff = (hash_diff << 16) + (self.hash.get_tail_u64() % 0xFFFF) as u32; + let hash_diff = hash_difficulty(other.hash.as_slice()) + key_hash_difficulty(other.hash.as_slice()); + let it_diff = (hash_diff << 16) + (other.hash.get_tail_u64() % 0xFFFF) as u32; + if my_diff > it_diff { return true; } diff --git a/src/p2p/network.rs b/src/p2p/network.rs index 0d5e20d..e4be91c 100644 --- a/src/p2p/network.rs +++ b/src/p2p/network.rs @@ -580,6 +580,8 @@ fn handle_block(context: Arc>, peers: &mut Peers, token: &Token, if zone { context.bus.post(crate::event::Event::ZonesChanged); } + } else { + debug!("Fork in not better than our block, dropping."); } let height = context.chain.get_height(); context.chain.update_max_height(height);