diff --git a/go/common/errutil/evm_serialisable.go b/go/common/errutil/evm_serialisable.go index c1eebf9aae..a3382a0fd8 100644 --- a/go/common/errutil/evm_serialisable.go +++ b/go/common/errutil/evm_serialisable.go @@ -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"` @@ -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) +} diff --git a/go/enclave/rpc/EstimateGas.go b/go/enclave/rpc/EstimateGas.go index 210cb65c75..d24773f9a6 100644 --- a/go/enclave/rpc/EstimateGas.go +++ b/go/enclave/rpc/EstimateGas.go @@ -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" @@ -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 } @@ -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.