Skip to content

Commit

Permalink
Delete the duplicate sprout key during an upgrade.
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Aug 28, 2023
1 parent 9bdaa47 commit a5bb035
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,12 @@ impl DbFormatChange {

// Writing the trees back to the database automatically caches their roots.
let mut batch = DiskWriteBatch::new();
// Delete the previous `Height` tip key format, which is now a duplicate.
// It's ok to do a full delete, because the trees are restored later in the batch.
batch.delete_range_sprout_tree(&db, &Height(0), &Height::MAX);
// Fix the cached root of the Sprout genesis tree in its anchors column family.
// The genesis update to the tip tree is overwritten by the actual tip in the batch.
// It's ok to write the genesis tree to the tip tree index, because is overwritten by
// the actual tip later in the batch.
batch.update_sprout_tree(&db, &sprout_genesis_tree);
// Update the sprout tip key format in the database.
batch.update_sprout_tree(&db, &sprout_tip_tree);
Expand Down
18 changes: 16 additions & 2 deletions zebra-state/src/service/finalized_state/zebra_db/shielded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,18 @@ impl DiskWriteBatch {
self.zs_insert(&orchard_tree_cf, height, tree);
}

/// Deletes the range of Sprout note commitment trees at the given [`Height`]s.
/// Doesn't delete anchors from the anchor index. Doesn't delete the upper bound.
pub fn delete_range_sprout_tree(&mut self, zebra_db: &ZebraDb, from: &Height, to: &Height) {
let sprout_tree_cf = zebra_db
.db
.cf_handle("sprout_note_commitment_tree")
.unwrap();

// TODO: convert zs_delete_range() to take std::ops::RangeBounds
self.zs_delete_range(&sprout_tree_cf, from, to);
}

/// Deletes the Sapling note commitment tree at the given [`Height`].
pub fn delete_sapling_tree(&mut self, zebra_db: &ZebraDb, height: &Height) {
let sapling_tree_cf = zebra_db
Expand All @@ -409,7 +421,8 @@ impl DiskWriteBatch {
self.zs_delete(&sapling_tree_cf, height);
}

/// Deletes the range of Sapling note commitment trees at the given [`Height`]s. Doesn't delete the upper bound.
/// Deletes the range of Sapling note commitment trees at the given [`Height`]s.
/// Doesn't delete anchors from the anchor index. Doesn't delete the upper bound.
#[allow(dead_code)]
pub fn delete_range_sapling_tree(&mut self, zebra_db: &ZebraDb, from: &Height, to: &Height) {
let sapling_tree_cf = zebra_db
Expand All @@ -430,7 +443,8 @@ impl DiskWriteBatch {
self.zs_delete(&orchard_tree_cf, height);
}

/// Deletes the range of Orchard note commitment trees at the given [`Height`]s. Doesn't delete the upper bound.
/// Deletes the range of Orchard note commitment trees at the given [`Height`]s.
/// Doesn't delete anchors from the anchor index. Doesn't delete the upper bound.
#[allow(dead_code)]
pub fn delete_range_orchard_tree(&mut self, zebra_db: &ZebraDb, from: &Height, to: &Height) {
let orchard_tree_cf = zebra_db
Expand Down

0 comments on commit a5bb035

Please sign in to comment.