Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
tudor-malene committed Dec 17, 2024
1 parent f6898d0 commit d762427
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions go/common/errutil/evm_serialisable.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package errutil

import "fmt"

// DataError is an API error that encompasses an EVM error with a code and a reason
type DataError struct {
Code int `json:"code"`
Expand All @@ -18,3 +20,7 @@ func (e DataError) ErrorCode() int {
func (e DataError) ErrorData() interface{} {
return e.Reason
}

func (e DataError) String() string {
return fmt.Sprintf("Data Error. Message: %s, Data: %v", e.Err, e.Reason)
}
9 changes: 9 additions & 0 deletions go/enclave/rpc/EstimateGas.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"math/big"

"github.com/status-im/keycard-go/hexutils"

"github.com/ethereum/go-ethereum/core/vm"

"github.com/ethereum/go-ethereum/params"
Expand Down Expand Up @@ -101,8 +103,10 @@ func EstimateGasExecute(builder *CallBuilder[CallParamsWithBlock, hexutil.Uint64
// but is quick.
executionGasEstimate, revert, gasPrice, err := estimateGasSinglePass(builder.ctx, rpc, txArgs, blockNumber, rpc.config.GasLocalExecutionCapFlag)
if err != nil {
rpc.logger.Debug("Gas estimation failed", "revert", hexutils.BytesToHex(revert), "error", err)
if len(revert) > 0 {
builder.Err = newRevertError(revert)
rpc.logger.Debug("revert error", "err", builder.Err)
return nil
}

Expand Down Expand Up @@ -200,22 +204,27 @@ func estimateGasSinglePass(ctx context.Context, rpc *EncryptionManager, args *ge
// Perform a single gas estimation pass using isGasEnough
failed, result, err := isGasEnough(ctx, rpc, args, allowance, blkNumber)
if err != nil {
rpc.logger.Debug("1", "error", err)
// Return zero values and the encountered error if estimation fails
return 0, nil, nil, err
}

if failed {
if result != nil && !errors.Is(result.Err, vm.ErrOutOfGas) {
rpc.logger.Debug("2", "error", result.Err)
return 0, result.Revert(), nil, result.Err
}
rpc.logger.Debug("3")
// If the gas cap is insufficient, return an appropriate error
return 0, nil, nil, fmt.Errorf("gas required exceeds allowance (%d)", globalGasCap)
}

if result == nil {
rpc.logger.Debug("4")
// If there's no result, something went wrong
return 0, nil, nil, fmt.Errorf("no execution result returned")
}
rpc.logger.Debug("5")

// Extract the gas used from the execution result.
// Add an overhead buffer to account for the fact that the execution might not be able to be completed in the same batch.
Expand Down

0 comments on commit d762427

Please sign in to comment.