forked from cerc-io/plugeth
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.
This commit is contained in:
parent
e9294a7fe9
commit
abc74a5ffe
@ -462,6 +462,9 @@ func (b *SimulatedBackend) PendingNonceAt(ctx context.Context, account common.Ad
|
|||||||
// SuggestGasPrice implements ContractTransactor.SuggestGasPrice. Since the simulated
|
// SuggestGasPrice implements ContractTransactor.SuggestGasPrice. Since the simulated
|
||||||
// chain doesn't have miners, we just return a gas price of 1 for any call.
|
// 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) {
|
func (b *SimulatedBackend) SuggestGasPrice(ctx context.Context) (*big.Int, error) {
|
||||||
|
b.mu.Lock()
|
||||||
|
defer b.mu.Unlock()
|
||||||
|
|
||||||
if b.pendingBlock.Header().BaseFee != nil {
|
if b.pendingBlock.Header().BaseFee != nil {
|
||||||
return b.pendingBlock.Header().BaseFee, nil
|
return b.pendingBlock.Header().BaseFee, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user