Skip to content

Commit

Permalink
docs: trace-log MUTXO info in wallet-updater
Browse files Browse the repository at this point in the history
Implement `Display` for `MonitoredUtxo` and trace-log this output in the
wallet-state method that updates the wallet state with a new block.

This feature was inspired by the bug hunt leading to #328.
  • Loading branch information
Sword-Smith committed Jan 14, 2025
1 parent 6ffa24b commit 0bb0086
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/models/state/wallet/monitored_utxo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::collections::VecDeque;
use std::fmt::Display;

use itertools::Itertools;
use serde::Deserialize;
use serde::Serialize;
use tasm_lib::triton_vm::prelude::Tip5;
Expand Down Expand Up @@ -40,6 +42,45 @@ pub struct MonitoredUtxo {
pub abandoned_at: Option<(Digest, Timestamp, BlockHeight)>,
}

impl Display for MonitoredUtxo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let aocl_leaf_index = match self.get_latest_membership_proof_entry() {
Some(msmp) => msmp.1.aocl_leaf_index.to_string(),
None => "not mined".to_owned(),
};
let spent = match self.spent_in_block {
Some((block_hash, block_timestamp, block_height)) => {
format!("spent in {block_hash}, at {block_timestamp}, block height {block_height}.")
}
None => "not spent".to_owned(),
};
let confirmed = match self.confirmed_in_block {
Some((block_hash, block_timestamp, block_height)) => {
format!(
"received in {block_hash}, at {block_timestamp}, block height {block_height}."
)
}
None => "not mined yet".to_owned(),
};
let msmp_for_blocks = format!(
"valid MSMPs for blocks\n{}\n",
self.blockhash_to_membership_proof
.iter()
.map(|(digest, _)| digest)
.join("\n")
);

write!(
f,
"AOCL-leaf index: {aocl_leaf_index}\n\
{spent}\n\
{confirmed}\n\
{msmp_for_blocks}\n
"
)
}
}

impl MonitoredUtxo {
pub(crate) fn new(utxo: Utxo, max_number_of_mps_stored: usize) -> Self {
Self {
Expand Down
9 changes: 9 additions & 0 deletions src/models/state/wallet/wallet_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,11 @@ impl WalletState {
let (mut valid_membership_proofs_and_own_utxo_count, all_existing_mutxos) =
preprocess_own_mutxos(monitored_utxos, new_block).await;

debug!(
"handling {} monitored UTXOs",
valid_membership_proofs_and_own_utxo_count.len()
);

// Loop over all input UTXOs, applying all addition records. In each iteration,
// a) Update all existing MS membership proofs
// b) Register incoming transactions and derive their membership proofs
Expand Down Expand Up @@ -1147,6 +1152,10 @@ impl WalletState {
valid_membership_proofs_and_own_utxo_count.values()
{
let mut monitored_utxo = monitored_utxos.get(*own_utxo_index).await;
trace!(
"Updating MSMP for MUTXO with wallet-index {own_utxo_index}; with AOCL leaf-index {}. MUTXO:\n{monitored_utxo}",
updated_ms_mp.aocl_leaf_index
);
monitored_utxo.add_membership_proof_for_tip(new_block.hash(), updated_ms_mp.to_owned());

// Sanity check that membership proofs of non-spent transactions are still valid
Expand Down

1 comment on commit 0bb0086

@jan-ferdinand
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: personally, I don't think this is the commit type “docs”. The angular CONTRIBUTING.md says “docs” is for “[d]ocumentation only changes”. Perhaps it's worth to have a commit type “trace”? For this commit specifically, one might even argue the type is “feat(MonitoredUtxo): Implement Display”.

Please sign in to comment.