Skip to content
This repository was archived by the owner on Mar 14, 2025. It is now read-only.

Commit 7b4e2e9

Browse files
committed
fixes for legacy version
1 parent 58e561b commit 7b4e2e9

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

core/chains/evm/logpoller/log_poller.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ func (lp *logPoller) Replay(ctx context.Context, fromBlock int64) (err error) {
407407
defer func() {
408408
if errors.Is(err, context.Canceled) {
409409
err = ErrReplayRequestAborted
410-
} else if errors.Is(err, commontypes.ErrFinalityViolated) {
410+
} else if errors.Is(err, ErrFinalityViolated) {
411411
// Replay only declares finality violation and does not resolve it, as it's possible that [fromBlock, savedFinalizedBlockNumber]
412412
// does not contain the violation.
413413
lp.lggr.Criticalw("Replay failed due to finality violation", "fromBlock", fromBlock, "err", err)
@@ -633,7 +633,7 @@ func (lp *logPoller) run() {
633633
}
634634
err := lp.BackupPollAndSaveLogs(ctx)
635635
switch {
636-
case errors.Is(err, commontypes.ErrFinalityViolated):
636+
case errors.Is(err, ErrFinalityViolated):
637637
// BackupPoll only declares finality violation and does not resolve it, as it's possible that processed range
638638
// does not contain the violation.
639639
lp.lggr.Criticalw("Backup poll failed due to finality violation", "err", err)
@@ -816,7 +816,7 @@ func (lp *logPoller) blocksFromFinalizedLogs(ctx context.Context, logs []types.L
816816

817817
for i, log := range logs {
818818
if log.BlockHash != blocks[i].BlockHash {
819-
return nil, fmt.Errorf("finalized log produced by tx %s has block hash %s that does not match fetched block's hash %s: %w", log.TxHash, log.BlockHash, blocks[i].BlockHash, commontypes.ErrFinalityViolated)
819+
return nil, fmt.Errorf("finalized log produced by tx %s has block hash %s that does not match fetched block's hash %s: %w", log.TxHash, log.BlockHash, blocks[i].BlockHash, ErrFinalityViolated)
820820
}
821821
}
822822

@@ -949,7 +949,7 @@ func (lp *logPoller) getCurrentBlockMaybeHandleReorg(ctx context.Context, curren
949949
// conditions this would be equal to lastProcessed.BlockNumber + 1.
950950
func (lp *logPoller) PollAndSaveLogs(ctx context.Context, currentBlockNumber int64) {
951951
err := lp.pollAndSaveLogs(ctx, currentBlockNumber)
952-
if errors.Is(err, commontypes.ErrFinalityViolated) {
952+
if errors.Is(err, ErrFinalityViolated) {
953953
lp.lggr.Criticalw("Failed to poll and save logs due to finality violation, retrying later", "err", err)
954954
lp.finalityViolated.Store(true)
955955
lp.SvcErrBuffer.Append(err)
@@ -1107,7 +1107,7 @@ func (lp *logPoller) findBlockAfterLCA(ctx context.Context, current *evmtypes.He
11071107
}
11081108

11091109
lp.lggr.Criticalw("Reorg greater than finality depth detected", "finalityTag", lp.useFinalityTag, "current", current.Number, "latestFinalized", latestFinalizedBlockNumber)
1110-
return nil, fmt.Errorf("%w: finalized block hash %s does not match RPC's %s at height %d", commontypes.ErrFinalityViolated, ourParentBlockHash, blockAfterLCA.Hash, blockAfterLCA.Number)
1110+
return nil, fmt.Errorf("%w: finalized block hash %s does not match RPC's %s at height %d", ErrFinalityViolated, ourParentBlockHash, blockAfterLCA.Hash, blockAfterLCA.Number)
11111111
}
11121112

11131113
// PruneOldBlocks removes blocks that are > lp.keepFinalizedBlocksDepth behind the latest finalized block.
@@ -1320,13 +1320,13 @@ func (lp *logPoller) fillRemainingBlocksFromRPC(
13201320

13211321
logPollerBlocks := make(map[uint64]LogPollerBlock)
13221322
for _, head := range evmBlocks {
1323-
logPollerBlocks[uint64(head.Number)] = LogPollerBlock{
1324-
EvmChainId: head.EVMChainID,
1325-
BlockHash: head.Hash,
1326-
BlockNumber: head.Number,
1327-
BlockTimestamp: head.Timestamp,
1328-
FinalizedBlockNumber: head.Number, // always finalized; only matters if this block is returned by LatestBlock()
1329-
CreatedAt: head.Timestamp,
1323+
logPollerBlocks[uint64(head.BlockNumber)] = LogPollerBlock{
1324+
EvmChainId: head.EvmChainId,
1325+
BlockHash: head.BlockHash,
1326+
BlockNumber: head.BlockNumber,
1327+
BlockTimestamp: head.BlockTimestamp,
1328+
FinalizedBlockNumber: head.BlockNumber, // always finalized; only matters if this block is returned by LatestBlock()
1329+
CreatedAt: head.BlockTimestamp,
13301330
}
13311331
}
13321332
return logPollerBlocks, nil
@@ -1382,7 +1382,7 @@ func (lp *logPoller) fetchBlocks(ctx context.Context, blocksRequested []uint64,
13821382

13831383
if rpcChainReference.Hash != chainReference.BlockHash {
13841384
return nil, fmt.Errorf("expected RPC's finalized block hash at hegiht %d to be %s but got %s: %w",
1385-
chainReference.BlockNumber, chainReference.BlockHash, rpcChainReference.Hash, commontypes.ErrFinalityViolated)
1385+
chainReference.BlockNumber, chainReference.BlockHash, rpcChainReference.Hash, ErrFinalityViolated)
13861386
}
13871387

13881388
reqs = reqs[:len(reqs)-1] // no need to include chain reference into results
@@ -1489,7 +1489,7 @@ func ensureIdenticalBlocksBatches(fetched1, fetched2 map[uint64]*evmtypes.Head)
14891489
}
14901490

14911491
if head1.Hash != head2.Hash {
1492-
return fmt.Errorf("expected block %d to be finalized but got different hashes %s and %s from RPC: %w", num, head1.Hash, head2.Hash, commontypes.ErrFinalityViolated)
1492+
return fmt.Errorf("expected block %d to be finalized but got different hashes %s and %s from RPC: %w", num, head1.Hash, head2.Hash, ErrFinalityViolated)
14931493
}
14941494
}
14951495

core/chains/evm/logpoller/log_poller_internal_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ func Test_PollAndSaveLogs_BackfillFinalityViolation(t *testing.T) {
709709
require.NoError(t, orm.InsertBlock(tests.Context(t), common.HexToHash("0x123"), 2, time.Unix(10, 0), 2))
710710
lp := NewLogPoller(orm, ec, lggr, headTracker, lpOpts)
711711
lp.PollAndSaveLogs(tests.Context(t), 4)
712-
require.ErrorIs(t, lp.HealthReport()[lp.Name()], commontypes.ErrFinalityViolated)
712+
require.ErrorIs(t, lp.HealthReport()[lp.Name()], ErrFinalityViolated)
713713
})
714714
t.Run("RPCs contradict each other and return different finalized blocks", func(t *testing.T) {
715715
lggr, _ := logger.TestObserved(t, zapcore.ErrorLevel)
@@ -729,7 +729,7 @@ func Test_PollAndSaveLogs_BackfillFinalityViolation(t *testing.T) {
729729
})
730730
lp := NewLogPoller(orm, ec, lggr, headTracker, lpOpts)
731731
lp.PollAndSaveLogs(tests.Context(t), 4)
732-
require.ErrorIs(t, lp.HealthReport()[lp.Name()], commontypes.ErrFinalityViolated)
732+
require.ErrorIs(t, lp.HealthReport()[lp.Name()], ErrFinalityViolated)
733733
})
734734
t.Run("Log's hash does not match block's", func(t *testing.T) {
735735
lggr, _ := logger.TestObserved(t, zapcore.ErrorLevel)
@@ -746,7 +746,7 @@ func Test_PollAndSaveLogs_BackfillFinalityViolation(t *testing.T) {
746746
mockBatchCallContext(t, ec)
747747
lp := NewLogPoller(orm, ec, lggr, headTracker, lpOpts)
748748
lp.PollAndSaveLogs(tests.Context(t), 4)
749-
require.ErrorIs(t, lp.HealthReport()[lp.Name()], commontypes.ErrFinalityViolated)
749+
require.ErrorIs(t, lp.HealthReport()[lp.Name()], ErrFinalityViolated)
750750
})
751751
t.Run("Happy path", func(t *testing.T) {
752752
lggr, _ := logger.TestObserved(t, zapcore.ErrorLevel)

core/chains/evm/logpoller/orm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,9 +993,9 @@ func (o *DSORM) FilteredLogs(ctx context.Context, filter []query.Expression, lim
993993
func (o *DSORM) SelectLatestFinalizedBlock(ctx context.Context) (*LogPollerBlock, error) {
994994
var b LogPollerBlock
995995
if err := o.ds.GetContext(ctx, &b,
996-
blocksQuery(`WHERE evm_chain_id = $1 AND block_number <= (
996+
`SELECT * FROM evm.log_poller_blocks WHERE evm_chain_id = $1 AND block_number <= (
997997
SELECT finalized_block_number FROM evm.log_poller_blocks WHERE evm_chain_id = $1 ORDER BY block_number DESC LIMIT 1
998-
) ORDER BY block_number DESC LIMIT 1`), ubig.New(o.chainID),
998+
) ORDER BY block_number DESC LIMIT 1`, ubig.New(o.chainID),
999999
); err != nil {
10001000
return nil, err
10011001
}

0 commit comments

Comments
 (0)