Skip to content

Commit fa42eb8

Browse files
committed
chore: instant panic
1 parent 2b543b2 commit fa42eb8

File tree

16 files changed

+136
-51
lines changed

16 files changed

+136
-51
lines changed

Cargo.lock

Lines changed: 110 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ckb-bin/src/subcommand/replay.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fn profile(shared: Shared, mut chain: ChainService, from: Option<u64>, to: Optio
7474
println!("start profiling, re-process blocks {}..{}:", from, to);
7575
let now = std::time::Instant::now();
7676
let tx_count = process_range_block(&shared, &mut chain, from..=to);
77-
let duration = now.elapsed();
77+
let duration = std::time::Instant::now().saturating_duration_since(now);
7878
println!(
7979
"end profiling, duration {:?} txs {} tps {}",
8080
duration,

miner/src/worker/eaglesong_simple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl Worker for EaglesongSimple {
9696
self.solve(pow_hash, work, rng());
9797
state_update_counter += 1;
9898

99-
let elapsed = start.elapsed();
99+
let elapsed = Instant::now().saturating_duration_since(start);
100100
if elapsed.as_millis() > STATE_UPDATE_DURATION_MILLIS {
101101
let elapsed_nanos: f64 = (elapsed.as_secs() * 1_000_000_000
102102
+ u64::from(elapsed.subsec_nanos()))

network/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ckb-stop-handler = { path = "../util/stop-handler", version = "= 0.102.0-pre" }
1616
ckb-logger = { path = "../util/logger", version = "= 0.102.0-pre" }
1717
ckb-app-config = { path = "../util/app-config", version = "= 0.102.0-pre" }
1818
tokio = { version = "1", features = ["sync", "macros"] }
19-
tokio-util = { version = "0.6", features = ["codec"] }
19+
tokio-util = { version = "0.7", features = ["codec"] }
2020
futures = "0.3"
2121
faketime = "0.2.0"
2222
lazy_static = { version = "1.3.0", optional = true }
@@ -33,7 +33,7 @@ serde_json = "1.0"
3333
bloom-filters = "0.1"
3434
ckb-spawn = { path = "../util/spawn", version = "= 0.102.0-pre" }
3535

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

3838
[features]
3939
with_sentry = ["sentry"]

network/src/network.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ impl NetworkState {
343343
peer_id,
344344
addr
345345
);
346-
if dial_started.elapsed() > DIAL_HANG_TIMEOUT {
346+
if Instant::now().saturating_duration_since(*dial_started) > DIAL_HANG_TIMEOUT {
347347
#[cfg(feature = "with_sentry")]
348348
with_scope(
349349
|scope| scope.set_fingerprint(Some(&["ckb-network", "dialing-timeout"])),
@@ -1285,7 +1285,7 @@ impl NetworkController {
12851285
return Ok(());
12861286
}
12871287
Err(SendErrorKind::WouldBlock) => {
1288-
if now.elapsed() > P2P_SEND_TIMEOUT {
1288+
if Instant::now().saturating_duration_since(now) > P2P_SEND_TIMEOUT {
12891289
warn!("broadcast message to {} timeout", proto_id);
12901290
return Err(SendErrorKind::WouldBlock);
12911291
}

network/src/peer_registry.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,14 @@ impl PeerRegistry {
145145
&mut candidate_peers,
146146
EVICTION_PROTECT_PEERS,
147147
|peer1, peer2| {
148+
let now = std::time::Instant::now();
148149
let peer1_last_message = peer1
149150
.last_ping_protocol_message_received_at
150-
.map(|t| t.elapsed().as_secs())
151+
.map(|t| now.saturating_duration_since(t).as_secs())
151152
.unwrap_or_else(|| std::u64::MAX);
152153
let peer2_last_message = peer2
153154
.last_ping_protocol_message_received_at
154-
.map(|t| t.elapsed().as_secs())
155+
.map(|t| now.saturating_duration_since(t).as_secs())
155156
.unwrap_or_else(|| std::u64::MAX);
156157
peer2_last_message.cmp(&peer1_last_message)
157158
},

0 commit comments

Comments
 (0)