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

P-chain state prune + height index #1719

Merged
merged 90 commits into from
Aug 8, 2023

Conversation

dhrubabasu
Copy link
Contributor

@dhrubabasu dhrubabasu commented Jul 15, 2023

Why this should be merged

Closes #1623.

This PR is a remake (with significant changes) of the original P-chain height index PR: #1447. We reverted the original PR as it was stalling nodes by populating the height index synchronously.

At the end of the process kicked off in this PR:

  • All existing non-accepted blocks in blockDB will be purged from disk.
  • blockDB will be a map of blockIDs to Blocks.
    • Since we are only storing accepted blocks on disk, we can simplify blockDB by removing stateBlk which takes up unnecessary space.

How this works

Kicks off a background process that goes through each block in blockDB. Per block, it does this logic:

  • Is the block accepted?
    • No
      • Remove it from disk.
    • Yes
      • Update the height to blockID index (blockIDDb)
      • If it's stored as a stateBlk in blockDB, replace it with block bytes

To prevent OOMing nodes and to minimize disruption, we commit periodically (currently set to every 1024 blocks) and sleep after each commit to prevent burning the DB too much.

How this was tested

  • CI
  • Manually on Fuji
  • Manually on Mainnet
  • Probe nodes

@dhrubabasu dhrubabasu changed the base branch from master to dev July 15, 2023 03:53
@dhrubabasu dhrubabasu self-assigned this Jul 15, 2023
@dhrubabasu dhrubabasu added this to the v1.10.6 milestone Jul 15, 2023
@dhrubabasu dhrubabasu linked an issue Jul 15, 2023 that may be closed by this pull request
@dhrubabasu dhrubabasu added the DO NOT MERGE This PR must not be merged in its current state label Jul 15, 2023
Base automatically changed from execution-config-cleanup to dev July 24, 2023 21:17
@dhrubabasu dhrubabasu changed the base branch from dev to fix-mockgen-txt August 3, 2023 06:38
Base automatically changed from fix-mockgen-txt to dev August 3, 2023 14:08
numIndexed = 0
)

for blockIterator.Next() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the early exit if the node shuts down?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we've really added any of these for any of our indexing - it'll exit when the DB errors due to being closed.. (or when the process exits 🤷)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And to ask a question I think I know the answer to, partial pruning will be handled gracefully (and the pruned value will only be written once we've iterated over all elements)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm this should be the case. But I think we should probably check for blockIterator.Error() before trying to write the pruned value. Specifically, because it doesn't seem like the corruptabledb has any handling for iterators.

@StephenButtolph StephenButtolph merged commit d018679 into dev Aug 8, 2023
14 checks passed
@StephenButtolph StephenButtolph deleted the platformvm-height-index-state-cleanup branch August 8, 2023 19:44
// Since we only store accepted blocks on disk, we only need to store a map of
// ids.ID to Block.
if isStateBlk {
if err := s.blockDB.Put(blkID[:], blkBytes); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been:

if err := s.blockDB.Put(blkID[:], blk.Bytes()); err != nil {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vm This involves virtual machines
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Purge rejected blocks from platformvm
4 participants