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

Current to transaction records by #925

Merged
merged 3 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
23 changes: 15 additions & 8 deletions integration-tests/tests/integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,14 @@ mod slow {
.await
.unwrap();

for txid_known in recipient.wallet.transactions().read().await.current.keys() {
for txid_known in recipient
.wallet
.transactions()
.read()
.await
.transaction_records_by_id
.keys()
{
dbg!(txid_known);
}

Expand All @@ -757,7 +764,7 @@ mod slow {
.transactions()
.read()
.await
.current
.transaction_records_by_id
.get(&txid)
.unwrap()
.orchard_notes
Expand Down Expand Up @@ -790,7 +797,7 @@ mod slow {
.transactions()
.read()
.await
.current
.transaction_records_by_id
.get(&txid)
.unwrap()
.orchard_notes
Expand Down Expand Up @@ -833,7 +840,7 @@ mod slow {
.transactions()
.read()
.await
.current
.transaction_records_by_id
.get(&txid)
.unwrap()
.orchard_notes
Expand Down Expand Up @@ -864,7 +871,7 @@ mod slow {
.transactions()
.read()
.await
.current
.transaction_records_by_id
.get(&txid)
.unwrap()
.orchard_notes
Expand Down Expand Up @@ -3304,7 +3311,7 @@ mod slow {
.transaction_metadata_set
.read()
.await
.current
.transaction_records_by_id
.get(requested_txid)
.unwrap()
.orchard_notes
Expand Down Expand Up @@ -3344,7 +3351,7 @@ mod slow {
.transaction_metadata_set
.read()
.await
.current
.transaction_records_by_id
.get(requested_txid)
.unwrap()
.orchard_notes
Expand Down Expand Up @@ -3449,7 +3456,7 @@ mod slow {
.transaction_metadata_set
.read()
.await
.current
.transaction_records_by_id
);

assert_eq!(bala_sim, bala_syn);
Expand Down
2 changes: 1 addition & 1 deletion zingolib/src/lightclient/deprecated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl LightClient {
.transaction_context.transaction_metadata_set
.read()
.await
.current
.transaction_records_by_id
.iter()
.flat_map(|(txid, wallet_transaction)| {
let mut consumer_notes_by_tx: Vec<JsonValue> = vec![];
Expand Down
10 changes: 5 additions & 5 deletions zingolib/src/lightclient/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl LightClient {
.transactions()
.read()
.await
.current
.transaction_records_by_id
.iter()
.for_each(|(_, tx)| {
let mature = tx
Expand Down Expand Up @@ -240,7 +240,7 @@ impl LightClient {
.transaction_metadata_set
.read()
.await
.current
.transaction_records_by_id
.iter()
{
LightClient::tx_summary_matcher(&mut summaries, *txid, transaction_md);
Expand Down Expand Up @@ -482,7 +482,7 @@ impl LightClient {
let mut pending_sapling_notes: Vec<JsonValue> = vec![];
let mut spent_sapling_notes: Vec<JsonValue> = vec![];
// Collect Sapling notes
self.wallet.transaction_context.transaction_metadata_set.read().await.current.iter()
self.wallet.transaction_context.transaction_metadata_set.read().await.transaction_records_by_id.iter()
.flat_map( |(transaction_id, transaction_metadata)| {
transaction_metadata.sapling_notes.iter().filter_map(move |note_metadata|
if !all_notes && note_metadata.spent.is_some() {
Expand Down Expand Up @@ -525,7 +525,7 @@ impl LightClient {
let mut unspent_orchard_notes: Vec<JsonValue> = vec![];
let mut pending_orchard_notes: Vec<JsonValue> = vec![];
let mut spent_orchard_notes: Vec<JsonValue> = vec![];
self.wallet.transaction_context.transaction_metadata_set.read().await.current.iter()
self.wallet.transaction_context.transaction_metadata_set.read().await.transaction_records_by_id.iter()
.flat_map( |(transaction_id, transaction_metadata)| {
transaction_metadata.orchard_notes.iter().filter_map(move |orch_note_metadata|
if !all_notes && orch_note_metadata.is_spent() {
Expand Down Expand Up @@ -568,7 +568,7 @@ impl LightClient {
let mut pending_transparent_notes: Vec<JsonValue> = vec![];
let mut spent_transparent_notes: Vec<JsonValue> = vec![];

self.wallet.transaction_context.transaction_metadata_set.read().await.current.iter()
self.wallet.transaction_context.transaction_metadata_set.read().await.transaction_records_by_id.iter()
.flat_map( |(transaction_id, wtx)| {
wtx.transparent_notes.iter().filter_map(move |utxo|
if !all_notes && utxo.is_spent() {
Expand Down
6 changes: 3 additions & 3 deletions zingolib/src/wallet/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl LightWallet {
.transaction_metadata_set
.read()
.await
.current
.transaction_records_by_id
.values()
.map(|transaction| {
let mut filtered_notes: Box<dyn Iterator<Item = &D::WalletNote>> = Box::new(
Expand Down Expand Up @@ -219,7 +219,7 @@ impl LightWallet {
.transaction_metadata_set
.read()
.await
.current
.transaction_records_by_id
.values()
.map(|wtx| u64::from(wtx.status.get_height()))
.min();
Expand All @@ -238,7 +238,7 @@ impl LightWallet {
.transaction_metadata_set
.read()
.await
.current
.transaction_records_by_id
.values()
.flat_map(|transaction| {
transaction
Expand Down
2 changes: 1 addition & 1 deletion zingolib/src/wallet/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl LightWallet {
TxMapAndMaybeTrees::read(&mut reader, &wallet_capability)
}?;
let txids = transactions
.current
.transaction_records_by_id
.keys()
.cloned()
.collect::<Vec<transaction::TxId>>();
Expand Down
2 changes: 1 addition & 1 deletion zingolib/src/wallet/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ impl LightWallet {
let tranmds_lth = self.transactions();
let transaction_metadata_set = tranmds_lth.read().await;
let mut candidate_notes = transaction_metadata_set
.current
.transaction_records_by_id
.iter()
.flat_map(|(transaction_id, transaction)| {
D::WalletNote::transaction_metadata_notes(transaction)
Expand Down
12 changes: 9 additions & 3 deletions zingolib/src/wallet/transaction_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,20 @@ pub mod decrypt_transaction {
let mut spent_utxos = vec![];

{
let current = &self.transaction_metadata_set.read().await.current;
let current_transaction_records_by_id = &self
.transaction_metadata_set
.read()
.await
.transaction_records_by_id;
if let Some(t_bundle) = transaction.transparent_bundle() {
for vin in t_bundle.vin.iter() {
// Find the prev txid that was spent
let prev_transaction_id = TxId::from_bytes(*vin.prevout.hash());
let prev_n = vin.prevout.n() as u64;

if let Some(wtx) = current.get(&prev_transaction_id) {
if let Some(wtx) =
current_transaction_records_by_id.get(&prev_transaction_id)
{
// One of the tx outputs is a match
if let Some(spent_utxo) = wtx
.transparent_notes
Expand Down Expand Up @@ -290,7 +296,7 @@ pub mod decrypt_transaction {
.transaction_metadata_set
.write()
.await
.current
.transaction_records_by_id
.get_mut(&txid)
{
if !transaction.outgoing_tx_data.is_empty() {
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 @@ -6,7 +6,7 @@ use crate::wallet::{data::WitnessTrees, transaction_records_by_id::TransactionRe
/// 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 TxMapAndMaybeTrees {
pub current: TransactionRecordsById,
pub transaction_records_by_id: TransactionRecordsById,
pub witness_trees: Option<WitnessTrees>,
}

Expand All @@ -17,18 +17,18 @@ pub mod recording;
impl TxMapAndMaybeTrees {
pub(crate) fn new_with_witness_trees() -> TxMapAndMaybeTrees {
Self {
current: TransactionRecordsById(HashMap::new()),
transaction_records_by_id: TransactionRecordsById(HashMap::new()),
witness_trees: Some(WitnessTrees::default()),
}
}
pub(crate) fn new_treeless() -> TxMapAndMaybeTrees {
Self {
current: TransactionRecordsById(HashMap::new()),
transaction_records_by_id: TransactionRecordsById(HashMap::new()),
witness_trees: None,
}
}
pub fn clear(&mut self) {
self.current.clear();
self.transaction_records_by_id.clear();
self.witness_trees.as_mut().map(WitnessTrees::clear);
}
}
16 changes: 8 additions & 8 deletions zingolib/src/wallet/transactions/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl TxMapAndMaybeTrees {
) -> Vec<(TxId, PoolNullifier, Option<u32>)> {
let before_block = BlockHeight::from_u32(before_block as u32);

self.current
self.transaction_records_by_id
.iter()
.filter(|(_, transaction_metadata)| transaction_metadata.status.is_confirmed_before_or_at(&before_block)) // Update only confirmed notes
.flat_map(|(txid, transaction_metadata)| {
Expand Down Expand Up @@ -64,7 +64,7 @@ impl TxMapAndMaybeTrees {
}

pub fn total_funds_spent_in(&self, txid: &TxId) -> u64 {
self.current
self.transaction_records_by_id
.get(txid)
.map(TransactionRecord::total_value_spent)
.unwrap_or(0)
Expand All @@ -83,7 +83,7 @@ impl TxMapAndMaybeTrees {
<D as Domain>::Note: PartialEq + Clone,
<D as Domain>::Recipient: Recipient,
{
self.current
self.transaction_records_by_id
.iter()
.flat_map(|(_, transaction_metadata)| {
D::to_notes_vec(transaction_metadata)
Expand All @@ -105,7 +105,7 @@ impl TxMapAndMaybeTrees {

/// This returns an _arbitrary_ confirmed txid from the latest block the wallet is aware of.
pub fn get_some_txid_from_highest_wallet_block(&self) -> Option<TxId> {
self.current
self.transaction_records_by_id
.values()
.fold(
None,
Expand Down Expand Up @@ -140,7 +140,7 @@ fn test_get_some_txid_from_highest_wallet_block() {
let txid_1 = TxId::from_bytes(txid_bytes_1);
let txid_2 = TxId::from_bytes(txid_bytes_2);
let txid_3 = TxId::from_bytes(txid_bytes_3);
tms.current.insert(
tms.transaction_records_by_id.insert(
txid_1,
TransactionRecord::new(
zingo_status::confirmation_status::ConfirmationStatus::Broadcast(
Expand All @@ -150,7 +150,7 @@ fn test_get_some_txid_from_highest_wallet_block() {
&txid_1,
),
);
tms.current.insert(
tms.transaction_records_by_id.insert(
txid_2,
TransactionRecord::new(
zingo_status::confirmation_status::ConfirmationStatus::Confirmed(
Expand All @@ -160,7 +160,7 @@ fn test_get_some_txid_from_highest_wallet_block() {
&txid_2,
),
);
tms.current.insert(
tms.transaction_records_by_id.insert(
txid_3,
TransactionRecord::new(
zingo_status::confirmation_status::ConfirmationStatus::Confirmed(
Expand All @@ -178,7 +178,7 @@ fn test_get_some_txid_from_highest_wallet_block() {
impl TxMapAndMaybeTrees {
pub fn get_fee_by_txid(&self, txid: &TxId) -> u64 {
match self
.current
.transaction_records_by_id
.get(txid)
.expect("To have the requested txid")
.get_transaction_fee()
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 @@ -60,7 +60,7 @@ impl TxMapAndMaybeTrees {
}

Ok(Self {
current: map,
transaction_records_by_id: map,
witness_trees,
})
}
Expand Down Expand Up @@ -125,7 +125,7 @@ impl TxMapAndMaybeTrees {
};

Ok(Self {
current: TransactionRecordsById::from_map(map),
transaction_records_by_id: TransactionRecordsById::from_map(map),
witness_trees,
})
}
Expand All @@ -138,7 +138,7 @@ impl TxMapAndMaybeTrees {
// deterministically saved
{
let mut transaction_metadatas = self
.current
.transaction_records_by_id
.iter()
.collect::<Vec<(&TxId, &TransactionRecord)>>();
// Don't write down metadata for transactions in the mempool, we'll rediscover
Expand Down
Loading
Loading