From ec6a8df98809c444cdeffd418bd43b94f6d9958a Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Mon, 11 May 2020 15:09:54 +0800 Subject: [PATCH] accounts, internal: extend log message --- accounts/abi/bind/backends/simulated.go | 13 +++++++------ internal/ethapi/api.go | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index 19af6f6c34..e1d8fcd782 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -404,18 +404,19 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMs } // Recap the highest gas allowance with account's balance. if call.GasPrice != nil && call.GasPrice.Uint64() != 0 { - balance := new(big.Int) - balance.Set(b.pendingState.GetBalance(call.From)) // from can't be nil + balance := b.pendingState.GetBalance(call.From) // from can't be nil + available := new(big.Int).Set(balance) if call.Value != nil { - if call.Value.Cmp(balance) >= 0 { + if call.Value.Cmp(available) >= 0 { return 0, errors.New("insufficient funds for transfer") } - balance.Sub(balance, call.Value) + available.Sub(available, call.Value) } - allowance := new(big.Int).Div(balance, call.GasPrice) + allowance := new(big.Int).Div(available, call.GasPrice) if hi > allowance.Uint64() { + log.Warn("Gas estimation capped by limited funds", "original", hi, "balance", balance, + "sent", call.Value, "gasprice", call.GasPrice, "fundable", allowance) hi = allowance.Uint64() - log.Warn("Gas estimation capped by limited funds", "original", hi, "fundable", allowance) } } cap = hi diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 779678c4f5..195da54fcd 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -927,18 +927,19 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash if err != nil { return 0, err } - balance := new(big.Int) - balance.Set(state.GetBalance(*args.From)) // from can't be nil + balance := state.GetBalance(*args.From) // from can't be nil + available := new(big.Int).Set(balance) if args.Value != nil { - if args.Value.ToInt().Cmp(balance) >= 0 { + if args.Value.ToInt().Cmp(available) >= 0 { return 0, errors.New("insufficient funds for transfer") } - balance.Sub(balance, args.Value.ToInt()) + available.Sub(available, args.Value.ToInt()) } - allowance := new(big.Int).Div(balance, args.GasPrice.ToInt()) + allowance := new(big.Int).Div(available, args.GasPrice.ToInt()) if hi > allowance.Uint64() { + log.Warn("Gas estimation capped by limited funds", "original", hi, "balance", balance, + "sent", args.Value, "gasprice", args.GasPrice, "fundable", allowance) hi = allowance.Uint64() - log.Warn("Gas estimation capped by limited funds", "original", hi, "fundable", allowance) } } // Recap the highest gas allowance with specified gascap.