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

Methodify witness trees #927

Merged
merged 4 commits into from
Apr 10, 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
35 changes: 12 additions & 23 deletions integration-tests/tests/integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,7 @@ mod slow {
.transaction_metadata_set
.read()
.await
.witness_trees
.as_ref()
.witness_trees()
.unwrap()
.witness_tree_orchard
.marked_positions()
Expand Down Expand Up @@ -811,8 +810,7 @@ mod slow {
.transaction_metadata_set
.read()
.await
.witness_trees
.as_ref()
.witness_trees()
.unwrap()
.witness_tree_orchard
.marked_positions()
Expand All @@ -825,8 +823,7 @@ mod slow {
.transaction_metadata_set
.read()
.await
.witness_trees
.as_ref()
.witness_trees()
.unwrap()
.witness_tree_orchard
);
Expand Down Expand Up @@ -854,8 +851,7 @@ mod slow {
.transaction_metadata_set
.read()
.await
.witness_trees
.as_ref()
.witness_trees()
.unwrap()
.witness_tree_orchard
.marked_positions()
Expand Down Expand Up @@ -887,8 +883,7 @@ mod slow {
.transaction_metadata_set
.read()
.await
.witness_trees
.as_ref()
.witness_trees()
.unwrap()
.witness_tree_orchard
);
Expand All @@ -898,8 +893,7 @@ mod slow {
.transaction_metadata_set
.read()
.await
.witness_trees
.as_ref()
.witness_trees()
.unwrap()
.witness_tree_orchard
.marked_positions()
Expand Down Expand Up @@ -2128,8 +2122,7 @@ mod slow {
.transaction_metadata_set
.read()
.await
.witness_trees
.as_ref()
.witness_trees()
.unwrap()
.witness_tree_orchard
.max_leaf_position(0),
Expand All @@ -2139,8 +2132,7 @@ mod slow {
.transaction_metadata_set
.read()
.await
.witness_trees
.as_ref()
.witness_trees()
.unwrap()
.witness_tree_orchard
.max_leaf_position(0)
Expand Down Expand Up @@ -2477,8 +2469,7 @@ mod slow {
.transaction_metadata_set
.read()
.await
.witness_trees
.as_ref()
.witness_trees()
.unwrap()
.witness_tree_orchard
);
Expand Down Expand Up @@ -2595,7 +2586,7 @@ mod slow {
.transaction_metadata_set
.read()
.await;
let wallet_trees = read_lock.witness_trees.as_ref().unwrap();
let wallet_trees = read_lock.witness_trees().unwrap();
let last_leaf = wallet_trees
.witness_tree_orchard
.max_leaf_position(0)
Expand Down Expand Up @@ -3300,8 +3291,7 @@ mod slow {
.transaction_metadata_set
.read()
.await
.witness_trees
.as_ref()
.witness_trees()
.unwrap()
.witness_tree_orchard
.witness_at_checkpoint_depth(
Expand Down Expand Up @@ -3340,8 +3330,7 @@ mod slow {
.transaction_metadata_set
.read()
.await
.witness_trees
.as_ref()
.witness_trees()
.unwrap()
.witness_tree_orchard
.witness_at_checkpoint_depth(
Expand Down
3 changes: 1 addition & 2 deletions zingolib/src/wallet/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ impl LightWallet {
.read()
.await;
let witness_trees = txmds_readlock
.witness_trees
.as_ref()
.witness_trees()
.ok_or("No spend capability.")?;
let (tx_builder, total_shielded_receivers) = match self
.create_and_populate_tx_builder(
Expand Down
6 changes: 2 additions & 4 deletions zingolib/src/wallet/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,16 +455,14 @@ where
txmds: &TxMapAndMaybeTrees,
) -> Option<&MemoryStoreShardTree<<Self::WalletNote as ShieldedNoteInterface>::Node>> {
txmds
.witness_trees
.as_ref()
.witness_trees()
.map(|trees| Self::get_shardtree(trees))
}
fn transaction_metadata_set_to_shardtree_mut(
txmds: &mut TxMapAndMaybeTrees,
) -> Option<&mut MemoryStoreShardTree<<Self::WalletNote as ShieldedNoteInterface>::Node>> {
txmds
.witness_trees
.as_mut()
.witness_trees_mut()
.map(|trees| Self::get_shardtree_mut(trees))
}
fn get_shardtree(
Expand Down
8 changes: 7 additions & 1 deletion zingolib/src/wallet/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::wallet::{data::WitnessTrees, transaction_records_by_id::TransactionRe
/// this struct are threadsafe/locked properly.
pub struct TxMapAndMaybeTrees {
pub transaction_records_by_id: TransactionRecordsById,
pub witness_trees: Option<WitnessTrees>,
witness_trees: Option<WitnessTrees>,
zancas marked this conversation as resolved.
Show resolved Hide resolved
}

pub mod get;
Expand All @@ -27,6 +27,12 @@ impl TxMapAndMaybeTrees {
witness_trees: None,
}
}
pub fn witness_trees(&self) -> Option<&WitnessTrees> {
zancas marked this conversation as resolved.
Show resolved Hide resolved
self.witness_trees.as_ref()
}
pub(crate) fn witness_trees_mut(&mut self) -> Option<&mut WitnessTrees> {
self.witness_trees.as_mut()
}
pub fn clear(&mut self) {
self.transaction_records_by_id.clear();
self.witness_trees.as_mut().map(WitnessTrees::clear);
Expand Down
7 changes: 3 additions & 4 deletions zingolib/src/wallet/witnesses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl LightWallet {
.transaction_metadata_set
.write()
.await
.witness_trees
.witness_trees_mut()
{
trees.insert_all_frontier_nodes(legacy_sapling_frontier, legacy_orchard_frontier)
};
Expand All @@ -25,7 +25,7 @@ impl LightWallet {
.transaction_metadata_set
.write()
.await;
if let Some(ref mut trees) = txmds_writelock.witness_trees {
if let Some(ref mut trees) = txmds_writelock.witness_trees_mut() {
trees
.witness_tree_sapling
.truncate_removing_checkpoint(&BlockHeight::from(last_synced_height as u32))
Expand All @@ -43,8 +43,7 @@ impl LightWallet {
.transaction_metadata_set
.read()
.await
.witness_trees
.as_ref()
.witness_trees()
.is_some_and(|trees| {
trees
.witness_tree_orchard
Expand Down