From 568b496c0751729686aa81fdfa52a260ff16ac56 Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Wed, 10 Apr 2024 21:58:29 +0000 Subject: [PATCH 1/2] swapped witness trees to a private field with a method for public access --- zingolib/src/wallet/send.rs | 3 +-- zingolib/src/wallet/traits.rs | 6 ++---- zingolib/src/wallet/transactions.rs | 8 +++++++- zingolib/src/wallet/witnesses.rs | 7 +++---- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/zingolib/src/wallet/send.rs b/zingolib/src/wallet/send.rs index 8a014022d..aaf25804a 100644 --- a/zingolib/src/wallet/send.rs +++ b/zingolib/src/wallet/send.rs @@ -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( diff --git a/zingolib/src/wallet/traits.rs b/zingolib/src/wallet/traits.rs index 713e4b8cf..bdd9c1612 100644 --- a/zingolib/src/wallet/traits.rs +++ b/zingolib/src/wallet/traits.rs @@ -455,16 +455,14 @@ where txmds: &TxMapAndMaybeTrees, ) -> Option<&MemoryStoreShardTree<::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<::Node>> { txmds - .witness_trees - .as_mut() + .witness_trees_mut() .map(|trees| Self::get_shardtree_mut(trees)) } fn get_shardtree( diff --git a/zingolib/src/wallet/transactions.rs b/zingolib/src/wallet/transactions.rs index ae06f3959..87edd795c 100644 --- a/zingolib/src/wallet/transactions.rs +++ b/zingolib/src/wallet/transactions.rs @@ -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, + witness_trees: Option, } pub mod get; @@ -27,6 +27,12 @@ impl TxMapAndMaybeTrees { witness_trees: None, } } + pub(crate) fn witness_trees(&self) -> Option<&WitnessTrees> { + 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); diff --git a/zingolib/src/wallet/witnesses.rs b/zingolib/src/wallet/witnesses.rs index a433f6491..531677051 100644 --- a/zingolib/src/wallet/witnesses.rs +++ b/zingolib/src/wallet/witnesses.rs @@ -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) }; @@ -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)) @@ -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 From e37fa614a7b1468233ad79fd71e61170ca8821f3 Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Wed, 10 Apr 2024 22:04:39 +0000 Subject: [PATCH 2/2] and updated tests --- integration-tests/tests/integrations.rs | 35 +++++++++---------------- zingolib/src/wallet/transactions.rs | 2 +- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/integration-tests/tests/integrations.rs b/integration-tests/tests/integrations.rs index 701ec7a3e..5a6c55167 100644 --- a/integration-tests/tests/integrations.rs +++ b/integration-tests/tests/integrations.rs @@ -778,8 +778,7 @@ mod slow { .transaction_metadata_set .read() .await - .witness_trees - .as_ref() + .witness_trees() .unwrap() .witness_tree_orchard .marked_positions() @@ -811,8 +810,7 @@ mod slow { .transaction_metadata_set .read() .await - .witness_trees - .as_ref() + .witness_trees() .unwrap() .witness_tree_orchard .marked_positions() @@ -825,8 +823,7 @@ mod slow { .transaction_metadata_set .read() .await - .witness_trees - .as_ref() + .witness_trees() .unwrap() .witness_tree_orchard ); @@ -854,8 +851,7 @@ mod slow { .transaction_metadata_set .read() .await - .witness_trees - .as_ref() + .witness_trees() .unwrap() .witness_tree_orchard .marked_positions() @@ -887,8 +883,7 @@ mod slow { .transaction_metadata_set .read() .await - .witness_trees - .as_ref() + .witness_trees() .unwrap() .witness_tree_orchard ); @@ -898,8 +893,7 @@ mod slow { .transaction_metadata_set .read() .await - .witness_trees - .as_ref() + .witness_trees() .unwrap() .witness_tree_orchard .marked_positions() @@ -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), @@ -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) @@ -2477,8 +2469,7 @@ mod slow { .transaction_metadata_set .read() .await - .witness_trees - .as_ref() + .witness_trees() .unwrap() .witness_tree_orchard ); @@ -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) @@ -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( @@ -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( diff --git a/zingolib/src/wallet/transactions.rs b/zingolib/src/wallet/transactions.rs index 87edd795c..60fc05d4d 100644 --- a/zingolib/src/wallet/transactions.rs +++ b/zingolib/src/wallet/transactions.rs @@ -27,7 +27,7 @@ impl TxMapAndMaybeTrees { witness_trees: None, } } - pub(crate) fn witness_trees(&self) -> Option<&WitnessTrees> { + pub fn witness_trees(&self) -> Option<&WitnessTrees> { self.witness_trees.as_ref() } pub(crate) fn witness_trees_mut(&mut self) -> Option<&mut WitnessTrees> {