Skip to content

Commit 13c8540

Browse files
committed
Tolerate clock skew in bitcoind timing logs
Use a zero-millisecond fallback for elapsed-time logging so clock adjustments do not panic the chain polling loop. Co-Authored-By: HAL 9000
1 parent dcca9f4 commit 13c8540

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/chain/bitcoind.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,7 @@ impl BitcoindChainSource {
195195
{
196196
Ok(chain_tip) => {
197197
{
198-
#[allow(clippy::unwrap_used)]
199-
let elapsed_ms = now.elapsed().unwrap().as_millis();
198+
let elapsed_ms = now.elapsed().map(|d| d.as_millis()).unwrap_or(0);
200199
log_info!(
201200
self.logger,
202201
"Finished synchronizing listeners in {}ms",
@@ -413,8 +412,7 @@ impl BitcoindChainSource {
413412
let now = SystemTime::now();
414413
match spv_client.poll_best_tip().await {
415414
Ok((ChainTip::Better(tip), true)) => {
416-
#[allow(clippy::unwrap_used)]
417-
let elapsed_ms = now.elapsed().unwrap().as_millis();
415+
let elapsed_ms = now.elapsed().map(|d| d.as_millis()).unwrap_or(0);
418416
log_trace!(self.logger, "Finished polling best tip in {}ms", elapsed_ms);
419417
*self.latest_chain_tip.wlck() = Some(tip);
420418
},
@@ -435,8 +433,7 @@ impl BitcoindChainSource {
435433
.await
436434
{
437435
Ok((unconfirmed_txs, evicted_txids)) => {
438-
#[allow(clippy::unwrap_used)]
439-
let elapsed_ms = now.elapsed().unwrap().as_millis();
436+
let elapsed_ms = now.elapsed().map(|d| d.as_millis()).unwrap_or(0);
440437
log_trace!(
441438
self.logger,
442439
"Finished polling mempool of size {} and {} evicted transactions in {}ms",

0 commit comments

Comments
 (0)