Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
537c5db510 | ||
|
|
40620b478c | ||
|
|
e81c728ff6 |
10
CHANGELOG.md
10
CHANGELOG.md
@@ -1,5 +1,15 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v1.0.3
|
||||||
|
|
||||||
|
IMPROVEMENT
|
||||||
|
* [\#36](https://github.com/binance-chain/bsc/pull/36) add max gas allwance calculation
|
||||||
|
|
||||||
|
## v1.0.2
|
||||||
|
|
||||||
|
IMPROVEMENT
|
||||||
|
* [\#29](https://github.com/binance-chain/bsc/pull/29) eth/tracers: revert reason in call_tracer + error for failed internal…
|
||||||
|
|
||||||
## v1.0.1-beta
|
## v1.0.1-beta
|
||||||
|
|
||||||
IMPROVEMENT
|
IMPROVEMENT
|
||||||
|
|||||||
@@ -887,6 +887,11 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash
|
|||||||
hi uint64
|
hi uint64
|
||||||
cap uint64
|
cap uint64
|
||||||
)
|
)
|
||||||
|
// Use zero address if sender unspecified.
|
||||||
|
if args.From == nil {
|
||||||
|
return 0, fmt.Errorf("missing from address")
|
||||||
|
}
|
||||||
|
// Determine the highest gas limit can be used during the estimation.
|
||||||
if args.Gas != nil && uint64(*args.Gas) >= params.TxGas {
|
if args.Gas != nil && uint64(*args.Gas) >= params.TxGas {
|
||||||
hi = uint64(*args.Gas)
|
hi = uint64(*args.Gas)
|
||||||
} else {
|
} else {
|
||||||
@@ -897,16 +902,40 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash
|
|||||||
}
|
}
|
||||||
hi = block.GasLimit()
|
hi = block.GasLimit()
|
||||||
}
|
}
|
||||||
|
// Recap the highest gas limit with account's available balance.
|
||||||
|
if args.GasPrice != nil && args.GasPrice.ToInt().BitLen() != 0 {
|
||||||
|
state, _, err := b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
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(available) >= 0 {
|
||||||
|
return 0, errors.New("insufficient funds for transfer")
|
||||||
|
}
|
||||||
|
available.Sub(available, args.Value.ToInt())
|
||||||
|
}
|
||||||
|
allowance := new(big.Int).Div(available, args.GasPrice.ToInt())
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
}
|
||||||
|
log.Warn("Gas estimation capped by limited funds", "original", hi, "balance", balance,
|
||||||
|
"sent", transfer.ToInt(), "gasprice", args.GasPrice.ToInt(), "fundable", allowance)
|
||||||
|
hi = allowance.Uint64()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Recap the highest gas allowance with specified gascap.
|
||||||
if gasCap != nil && hi > gasCap.Uint64() {
|
if gasCap != nil && hi > gasCap.Uint64() {
|
||||||
log.Warn("Caller gas above allowance, capping", "requested", hi, "cap", gasCap)
|
log.Warn("Caller gas above allowance, capping", "requested", hi, "cap", gasCap)
|
||||||
hi = gasCap.Uint64()
|
hi = gasCap.Uint64()
|
||||||
}
|
}
|
||||||
cap = hi
|
cap = hi
|
||||||
|
|
||||||
// Use zero address if sender unspecified.
|
|
||||||
if args.From == nil {
|
|
||||||
args.From = new(common.Address)
|
|
||||||
}
|
|
||||||
// Create a helper to check if a gas allowance results in an executable transaction
|
// Create a helper to check if a gas allowance results in an executable transaction
|
||||||
executable := func(gas uint64) bool {
|
executable := func(gas uint64) bool {
|
||||||
args.Gas = (*hexutil.Uint64)(&gas)
|
args.Gas = (*hexutil.Uint64)(&gas)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
VersionMajor = 1 // Major version component of the current release
|
VersionMajor = 1 // Major version component of the current release
|
||||||
VersionMinor = 0 // Minor version component of the current release
|
VersionMinor = 0 // Minor version component of the current release
|
||||||
VersionPatch = 2 // Patch version component of the current release
|
VersionPatch = 3 // Patch version component of the current release
|
||||||
VersionMeta = "" // Version metadata to append to the version string
|
VersionMeta = "" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user