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 6ee883c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.7"

services:
census3:
image: ghcr.io/vocdoni/census3:main
image: ghcr.io/vocdoni/census3:aragon
build: .
env_file: ".env"
restart: always
Expand Down
2 changes: 1 addition & 1 deletion scanner/providers/gitcoin/gitcoin_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestGitcoinPassport(t *testing.T) {
})
// create the provider
provider := new(GitcoinPassport)
c.Assert(provider.Init(ctx, GitcoinPassportConf{endpoints["/original"], time.Second * 2, testDB}), qt.IsNil)
c.Assert(provider.Init(ctx, GitcoinPassportConf{endpoints["/original"], time.Second, testDB}), qt.IsNil)
// start the first download
emptyBalances, _, _, _, _, err := provider.HoldersBalances(context.TODO(), nil, 0)
c.Assert(err, qt.IsNil)
Expand Down
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 6ee883c

Please sign in to comment.