From 5d0dea852ef56ec72bc968634622a4163a6458d1 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Tue, 14 Jan 2025 10:56:08 +0800 Subject: [PATCH] accounts/abi: mutex lock in TransactionByHash and code cleanup (#19133) --- accounts/abi/bind/backends/simulated.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index b78262d213..b129609e31 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -269,17 +269,18 @@ func (b *SimulatedBackend) TransactionReceipt(ctx context.Context, txHash common // blockchain. The isPending return value indicates whether the transaction has been // mined yet. Note that the transaction may not be part of the canonical chain even if // it's not pending. -func (b *SimulatedBackend) TransactionByHash(ctx context.Context, txHash common.Hash) (tx *types.Transaction, isPending bool, err error) { - tx = b.pendingBlock.Transaction(txHash) +func (b *SimulatedBackend) TransactionByHash(ctx context.Context, txHash common.Hash) (*types.Transaction, bool, error) { + b.mu.Lock() + defer b.mu.Unlock() + + tx := b.pendingBlock.Transaction(txHash) if tx != nil { return tx, true, nil } - tx, _, _, _ = rawdb.ReadTransaction(b.database, txHash) if tx != nil { return tx, false, nil } - return nil, false, ethereum.ErrNotFound }