Skip to content
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

Handle LogPoller edge case involving backfill followed by an error #11298

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/chains/evm/logpoller/log_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ func (lp *logPoller) backfill(ctx context.Context, start, end int64) error {
}

lp.lggr.Debugw("Backfill found logs", "from", from, "to", to, "logs", len(gethLogs), "blocks", blocks)
err = lp.orm.InsertLogs(convertLogs(gethLogs, blocks, lp.lggr, lp.ec.ConfiguredChainID()), pg.WithParentCtx(ctx))
err = lp.orm.InsertLogsWithBlock(convertLogs(gethLogs, blocks, lp.lggr, lp.ec.ConfiguredChainID()), blocks[len(blocks)-1], pg.WithParentCtx(ctx))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if err != nil {
lp.lggr.Warnw("Unable to insert logs, retrying", "err", err, "from", from, "to", to)
return err
Expand Down
8 changes: 4 additions & 4 deletions core/chains/evm/logpoller/log_poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -965,8 +965,8 @@ func TestLogPoller_PollAndSaveLogs(t *testing.T) {
lgs, err = th.ORM.SelectLogsByBlockRange(11, 17)
require.NoError(t, err)
assert.Equal(t, 7, len(lgs))
th.assertHaveCanonical(t, 15, 16)
th.assertDontHave(t, 11, 14) // Do not expect to save backfilled blocks.
th.assertHaveCanonical(t, 14, 16) // Should have last finalized block plus unfinalized blocks
th.assertDontHave(t, 11, 13) // Should not have older finalized blocks

// Verify that a custom block timestamp will get written to db correctly also
b, err = th.Client.BlockByNumber(testutils.Context(t), nil)
Expand Down Expand Up @@ -1057,8 +1057,8 @@ func TestLogPoller_PollAndSaveLogsDeepReorg(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, hexutil.MustDecode(`0x0000000000000000000000000000000000000000000000000000000000000002`), lgs[0].Data)
th.assertHaveCanonical(t, 1, 1)
th.assertDontHave(t, 2, 5) // These blocks are backfilled
th.assertHaveCanonical(t, 6, 10)
th.assertDontHave(t, 2, 3) // These blocks are backfilled
th.assertHaveCanonical(t, 5, 10)
})
}
}
Expand Down
Loading