Skip to content

Commit

Permalink
fix: uncheck subtract overflow (#88)
Browse files Browse the repository at this point in the history
* fix: uncheck subtract overflow
* turn off `kad` temporarily
* fix debug log format
  • Loading branch information
zhangsoledad authored and doitian committed Dec 13, 2018
1 parent e5da1ae commit 36b541f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 24 deletions.
21 changes: 15 additions & 6 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,17 @@ impl<CI: ChainIndex + 'static> ChainService<CI> {
};

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,
);
Expand All @@ -170,7 +174,12 @@ impl<CI: ChainIndex + 'static> ChainService<CI> {
|| (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;
Expand Down Expand Up @@ -343,7 +352,7 @@ impl<CI: ChainIndex + 'static> ChainService<CI> {
.iter()
.enumerate()
{
debug!(target: "chain", " {} => {:#?}", index, uncle);
debug!(target: "chain", " {} => {:?}", index, uncle);
}
debug!(target: "chain", "}}");
}
Expand Down
14 changes: 7 additions & 7 deletions network/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -697,12 +697,12 @@ impl Network {
// prepare services futures
let futures: Vec<Box<Future<Item = (), Error = IoError> + Send>> = vec![
Box::new(swarm_events.for_each(|_| Ok(()))),
Box::new(
discovery_query_service
.into_future()
.map(|_| ())
.map_err(|(err, _)| err),
) as Box<Future<Item = (), Error = IoError> + Send>,
// Box::new(
// discovery_query_service
// .into_future()
// .map(|_| ())
// .map_err(|(err, _)| err),
// ) as Box<Future<Item = (), Error = IoError> + Send>,
ping_service.start_protocol(
Arc::clone(&network),
swarm_controller.clone(),
Expand Down
9 changes: 6 additions & 3 deletions sync/src/relayer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ where
}

pub fn accept_block(&self, nc: &CKBProtocolContext, peer: PeerIndex, block: &Arc<Block>) {
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);
Expand All @@ -150,6 +151,8 @@ where
let _ = nc.send(peer_id, fbb.finished_data().to_vec());
}
}
} else {
debug!(target: "relay", "accept_block verify error {:?}", ret);
}
}

Expand Down Expand Up @@ -262,12 +265,12 @@ where
}

fn connected(&self, _nc: Box<CKBProtocolContext>, peer: PeerIndex) {
info!(target: "sync", "peer={} RelayProtocol.connected", peer);
info!(target: "relay", "peer={} RelayProtocol.connected", peer);
// do nothing
}

fn disconnected(&self, _nc: Box<CKBProtocolContext>, peer: PeerIndex) {
info!(target: "sync", "peer={} RelayProtocol.disconnected", peer);
info!(target: "relay", "peer={} RelayProtocol.disconnected", peer);
// TODO
}

Expand Down
2 changes: 1 addition & 1 deletion sync/src/synchronizer/block_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
2 changes: 1 addition & 1 deletion sync/src/synchronizer/get_headers_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sync/src/synchronizer/headers_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ where
fn is_continuous(&self, headers: &[Header]) -> bool {
debug!(
target: "sync",
"headers\n {:#?}",
"headers\n {:?}",
headers
.iter()
.map(|h| format!(
Expand Down Expand Up @@ -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;
}

Expand Down
8 changes: 4 additions & 4 deletions sync/src/synchronizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,14 @@ impl<CI: ChainIndex> Synchronizer<CI> {
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()
);
Expand All @@ -457,14 +457,14 @@ impl<CI: ChainIndex> Synchronizer<CI> {
}
} 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()
);
Expand Down

0 comments on commit 36b541f

Please sign in to comment.