From 5aabe43215f8e8bf5fbbfb31003058b599639bb9 Mon Sep 17 00:00:00 2001 From: danda Date: Tue, 23 Apr 2024 22:25:10 -0700 Subject: [PATCH] fix: utxo_digest() must call count_leaves() utxo_digest() lookup logic was incorrect. --- src/rpc_server.rs | 10 +++++----- src/util_types/mutator_set/archival_mmr.rs | 6 ------ 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/rpc_server.rs b/src/rpc_server.rs index 03a3db83..936bc28e 100644 --- a/src/rpc_server.rs +++ b/src/rpc_server.rs @@ -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; - /// Return the digest for the specified UTXO index - async fn utxo_digest(index: u64) -> Option; + /// Return the digest for the specified UTXO leaf index + async fn utxo_digest(leaf_index: u64) -> Option; /// Return the block header for the specified block async fn header(block_selector: BlockSelector) -> Option; @@ -258,12 +258,12 @@ impl RPC for NeptuneRPCServer { self.confirmations_internal().await } - async fn utxo_digest(self, _: context::Context, index: u64) -> Option { + async fn utxo_digest(self, _: context::Context, leaf_index: u64) -> Option { 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, } } diff --git a/src/util_types/mutator_set/archival_mmr.rs b/src/util_types/mutator_set/archival_mmr.rs index 60a177a0..fb352368 100644 --- a/src/util_types/mutator_set/archival_mmr.rs +++ b/src/util_types/mutator_set/archival_mmr.rs @@ -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()