Skip to content

Commit

Permalink
zcash_client_backend: Add Orchard frontier to AccountBirthday
Browse files Browse the repository at this point in the history
  • Loading branch information
nuttycom committed Mar 7, 2024
1 parent 8130359 commit 4532520
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
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 @@ impl<AccountId> SentTransactionOutput<AccountId> {
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 }>,
recover_until: Option<BlockHeight>,
}

Expand Down Expand Up @@ -1002,11 +1005,17 @@ impl AccountBirthday {
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 @@ impl AccountBirthday {
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(),
recover_until,
})
}
Expand All @@ -1040,6 +1051,16 @@ impl AccountBirthday {
&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 @@ impl AccountBirthday {
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

0 comments on commit 4532520

Please sign in to comment.