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

fix(rpc): Avoid possibly returning data from different blocks in z_get_treestate RPC method #8460

Merged
merged 1 commit into from
Apr 24, 2024
Merged
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
10 changes: 8 additions & 2 deletions zebra-rpc/src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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");
Expand Down
Loading