From 1f2466ca49ad897795e7dabfda1460fddb8a4198 Mon Sep 17 00:00:00 2001 From: komika Date: Tue, 1 Feb 2022 16:42:51 +0100 Subject: [PATCH] accounts/abi/bind: improve WaitMined error handling (#24321) This change makes it so WaitMined no longer logs an error when the receipt is unavailable. It also changes the simulated backend to return NotFound for unavailable receipts, just like ethclient does. --- accounts/abi/bind/backends/simulated.go | 3 +++ accounts/abi/bind/util.go | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index f353ea25ffee..ac696f446be6 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -230,6 +230,9 @@ func (b *SimulatedBackend) TransactionReceipt(ctx context.Context, txHash common defer b.mu.Unlock() receipt, _, _, _ := rawdb.ReadReceipt(b.database, txHash, b.config) + if receipt == nil { + return nil, ethereum.NotFound + } return receipt, nil } diff --git a/accounts/abi/bind/util.go b/accounts/abi/bind/util.go index 118abc59a7f1..b931fbb04d64 100644 --- a/accounts/abi/bind/util.go +++ b/accounts/abi/bind/util.go @@ -21,6 +21,7 @@ import ( "errors" "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" @@ -35,14 +36,16 @@ func WaitMined(ctx context.Context, b DeployBackend, tx *types.Transaction) (*ty logger := log.New("hash", tx.Hash()) for { receipt, err := b.TransactionReceipt(ctx, tx.Hash()) - if receipt != nil { + if err == nil { return receipt, nil } - if err != nil { - logger.Trace("Receipt retrieval failed", "err", err) - } else { + + if errors.Is(err, ethereum.NotFound) { logger.Trace("Transaction not yet mined") + } else { + logger.Trace("Receipt retrieval failed", "err", err) } + // Wait for the next round. select { case <-ctx.Done():