Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zcash_client_backend: Add Orchard frontier to AccountBirthday #1232

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions zcash_client_backend/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this library adheres to Rust's notion of
flag.
- `zcash_client_backend::data_api`:
- `AccountBalance::with_orchard_balance_mut`
- `AccountBirthday::orchard_frontier`
- `BlockMetadata::orchard_tree_size`
- `ScannedBlock::orchard`
- `ScannedBlockCommitments::orchard`
Expand Down Expand Up @@ -41,6 +42,7 @@ and this library adheres to Rust's notion of

### Changed
- `zcash_client_backend::data_api`:
- Arguments to `AccountBirthday::from_parts` have changed.
- Arguments to `BlockMetadata::from_parts` have changed.
- Arguments to `ScannedBlock::from_parts` have changed.
- Changes to the `WalletRead` trait:
Expand Down
23 changes: 23 additions & 0 deletions zcash_client_backend/src/data_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,9 @@
pub struct AccountBirthday {
height: BlockHeight,
sapling_frontier: Frontier<sapling::Node, { sapling::NOTE_COMMITMENT_TREE_DEPTH }>,
#[cfg(feature = "orchard")]
orchard_frontier:
Frontier<orchard::tree::MerkleHashOrchard, { orchard::NOTE_COMMITMENT_TREE_DEPTH as u8 }>,
Comment on lines 963 to +966
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking suggestion: add SaplingFrontier and OrchardFrontier type aliases.

recover_until: Option<BlockHeight>,
}

Expand Down Expand Up @@ -1002,11 +1005,17 @@
pub fn from_parts(
height: BlockHeight,
sapling_frontier: Frontier<sapling::Node, { sapling::NOTE_COMMITMENT_TREE_DEPTH }>,
#[cfg(feature = "orchard")] orchard_frontier: Frontier<
orchard::tree::MerkleHashOrchard,
{ orchard::NOTE_COMMITMENT_TREE_DEPTH as u8 },
>,
recover_until: Option<BlockHeight>,
) -> Self {
Self {
height,
sapling_frontier,
#[cfg(feature = "orchard")]
orchard_frontier,
recover_until,
}
}
Expand All @@ -1028,6 +1037,8 @@
Ok(Self {
height: BlockHeight::try_from(treestate.height + 1)?,
sapling_frontier: treestate.sapling_tree()?.to_frontier(),
#[cfg(feature = "orchard")]
orchard_frontier: treestate.orchard_tree()?.to_frontier(),

Check warning on line 1041 in zcash_client_backend/src/data_api.rs

View check run for this annotation

Codecov / codecov/patch

zcash_client_backend/src/data_api.rs#L1040-L1041

Added lines #L1040 - L1041 were not covered by tests
recover_until,
})
}
Expand All @@ -1040,6 +1051,16 @@
&self.sapling_frontier
}

/// Returns the Orchard note commitment tree frontier as of the end of the block at
/// [`Self::height`].
#[cfg(feature = "orchard")]
pub fn orchard_frontier(
&self,
) -> &Frontier<orchard::tree::MerkleHashOrchard, { orchard::NOTE_COMMITMENT_TREE_DEPTH as u8 }>
{
&self.orchard_frontier
}

/// Returns the birthday height of the account.
pub fn height(&self) -> BlockHeight {
self.height
Expand All @@ -1065,6 +1086,8 @@
AccountBirthday::from_parts(
params.activation_height(NetworkUpgrade::Sapling).unwrap(),
Frontier::empty(),
#[cfg(feature = "orchard")]
Frontier::empty(),
None,
)
}
Expand Down
16 changes: 14 additions & 2 deletions zcash_client_sqlite/src/wallet/scanning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,13 @@ pub(crate) mod tests {
vec![Node::empty_leaf(); frontier_position.past_ommer_count().into()],
)
.unwrap();
AccountBirthday::from_parts(birthday_height, frontier, None)
AccountBirthday::from_parts(
birthday_height,
frontier,
#[cfg(feature = "orchard")]
Frontier::empty(),
None,
)
})
.build();

Expand Down Expand Up @@ -717,7 +723,13 @@ pub(crate) mod tests {
st.wallet_mut()
.create_account(
&SecretVec::new(vec![0; 32]),
AccountBirthday::from_parts(wallet_birthday, Frontier::empty(), None),
AccountBirthday::from_parts(
wallet_birthday,
Frontier::empty(),
#[cfg(feature = "orchard")]
Frontier::empty(),
None,
),
)
.unwrap();

Expand Down
Loading