Skip to content

Commit

Permalink
feat: explicitly return invalid txs when simulate gasless bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
irrun committed Oct 22, 2024
1 parent ceb1993 commit c6f24ef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 4 additions & 2 deletions core/types/bundle_gasless.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ type SimulateGaslessBundleArgs struct {
}

type GaslessTxSimResult struct {
Hash common.Hash
GasUsed uint64
Hash common.Hash
GasUsed uint64
ErrorCode int
}

type SimulateGaslessBundleResp struct {
ValidResults []GaslessTxSimResult
InvalidResults []GaslessTxSimResult
BasedBlockNumber int64
}
12 changes: 9 additions & 3 deletions miner/worker_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@ func (w *worker) simulateBundle(
}

func (w *worker) simulateGaslessBundle(env *environment, bundle *types.Bundle) (*types.SimulateGaslessBundleResp, error) {
result := make([]types.GaslessTxSimResult, 0)
validResults := make([]types.GaslessTxSimResult, 0)
invalidResults := make([]types.GaslessTxSimResult, 0)

txIdx := 0
for _, tx := range bundle.Txs {
Expand All @@ -520,18 +521,23 @@ func (w *worker) simulateGaslessBundle(env *environment, bundle *types.Bundle) (
env.state.RevertToSnapshot(snap)
env.gasPool.SetGas(gp)
log.Error("fail to simulate gasless tx, skipped", "hash", tx.Hash(), "err", err)

if err != core.ErrGasLimitReached {
invalidResults = append(invalidResults, types.GaslessTxSimResult{Hash: tx.Hash()})
}
} else {
txIdx++

result = append(result, types.GaslessTxSimResult{
validResults = append(validResults, types.GaslessTxSimResult{
Hash: tx.Hash(),
GasUsed: receipt.GasUsed,
})
}
}

return &types.SimulateGaslessBundleResp{
ValidResults: result,
ValidResults: validResults,
InvalidResults: invalidResults,
BasedBlockNumber: env.header.Number.Int64(),
}, nil
}
Expand Down

0 comments on commit c6f24ef

Please sign in to comment.