Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
expose revert reason and execution error (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
TymKh authored Apr 11, 2024
1 parent 60fcb6a commit b996797
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion core/sbundle_sim.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type SimBundleResult struct {
GasUsed uint64
MevGasPrice *uint256.Int
BodyLogs []SimBundleBodyLogs
Revert []byte
ExecError string
}

type SimBundleBodyLogs struct {
Expand Down Expand Up @@ -80,10 +82,12 @@ func SimBundle(config *params.ChainConfig, bc *BlockChain, author *common.Addres
if el.Tx != nil {
statedb.SetTxContext(el.Tx.Hash(), txIdx)
txIdx++
receipt, err := ApplyTransaction(config, bc, author, gp, statedb, header, el.Tx, usedGas, cfg, nil)
receipt, result, err := ApplyTransactionWithResult(config, bc, author, gp, statedb, header, el.Tx, usedGas, cfg)
if err != nil {
return res, err
}
res.Revert = result.Revert()
res.ExecError = result.Err.Error()
if receipt.Status != types.ReceiptStatusSuccessful && !el.CanRevert {
return res, ErrTxFailed
}
Expand All @@ -96,6 +100,13 @@ func SimBundle(config *params.ChainConfig, bc *BlockChain, author *common.Addres
if err != nil {
return res, err
}
// basically return first exec error if exists, helpful for single-tx sbundles
if len(res.Revert) == 0 {
res.Revert = innerRes.Revert
}
if len(res.ExecError) == 0 {
res.ExecError = innerRes.ExecError
}
res.GasUsed += innerRes.GasUsed
if logs {
res.BodyLogs = append(res.BodyLogs, SimBundleBodyLogs{BundleLogs: innerRes.BodyLogs})
Expand Down
4 changes: 4 additions & 0 deletions internal/ethapi/sbundle_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ type SimMevBundleResponse struct {
RefundableValue hexutil.U256 `json:"refundableValue"`
GasUsed hexutil.Uint64 `json:"gasUsed"`
BodyLogs []core.SimBundleBodyLogs `json:"logs,omitempty"`
ExecError string `json:"execError,omitempty"`
Revert hexutil.Bytes `json:"revert,omitempty"`
}

type SimMevBundleAuxArgs struct {
Expand Down Expand Up @@ -276,6 +278,8 @@ func (api *MevAPI) SimBundle(ctx context.Context, args SendMevBundleArgs, aux Si
result.Success = true
result.BodyLogs = bundleRes.BodyLogs
}
result.ExecError = bundleRes.ExecError
result.Revert = bundleRes.Revert
result.StateBlock = hexutil.Uint64(parentHeader.Number.Uint64())
result.MevGasPrice = hexutil.U256(*bundleRes.MevGasPrice)
result.Profit = hexutil.U256(*bundleRes.TotalProfit)
Expand Down

0 comments on commit b996797

Please sign in to comment.