Skip to content

Commit

Permalink
fix estimateGas (handle ErrInsufficientBalanceWitness). Return proper…
Browse files Browse the repository at this point in the history
… error message when ErrInsufficientBalanceWitness is encountered (ethereum#81)
  • Loading branch information
jwasinger authored Feb 11, 2022
1 parent 7af62ef commit 94b2e58
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {

statelessGasOrigin := st.evm.Accesses.TouchTxOriginAndComputeGas(originAddr.Bytes(), msg.Value().Sign() != 0)
if !tryConsumeGas(&st.gas, statelessGasOrigin) {
return nil, ErrInsufficientBalanceWitness
return nil, fmt.Errorf("%w: Insufficient funds to cover witness access costs for transaction: have %d, want %d", ErrInsufficientBalanceWitness, st.gas, gas)
}
originBalance = st.evm.StateDB.GetBalanceLittleEndian(originAddr)
originNonce := st.evm.StateDB.GetNonce(originAddr)
Expand All @@ -334,7 +334,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
if msg.To() != nil {
statelessGasDest := st.evm.Accesses.TouchTxExistingAndComputeGas(targetAddr.Bytes(), msg.Value().Sign() != 0)
if !tryConsumeGas(&st.gas, statelessGasDest) {
return nil, ErrInsufficientBalanceWitness
return nil, fmt.Errorf("%w: Insufficient funds to cover witness access costs for transaction: have %d, want %d", ErrInsufficientBalanceWitness, st.gas, gas)
}
targetBalance = st.evm.StateDB.GetBalanceLittleEndian(*targetAddr)
targetNonce = st.evm.StateDB.GetNonceLittleEndian(*targetAddr)
Expand All @@ -347,12 +347,12 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
} else {
contractAddr := crypto.CreateAddress(originAddr, originNonce)
if !tryConsumeGas(&st.gas, st.evm.Accesses.TouchAndChargeContractCreateInit(contractAddr.Bytes(), msg.Value().Sign() != 0)) {
return nil, ErrInsufficientBalanceWitness
return nil, fmt.Errorf("%w: Insufficient funds to cover witness access costs for transaction: have %d, want %d", ErrInsufficientBalanceWitness, st.gas, gas)
}
}

if st.gas < gas {
return nil, fmt.Errorf("Insufficient funds to cover witness access costs for transaction: have %d, want %d", st.gas, gas)
return nil, fmt.Errorf("%w: Insufficient funds to cover witness access costs for transaction: have %d, want %d", ErrInsufficientBalanceWitness, st.gas, gas)
}
}
st.gas -= gas
Expand Down
2 changes: 1 addition & 1 deletion internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr

result, err := DoCall(ctx, b, args, blockNrOrHash, nil, 0, gasCap)
if err != nil {
if errors.Is(err, core.ErrIntrinsicGas) {
if errors.Is(err, core.ErrIntrinsicGas) || errors.Is(err, core.ErrInsufficientBalanceWitness) {
return true, nil, nil // Special case, raise gas limit
}
return true, nil, err // Bail out
Expand Down

0 comments on commit 94b2e58

Please sign in to comment.