Skip to content

Commit 54c15d8

Browse files
committed
Merge branch 'feature/PLEX-2473-fix-reorg-handing-on-replay' into feature/PLEX-2473-lp-batch-insert-blocks
2 parents 57b73d1 + f60d8b4 commit 54c15d8

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

pkg/logpoller/log_poller.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,6 @@ func (lp *logPoller) backfill(ctx context.Context, start, end int64) error {
955955
}
956956

957957
func (lp *logPoller) headerByNumber(ctx context.Context, blockNumber int64) (*evmtypes.Head, error) {
958-
// If we don't have the current block already, lets get it.
959958
header, err := lp.latencyMonitor.HeadByNumber(ctx, big.NewInt(blockNumber))
960959
if err != nil {
961960
lp.lggr.Warnw("Unable to get currentBlock", "err", err, "blockNumber", blockNumber)
@@ -1045,14 +1044,13 @@ func (lp *logPoller) getCurrentBlockMaybeHandleReorg(ctx context.Context, curren
10451044

10461045
if latestBlockRPC.Hash != latestBlockDB.BlockHash {
10471046
// Reorg detected, handle it
1048-
lca, err := lp.handleReorg(ctx, latestBlockRPC)
1047+
blockAfterLCA, err := lp.handleReorg(ctx, latestBlockRPC)
10491048
if err != nil {
10501049
return nil, fmt.Errorf("failed to handle reorg: %w", err)
10511050
}
10521051

1053-
if lca.Number < currentBlock.BlockNumber() {
1054-
// LCA is older than current block, we need to get the new current block after reorg
1055-
return lca, nil
1052+
if blockAfterLCA.Number < currentBlock.BlockNumber() {
1053+
return blockAfterLCA, nil
10561054
}
10571055
}
10581056

pkg/logpoller/log_poller_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,7 +2163,7 @@ func TestLogPoller_Reorg_On_Replay(t *testing.T) {
21632163
// Expected behaviour:
21642164
// 1. LogPoller should replace reorged block 11 with a new data.
21652165
// 2. DB must not contain at any point logs from both old and new block 11.
2166-
// 3. Finality Violation must not occur, since chain did not violate finality depth.
2166+
// 3. Finality Violation must not occur, since chain did not violate finality depth.
21672167
t.Parallel()
21682168
const reorgedBlockNumber = 11
21692169
testCases := []struct {
@@ -2210,7 +2210,7 @@ func TestLogPoller_Reorg_On_Replay(t *testing.T) {
22102210
th.Backend.Commit()
22112211
}
22122212

2213-
// start LogPoller and wait for it to complete first poll. Second poll won't happen until we call PollAndSaveLogs again, since poll period is very long.
2213+
// Start LogPoller and wait for it to complete the first poll. The second poll won't happen until we call Replay, since the poll period is very long.
22142214
require.NoError(t, th.LogPoller.Start(t.Context()))
22152215
defer func() {
22162216
require.NoError(t, th.LogPoller.Close())
@@ -2224,16 +2224,17 @@ func TestLogPoller_Reorg_On_Replay(t *testing.T) {
22242224
require.NoError(t, err)
22252225
require.Equal(t, int64(reorgedBlockNumber), reorgedBlock.Number().Int64())
22262226

2227-
// Replace block 11 with a new block and burry it under 1 new block
2227+
// Replace block 11 with a new block and bury it under 1 new block
22282228
require.NoError(t, th.Backend.Fork(reorgedBlock.ParentHash()))
22292229
const newLogData = int64(123)
22302230
// Commit reorgedBlock and numberOfBlocksAfterReorg on top of it
22312231
for range tc.numberOfBlocksAfterReorg + 1 {
22322232
// emit log that is not tracked by LP to ensure that tracked log has a different index.
2233-
// So if reorg is not properly handled and both logs end up in the database
2233+
// So if reorg is not properly handled, both logs end up in the database and the test fails.
22342234
_, err = th.Emitter2.EmitLog1(th.Owner, []*big.Int{big.NewInt(int64(10))})
22352235
require.NoError(t, err)
22362236
_, err = th.Emitter1.EmitLog1(th.Owner, []*big.Int{big.NewInt(newLogData)})
2237+
require.NoError(t, err)
22372238
th.Backend.Commit()
22382239
}
22392240

0 commit comments

Comments
 (0)