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

created TxMapAndMaybeTrees #886

Merged
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
14 changes: 7 additions & 7 deletions zingolib/src/blaze/block_management_reorg_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::wallet::{
data::{BlockData, PoolNullifier},
notes::ShieldedNoteInterface,
traits::DomainWalletExt,
transactions::TransactionMetadataSet,
transactions::TxMapAndMaybeTrees,
};
use incrementalmerkletree::frontier::CommitmentTree;
use incrementalmerkletree::{frontier, witness::IncrementalWitness, Hashable};
Expand Down Expand Up @@ -317,7 +317,7 @@ impl BlockManagementData {
pub async fn invalidate_block(
reorg_height: u64,
existing_blocks: Arc<RwLock<Vec<BlockData>>>,
transaction_metadata_set: Arc<RwLock<TransactionMetadataSet>>,
transaction_metadata_set: Arc<RwLock<TxMapAndMaybeTrees>>,
) {
let mut existing_blocks_writelock = existing_blocks.write().await;
if existing_blocks_writelock.len() != 0 {
Expand All @@ -343,7 +343,7 @@ impl BlockManagementData {
&self,
start_block: u64,
end_block: u64,
transaction_metadata_set: Arc<RwLock<TransactionMetadataSet>>,
transaction_metadata_set: Arc<RwLock<TxMapAndMaybeTrees>>,
reorg_transmitter: UnboundedSender<Option<u64>>,
) -> (
JoinHandle<Result<Option<u64>, String>>,
Expand Down Expand Up @@ -589,7 +589,7 @@ struct BlockManagementThreadData {
impl BlockManagementThreadData {
async fn handle_reorgs_populate_data_inner(
mut self,
transaction_metadata_set: Arc<RwLock<TransactionMetadataSet>>,
transaction_metadata_set: Arc<RwLock<TxMapAndMaybeTrees>>,
reorg_transmitter: UnboundedSender<Option<u64>>,
) -> Result<Option<u64>, String> {
// Temporary holding place for blocks while we process them.
Expand Down Expand Up @@ -835,7 +835,7 @@ mod test {
.handle_reorgs_and_populate_block_mangement_data(
start_block,
end_block,
Arc::new(RwLock::new(TransactionMetadataSet::new_with_witness_trees())),
Arc::new(RwLock::new(TxMapAndMaybeTrees::new_with_witness_trees())),
reorg_transmitter,
)
.await;
Expand Down Expand Up @@ -884,7 +884,7 @@ mod test {
.handle_reorgs_and_populate_block_mangement_data(
start_block,
end_block,
Arc::new(RwLock::new(TransactionMetadataSet::new_with_witness_trees())),
Arc::new(RwLock::new(TxMapAndMaybeTrees::new_with_witness_trees())),
reorg_transmitter,
)
.await;
Expand Down Expand Up @@ -980,7 +980,7 @@ mod test {
.handle_reorgs_and_populate_block_mangement_data(
start_block,
end_block,
Arc::new(RwLock::new(TransactionMetadataSet::new_with_witness_trees())),
Arc::new(RwLock::new(TxMapAndMaybeTrees::new_with_witness_trees())),
reorg_transmitter,
)
.await;
Expand Down
12 changes: 6 additions & 6 deletions zingolib/src/blaze/trial_decryptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::wallet::{
data::PoolNullifier,
keys::unified::WalletCapability,
traits::{CompactOutput as _, DomainWalletExt, FromCommitment, Recipient},
transactions::TransactionMetadataSet,
transactions::TxMapAndMaybeTrees,
utils::txid_from_slice,
MemoDownloadOption,
};
Expand Down Expand Up @@ -41,15 +41,15 @@ use super::syncdata::BlazeSyncData;

pub struct TrialDecryptions {
wc: Arc<WalletCapability>,
transaction_metadata_set: Arc<RwLock<TransactionMetadataSet>>,
transaction_metadata_set: Arc<RwLock<TxMapAndMaybeTrees>>,
config: Arc<ZingoConfig>,
}

impl TrialDecryptions {
pub fn new(
config: Arc<ZingoConfig>,
wc: Arc<WalletCapability>,
transaction_metadata_set: Arc<RwLock<TransactionMetadataSet>>,
transaction_metadata_set: Arc<RwLock<TxMapAndMaybeTrees>>,
) -> Self {
Self {
config,
Expand Down Expand Up @@ -130,7 +130,7 @@ impl TrialDecryptions {
bsync_data: Arc<RwLock<BlazeSyncData>>,
sapling_ivk: Option<SaplingIvk>,
orchard_ivk: Option<OrchardIvk>,
transaction_metadata_set: Arc<RwLock<TransactionMetadataSet>>,
transaction_metadata_set: Arc<RwLock<TxMapAndMaybeTrees>>,
transaction_size_filter: Option<u32>,
detected_transaction_id_sender: UnboundedSender<(
TxId,
Expand Down Expand Up @@ -263,7 +263,7 @@ impl TrialDecryptions {
config: &zingoconfig::ZingoConfig,
wc: &Arc<WalletCapability>,
bsync_data: &Arc<RwLock<BlazeSyncData>>,
transaction_metadata_set: &Arc<RwLock<TransactionMetadataSet>>,
transaction_metadata_set: &Arc<RwLock<TxMapAndMaybeTrees>>,
detected_transaction_id_sender: &UnboundedSender<(
TxId,
PoolNullifier,
Expand Down Expand Up @@ -418,7 +418,7 @@ fn update_witnesses<D>(
)>,
BlockHeight,
)>,
txmds_writelock: &mut TransactionMetadataSet,
txmds_writelock: &mut TxMapAndMaybeTrees,
wc: &Arc<WalletCapability>,
) -> ZingoLibResult<()>
where
Expand Down
6 changes: 3 additions & 3 deletions zingolib/src/blaze/update_notes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::wallet::MemoDownloadOption;
use crate::wallet::{
data::PoolNullifier, transactions::TransactionMetadataSet, utils::txid_from_slice,
data::PoolNullifier, transactions::TxMapAndMaybeTrees, utils::txid_from_slice,
};
use std::sync::Arc;

Expand All @@ -27,11 +27,11 @@ use super::syncdata::BlazeSyncData;
/// If No, then:
/// - Update the witness for this note
pub struct UpdateNotes {
transaction_metadata_set: Arc<RwLock<TransactionMetadataSet>>,
transaction_metadata_set: Arc<RwLock<TxMapAndMaybeTrees>>,
}

impl UpdateNotes {
pub fn new(wallet_txns: Arc<RwLock<TransactionMetadataSet>>) -> Self {
pub fn new(wallet_txns: Arc<RwLock<TxMapAndMaybeTrees>>) -> Self {
Self {
transaction_metadata_set: wallet_txns,
}
Expand Down
12 changes: 6 additions & 6 deletions zingolib/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use self::{
data::{BlockData, WalletZecPriceInfo},
message::Message,
transaction_context::TransactionContext,
transactions::TransactionMetadataSet,
transactions::TxMapAndMaybeTrees,
};
use zingoconfig::ZingoConfig;

Expand Down Expand Up @@ -594,9 +594,9 @@ impl LightWallet {
));
};
let transaction_metadata_set = if wc.can_spend_from_all_pools() {
Arc::new(RwLock::new(TransactionMetadataSet::new_with_witness_trees()))
Arc::new(RwLock::new(TxMapAndMaybeTrees::new_with_witness_trees()))
} else {
Arc::new(RwLock::new(TransactionMetadataSet::new_treeless()))
Arc::new(RwLock::new(TxMapAndMaybeTrees::new_treeless()))
};
let transaction_context =
TransactionContext::new(&config, Arc::new(wc), transaction_metadata_set);
Expand Down Expand Up @@ -677,9 +677,9 @@ impl LightWallet {
}

let mut transactions = if external_version <= 14 {
TransactionMetadataSet::read_old(&mut reader, &wallet_capability)
TxMapAndMaybeTrees::read_old(&mut reader, &wallet_capability)
} else {
TransactionMetadataSet::read(&mut reader, &wallet_capability)
TxMapAndMaybeTrees::read(&mut reader, &wallet_capability)
}?;
let txids = transactions
.current
Expand Down Expand Up @@ -930,7 +930,7 @@ impl LightWallet {
}
}

pub fn transactions(&self) -> Arc<RwLock<TransactionMetadataSet>> {
pub fn transactions(&self) -> Arc<RwLock<TxMapAndMaybeTrees>> {
self.transaction_context.transaction_metadata_set.clone()
}

Expand Down
6 changes: 3 additions & 3 deletions zingolib/src/wallet/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::{
},
keys::unified::WalletCapability,
notes::{OrchardNote, SaplingNote},
transactions::TransactionMetadataSet,
transactions::TxMapAndMaybeTrees,
};
use crate::wallet::notes::NoteInterface;
use crate::wallet::notes::ShieldedNoteInterface;
Expand Down Expand Up @@ -450,15 +450,15 @@ where
.sum()
}
fn transaction_metadata_set_to_shardtree(
txmds: &TransactionMetadataSet,
txmds: &TxMapAndMaybeTrees,
) -> Option<&MemoryStoreShardTree<<Self::WalletNote as ShieldedNoteInterface>::Node>> {
txmds
.witness_trees
.as_ref()
.map(|trees| Self::get_shardtree(trees))
}
fn transaction_metadata_set_to_shardtree_mut(
txmds: &mut TransactionMetadataSet,
txmds: &mut TxMapAndMaybeTrees,
) -> Option<&mut MemoryStoreShardTree<<Self::WalletNote as ShieldedNoteInterface>::Node>> {
txmds
.witness_trees
Expand Down
6 changes: 3 additions & 3 deletions zingolib/src/wallet/transaction_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
self as zingo_traits, Bundle as _, DomainWalletExt, Recipient as _,
ShieldedOutputExt as _, Spend as _, ToBytes as _,
},
transactions::TransactionMetadataSet,
transactions::TxMapAndMaybeTrees,
},
};
use orchard::note_encryption::OrchardDomain;
Expand All @@ -29,14 +29,14 @@ use zingoconfig::ZingoConfig;
pub struct TransactionContext {
pub config: ZingoConfig,
pub(crate) key: Arc<WalletCapability>,
pub transaction_metadata_set: Arc<RwLock<TransactionMetadataSet>>,
pub transaction_metadata_set: Arc<RwLock<TxMapAndMaybeTrees>>,
}

impl TransactionContext {
pub fn new(
config: &ZingoConfig,
key: Arc<WalletCapability>,
transaction_metadata_set: Arc<RwLock<TransactionMetadataSet>>,
transaction_metadata_set: Arc<RwLock<TxMapAndMaybeTrees>>,
) -> Self {
Self {
config: config.clone(),
Expand Down
8 changes: 4 additions & 4 deletions zingolib/src/wallet/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::data::{TransactionRecord, WitnessTrees};
/// HashMap of all transactions in a wallet, keyed by txid.
/// Note that the parent is expected to hold a RwLock, so we will assume that all accesses to
/// this struct are threadsafe/locked properly.
pub struct TransactionMetadataSet {
pub struct TxMapAndMaybeTrees {
pub current: HashMap<TxId, TransactionRecord>,
pub witness_trees: Option<WitnessTrees>,
}
Expand All @@ -16,14 +16,14 @@ pub mod get;
pub mod read_write;
pub mod recording;

impl TransactionMetadataSet {
pub(crate) fn new_with_witness_trees() -> TransactionMetadataSet {
impl TxMapAndMaybeTrees {
pub(crate) fn new_with_witness_trees() -> TxMapAndMaybeTrees {
Self {
current: HashMap::default(),
witness_trees: Some(WitnessTrees::default()),
}
}
pub(crate) fn new_treeless() -> TransactionMetadataSet {
pub(crate) fn new_treeless() -> TxMapAndMaybeTrees {
Self {
current: HashMap::default(),
witness_trees: None,
Expand Down
8 changes: 4 additions & 4 deletions zingolib/src/wallet/transactions/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use crate::wallet::{
traits::{DomainWalletExt, Recipient},
};

use super::TransactionMetadataSet;
use super::TxMapAndMaybeTrees;

impl TransactionMetadataSet {
impl TxMapAndMaybeTrees {
pub fn get_notes_for_updating(
&self,
before_block: u64,
Expand Down Expand Up @@ -132,7 +132,7 @@ impl TransactionMetadataSet {

#[test]
fn test_get_some_txid_from_highest_wallet_block() {
let mut tms = TransactionMetadataSet::new_treeless();
let mut tms = TxMapAndMaybeTrees::new_treeless();
assert_eq!(tms.get_some_txid_from_highest_wallet_block(), None);
let txid_bytes_1 = [0u8; 32];
let txid_bytes_2 = [1u8; 32];
Expand Down Expand Up @@ -175,7 +175,7 @@ fn test_get_some_txid_from_highest_wallet_block() {
}

#[cfg(feature = "lightclient-deprecated")]
impl TransactionMetadataSet {
impl TxMapAndMaybeTrees {
pub fn get_fee_by_txid(&self, txid: &TxId) -> u64 {
match self
.current
Expand Down
6 changes: 3 additions & 3 deletions zingolib/src/wallet/transactions/read_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use zcash_primitives::transaction::TxId;

use crate::wallet::{data::TransactionRecord, keys::unified::WalletCapability, WitnessTrees};

use super::TransactionMetadataSet;
impl TransactionMetadataSet {
use super::TxMapAndMaybeTrees;
impl TxMapAndMaybeTrees {
pub fn serialized_version() -> u64 {
22
}
Expand Down Expand Up @@ -160,7 +160,7 @@ mod tests {

#[tokio::test]
async fn test_write() {
let mut tms = TransactionMetadataSet {
let mut tms = TxMapAndMaybeTrees {
current: HashMap::new(), // Populate with test data as necessary
witness_trees: Some(WitnessTrees::default()), // Adjust as needed
};
Expand Down
6 changes: 3 additions & 3 deletions zingolib/src/wallet/transactions/recording.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use crate::{
},
};

use super::TransactionMetadataSet;
impl TransactionMetadataSet {
use super::TxMapAndMaybeTrees;
impl TxMapAndMaybeTrees {
pub fn remove_txids(&mut self, txids_to_remove: Vec<TxId>) {
for txid in &txids_to_remove {
self.current.remove(txid);
Expand Down Expand Up @@ -509,7 +509,7 @@ impl TransactionMetadataSet {
}

// shardtree
impl TransactionMetadataSet {
impl TxMapAndMaybeTrees {
/// A mark designates a leaf as non-ephemeral, mark removal causes
/// the leaf to eventually transition to the ephemeral state
pub fn remove_witness_mark<D>(
Expand Down
Loading