Skip to content

Commit

Permalink
feat: adds retries to all calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ckartik committed Jul 3, 2024
1 parent a7a4fc0 commit 4bcf910
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
1 change: 1 addition & 0 deletions oracle/pkg/l1Listener/l1Listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions oracle/pkg/l1Listener/l1Listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
51 changes: 50 additions & 1 deletion oracle/pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -232,7 +234,7 @@ func NewNode(opts *Options) (*Node, error) {

updtr, err := updater.NewUpdater(
nd.logger.With("component", "updater"),
l1Client,
listenerL1Client,
st,
evtMgr,
oracleTransactorSession,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion x/contracts/txmonitor/eth_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4bcf910

Please sign in to comment.