diff --git a/eth/stagedsync/stage_log_index.go b/eth/stagedsync/stage_log_index.go index 9f7d91833b0..6919ffbfc0f 100644 --- a/eth/stagedsync/stage_log_index.go +++ b/eth/stagedsync/stage_log_index.go @@ -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 } diff --git a/eth/stagedsync/stage_log_index_test.go b/eth/stagedsync/stage_log_index_test.go index a16eee3f27f..b736d2254d3 100644 --- a/eth/stagedsync/stage_log_index_test.go +++ b/eth/stagedsync/stage_log_index_test.go @@ -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 @@ -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) { @@ -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 } }