Skip to content

Commit

Permalink
ethmonitor: add network timeout when fetching chainId
Browse files Browse the repository at this point in the history
  • Loading branch information
pkieltyka committed Apr 4, 2024
1 parent 1eed224 commit 91fd5b3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ethmonitor/ethmonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1025,16 +1025,21 @@ func (m *Monitor) setPayload(value []byte) []byte {
func getChainID(provider ethrpc.Interface) (*big.Int, error) {
var chainID *big.Int
err := breaker.Do(context.Background(), func() error {
id, err := provider.ChainID(context.Background())
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
defer cancel()

id, err := provider.ChainID(ctx)
if err != nil {
return err
}
chainID = id
return nil
}, nil, 1*time.Second, 2, 20)
}, nil, 1*time.Second, 2, 3)

if err != nil {
return nil, err
}

return chainID, nil
}

Expand Down

0 comments on commit 91fd5b3

Please sign in to comment.