Skip to content

Commit

Permalink
fix: add timeout and view blockNumber as the sucessful dial
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawn-Huang-Tron committed Mar 25, 2024
1 parent dc5139d commit d4ac7c1
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,35 @@ func InitChain(
for _, endpoint := range chainconfig.MultiEndpoint {
go func(e string) {
b, err := ethclient.Dial(e)
if err == nil {
backendChan <- b
if err != nil {
return
}
_, err = backend.BlockNumber(context.Background())
if err != nil {
return
}
backendChan <- b
}(endpoint)
}
backend = <-backendChan
select {
case backend = <-backendChan:
case <-time.After(time.Second * 60):
return nil, errors.New("could not connect all rpc configuration after 1 min, please try again or check your network")
}
} else {
backend, err = ethclient.Dial(chainconfig.Endpoint)
if err != nil {
return nil, fmt.Errorf("dial eth client: %w", err)
}
}
_, err = backend.BlockNumber(context.Background())
if err != nil {
errMsg := "Could not connect to blockchain rpc, please check your network connection"
if err == io.EOF {
return nil, errors.New(errMsg)
_, err = backend.BlockNumber(context.Background())
if err != nil {
errMsg := "Could not connect to blockchain rpc, please check your network connection"
if err == io.EOF {
return nil, errors.New(errMsg)

}
return nil, fmt.Errorf("%s.%w", errMsg, err)
}
return nil, fmt.Errorf("%s.%w", errMsg, err)
}

overlayEthAddress, err := signer.EthereumAddress()
Expand Down

0 comments on commit d4ac7c1

Please sign in to comment.