Skip to content

Commit

Permalink
Fix older logs pruning (#9932)
Browse files Browse the repository at this point in the history
Improves upon #9913
Closes #9889
  • Loading branch information
somnathb1 authored Apr 15, 2024
1 parent 1d95570 commit 1248831
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion eth/stagedsync/stage_log_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ func pruneLogIndex(logPrefix string, tx kv.RwTx, tmpDir string, pruneFrom, prune

notToPrune := false // To identify whether this log key has addr in noPruneContracts
for _, l := range logs {
if noPruneContracts != nil && noPruneContracts[l.Address] {
// If any of the logs have an address in noPruneContracts, then the whole tx is related to it, and must not be pruned, including addr and topic indexes
if noPruneContracts != nil && noPruneContracts[l.Address] || notToPrune {
notToPrune = true
continue
}
Expand Down
6 changes: 3 additions & 3 deletions eth/stagedsync/stage_log_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestPruneLogIndex(t *testing.T) {
require, tmpDir, ctx := require.New(t), t.TempDir(), context.Background()
_, tx := memdb.NewTestTx(t)

_, _ = genReceipts(t, tx, 100)
_, _ = genReceipts(t, tx, 90)

cfg := StageLogIndexCfg(nil, prune.DefaultMode, "", nil)
cfgCopy := cfg
Expand All @@ -135,7 +135,7 @@ func TestPruneLogIndex(t *testing.T) {
require.NoError(err)

// Mode test
err = pruneLogIndex("", tx, tmpDir, 0, 50, ctx, logger, nil)
err = pruneLogIndex("", tx, tmpDir, 0, 45, ctx, logger, map[libcommon.Address]bool{{1}: true}) // using addr {1} from genReceipts
require.NoError(err)

{
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestPruneLogIndex(t *testing.T) {
return nil
})
require.NoError(err)
require.True(total == 49) // 51 logs have been pruned
require.Equal(total, 60) // 1/3rd of 45 not pruned as it has address "1", so 30 Pruned in total, remaining 90-30
}
}

Expand Down

0 comments on commit 1248831

Please sign in to comment.