Skip to content

Commit

Permalink
get a new client in every attempt to check if the web3 endpoint suppo…
Browse files Browse the repository at this point in the history
…rt CodeAt, increase the number of retries to get the token creation block
  • Loading branch information
lucasmenendez committed Apr 17, 2024
1 parent 1ac7432 commit adee72c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion scanner/providers/web3/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package web3
import "time"

const (
DefaultMaxWeb3ClientRetries = 3
DefaultMaxWeb3ClientRetries = 5
RetryWeb3Cooldown = 500 * time.Millisecond
)

Expand Down
9 changes: 5 additions & 4 deletions scanner/providers/web3/web3_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ func creationBlock(client *Client, ctx context.Context, addr common.Address) (ui
// check if the current client supports `eth_getCode` method, if not, return
// 1 and nil. It is assumed that the contract is created at block 1 to start
// scanning from the first block.
ethClient, err := client.EthClient()
if err != nil {
return 0, err
}
getCodeSupport := false
for i := 0; i < DefaultMaxWeb3ClientRetries; i++ {
ethClient, err := client.EthClient()
if err != nil {
return 0, err
}
if getCodeSupport = providers.ClientSupportsGetCode(ctx, ethClient, addr); getCodeSupport {
break
}
Expand All @@ -50,6 +50,7 @@ func creationBlock(client *Client, ctx context.Context, addr common.Address) (ui
return 1, nil
}
// get the latest block number
var err error
var lastBlock uint64
for i := 0; i < DefaultMaxWeb3ClientRetries; i++ {
lastBlock, err = client.BlockNumber(ctx)
Expand Down

0 comments on commit adee72c

Please sign in to comment.