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(db): Fix a sprout/history tree read panic in Zebra 1.4.0, which only happens before the 25.3.0 state upgrade completes #7972

Merged
merged 8 commits into from
Nov 22, 2023
Prev Previous commit
Next Next commit
Get the latest history tree not the tip height history tree
  • Loading branch information
teor2345 authored Nov 21, 2023
commit f7a43b7f5f3672824dd97b36bf21735bfc766d67
9 changes: 4 additions & 5 deletions zebra-state/src/service/finalized_state/zebra_db/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@
let mut history_tree: Option<Arc<HistoryTree>> = self.db.zs_get(&history_tree_cf, &());

if history_tree.is_none() {
let tip_height = self
.finalized_tip_height()
.expect("just checked for an empty database");

history_tree = self.db.zs_get(&history_tree_cf, &tip_height);
// In Zebra 1.4.0 and later, we only update the history tip tree when it has changed (for every block after heartwood).
// But we write with a `()` key, not a height key.
// So we need to look for the most recent update height if the `()` key has never been written.
history_tree = self.db.zs_last_key_value(&history_tree_cf);

Check failure on line 65 in zebra-state/src/service/finalized_state/zebra_db/chain.rs

View workflow job for this annotation

GitHub Actions / Build and Deploy Zebra Internal Docs

mismatched types

Check failure on line 65 in zebra-state/src/service/finalized_state/zebra_db/chain.rs

View workflow job for this annotation

GitHub Actions / Install zebrad from lockfile without cache on ubuntu-latest

mismatched types

Check failure on line 65 in zebra-state/src/service/finalized_state/zebra_db/chain.rs

View workflow job for this annotation

GitHub Actions / Test stable on ubuntu-latest

mismatched types

Check failure on line 65 in zebra-state/src/service/finalized_state/zebra_db/chain.rs

View workflow job for this annotation

GitHub Actions / Check Cargo.lock is up to date

mismatched types

Check failure on line 65 in zebra-state/src/service/finalized_state/zebra_db/chain.rs

View workflow job for this annotation

GitHub Actions / Test beta on ubuntu-latest

mismatched types

Check failure on line 65 in zebra-state/src/service/finalized_state/zebra_db/chain.rs

View workflow job for this annotation

GitHub Actions / Test stable on macos-latest

mismatched types

Check failure on line 65 in zebra-state/src/service/finalized_state/zebra_db/chain.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable) Results

mismatched types

error[E0308]: mismatched types --> zebra-state/src/service/finalized_state/zebra_db/chain.rs:65:28 | 59 | let mut history_tree: Option<Arc<HistoryTree>> = self.db.zs_get(&history_tree_cf, &()); | ------------------------ expected due to this type ... 65 | history_tree = self.db.zs_last_key_value(&history_tree_cf); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Option<Arc<HistoryTree>>`, found `Option<(_, _)>` | = note: expected enum `std::option::Option<std::sync::Arc<zebra_chain::history_tree::HistoryTree>>` found enum `std::option::Option<(_, _)>`

Check failure on line 65 in zebra-state/src/service/finalized_state/zebra_db/chain.rs

View workflow job for this annotation

GitHub Actions / Clippy (stable) Results

mismatched types

error[E0308]: mismatched types --> zebra-state/src/service/finalized_state/zebra_db/chain.rs:65:28 | 59 | let mut history_tree: Option<Arc<HistoryTree>> = self.db.zs_get(&history_tree_cf, &()); | ------------------------ expected due to this type ... 65 | history_tree = self.db.zs_last_key_value(&history_tree_cf); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Option<Arc<HistoryTree>>`, found `Option<(_, _)>` | = note: expected enum `std::option::Option<std::sync::Arc<zebra_chain::history_tree::HistoryTree>>` found enum `std::option::Option<(_, _)>`
teor2345 marked this conversation as resolved.
Show resolved Hide resolved
}

history_tree.unwrap_or_default()
Expand Down
Loading