Skip to content

Commit f60d8b4

Browse files
committed
Fix nits
1 parent abead20 commit f60d8b4

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
@@ -2161,7 +2161,7 @@ func TestLogPoller_Reorg_On_Replay(t *testing.T) {
21612161
// Expected behaviour:
21622162
// 1. LogPoller should replace reorged block 11 with a new data.
21632163
// 2. DB must not contain at any point logs from both old and new block 11.
2164-
// 3. Finality Violation must not occur, since chain did not violate finality depth.
2164+
// 3. Finality Violation must not occur, since chain did not violate finality depth.
21652165
t.Parallel()
21662166
const reorgedBlockNumber = 11
21672167
testCases := []struct {
@@ -2208,7 +2208,7 @@ func TestLogPoller_Reorg_On_Replay(t *testing.T) {
22082208
th.Backend.Commit()
22092209
}
22102210

2211-
// 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.
2211+
// 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.
22122212
require.NoError(t, th.LogPoller.Start(t.Context()))
22132213
defer func() {
22142214
require.NoError(t, th.LogPoller.Close())
@@ -2222,16 +2222,17 @@ func TestLogPoller_Reorg_On_Replay(t *testing.T) {
22222222
require.NoError(t, err)
22232223
require.Equal(t, int64(reorgedBlockNumber), reorgedBlock.Number().Int64())
22242224

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

0 commit comments

Comments
 (0)