aboutsummaryrefslogtreecommitdiffstats
path: root/accounts
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-10-02 21:23:21 +0800
committerGitHub <noreply@github.com>2017-10-02 21:23:21 +0800
commitf4c49bc0f03910f0caa16c4a067c0f201de293b7 (patch)
treeaf3a734392c524662d3f2fc63be3f926f10793b7 /accounts
parentd3476562805a5b1026d91f0d954596e57e9de483 (diff)
parent94903d572b4ee72c7ea62ce9856f51def85fdd2a (diff)
downloaddexon-f4c49bc0f03910f0caa16c4a067c0f201de293b7.tar.gz
dexon-f4c49bc0f03910f0caa16c4a067c0f201de293b7.tar.zst
dexon-f4c49bc0f03910f0caa16c4a067c0f201de293b7.zip
Merge pull request #15030 from rjl493456442/expose_vm_failed
internal, accounts, eth: utilize vm failed flag to help gas estimation
Diffstat (limited to 'accounts')
-rw-r--r--accounts/abi/bind/backends/simulated.go24
1 files changed, 13 insertions, 11 deletions
diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go
index d6d16eb3f..0621e81c2 100644
--- a/accounts/abi/bind/backends/simulated.go
+++ b/accounts/abi/bind/backends/simulated.go
@@ -168,7 +168,7 @@ func (b *SimulatedBackend) CallContract(ctx context.Context, call ethereum.CallM
if err != nil {
return nil, err
}
- rval, _, err := b.callContract(ctx, call, b.blockchain.CurrentBlock(), state)
+ rval, _, _, err := b.callContract(ctx, call, b.blockchain.CurrentBlock(), state)
return rval, err
}
@@ -178,7 +178,7 @@ func (b *SimulatedBackend) PendingCallContract(ctx context.Context, call ethereu
defer b.mu.Unlock()
defer b.pendingState.RevertToSnapshot(b.pendingState.Snapshot())
- rval, _, err := b.callContract(ctx, call, b.pendingBlock, b.pendingState)
+ rval, _, _, err := b.callContract(ctx, call, b.pendingBlock, b.pendingState)
return rval, err
}
@@ -204,8 +204,11 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMs
defer b.mu.Unlock()
// Binary search the gas requirement, as it may be higher than the amount used
- var lo, hi uint64
- if call.Gas != nil {
+ var (
+ lo uint64 = params.TxGas - 1
+ hi uint64
+ )
+ if call.Gas != nil && call.Gas.Uint64() >= params.TxGas {
hi = call.Gas.Uint64()
} else {
hi = b.pendingBlock.GasLimit().Uint64()
@@ -216,11 +219,11 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMs
call.Gas = new(big.Int).SetUint64(mid)
snapshot := b.pendingState.Snapshot()
- _, gas, err := b.callContract(ctx, call, b.pendingBlock, b.pendingState)
+ _, _, failed, err := b.callContract(ctx, call, b.pendingBlock, b.pendingState)
b.pendingState.RevertToSnapshot(snapshot)
- // If the transaction became invalid or used all the gas (failed), raise the gas limit
- if err != nil || gas.Cmp(call.Gas) == 0 {
+ // If the transaction became invalid or execution failed, raise the gas limit
+ if err != nil || failed {
lo = mid
continue
}
@@ -232,7 +235,7 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMs
// callContract implemens common code between normal and pending contract calls.
// state is modified during execution, make sure to copy it if necessary.
-func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallMsg, block *types.Block, statedb *state.StateDB) ([]byte, *big.Int, error) {
+func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallMsg, block *types.Block, statedb *state.StateDB) ([]byte, *big.Int, bool, error) {
// Ensure message is initialized properly.
if call.GasPrice == nil {
call.GasPrice = big.NewInt(1)
@@ -254,9 +257,8 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallM
// about the transaction and calling mechanisms.
vmenv := vm.NewEVM(evmContext, statedb, b.config, vm.Config{})
gaspool := new(core.GasPool).AddGas(math.MaxBig256)
- // TODO utilize returned failed flag to help gas estimation.
- ret, gasUsed, _, _, err := core.NewStateTransition(vmenv, msg, gaspool).TransitionDb()
- return ret, gasUsed, err
+ ret, gasUsed, _, failed, err := core.NewStateTransition(vmenv, msg, gaspool).TransitionDb()
+ return ret, gasUsed, failed, err
}
// SendTransaction updates the pending block to include the given transaction.