diff --git a/src/blockchain/rpc.rs b/src/blockchain/rpc.rs index 32c2d82e..1c4c6cf6 100644 --- a/src/blockchain/rpc.rs +++ b/src/blockchain/rpc.rs @@ -130,25 +130,12 @@ impl Blockchain for RpcBlockchain { // https://bitcoindevkit.org/descriptors/#compatibility-matrix //TODO maybe convenient using import_descriptor for compatible descriptor and import_multi as fallback self.client.import_multi(&requests, Some(&options))?; - self.sync(stop_gap, database, progress_update) - } - fn sync( - &self, - _stop_gap: Option, - db: &mut D, - progress_update: P, - ) -> Result<(), Error> { let current_height = self.get_height()?; // min because block invalidate may cause height to go down let node_synced = self.get_node_synced_height()?.min(current_height); - let mut indexes = HashMap::new(); - for keykind in &[KeychainKind::External, KeychainKind::Internal] { - indexes.insert(*keykind, db.get_last_index(*keykind)?.unwrap_or(0)); - } - //TODO call rescan in chunks (updating node_synced_height) so that in case of // interruption work can be partially recovered debug!( @@ -159,6 +146,22 @@ impl Blockchain for RpcBlockchain { .rescan_blockchain(Some(node_synced as usize), Some(current_height as usize))?; progress_update.update(1.0, None)?; + self.set_node_synced_height(current_height)?; + + self.sync(stop_gap, database, progress_update) + } + + fn sync( + &self, + _stop_gap: Option, + db: &mut D, + _progress_update: P, + ) -> Result<(), Error> { + let mut indexes = HashMap::new(); + for keykind in &[KeychainKind::External, KeychainKind::Internal] { + indexes.insert(*keykind, db.get_last_index(*keykind)?.unwrap_or(0)); + } + let mut known_txs: HashMap<_, _> = db .iter_txs(true)? .into_iter() @@ -275,7 +278,6 @@ impl Blockchain for RpcBlockchain { db.set_last_index(keykind, index)?; } - self.set_node_synced_height(current_height)?; Ok(()) }