Skip to content

Commit

Permalink
required_finalized_diff_state_slots
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Dec 11, 2024
1 parent 8eaee8d commit 3fd8f4b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
12 changes: 12 additions & 0 deletions beacon_node/store/src/hdiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,18 @@ impl HierarchyModuli {
|second_layer_moduli| Ok(slot % *second_layer_moduli == 0),
)
}

/// For each layer, returns the closest diff less that or equal to `slot`.
pub fn closest_layer_points(&self, slot: Slot) -> Vec<Slot> {
self.moduli
.iter()
.map(|&n| {
let from = slot / n * n;
// Or from start point
std::cmp::max(from, self.start)
})
.collect()
}
}

impl StorageStrategy {
Expand Down
23 changes: 15 additions & 8 deletions beacon_node/store/src/hot_cold_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3083,8 +3083,8 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
state_delete_batch.push(StoreOp::DeleteState {
state_root,
state_slot: Some(summary.slot),
// TODO(hdiff): The logic here is duplicated from `migrate_database`
prune_hot_diff: false,
// Delete the diff as descendants of this state will never be used.
prune_hot_diff: true,
});
}
}
Expand Down Expand Up @@ -3140,7 +3140,14 @@ pub fn migrate_database<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>(

// Compute the set of finalized state roots that we must keep to make the dynamic HDiff system
// work.
let required_finalized_diff_state_roots = HashSet::<Hash256>::new();
// TODO(hdiff): must not delete *all* finalized hdiffs. Instead, keep
// the more recent diff of each layer including the snapshot.
// Implement a routine somewhere to figure out which diffs should be kept
// Given a start slot, and the current finalized state:
// - iterate each hdiff layer and compute the most recent point <= finalized slot
let required_finalized_diff_state_slots = store
.hierarchy_hot
.closest_layer_points(finalized_state.slot());

// Iterate in descending order until the current split slot
let state_roots = RootsIterator::new(&store, finalized_state)
Expand Down Expand Up @@ -3186,14 +3193,14 @@ pub fn migrate_database<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>(
}

// Delete the old summary, and the full state if we lie on an epoch boundary.
if !required_finalized_diff_state_roots.contains(&state_root) {
if !required_finalized_diff_state_slots.contains(&slot) {
hot_db_ops.push(StoreOp::DeleteState {
state_root,
state_slot: Some(slot),
// TODO(hdiff): must not delete *all* finalized hdiffs. Instead, keep
// the more recent diff of each layer including the snapshot.
// Implement a routine somewhere to figure out which diffs should be kept
prune_hot_diff: false,
// Note: we checked that this diff is not necessary for the finalized section
// of hot hdiffs, delete.
// TODO(hdiff): This diff has to be pruned eventually, implement routine.
prune_hot_diff: true,
});
}

Expand Down

0 comments on commit 3fd8f4b

Please sign in to comment.