commands: check if the Bitcoin backend is already rescanning

This is racy, but good enough for now.
This commit is contained in:
Antoine Poinsot 2022-11-12 15:38:59 +01:00
parent 8a22f5e8c9
commit 4a7fd1af29
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304

View File

@ -511,13 +511,16 @@ impl DaemonControl {
pub fn start_rescan(&self, timestamp: u32) -> Result<(), CommandError> {
let mut db_conn = self.db.connection();
if db_conn.rescan_timestamp().is_some() {
return Err(CommandError::AlreadyRescanning);
}
if timestamp < MAINNET_GENESIS_TIME || timestamp >= self.bitcoin.tip_time() {
return Err(CommandError::InsaneRescanTimestamp(timestamp));
}
if db_conn.rescan_timestamp().is_some() || self.bitcoin.rescan_progress().is_some() {
return Err(CommandError::AlreadyRescanning);
}
// TODO: there is a race with the above check for whether the backend is already
// rescanning. This could make us crash with the bitcoind backend if someone triggered a
// rescan of the wallet just after we checked above and did now.
self.bitcoin
.start_rescan(&self.config.main_descriptor, timestamp);
db_conn.set_rescan(timestamp);