move scan in setup

This commit is contained in:
Riccardo Casatta 2021-06-03 15:10:31 +02:00
parent ab54a17eb7
commit 1639984b56
No known key found for this signature in database
GPG Key ID: FD986A969E450397

View File

@ -130,25 +130,12 @@ impl Blockchain for RpcBlockchain {
// https://bitcoindevkit.org/descriptors/#compatibility-matrix // https://bitcoindevkit.org/descriptors/#compatibility-matrix
//TODO maybe convenient using import_descriptor for compatible descriptor and import_multi as fallback //TODO maybe convenient using import_descriptor for compatible descriptor and import_multi as fallback
self.client.import_multi(&requests, Some(&options))?; self.client.import_multi(&requests, Some(&options))?;
self.sync(stop_gap, database, progress_update)
}
fn sync<D: BatchDatabase, P: 'static + Progress>(
&self,
_stop_gap: Option<usize>,
db: &mut D,
progress_update: P,
) -> Result<(), Error> {
let current_height = self.get_height()?; let current_height = self.get_height()?;
// min because block invalidate may cause height to go down // min because block invalidate may cause height to go down
let node_synced = self.get_node_synced_height()?.min(current_height); 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 //TODO call rescan in chunks (updating node_synced_height) so that in case of
// interruption work can be partially recovered // interruption work can be partially recovered
debug!( debug!(
@ -159,6 +146,22 @@ impl Blockchain for RpcBlockchain {
.rescan_blockchain(Some(node_synced as usize), Some(current_height as usize))?; .rescan_blockchain(Some(node_synced as usize), Some(current_height as usize))?;
progress_update.update(1.0, None)?; progress_update.update(1.0, None)?;
self.set_node_synced_height(current_height)?;
self.sync(stop_gap, database, progress_update)
}
fn sync<D: BatchDatabase, P: 'static + Progress>(
&self,
_stop_gap: Option<usize>,
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 let mut known_txs: HashMap<_, _> = db
.iter_txs(true)? .iter_txs(true)?
.into_iter() .into_iter()
@ -275,7 +278,6 @@ impl Blockchain for RpcBlockchain {
db.set_last_index(keykind, index)?; db.set_last_index(keykind, index)?;
} }
self.set_node_synced_height(current_height)?;
Ok(()) Ok(())
} }