Skip to content

Commit

Permalink
feat: explicitly return invalid txs when simulate gasless bundle (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
irrun authored Oct 23, 2024
1 parent ceb1993 commit d07ee29
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 3 additions & 2 deletions core/types/bundle_gasless.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type GaslessTxSimResult struct {
}

type SimulateGaslessBundleResp struct {
ValidResults []GaslessTxSimResult
BasedBlockNumber int64
ValidResults []GaslessTxSimResult
GasReachedResults []GaslessTxSimResult
BasedBlockNumber int64
}
14 changes: 10 additions & 4 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)
gasReachedResults := make([]types.GaslessTxSimResult, 0)

txIdx := 0
for _, tx := range bundle.Txs {
Expand All @@ -520,19 +521,24 @@ 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 {
gasReachedResults = append(gasReachedResults, 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,
BasedBlockNumber: env.header.Number.Int64(),
ValidResults: validResults,
GasReachedResults: gasReachedResults,
BasedBlockNumber: env.header.Number.Int64(),
}, nil
}

Expand Down

0 comments on commit d07ee29

Please sign in to comment.