Skip to content

Commit

Permalink
fix: simulate gasless bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
irrun committed Aug 2, 2024
1 parent 32fc8a8 commit f4ab1c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
3 changes: 1 addition & 2 deletions core/types/bundle_gasless.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ type SimulateGaslessBundleArgs struct {
type GaslessTxSimResult struct {
Hash common.Hash
GasUsed uint64
Valid bool
}

type SimulateGaslessBundleResp struct {
Results []GaslessTxSimResult
ValidResults []GaslessTxSimResult
BasedBlockNumber int64
}
22 changes: 7 additions & 15 deletions miner/worker_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,36 +503,28 @@ func (w *worker) simulateGaslessBundle(env *environment, bundle *types.Bundle) (
env.state.SetTxContext(tx.Hash(), txIdx)

var (
snap = env.state.Snapshot()
gp = env.gasPool.Gas()
valid = true
gasUsed uint64 = 0
snap = env.state.Snapshot()
gp = env.gasPool.Gas()
)

receipt, err := core.ApplyTransaction(w.chainConfig, w.chain, &w.coinbase, env.gasPool, env.state, env.header, tx,
&env.header.GasUsed, *w.chain.GetVMConfig())
if err != nil {
env.state.RevertToSnapshot(snap)
env.gasPool.SetGas(gp)
valid = false
log.Error("fail to simulate gasless tx, skipped", "hash", tx.Hash(), "err", err)
} else {
txIdx++
}

if receipt != nil {
gasUsed = receipt.GasUsed
result = append(result, types.GaslessTxSimResult{
Hash: tx.Hash(),
GasUsed: receipt.GasUsed,
})
}

result = append(result, types.GaslessTxSimResult{
Hash: tx.Hash(),
GasUsed: gasUsed,
Valid: valid,
})
}

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

0 comments on commit f4ab1c9

Please sign in to comment.