Progress report
This commit is contained in:
parent
f27283c521
commit
6e95f609ea
17
src/scan.rs
17
src/scan.rs
|
@ -82,7 +82,7 @@ pub async fn sync_async<'a>(
|
||||||
get_tx: bool, // TODO
|
get_tx: bool, // TODO
|
||||||
target_height_offset: u32,
|
target_height_offset: u32,
|
||||||
max_cost: u32,
|
max_cost: u32,
|
||||||
_progress_callback: AMProgressCallback, // TODO
|
progress_callback: AMProgressCallback, // TODO
|
||||||
cancel: &'static std::sync::Mutex<bool>,
|
cancel: &'static std::sync::Mutex<bool>,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let c = CoinConfig::get(coin);
|
let c = CoinConfig::get(coin);
|
||||||
|
@ -127,6 +127,12 @@ pub async fn sync_async<'a>(
|
||||||
coin_type: c.coin_type,
|
coin_type: c.coin_type,
|
||||||
db_path: db_path.clone(),
|
db_path: db_path.clone(),
|
||||||
};
|
};
|
||||||
|
let mut progress = Progress {
|
||||||
|
height: 0,
|
||||||
|
trial_decryptions: 0,
|
||||||
|
downloaded: 0,
|
||||||
|
};
|
||||||
|
|
||||||
while let Some(blocks) = blocks_rx.recv().await {
|
while let Some(blocks) = blocks_rx.recv().await {
|
||||||
let first_block = blocks.0.first().unwrap(); // cannot be empty because blocks are not
|
let first_block = blocks.0.first().unwrap(); // cannot be empty because blocks are not
|
||||||
log::info!("Height: {}", first_block.height);
|
log::info!("Height: {}", first_block.height);
|
||||||
|
@ -135,6 +141,9 @@ pub async fn sync_async<'a>(
|
||||||
let last_height = last_block.height as u32;
|
let last_height = last_block.height as u32;
|
||||||
let last_timestamp = last_block.time;
|
let last_timestamp = last_block.time;
|
||||||
|
|
||||||
|
progress.downloaded += blocks.1;
|
||||||
|
progress.height = last_height;
|
||||||
|
|
||||||
// Sapling
|
// Sapling
|
||||||
log::info!("Sapling");
|
log::info!("Sapling");
|
||||||
{
|
{
|
||||||
|
@ -148,7 +157,7 @@ pub async fn sync_async<'a>(
|
||||||
"sapling".to_string(),
|
"sapling".to_string(),
|
||||||
);
|
);
|
||||||
synchronizer.initialize(height)?;
|
synchronizer.initialize(height)?;
|
||||||
synchronizer.process(&blocks.0)?;
|
progress.trial_decryptions += synchronizer.process(&blocks.0)? as u64;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Orchard
|
// Orchard
|
||||||
|
@ -164,12 +173,14 @@ pub async fn sync_async<'a>(
|
||||||
"orchard".to_string(),
|
"orchard".to_string(),
|
||||||
);
|
);
|
||||||
synchronizer.initialize(height)?;
|
synchronizer.initialize(height)?;
|
||||||
synchronizer.process(&blocks.0)?;
|
progress.trial_decryptions += synchronizer.process(&blocks.0)? as u64;
|
||||||
}
|
}
|
||||||
|
|
||||||
let db = db_builder.build()?;
|
let db = db_builder.build()?;
|
||||||
db.store_block_timestamp(last_height, &last_hash, last_timestamp)?;
|
db.store_block_timestamp(last_height, &last_hash, last_timestamp)?;
|
||||||
height = last_height;
|
height = last_height;
|
||||||
|
let cb = progress_callback.lock().await;
|
||||||
|
cb(progress.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
if get_tx {
|
if get_tx {
|
||||||
|
|
11
src/sync.rs
11
src/sync.rs
|
@ -84,15 +84,20 @@ impl<
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process(&mut self, blocks: &[CompactBlock]) -> Result<()> {
|
pub fn process(&mut self, blocks: &[CompactBlock]) -> Result<usize> {
|
||||||
if blocks.is_empty() {
|
if blocks.is_empty() {
|
||||||
return Ok(());
|
return Ok(0);
|
||||||
}
|
}
|
||||||
let decrypter = self.decrypter.clone();
|
let decrypter = self.decrypter.clone();
|
||||||
let decrypted_blocks: Vec<_> = blocks
|
let decrypted_blocks: Vec<_> = blocks
|
||||||
.par_iter()
|
.par_iter()
|
||||||
.map(|b| decrypter.decrypt_notes(b, &self.vks))
|
.map(|b| decrypter.decrypt_notes(b, &self.vks))
|
||||||
.collect();
|
.collect();
|
||||||
|
let count_outputs: usize = decrypted_blocks
|
||||||
|
.iter()
|
||||||
|
.map(|b| b.count_outputs)
|
||||||
|
.sum::<u32>() as usize;
|
||||||
|
|
||||||
let mut db = self.db.build()?;
|
let mut db = self.db.build()?;
|
||||||
self.warper.initialize(&self.tree, &self.witnesses);
|
self.warper.initialize(&self.tree, &self.witnesses);
|
||||||
let db_tx = db.begin_transaction()?;
|
let db_tx = db.begin_transaction()?;
|
||||||
|
@ -179,7 +184,7 @@ impl<
|
||||||
self.witnesses = updated_witnesses;
|
self.witnesses = updated_witnesses;
|
||||||
|
|
||||||
db_tx.commit()?;
|
db_tx.commit()?;
|
||||||
Ok(())
|
Ok(count_outputs * self.vks.len())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue