From ee9ab3162a2e8da4e20101b1d3e5c6cfbb200e52 Mon Sep 17 00:00:00 2001 From: Arya Date: Wed, 24 Apr 2024 16:27:56 -0400 Subject: [PATCH] fixes concurrency bug in z_get_treestate RPC method (#8460) --- zebra-rpc/src/methods.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/zebra-rpc/src/methods.rs b/zebra-rpc/src/methods.rs index d1dd05649..92c7aa22a 100644 --- a/zebra-rpc/src/methods.rs +++ b/zebra-rpc/src/methods.rs @@ -1098,6 +1098,11 @@ where data: None, })?; + // # Concurrency + // + // For consistency, this lookup must be performed first, then all the other + // lookups must be based on the hash. + // Fetch the block referenced by [`hash_or_height`] from the state. // TODO: If this RPC is called a lot, just get the block header, // rather than the whole block. @@ -1128,6 +1133,9 @@ where _ => unreachable!("unmatched response to a block request"), }; + let hash = hash_or_height.hash().unwrap_or_else(|| block.hash()); + let hash_or_height = hash.into(); + // Fetch the Sapling & Orchard treestates referenced by // [`hash_or_height`] from the state. @@ -1156,8 +1164,6 @@ where // We've got all the data we need for the RPC response, so we // assemble the response. - let hash = block.hash(); - let height = block .coinbase_height() .expect("verified blocks have a valid height");