Skip to content

Commit

Permalink
chore: instant panic
Browse files Browse the repository at this point in the history
  • Loading branch information
driftluo committed Feb 21, 2022
1 parent 2b543b2 commit fa42eb8
Show file tree
Hide file tree
Showing 16 changed files with 136 additions and 51 deletions.
139 changes: 110 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ckb-bin/src/subcommand/replay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn profile(shared: Shared, mut chain: ChainService, from: Option<u64>, to: Optio
println!("start profiling, re-process blocks {}..{}:", from, to);
let now = std::time::Instant::now();
let tx_count = process_range_block(&shared, &mut chain, from..=to);
let duration = now.elapsed();
let duration = std::time::Instant::now().saturating_duration_since(now);
println!(
"end profiling, duration {:?} txs {} tps {}",
duration,
Expand Down
2 changes: 1 addition & 1 deletion miner/src/worker/eaglesong_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Worker for EaglesongSimple {
self.solve(pow_hash, work, rng());
state_update_counter += 1;

let elapsed = start.elapsed();
let elapsed = Instant::now().saturating_duration_since(start);
if elapsed.as_millis() > STATE_UPDATE_DURATION_MILLIS {
let elapsed_nanos: f64 = (elapsed.as_secs() * 1_000_000_000
+ u64::from(elapsed.subsec_nanos()))
Expand Down
4 changes: 2 additions & 2 deletions network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ckb-stop-handler = { path = "../util/stop-handler", version = "= 0.102.0-pre" }
ckb-logger = { path = "../util/logger", version = "= 0.102.0-pre" }
ckb-app-config = { path = "../util/app-config", version = "= 0.102.0-pre" }
tokio = { version = "1", features = ["sync", "macros"] }
tokio-util = { version = "0.6", features = ["codec"] }
tokio-util = { version = "0.7", features = ["codec"] }
futures = "0.3"
faketime = "0.2.0"
lazy_static = { version = "1.3.0", optional = true }
Expand All @@ -33,7 +33,7 @@ serde_json = "1.0"
bloom-filters = "0.1"
ckb-spawn = { path = "../util/spawn", version = "= 0.102.0-pre" }

p2p = { version="=0.4.0-alpha.3", package="tentacle", features = ["upnp", "parking_lot"] }
p2p = { version="=0.4.0-alpha.4", package="tentacle", features = ["upnp", "parking_lot"] }

[features]
with_sentry = ["sentry"]
Expand Down
4 changes: 2 additions & 2 deletions network/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ impl NetworkState {
peer_id,
addr
);
if dial_started.elapsed() > DIAL_HANG_TIMEOUT {
if Instant::now().saturating_duration_since(*dial_started) > DIAL_HANG_TIMEOUT {
#[cfg(feature = "with_sentry")]
with_scope(
|scope| scope.set_fingerprint(Some(&["ckb-network", "dialing-timeout"])),
Expand Down Expand Up @@ -1285,7 +1285,7 @@ impl NetworkController {
return Ok(());
}
Err(SendErrorKind::WouldBlock) => {
if now.elapsed() > P2P_SEND_TIMEOUT {
if Instant::now().saturating_duration_since(now) > P2P_SEND_TIMEOUT {
warn!("broadcast message to {} timeout", proto_id);
return Err(SendErrorKind::WouldBlock);
}
Expand Down
5 changes: 3 additions & 2 deletions network/src/peer_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,14 @@ impl PeerRegistry {
&mut candidate_peers,
EVICTION_PROTECT_PEERS,
|peer1, peer2| {
let now = std::time::Instant::now();
let peer1_last_message = peer1
.last_ping_protocol_message_received_at
.map(|t| t.elapsed().as_secs())
.map(|t| now.saturating_duration_since(t).as_secs())
.unwrap_or_else(|| std::u64::MAX);
let peer2_last_message = peer2
.last_ping_protocol_message_received_at
.map(|t| t.elapsed().as_secs())
.map(|t| now.saturating_duration_since(t).as_secs())
.unwrap_or_else(|| std::u64::MAX);
peer2_last_message.cmp(&peer1_last_message)
},
Expand Down
Loading

0 comments on commit fa42eb8

Please sign in to comment.