Skip to content

Commit

Permalink
Restoring previous version of pruning (without left join)
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-sekara committed Nov 21, 2024
1 parent f8d5b19 commit 8028030
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
7 changes: 1 addition & 6 deletions core/chains/evm/logpoller/observability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,7 @@ func TestCountersAreProperlyPopulatedForWrites(t *testing.T) {
assert.Equal(t, float64(20), testutil.ToFloat64(orm.logsInserted.WithLabelValues("420")))
assert.Equal(t, float64(2), testutil.ToFloat64(orm.blocksInserted.WithLabelValues("420")))

rowsAffected, err := orm.DeleteExpiredLogs(ctx, 3)
require.NoError(t, err)
require.Equal(t, int64(3), rowsAffected)
assert.Equal(t, 3, counterFromGaugeByLabels(orm.datasetSize, "420", "DeleteExpiredLogs", "delete"))

rowsAffected, err = orm.DeleteBlocksBefore(ctx, 30, 0)
rowsAffected, err := orm.DeleteBlocksBefore(ctx, 30, 0)
require.NoError(t, err)
require.Equal(t, int64(2), rowsAffected)
assert.Equal(t, 2, counterFromGaugeByLabels(orm.datasetSize, "420", "DeleteBlocksBefore", "delete"))
Expand Down
46 changes: 43 additions & 3 deletions core/chains/evm/logpoller/orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func TestORM_GetBlocks_From_Range_Recent_Blocks(t *testing.T) {
}

func TestORM(t *testing.T) {
t.Parallel()
th := SetupTH(t, lpOpts)
o1 := th.ORM
o2 := th.ORM2
Expand Down Expand Up @@ -334,6 +335,36 @@ func TestORM(t *testing.T) {
},
}))

// Insert a couple logs on a different chain, to make sure
// these aren't affected by any operations on the chain LogPoller
// is managing.
require.NoError(t, o2.InsertLogs(ctx, []logpoller.Log{
{
EvmChainId: ubig.New(th.ChainID2),
LogIndex: 8,
BlockHash: common.HexToHash("0x1238"),
BlockNumber: int64(17),
EventSig: topic2,
Topics: [][]byte{topic2[:]},
Address: common.HexToAddress("0x1236"),
TxHash: common.HexToHash("0x1888"),
Data: []byte("same log on unrelated chain"),
BlockTimestamp: time.Now(),
},
{
EvmChainId: ubig.New(th.ChainID2),
LogIndex: 9,
BlockHash: common.HexToHash("0x1999"),
BlockNumber: int64(18),
EventSig: topic,
Topics: [][]byte{topic[:], topic2[:]},
Address: common.HexToAddress("0x5555"),
TxHash: common.HexToHash("0x1543"),
Data: []byte("different log on unrelated chain"),
BlockTimestamp: time.Now(),
},
}))

t.Log(latest.BlockNumber)
logs, err := o1.SelectLogsByBlockRange(ctx, 1, 17)
require.NoError(t, err)
Expand Down Expand Up @@ -454,11 +485,20 @@ func TestORM(t *testing.T) {
require.NoError(t, err)
require.Len(t, logs, 8)

// Delete expired logs
// Delete expired logs with page limit
time.Sleep(2 * time.Millisecond) // just in case we haven't reached the end of the 1ms retention period
deleted, err := o1.DeleteExpiredLogs(ctx, 0)
deleted, err := o1.DeleteExpiredLogs(ctx, 2)
require.NoError(t, err)
assert.Equal(t, int64(1), deleted)

// Ensure that both of the logs from the second chain are still there
logs, err = o2.SelectLogs(ctx, 0, 100, common.HexToAddress("0x1236"), topic2)
require.NoError(t, err)
assert.Len(t, logs, 1)
logs, err = o2.SelectLogs(ctx, 0, 100, common.HexToAddress("0x5555"), topic)
require.NoError(t, err)
assert.Len(t, logs, 1)

logs, err = o1.SelectLogsByBlockRange(ctx, 1, latest.BlockNumber)
require.NoError(t, err)
// The only log which should be deleted is the one which matches filter1 (ret=1ms) but not filter12 (ret=1 hour)
Expand All @@ -471,7 +511,7 @@ func TestORM(t *testing.T) {
require.NoError(t, err)
logs, err = o1.SelectLogsByBlockRange(ctx, 1, latest.BlockNumber)
require.NoError(t, err)
require.Zero(t, len(logs))
assert.Zero(t, len(logs))
}

type PgxLogger struct {
Expand Down

0 comments on commit 8028030

Please sign in to comment.