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

Add logic to prune all historic states #4481

Closed
michaelsproul opened this issue Jul 7, 2023 · 1 comment
Closed

Add logic to prune all historic states #4481

michaelsproul opened this issue Jul 7, 2023 · 1 comment
Assignees
Labels
database tree-states Upcoming state and database overhaul

Comments

@michaelsproul
Copy link
Member

Description

It would be useful for several purposes to be able to drop all of the states in the freezer DB. Some uses include:

Steps to resolve

I think for forwards-compatibility with tree-states it would be best to implement the deletion as several iterators over the relevant columns, which just delete everything in the column without parsing it. Basically:

for column in relevant {
  for key in db.iter_column(column) {
    to_delete.push(key);
  }
}

Where relevant consists of:

  • DBColumn::BeaconStateSummary (where the ColdStateSummary is stored)
  • DBColumn::BeaconState (where the PartialBeaconState is stored)
  • DBColumn::BeaconRestorePoint (where the restore point -> state root index is stored)
  • DBColumn::BeaconStateRoots
  • DBColumn::BeaconHistoricalRoots
  • DBColumn::BeaconRandaoMixes
  • DBColumn::BeaconHistoricalSummaries

I think on unstable the beacon block roots should be left intact, as we expect them to exist whenever we've stored historic blocks in the DB.

Atomically with those deletions we should update the state_upper_limit in the Anchor to reflect the fact that those states are gone. I think setting it to u64::MAX could be a good way to signal a new mode of operation where "this node isn't storing any historic states". Alternatively, we set it to the next restore point slot (or snapshot slot for tree-states) which is >= split.slot. Either way, we need this block of logic from the tree-states branch that prevents the finalization migration from trying to write bad states:

// Do not try to store states if the first snapshot is yet to be stored.
if anchor_info
.as_ref()
.map_or(false, |anchor| slot < anchor.state_upper_limit)
{
debug!(store.log, "Skipping cold state storage"; "slot" => slot);
continue;
}

I think we probably also want to solve the alignment issues for checkpoint sync first, otherwise we'll have to avoid deleting all the states when the split point is at a skipped slot. See: #3210 (comment).

@michaelsproul
Copy link
Member Author

I'm going to work on this now that #4610 is merged. We should be able to get a lighthouse db prune-states command working with relative ease 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database tree-states Upcoming state and database overhaul
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants