diff --git a/tools/faucet/faucet/faucet.go b/tools/faucet/faucet/faucet.go index 32508550fa..c45dd4727f 100644 --- a/tools/faucet/faucet/faucet.go +++ b/tools/faucet/faucet/faucet.go @@ -3,12 +3,15 @@ package faucet import ( "context" "encoding/json" + "errors" "fmt" "math/big" "os" "sync" "time" + "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" @@ -82,14 +85,16 @@ func (f *Faucet) Fund(address *common.Address, token string, amount *big.Int) (s func (f *Faucet) validateTx(tx *types.Transaction) error { for now := time.Now(); time.Since(now) < _timeout; time.Sleep(time.Second) { receipt, err := f.client.TransactionReceipt(context.Background(), tx.Hash()) - if err != nil { - if receipt == nil { - // tx receipt is not available yet - continue - } + // end eagerly for unexpected errors + if err != nil && !errors.Is(err, ethereum.NotFound) { return fmt.Errorf("could not retrieve transaction receipt in eth_getTransactionReceipt request. Cause: %w", err) } + // try again until timeout + if receipt == nil { + continue + } + txReceiptBytes, err := receipt.MarshalJSON() if err != nil { return fmt.Errorf("could not marshal transaction receipt to JSON in eth_getTransactionReceipt request. Cause: %w", err)