Skip to content

Commit 8b5236a

Browse files
authored
Merge pull request #1541 from zcash/1070-zcb-wallet-summary-progress
Improve progress representation in `WalletSummary`
2 parents 4b3bc8f + b4da98e commit 8b5236a

File tree

6 files changed

+572
-206
lines changed

6 files changed

+572
-206
lines changed

zcash_client_backend/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@ and this library adheres to Rust's notion of
77

88
## [Unreleased]
99

10+
### Added
11+
- `zcash_client_backend::data_api`:
12+
- `WalletSummary::recovery_progress`
13+
1014
### Changed
1115
- The `Account` trait now uses an associated type for its `AccountId`
1216
type instead of a type parameter. This change allows for the simplification
1317
of some type signatures.
18+
- `zcash_client_backend::data_api`:
19+
- `WalletSummary::scan_progress` now only reports progress for scanning blocks
20+
"near" the chain tip. Progress for scanning earlier blocks is now reported
21+
via `WalletSummary::recovery_progress`.
1422
- `zcash_client_backend::sync::run`:
1523
- Transparent outputs are now refreshed in addition to shielded notes.
1624

zcash_client_backend/src/data_api.rs

+39-5
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ pub struct WalletSummary<AccountId: Eq + Hash> {
471471
chain_tip_height: BlockHeight,
472472
fully_scanned_height: BlockHeight,
473473
scan_progress: Option<Ratio<u64>>,
474+
recovery_progress: Option<Ratio<u64>>,
474475
next_sapling_subtree_index: u64,
475476
#[cfg(feature = "orchard")]
476477
next_orchard_subtree_index: u64,
@@ -483,6 +484,7 @@ impl<AccountId: Eq + Hash> WalletSummary<AccountId> {
483484
chain_tip_height: BlockHeight,
484485
fully_scanned_height: BlockHeight,
485486
scan_progress: Option<Ratio<u64>>,
487+
recovery_progress: Option<Ratio<u64>>,
486488
next_sapling_subtree_index: u64,
487489
#[cfg(feature = "orchard")] next_orchard_subtree_index: u64,
488490
) -> Self {
@@ -491,6 +493,7 @@ impl<AccountId: Eq + Hash> WalletSummary<AccountId> {
491493
chain_tip_height,
492494
fully_scanned_height,
493495
scan_progress,
496+
recovery_progress,
494497
next_sapling_subtree_index,
495498
#[cfg(feature = "orchard")]
496499
next_orchard_subtree_index,
@@ -513,16 +516,47 @@ impl<AccountId: Eq + Hash> WalletSummary<AccountId> {
513516
self.fully_scanned_height
514517
}
515518

516-
/// Returns the progress of scanning shielded outputs, in terms of the ratio between notes
517-
/// scanned and the total number of notes added to the chain since the wallet birthday.
519+
/// Returns the progress of scanning the chain to bring the wallet up to date.
518520
///
519-
/// This ratio should only be used to compute progress percentages, and the numerator and
520-
/// denominator should not be treated as authoritative note counts. Returns `None` if the
521-
/// wallet is unable to determine the size of the note commitment tree.
521+
/// This progress metric is intended as an indicator of how close the wallet is to
522+
/// general usability, including the ability to spend existing funds that were
523+
/// previously spendable.
524+
///
525+
/// The window over which progress is computed spans from the wallet's recovery height
526+
/// to the current chain tip. This may be adjusted in future updates to better match
527+
/// the intended semantics.
528+
///
529+
/// Progress is represented in terms of the ratio between notes scanned and the total
530+
/// number of notes added to the chain in the relevant window. This ratio should only
531+
/// be used to compute progress percentages, and the numerator and denominator should
532+
/// not be treated as authoritative note counts.
533+
///
534+
/// Returns `None` if the wallet is unable to determine the size of the note
535+
/// commitment tree.
522536
pub fn scan_progress(&self) -> Option<Ratio<u64>> {
523537
self.scan_progress
524538
}
525539

540+
/// Returns the progress of recovering the wallet from seed.
541+
///
542+
/// This progress metric is intended as an indicator of how close the wallet is to
543+
/// having a complete history.
544+
///
545+
/// The window over which progress is computed spans from the wallet birthday to the
546+
/// wallet's recovery height. This may be adjusted in future updates to better match
547+
/// the intended semantics.
548+
///
549+
/// Progress is represented in terms of the ratio between notes scanned and the total
550+
/// number of notes added to the chain in the relevant window. This ratio should only
551+
/// be used to compute progress percentages, and the numerator and denominator should
552+
/// not be treated as authoritative note counts.
553+
///
554+
/// Returns `None` if the wallet is unable to determine the size of the note
555+
/// commitment tree.
556+
pub fn recovery_progress(&self) -> Option<Ratio<u64>> {
557+
self.recovery_progress
558+
}
559+
526560
/// Returns the Sapling subtree index that should start the next range of subtree
527561
/// roots passed to [`WalletCommitmentTrees::put_sapling_subtree_roots`].
528562
pub fn next_sapling_subtree_index(&self) -> u64 {

zcash_client_sqlite/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ use zip32::fingerprint::SeedFingerprint;
7474

7575
use crate::{error::SqliteClientError, wallet::commitment_tree::SqliteShardStore};
7676

77-
#[cfg(any(feature = "test-dependencies", not(feature = "orchard")))]
77+
#[cfg(any(test, feature = "test-dependencies", not(feature = "orchard")))]
7878
use zcash_protocol::PoolType;
7979

8080
#[cfg(feature = "orchard")]

zcash_client_sqlite/src/testing/pool.rs

+17
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,21 @@ pub(crate) fn spend_fails_on_unverified_notes<T: ShieldedPoolTester>() {
686686
NonNegativeAmount::ZERO
687687
);
688688

689+
// The account is configured without a recover-until height, so is by definition
690+
// fully recovered, and we count 1 per pool for both numerator and denominator.
691+
let fully_recovered = {
692+
let n = 1;
693+
#[cfg(feature = "orchard")]
694+
let n = n * 2;
695+
Some(Ratio::new(n, n))
696+
};
697+
689698
// Wallet is fully scanned
690699
let summary = st.get_wallet_summary(1);
700+
assert_eq!(
701+
summary.as_ref().and_then(|s| s.recovery_progress()),
702+
fully_recovered,
703+
);
691704
assert_eq!(
692705
summary.and_then(|s| s.scan_progress()),
693706
Some(Ratio::new(1, 1))
@@ -705,6 +718,10 @@ pub(crate) fn spend_fails_on_unverified_notes<T: ShieldedPoolTester>() {
705718

706719
// Wallet is still fully scanned
707720
let summary = st.get_wallet_summary(1);
721+
assert_eq!(
722+
summary.as_ref().and_then(|s| s.recovery_progress()),
723+
fully_recovered
724+
);
708725
assert_eq!(
709726
summary.and_then(|s| s.scan_progress()),
710727
Some(Ratio::new(2, 2))

0 commit comments

Comments
 (0)