diff --git a/oracle/pkg/l1Listener/l1Listener.go b/oracle/pkg/l1Listener/l1Listener.go index b8f3d0e71..e590afb2c 100644 --- a/oracle/pkg/l1Listener/l1Listener.go +++ b/oracle/pkg/l1Listener/l1Listener.go @@ -27,6 +27,7 @@ type WinnerRegister interface { type EthClient interface { BlockNumber(ctx context.Context) (uint64, error) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) + BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) } type L1Listener struct { diff --git a/oracle/pkg/l1Listener/l1Listener_test.go b/oracle/pkg/l1Listener/l1Listener_test.go index db9e7b634..c85695965 100644 --- a/oracle/pkg/l1Listener/l1Listener_test.go +++ b/oracle/pkg/l1Listener/l1Listener_test.go @@ -205,6 +205,10 @@ func (t *testEthClient) HeaderByNumber(_ context.Context, number *big.Int) (*typ return hdr, nil } +func (t *testEthClient) BlockByNumber(_ context.Context, number *big.Int) (*types.Block, error) { + return nil, nil +} + func publishLog( eventManager events.EventManager, blockNum *big.Int, diff --git a/oracle/pkg/node/node.go b/oracle/pkg/node/node.go index 74b0b2a9f..11a84b34d 100644 --- a/oracle/pkg/node/node.go +++ b/oracle/pkg/node/node.go @@ -164,6 +164,8 @@ func NewNode(opts *Options) (*Node, error) { listenerL1Client = &laggerdL1Client{EthClient: listenerL1Client, amount: opts.LaggerdMode} } + listenerL1Client = &infiniteRetryL1Client{EthClient: listenerL1Client, logger: nd.logger} + blockTracker, err := blocktracker.NewBlocktrackerTransactor( opts.BlockTrackerContractAddr, settlementRPC, @@ -232,7 +234,7 @@ func NewNode(opts *Options) (*Node, error) { updtr, err := updater.NewUpdater( nd.logger.With("component", "updater"), - l1Client, + listenerL1Client, st, evtMgr, oracleTransactorSession, @@ -404,6 +406,53 @@ func (w *winnerOverrideL1Client) HeaderByNumber(ctx context.Context, number *big return hdr, nil } +type infiniteRetryL1Client struct { + l1Listener.EthClient + logger *slog.Logger +} + +func (i *infiniteRetryL1Client) BlockNumber(ctx context.Context) (uint64, error) { + var blkNum uint64 + var err error + for { + blkNum, err = i.EthClient.BlockNumber(ctx) + if err == nil { + break + } + i.logger.Error("failed to get block number, retrying...", "error", err) + time.Sleep(1 * time.Second) + } + return blkNum, nil +} + +func (i *infiniteRetryL1Client) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) { + var hdr *types.Header + var err error + for { + hdr, err = i.EthClient.HeaderByNumber(ctx, number) + if err == nil { + break + } + i.logger.Error("failed to get header by number, retrying...", "error", err) + time.Sleep(1 * time.Second) + } + return hdr, nil +} + +func (i *infiniteRetryL1Client) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) { + var blk *types.Block + var err error + for { + blk, err = i.EthClient.BlockByNumber(ctx, number) + if err == nil { + break + } + i.logger.Error("failed to get block by number, retrying...", "error", err) + time.Sleep(1 * time.Second) + } + return blk, nil +} + func setBuilderMapping( ctx context.Context, bt *blocktracker.BlocktrackerTransactorSession, diff --git a/x/contracts/txmonitor/eth_helper.go b/x/contracts/txmonitor/eth_helper.go index 77113b3c4..0d4c84ed4 100644 --- a/x/contracts/txmonitor/eth_helper.go +++ b/x/contracts/txmonitor/eth_helper.go @@ -114,7 +114,7 @@ func (e *evmHelper) BatchReceipts(ctx context.Context, txHashes []common.Hash) ( var receipts []Result var err error - for retries := 0; retries < 3; retries++ { + for retries := 0; retries < 100; retries++ { // Execute the batch request err = e.client.BatchCallContext(ctx, batch) if err == nil {