Skip to content

Commit 0958a33

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 a7579f4 commit 0958a33

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/chain/bitcoind.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,11 @@ impl BitcoindChainSource {
194194
{
195195
Ok(chain_tip) => {
196196
{
197+
let elapsed_ms = now.elapsed().map(|d| d.as_millis()).unwrap_or(0);
197198
log_info!(
198199
self.logger,
199200
"Finished synchronizing listeners in {}ms",
200-
now.elapsed().expect("system time must not go backwards").as_millis()
201+
elapsed_ms,
201202
);
202203
*self.latest_chain_tip.write().expect("lock") = Some(chain_tip);
203204
let unix_time_secs_opt =
@@ -410,11 +411,8 @@ impl BitcoindChainSource {
410411
let now = SystemTime::now();
411412
match spv_client.poll_best_tip().await {
412413
Ok((ChainTip::Better(tip), true)) => {
413-
log_trace!(
414-
self.logger,
415-
"Finished polling best tip in {}ms",
416-
now.elapsed().expect("system time must not go backwards").as_millis()
417-
);
414+
let elapsed_ms = now.elapsed().map(|d| d.as_millis()).unwrap_or(0);
415+
log_trace!(self.logger, "Finished polling best tip in {}ms", elapsed_ms);
418416
*self.latest_chain_tip.write().expect("lock") = Some(tip);
419417
},
420418
Ok(_) => {},
@@ -434,12 +432,13 @@ impl BitcoindChainSource {
434432
.await
435433
{
436434
Ok((unconfirmed_txs, evicted_txids)) => {
435+
let elapsed_ms = now.elapsed().map(|d| d.as_millis()).unwrap_or(0);
437436
log_trace!(
438437
self.logger,
439438
"Finished polling mempool of size {} and {} evicted transactions in {}ms",
440439
unconfirmed_txs.len(),
441440
evicted_txids.len(),
442-
now.elapsed().expect("system time must not go backwards").as_millis()
441+
elapsed_ms,
443442
);
444443
onchain_wallet.apply_mempool_txs(unconfirmed_txs, evicted_txids).unwrap_or_else(
445444
|e| {

0 commit comments

Comments
 (0)