From bdf9d80b56faf0293a22f9f6e769c8c4f752d93d Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Tue, 14 Jan 2025 10:56:13 +0800 Subject: [PATCH] accounts/abi/bind/backends: fix race condition in simulated backend (#23898) Now that `SimulatedBackend.SuggestGasPrice` inspects member values, a lock needs to be added to prevent a race condition. --- accounts/abi/bind/backends/simulated.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index 62530c782e..0fff0f8fb5 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -549,6 +549,9 @@ func (b *SimulatedBackend) PendingNonceAt(ctx context.Context, account common.Ad // SuggestGasPrice implements ContractTransactor.SuggestGasPrice. Since the simulated // chain doesn't have miners, we just return a gas price of 1 for any call. func (b *SimulatedBackend) SuggestGasPrice(ctx context.Context) (*big.Int, error) { + b.mu.Lock() + defer b.mu.Unlock() + if b.pendingBlock.Header().BaseFee != nil { return b.pendingBlock.Header().BaseFee, nil }