Skip to content

Commit

Permalink
refactor(gas): simplify estimate gas error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yang committed Nov 2, 2024
1 parent c43219e commit e53d6ad
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions x/evm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,24 +438,27 @@ func (k Keeper) EstimateGasForEvmCallType(
return nil, err
}

// The gas limit is now the highest gas limit that results in an executable transaction
// Reject the transaction as invalid if it still fails at the highest allowance
if hi == gasCap {
failed, result, err := executable(hi)
if err != nil {
return nil, fmt.Errorf("eth call exec error: %w", err)
}

if failed {
if result != nil && result.VmError != vm.ErrOutOfGas.Error() {
if result.VmError == vm.ErrExecutionReverted.Error() {
return nil, fmt.Errorf("VMError: %w", evm.NewExecErrorWithReason(result.Ret))
}
return nil, fmt.Errorf("VMError: %s", result.VmError)
if failed && result != nil {
if result.VmError == vm.ErrExecutionReverted.Error() {
return nil, fmt.Errorf("Estimate gas VMError: %w", evm.NewExecErrorWithReason(result.Ret))
}
// Otherwise, the specified gas cap is too low
return nil, fmt.Errorf("gas required exceeds allowance (%d)", gasCap)

if result.VmError == vm.ErrOutOfGas.Error() {
return nil, fmt.Errorf("gas required exceeds allowance (%d)", gasCap)
}

return nil, fmt.Errorf("Estimgate gas VMError: %s", result.VmError)
}
}

return &evm.EstimateGasResponse{Gas: hi}, nil
}

Expand Down

0 comments on commit e53d6ad

Please sign in to comment.