diff --git a/src/bitcoin/mod.rs b/src/bitcoin/mod.rs index 86bf5ccd..fcbffd91 100644 --- a/src/bitcoin/mod.rs +++ b/src/bitcoin/mod.rs @@ -51,7 +51,7 @@ pub trait BitcoinInterface: Send { fn chain_tip(&self) -> BlockChainTip; /// Get the timestamp set in the best block's header. - fn tip_time(&self) -> u32; + fn tip_time(&self) -> Option; /// Check whether this former tip is part of the current best chain. fn is_in_chain(&self, tip: &BlockChainTip) -> bool; @@ -316,9 +316,9 @@ impl BitcoinInterface for d::BitcoinD { self.tip_before_timestamp(timestamp) } - fn tip_time(&self) -> u32 { + fn tip_time(&self) -> Option { let tip = self.chain_tip(); - self.get_block_stats(tip.hash).time + Some(self.get_block_stats(tip.hash).time) } fn wallet_transaction( @@ -400,7 +400,7 @@ impl BitcoinInterface for sync::Arc> self.lock().unwrap().block_before_date(timestamp) } - fn tip_time(&self) -> u32 { + fn tip_time(&self) -> Option { self.lock().unwrap().tip_time() } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index cea453e1..b79b2eff 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -694,7 +694,12 @@ impl DaemonControl { pub fn start_rescan(&self, timestamp: u32) -> Result<(), CommandError> { let mut db_conn = self.db.connection(); - if timestamp < MAINNET_GENESIS_TIME || timestamp >= self.bitcoin.tip_time() { + let future_timestamp = self + .bitcoin + .tip_time() + .map(|t| timestamp >= t) + .unwrap_or(false); + if timestamp < MAINNET_GENESIS_TIME || future_timestamp { return Err(CommandError::InsaneRescanTimestamp(timestamp)); } if db_conn.rescan_timestamp().is_some() || self.bitcoin.rescan_progress().is_some() { diff --git a/src/testutils.rs b/src/testutils.rs index c01b744d..ffc75a64 100644 --- a/src/testutils.rs +++ b/src/testutils.rs @@ -106,7 +106,7 @@ impl BitcoinInterface for DummyBitcoind { todo!() } - fn tip_time(&self) -> u32 { + fn tip_time(&self) -> Option { todo!() }