From 43e2e58cbda97c22ddbb616cb74a03c7bc916833 Mon Sep 17 00:00:00 2001 From: gary rong Date: Mon, 20 Jul 2020 20:52:42 +0800 Subject: [PATCH] accounts, internal: fix funding check when estimating gas (#21346) * internal, accounts: fix funding check when estimate gas * accounts, internal: address comments --- accounts/abi/bind/backends/simulated.go | 4 ++-- internal/ethapi/api.go | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index 0783b586e..4b9372a20 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -448,7 +448,7 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMs hi = b.pendingBlock.GasLimit() } // Recap the highest gas allowance with account's balance. - if call.GasPrice != nil && call.GasPrice.Uint64() != 0 { + if call.GasPrice != nil && call.GasPrice.BitLen() != 0 { balance := b.pendingState.GetBalance(call.From) // from can't be nil available := new(big.Int).Set(balance) if call.Value != nil { @@ -458,7 +458,7 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMs available.Sub(available, call.Value) } allowance := new(big.Int).Div(available, call.GasPrice) - if hi > allowance.Uint64() { + if allowance.IsUint64() && hi > allowance.Uint64() { transfer := call.Value if transfer == nil { transfer = new(big.Int) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index ac0b7bed3..c035b7a9e 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -966,7 +966,7 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash hi = block.GasLimit() } // Recap the highest gas limit with account's available balance. - if args.GasPrice != nil && args.GasPrice.ToInt().Uint64() != 0 { + if args.GasPrice != nil && args.GasPrice.ToInt().BitLen() != 0 { state, _, err := b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash) if err != nil { return 0, err @@ -980,7 +980,9 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash available.Sub(available, args.Value.ToInt()) } allowance := new(big.Int).Div(available, args.GasPrice.ToInt()) - if hi > allowance.Uint64() { + + // If the allowance is larger than maximum uint64, skip checking + if allowance.IsUint64() && hi > allowance.Uint64() { transfer := args.Value if transfer == nil { transfer = new(hexutil.Big)