Restore progresscounter.

This commit is contained in:
Kris Nuttycombe 2021-06-01 08:53:53 -06:00
parent 3770e5de8b
commit c872f39547
2 changed files with 30 additions and 2 deletions

View File

@ -83,7 +83,7 @@ pub struct Progress {
}
impl Progress {
fn new(cur: u32, end: Option<u32>) -> Self {
pub fn new(cur: u32, end: Option<u32>) -> Self {
Self { cur, end }
}
@ -312,6 +312,7 @@ impl<'a, P: consensus::Parameters, R: RngCore> Builder<'a, P, R> {
&mut ctx,
&mut self.rng,
self.target_height,
self.progress_notifier.as_ref(),
)
.map_err(Error::SaplingBuildError)?;

View File

@ -2,6 +2,7 @@
use std::fmt;
use std::marker::PhantomData;
use std::sync::mpsc::Sender;
use ff::Field;
use rand::{seq::SliceRandom, CryptoRng, RngCore};
@ -19,7 +20,10 @@ use crate::{
util::generate_random_rseed_internal,
Diversifier, Node, Note, PaymentAddress,
},
transaction::components::{amount::Amount, OutputDescription, SpendDescription},
transaction::{
builder::Progress,
components::{amount::Amount, OutputDescription, SpendDescription},
},
zip32::ExtendedSpendingKey,
};
@ -314,6 +318,7 @@ impl<P: consensus::Parameters> SaplingBuilder<P> {
ctx: &mut Pr::SaplingProvingContext,
mut rng: R,
target_height: BlockHeight,
progress_notifier: Option<&Sender<Progress>>,
) -> Result<
(
Vec<SpendDescription>,
@ -348,6 +353,10 @@ impl<P: consensus::Parameters> SaplingBuilder<P> {
indexed_spends.shuffle(&mut rng);
indexed_outputs.shuffle(&mut rng);
// Keep track of the total number of steps computed
let total_progress = indexed_spends.len() as u32 + indexed_outputs.len() as u32;
let mut progress = 0u32;
// Create Sapling SpendDescriptions
let spend_descs = if !indexed_spends.is_empty() {
let anchor = self
@ -381,6 +390,15 @@ impl<P: consensus::Parameters> SaplingBuilder<P> {
// Record the post-randomized spend location
tx_metadata.spend_indices[*pos] = i;
// Update progress and send a notification on the channel
progress += 1;
if let Some(sender) = progress_notifier {
// If the send fails, we should ignore the error, not crash.
sender
.send(Progress::new(progress, Some(total_progress)))
.unwrap_or(());
}
Ok(SpendDescription {
cv,
anchor,
@ -457,6 +475,15 @@ impl<P: consensus::Parameters> SaplingBuilder<P> {
rng.fill_bytes(&mut enc_ciphertext[..]);
rng.fill_bytes(&mut out_ciphertext[..]);
// Update progress and send a notification on the channel
progress += 1;
if let Some(sender) = progress_notifier {
// If the send fails, we should ignore the error, not crash.
sender
.send(Progress::new(progress, Some(total_progress)))
.unwrap_or(());
}
OutputDescription {
cv,
cmu,