Skip to content

Commit

Permalink
fix: utxo_digest() must call count_leaves()
Browse files Browse the repository at this point in the history
utxo_digest() lookup logic was incorrect.
  • Loading branch information
dan-da committed Apr 24, 2024
1 parent bc8ba6a commit 5aabe43
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ pub trait RPC {
/// Return the digest for the specified block selector (genesis, tip, or height)
async fn block_digest(block_selector: BlockSelector) -> Option<Digest>;

/// Return the digest for the specified UTXO index
async fn utxo_digest(index: u64) -> Option<Digest>;
/// Return the digest for the specified UTXO leaf index
async fn utxo_digest(leaf_index: u64) -> Option<Digest>;

/// Return the block header for the specified block
async fn header(block_selector: BlockSelector) -> Option<BlockHeader>;
Expand Down Expand Up @@ -258,12 +258,12 @@ impl RPC for NeptuneRPCServer {
self.confirmations_internal().await
}

async fn utxo_digest(self, _: context::Context, index: u64) -> Option<Digest> {
async fn utxo_digest(self, _: context::Context, leaf_index: u64) -> Option<Digest> {
let state = self.state.lock_guard().await;
let aocl = &state.chain.archival_state().archival_mutator_set.ams().aocl;

match index > 0 && index < aocl.len().await {
true => Some(aocl.get_leaf_async(index).await),
match leaf_index > 0 && leaf_index < aocl.count_leaves().await {
true => Some(aocl.get_leaf_async(leaf_index).await),
false => None,
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/util_types/mutator_set/archival_mmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ where
self.digests.len().await == 1
}

/// Returns len of Digests. Note that elem 0
/// is always a dummy digest.
pub async fn len(&self) -> u64 {
self.digests.len().await
}

/// Return the number of leaves in the tree
pub async fn count_leaves(&self) -> u64 {
node_index_to_leaf_index(self.digests.len().await).unwrap()
Expand Down

0 comments on commit 5aabe43

Please sign in to comment.