accounts, internal: extend log message

This commit is contained in:
rjl493456442 2020-05-11 15:09:54 +08:00
parent 1dbb69c692
commit ec6a8df988
2 changed files with 14 additions and 12 deletions

View file

@ -404,18 +404,19 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMs
} }
// Recap the highest gas allowance with account's balance. // Recap the highest gas allowance with account's balance.
if call.GasPrice != nil && call.GasPrice.Uint64() != 0 { if call.GasPrice != nil && call.GasPrice.Uint64() != 0 {
balance := new(big.Int) balance := b.pendingState.GetBalance(call.From) // from can't be nil
balance.Set(b.pendingState.GetBalance(call.From)) // from can't be nil available := new(big.Int).Set(balance)
if call.Value != nil { if call.Value != nil {
if call.Value.Cmp(balance) >= 0 { if call.Value.Cmp(available) >= 0 {
return 0, errors.New("insufficient funds for transfer") 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() { 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() hi = allowance.Uint64()
log.Warn("Gas estimation capped by limited funds", "original", hi, "fundable", allowance)
} }
} }
cap = hi cap = hi

View file

@ -927,18 +927,19 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash
if err != nil { if err != nil {
return 0, err return 0, err
} }
balance := new(big.Int) balance := state.GetBalance(*args.From) // from can't be nil
balance.Set(state.GetBalance(*args.From)) // from can't be nil available := new(big.Int).Set(balance)
if args.Value != nil { 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") 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() { 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() hi = allowance.Uint64()
log.Warn("Gas estimation capped by limited funds", "original", hi, "fundable", allowance)
} }
} }
// Recap the highest gas allowance with specified gascap. // Recap the highest gas allowance with specified gascap.