-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Filter deposit contract logs before pruning #9123
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4fdd316
Working Prune filter
somnergy 1848a36
Add NoPrune config
somnergy 899b83c
Add comment
somnergy dd15d63
Merge branch 'devel' into som/pruned-hack
somnergy 88bfcee
Add missed parameter
somnergy 05e5d1c
Review comments
somnergy b8db8e8
Merge branch 'devel' into docker_prune_optimized
somnergy 53e0e8f
Refresh noPruneContracts
somnergy 7edc25a
Pass by ref
somnergy eafe563
fmt
somnergy d4220f1
Remove pruneBlockDefault
somnergy 3c74d8d
Add noPruneContracts for goerli and holesky
somnergy 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,20 +31,22 @@ const ( | |
| ) | ||
|
|
||
| type LogIndexCfg struct { | ||
| tmpdir string | ||
| db kv.RwDB | ||
| prune prune.Mode | ||
| bufLimit datasize.ByteSize | ||
| flushEvery time.Duration | ||
| tmpdir string | ||
| db kv.RwDB | ||
| prune prune.Mode | ||
| bufLimit datasize.ByteSize | ||
| flushEvery time.Duration | ||
| noPruneContracts map[libcommon.Address]bool | ||
| } | ||
|
|
||
| func StageLogIndexCfg(db kv.RwDB, prune prune.Mode, tmpDir string) LogIndexCfg { | ||
| func StageLogIndexCfg(db kv.RwDB, prune prune.Mode, tmpDir string, noPruneContracts map[libcommon.Address]bool) LogIndexCfg { | ||
| return LogIndexCfg{ | ||
| db: db, | ||
| prune: prune, | ||
| bufLimit: bitmapsBufLimit, | ||
| flushEvery: bitmapsFlushEvery, | ||
| tmpdir: tmpDir, | ||
| db: db, | ||
| prune: prune, | ||
| bufLimit: bitmapsBufLimit, | ||
| flushEvery: bitmapsFlushEvery, | ||
| tmpdir: tmpDir, | ||
| noPruneContracts: noPruneContracts, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -80,14 +82,14 @@ func SpawnLogIndex(s *StageState, tx kv.RwTx, cfg LogIndexCfg, ctx context.Conte | |
| } | ||
|
|
||
| startBlock := s.BlockNumber | ||
| pruneTo := cfg.prune.Receipts.PruneTo(endBlock) | ||
| if startBlock < pruneTo { | ||
| startBlock = pruneTo | ||
| } | ||
| pruneTo := cfg.prune.Receipts.PruneTo(endBlock) //endBlock - prune.r.older | ||
| // if startBlock < pruneTo { | ||
| // startBlock = pruneTo | ||
| // } | ||
| if startBlock > 0 { | ||
| startBlock++ | ||
| } | ||
| if err = promoteLogIndex(logPrefix, tx, startBlock, endBlock, cfg, ctx, logger); err != nil { | ||
| if err = promoteLogIndex(logPrefix, tx, startBlock, endBlock, pruneTo, cfg, ctx, logger); err != nil { | ||
| return err | ||
| } | ||
| if err = s.Update(tx, endBlock); err != nil { | ||
|
|
@@ -103,7 +105,7 @@ func SpawnLogIndex(s *StageState, tx kv.RwTx, cfg LogIndexCfg, ctx context.Conte | |
| return nil | ||
| } | ||
|
|
||
| func promoteLogIndex(logPrefix string, tx kv.RwTx, start uint64, endBlock uint64, cfg LogIndexCfg, ctx context.Context, logger log.Logger) error { | ||
| func promoteLogIndex(logPrefix string, tx kv.RwTx, start uint64, endBlock uint64, pruneBlock uint64, cfg LogIndexCfg, ctx context.Context, logger log.Logger) error { | ||
| quit := ctx.Done() | ||
| logEvery := time.NewTicker(30 * time.Second) | ||
| defer logEvery.Stop() | ||
|
|
@@ -175,6 +177,9 @@ func promoteLogIndex(logPrefix string, tx kv.RwTx, start uint64, endBlock uint64 | |
| } | ||
|
|
||
| for _, l := range ll { | ||
| if cfg.noPruneContracts != nil && !cfg.noPruneContracts[l.Address] && l.BlockNumber < pruneBlock { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for performance maybe better place |
||
| continue | ||
| } | ||
| for _, topic := range l.Topics { | ||
| topicStr := string(topic.Bytes()) | ||
| m, ok := topics[topicStr] | ||
|
|
@@ -405,7 +410,7 @@ func PruneLogIndex(s *PruneState, tx kv.RwTx, cfg LogIndexCfg, ctx context.Conte | |
| } | ||
|
|
||
| pruneTo := cfg.prune.Receipts.PruneTo(s.ForwardProgress) | ||
| if err = pruneLogIndex(logPrefix, tx, cfg.tmpdir, pruneTo, ctx, logger); err != nil { | ||
| if err = pruneLogIndex(logPrefix, tx, cfg.tmpdir, pruneTo, ctx, logger, cfg.noPruneContracts); err != nil { | ||
| return err | ||
| } | ||
| if err = s.Done(tx); err != nil { | ||
|
|
@@ -420,7 +425,7 @@ func PruneLogIndex(s *PruneState, tx kv.RwTx, cfg LogIndexCfg, ctx context.Conte | |
| return nil | ||
| } | ||
|
|
||
| func pruneLogIndex(logPrefix string, tx kv.RwTx, tmpDir string, pruneTo uint64, ctx context.Context, logger log.Logger) error { | ||
| func pruneLogIndex(logPrefix string, tx kv.RwTx, tmpDir string, pruneTo uint64, ctx context.Context, logger log.Logger, noPruneContracts map[libcommon.Address]bool) error { | ||
| logEvery := time.NewTicker(logInterval) | ||
| defer logEvery.Stop() | ||
|
|
||
|
|
@@ -461,6 +466,9 @@ func pruneLogIndex(logPrefix string, tx kv.RwTx, tmpDir string, pruneTo uint64, | |
| } | ||
|
|
||
| for _, l := range logs { | ||
| if noPruneContracts != nil && noPruneContracts[l.Address] { | ||
| continue | ||
| } | ||
| for _, topic := range l.Topics { | ||
| if err := topics.Collect(topic.Bytes(), nil); err != nil { | ||
| return err | ||
|
|
||
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.
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.
let's add here more comments. if you know more information now. like: "why CL need it" and "in which mode (archive/non-archive) CL need it" and maybe something else.
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.
Actually, I am only aware that both modes need it initially for constructing deposit data. Deeper dive into CL logic may be needed for me. And here I am just trying to preserve the logs, by default, irrespective of the specification of
prune=flag.I must run a validator test for this, although I am getting the desired results through RPC, the CL may have more expectations that I am not aware of.
There are also talks about Deposit snapshots which, then, would make this whole jutsu pointless