-
Notifications
You must be signed in to change notification settings - Fork 247
feat: block Pruning #2984
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
Draft
pthmas
wants to merge
9
commits into
main
Choose a base branch
from
pierrick/prunning
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat: block Pruning #2984
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1406a96
basic prunning
pthmas 2777028
prune metadata from ev-node store
pthmas 1d44f27
wiring prunning config to go-header
pthmas 2996d98
prune evm exec store
pthmas 961b3f7
add parameters validation
pthmas ed66fe6
make error handling consistent
pthmas 62bcb56
add method to tracedstore to respect interface
pthmas cf4635c
add prune block to mockstore
pthmas a6daab3
fix test with correct flag count
pthmas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package evm | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/binary" | ||
| "testing" | ||
|
|
||
| ds "github.com/ipfs/go-datastore" | ||
| dssync "github.com/ipfs/go-datastore/sync" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // newTestDatastore creates an in-memory datastore for testing. | ||
| func newTestDatastore(t *testing.T) ds.Batching { | ||
| t.Helper() | ||
| // Wrap the in-memory MapDatastore to satisfy the Batching interface. | ||
| return dssync.MutexWrap(ds.NewMapDatastore()) | ||
| } | ||
|
|
||
| func TestPruneExecMeta_PrunesUpToTargetHeight(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| ctx := context.Background() | ||
| db := newTestDatastore(t) | ||
| store := NewEVMStore(db) | ||
|
|
||
| // Seed ExecMeta entries at heights 1..5 | ||
| for h := uint64(1); h <= 5; h++ { | ||
| meta := &ExecMeta{Height: h} | ||
| require.NoError(t, store.SaveExecMeta(ctx, meta)) | ||
| } | ||
|
|
||
| // Sanity: all heights should be present | ||
| for h := uint64(1); h <= 5; h++ { | ||
| meta, err := store.GetExecMeta(ctx, h) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, meta) | ||
| require.Equal(t, h, meta.Height) | ||
| } | ||
|
|
||
| // Prune up to height 3 | ||
| require.NoError(t, store.PruneExecMeta(ctx, 3)) | ||
|
|
||
| // Heights 1..3 should be gone | ||
| for h := uint64(1); h <= 3; h++ { | ||
| meta, err := store.GetExecMeta(ctx, h) | ||
| require.NoError(t, err) | ||
| require.Nil(t, meta) | ||
| } | ||
|
|
||
| // Heights 4..5 should remain | ||
| for h := uint64(4); h <= 5; h++ { | ||
| meta, err := store.GetExecMeta(ctx, h) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, meta) | ||
| } | ||
|
|
||
| // Re-pruning with the same height should be a no-op | ||
| require.NoError(t, store.PruneExecMeta(ctx, 3)) | ||
| } | ||
|
|
||
| func TestPruneExecMeta_TracksLastPrunedHeight(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| ctx := context.Background() | ||
| db := newTestDatastore(t) | ||
| store := NewEVMStore(db) | ||
|
|
||
| // Seed ExecMeta entries at heights 1..5 | ||
| for h := uint64(1); h <= 5; h++ { | ||
| meta := &ExecMeta{Height: h} | ||
| require.NoError(t, store.SaveExecMeta(ctx, meta)) | ||
| } | ||
|
|
||
| // First prune up to 2 | ||
| require.NoError(t, store.PruneExecMeta(ctx, 2)) | ||
|
|
||
| // Then prune up to 4; heights 3..4 should be deleted in this run | ||
| require.NoError(t, store.PruneExecMeta(ctx, 4)) | ||
|
|
||
| // Verify all heights 1..4 are gone, 5 remains | ||
| for h := uint64(1); h <= 4; h++ { | ||
| meta, err := store.GetExecMeta(ctx, h) | ||
| require.NoError(t, err) | ||
| require.Nil(t, meta) | ||
| } | ||
|
|
||
| meta, err := store.GetExecMeta(ctx, 5) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, meta) | ||
| require.Equal(t, uint64(5), meta.Height) | ||
|
|
||
| // Ensure last-pruned marker is set to 4 | ||
| raw, err := db.Get(ctx, ds.NewKey(lastPrunedExecMetaKey)) | ||
| require.NoError(t, err) | ||
| require.Len(t, raw, 8) | ||
| last := binary.BigEndian.Uint64(raw) | ||
| require.Equal(t, uint64(4), last) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(0 = keep all) does not look correct in relation with the validation before.