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

Remove duplicate read::hash() and read::hash_by_height() consensus-critical code #5910

Closed
teor2345 opened this issue Jan 4, 2023 · 2 comments · Fixed by #5915
Closed

Remove duplicate read::hash() and read::hash_by_height() consensus-critical code #5910

teor2345 opened this issue Jan 4, 2023 · 2 comments · Fixed by #5915
Labels
A-consensus Area: Consensus rule updates A-state Area: State / database changes C-bug Category: This is a bug

Comments

@teor2345
Copy link
Contributor

teor2345 commented Jan 4, 2023

Motivation

Zebra has two duplicate state functions for reading a block hash: read::hash() and read::hash_by_height(). We don't want to have duplicate code in Zebra, because it risks breaking consensus. It's also hard to maintain and audit.

This is a simple search-and-replace fix.

/// Return the hash for the block at `height`, if `height` is in `chain` or `db`.
pub fn hash_by_height<C>(chain: Option<C>, db: &ZebraDb, height: Height) -> Option<block::Hash>

#[cfg(feature = "getblocktemplate-rpcs")]
/// Returns the [`Hash`] given [`block::Height`](zebra_chain::block::Height), if it exists in
/// the non-finalized `chain` or finalized `db`.
pub fn hash<C>(chain: Option<C>, db: &ZebraDb, height: Height) -> Option<zebra_chain::block::Hash>

Testing

This change will improve testing, because the existing tests will all check the same function, rather than some tests checking one function, and some checking the other function.

Related Work

Discovered as part of PR #5894.

@teor2345 teor2345 added C-bug Category: This is a bug A-consensus Area: Consensus rule updates S-needs-triage Status: A bug report needs triage P-Medium ⚡ A-state Area: State / database changes labels Jan 4, 2023
@teor2345
Copy link
Contributor Author

teor2345 commented Jan 4, 2023

@mpguerra can we schedule this fix soon?

It's very small, and it's a consensus compatibility risk.

@mpguerra
Copy link
Contributor

mpguerra commented Jan 9, 2023

@teor2345 can you please add an estimate to this issue?

@mpguerra mpguerra moved this to 🛑 Won't Fix in Zebra Jan 19, 2023
@mpguerra mpguerra added this to Zebra Jan 19, 2023
@mpguerra mpguerra moved this from 🛑 Won't Fix to ✅ Done in Zebra Jan 19, 2023
@mpguerra mpguerra removed the S-needs-triage Status: A bug report needs triage label Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-consensus Area: Consensus rule updates A-state Area: State / database changes C-bug Category: This is a bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants