Skip to content

feat: prune persisted cp states - #7510

Merged
twoeths merged 1 commit into
holesky-rescuefrom
te/prune_persisted_cp_states
Feb 28, 2025
Merged

feat: prune persisted cp states#7510
twoeths merged 1 commit into
holesky-rescuefrom
te/prune_persisted_cp_states

Conversation

@twoeths

@twoeths twoeths commented Feb 28, 2025

Copy link
Copy Markdown
Member

Motivation

Description

@twoeths

twoeths commented Feb 28, 2025

Copy link
Copy Markdown
Member Author

works fine on feat1, persisted checkpoint states are never more than 10

Screenshot 2025-02-28 at 13 07 12

sometimes it's only 9 persisted checkpoint states because epoch states in memory = 4

also checked on disc:

ls beacon/checkpoint_states/
0x10c60100000000008d8a4ecd71db3bffa750f3985b8daade5f4f781b5ea2708cefb0748edb0bef6d  0x15c601000000000052cbd98e3004dec6ea22d1f4110f61e25dd5e66b9dfbde3d36a2aa39508e5a7c
0x11c6010000000000647ff31d91637a9fae86db331f63b8b4c7b6605b5032bb42d4af0e2f8f6f4700  0x16c60100000000000c7a0bc10011c5e95fc6a197a6f218ffb6806e1fb109c5305ed6f71d3fd0a1a2
0x12c6010000000000fbdf3330f597bd28a8ca8e54d163a0d3fe6918e7ce4d29b06618ee54357cf0b9  0x17c6010000000000635e5f95c38817bdd3eb0dd31bce4852f03e0cc41a2852cc7e939cbb44c572f4
0x13c601000000000072c6308ccdb1e521bf88b68af6e5c890eb9d15547790b125b006e994d3e339a8  0x18c601000000000025922cccecb7eec6559b61aa949574bcce5f7119a8f6866966b3312ef2aaa932
0x14c6010000000000faa3739e4cea4cd7d9975d4fc9faf6dfa795ac4bbe5e1b50938fb20de6a3cbd7

@twoeths
twoeths marked this pull request as ready for review February 28, 2025 06:09
@twoeths
twoeths requested a review from a team as a code owner February 28, 2025 06:09
@twoeths
twoeths merged commit b45c6ec into holesky-rescue Feb 28, 2025
@twoeths
twoeths deleted the te/prune_persisted_cp_states branch February 28, 2025 06:10
@nflaig

nflaig commented Feb 28, 2025

Copy link
Copy Markdown
Member

do we wanna re-open this and target unstable branch to merge it there as well later on?

* During nft state of Holesky in Feb 2025, lodestar stores ~250MB per epoch and it's not sustainable to keep all states on disk.
* It's not likely to have reorgs that go back to 10 epochs ago, so we only keep 10 epochs on disk.
*/
export const DEFAULT_MAX_CP_STATE_ON_DISK = 10;

@nflaig nflaig Feb 28, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I bumped this number up to 100 on the holesky-rescue branch just to make it a bit safer and 25GB is really not a lot considering we have an increase of ~56GB today. I notified people in the telegram group to use the new image if they run low on strorage.

But I talked with @wemeetagain about your changes and we concluded this is not really safe behavior so we might need to come up with a better strategy. One idea was to use ERA files to compress states that are older than last 10 (or 100) epochs, I don't have any numbers but that might reduce storage increase quite a bit.

I also like the idea to just use file storage and let people manually delete states but that sounds a bit tricky as well, like how do you figure out which states to delete..

Would be interesting to get your view @twoeths on this

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

One idea was to use ERA files to compress states that are older than last 10 (or 100) epochs

yes we should explore it

I also like the idea to just use file storage and let people manually delete states but that sounds a bit tricky as well, like how do you figure out which states to delete..

the benefit of that is to share checkpoint state to other node, and we can view checkpoint states visually. The file name is checkpoint's serialized data so we know the epoch + root there, and it's sorted by persisted time. Also I don't think leveldb is efficient as a hot db, ie to push data and remove that later since it has to deal with multiple levels inside

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

just think about that again, we can just store state diff work in #7005 to save disc space, it's the best strategy to me. The state.validators does not seem to change much over epochs, we can diff that separately to save the diff file. Need to see how much the state is without validators

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

just think about that again, we can just store state diff work in #7005 to save disc space, it's the best strategy to me.

yeah wanted to ask you this as well if that was a possibility once we get it working

nflaig pushed a commit that referenced this pull request Oct 28, 2025
wemeetagain pushed a commit that referenced this pull request Oct 28, 2025
**Motivation**

Last change from #7501 which
we implemented because persisted checkpoint states are added each epoch
during non-finality and never pruned until the chain finalizes again. It
turns out this is not sustainable if we have multiple weeks of
non-finality since it takes up hundreds of GB of disk space and many
nodes don't have sufficient disk space to handle this.

The long term solution is to store states more efficiently but for now
we should at least have a option to enable pruning, there is also always
the options to clean up the `checkpoint_states` folder manually.

**Description**

This PR adds a new flag `--chain.maxCPStateEpochsOnDisk` to enable
pruning of persisted checkpoint states. By default we don't prune any
persistent checkpoint states as it's not safe to delete them during long
non-finality as we don't know the state of the chain and there could be
a deep (hundreds of epochs) reorg if there two competing chains with
similar weight but we wouldn't have a close enough state to pivot to
this chain and instead require a resync from last finalized checkpoint
state which could be very far in the past.


Previous PR #7510

---------

Co-authored-by: twoeths <10568965+twoeths@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants