From 2b0976f1f05228f39223cb79c99b5b0598e7645d Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Thu, 13 Dec 2018 10:53:06 +0800 Subject: [PATCH] fix: uncheck subtract overflow (#88) * fix: uncheck subtract overflow * turn off `kad` temporarily * fix debug log format --- chain/src/chain.rs | 21 ++++++++++++++------ network/src/network.rs | 14 ++++++------- sync/src/relayer/mod.rs | 9 ++++++--- sync/src/synchronizer/block_fetcher.rs | 2 +- sync/src/synchronizer/get_headers_process.rs | 2 +- sync/src/synchronizer/headers_process.rs | 4 ++-- sync/src/synchronizer/mod.rs | 8 ++++---- 7 files changed, 36 insertions(+), 24 deletions(-) diff --git a/chain/src/chain.rs b/chain/src/chain.rs index f654b1109b..b2c79efb17 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -155,13 +155,17 @@ impl ChainService { }; self.shared.store().insert_block(batch, block); - self.shared.store().insert_output_root(batch, &block.header().hash(), &root); - self.shared.store().insert_block_ext(batch, &block.header().hash(), &ext); + self.shared + .store() + .insert_output_root(batch, &block.header().hash(), &root); + self.shared + .store() + .insert_block_ext(batch, &block.header().hash(), &ext); let current_total_difficulty = tip_header.total_difficulty(); debug!( - "difficulty diff = {}; current = {}, cannon = {}", - &cannon_total_difficulty - current_total_difficulty, + target: "chain", + "difficulty current = {}, cannon = {}", current_total_difficulty, cannon_total_difficulty, ); @@ -170,7 +174,12 @@ impl ChainService { || (current_total_difficulty == &cannon_total_difficulty && block.header().hash() < tip_header.hash()) { - debug!(target: "chain", "new best block found: {} => {}", block.header().number(), block.header().hash()); + debug!( + target: "chain", + "new best block found: {} => {}, difficulty diff = {}", + block.header().number(), block.header().hash(), + &cannon_total_difficulty - current_total_difficulty + ); new_best_block = true; output_root = root; total_difficulty = cannon_total_difficulty; @@ -343,7 +352,7 @@ impl ChainService { .iter() .enumerate() { - debug!(target: "chain", " {} => {:#?}", index, uncle); + debug!(target: "chain", " {} => {:?}", index, uncle); } debug!(target: "chain", "}}"); } diff --git a/network/src/network.rs b/network/src/network.rs index becd06437e..13f454da8b 100644 --- a/network/src/network.rs +++ b/network/src/network.rs @@ -685,7 +685,7 @@ impl Network { } } - let discovery_query_service = DiscoveryQueryService::new( + let _discovery_query_service = DiscoveryQueryService::new( Arc::clone(&network), swarm_controller.clone(), basic_transport.clone(), @@ -697,12 +697,12 @@ impl Network { // prepare services futures let futures: Vec + Send>> = vec![ Box::new(swarm_events.for_each(|_| Ok(()))), - Box::new( - discovery_query_service - .into_future() - .map(|_| ()) - .map_err(|(err, _)| err), - ) as Box + Send>, + // Box::new( + // discovery_query_service + // .into_future() + // .map(|_| ()) + // .map_err(|(err, _)| err), + // ) as Box + Send>, ping_service.start_protocol( Arc::clone(&network), swarm_controller.clone(), diff --git a/sync/src/relayer/mod.rs b/sync/src/relayer/mod.rs index c45f8932fb..2ff67720b1 100644 --- a/sync/src/relayer/mod.rs +++ b/sync/src/relayer/mod.rs @@ -140,7 +140,8 @@ where } pub fn accept_block(&self, nc: &CKBProtocolContext, peer: PeerIndex, block: &Arc) { - if self.chain.process_block(Arc::clone(&block)).is_ok() { + let ret = self.chain.process_block(Arc::clone(&block)); + if ret.is_ok() { let fbb = &mut FlatBufferBuilder::new(); let message = RelayMessage::build_compact_block(fbb, block, &HashSet::new()); fbb.finish(message, None); @@ -150,6 +151,8 @@ where let _ = nc.send(peer_id, fbb.finished_data().to_vec()); } } + } else { + debug!(target: "relay", "accept_block verify error {:?}", ret); } } @@ -262,12 +265,12 @@ where } fn connected(&self, _nc: Box, peer: PeerIndex) { - info!(target: "sync", "peer={} RelayProtocol.connected", peer); + info!(target: "relay", "peer={} RelayProtocol.connected", peer); // do nothing } fn disconnected(&self, _nc: Box, peer: PeerIndex) { - info!(target: "sync", "peer={} RelayProtocol.disconnected", peer); + info!(target: "relay", "peer={} RelayProtocol.disconnected", peer); // TODO } diff --git a/sync/src/synchronizer/block_fetcher.rs b/sync/src/synchronizer/block_fetcher.rs index 7895b5badc..463917642a 100644 --- a/sync/src/synchronizer/block_fetcher.rs +++ b/sync/src/synchronizer/block_fetcher.rs @@ -189,7 +189,7 @@ where && inflight.insert(to_fetch_hash.clone().clone()) { debug!( - target: "sync", "[Synchronizer] inflight insert {:#?}------------{:?}", + target: "sync", "[Synchronizer] inflight insert {:?}------------{:?}", to_fetch.number(), to_fetch_hash ); diff --git a/sync/src/synchronizer/get_headers_process.rs b/sync/src/synchronizer/get_headers_process.rs index ad02769a3a..5e7de4e967 100644 --- a/sync/src/synchronizer/get_headers_process.rs +++ b/sync/src/synchronizer/get_headers_process.rs @@ -71,7 +71,7 @@ where fbb.finish(message, None); let _ = self.nc.send(self.peer, fbb.finished_data().to_vec()); } else { - warn!(target: "sync", "\n\nunknown block headers from peer {} {:#?}\n\n", self.peer, block_locator_hashes); + warn!(target: "sync", "\n\nunknown block headers from peer {} {:?}\n\n", self.peer, block_locator_hashes); // Got 'headers' message without known blocks // ban or close peers self.nc diff --git a/sync/src/synchronizer/headers_process.rs b/sync/src/synchronizer/headers_process.rs index 0ef4557bc0..622bca9b93 100644 --- a/sync/src/synchronizer/headers_process.rs +++ b/sync/src/synchronizer/headers_process.rs @@ -128,7 +128,7 @@ where fn is_continuous(&self, headers: &[Header]) -> bool { debug!( target: "sync", - "headers\n {:#?}", + "headers\n {:?}", headers .iter() .map(|h| format!( @@ -201,7 +201,7 @@ where .peers .misbehavior(self.peer, result.misbehavior); } - debug!(target: "sync", "\n\nHeadersProcess accept_first is_valid {:?} headers = {:#?}\n\n", result, headers[0]); + debug!(target: "sync", "\n\nHeadersProcess accept_first is_valid {:?} headers = {:?}\n\n", result, headers[0]); return; } diff --git a/sync/src/synchronizer/mod.rs b/sync/src/synchronizer/mod.rs index a1d79c2cda..65d215aff7 100644 --- a/sync/src/synchronizer/mod.rs +++ b/sync/src/synchronizer/mod.rs @@ -441,14 +441,14 @@ impl Synchronizer { let ret = self.accept_block(peer, &block); if ret.is_err() { debug!( - target: "sync", "[Synchronizer] accept_block {:#?} error {:?}", + target: "sync", "[Synchronizer] accept_block {:?} error {:?}", block, ret.unwrap_err() ); } } else { debug!( - target: "sync", "[Synchronizer] insert_orphan_block {:#?}------------{:?}", + target: "sync", "[Synchronizer] insert_orphan_block {:?}------------{:?}", block.header().number(), block.header().hash() ); @@ -457,14 +457,14 @@ impl Synchronizer { } } else { debug!( - target: "sync", "[Synchronizer] accept_block {:#?} error {:?}", + target: "sync", "[Synchronizer] accept_block {:?} error {:?}", block, accept_ret.unwrap_err() ) } } else { debug!( - target: "sync", "[Synchronizer] insert_orphan_block {:#?}------------{:?}", + target: "sync", "[Synchronizer] insert_orphan_block {:?}------------{:?}", block.header().number(), block.header().hash() );