Skip to content

Commit

Permalink
fix: skip incorrect tx in simulate gasless bundle (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
irrun authored Aug 2, 2024
1 parent dc3c294 commit 957523e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 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
}
4 changes: 3 additions & 1 deletion internal/ethapi/api_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
)

const InvalidBundleParamError = -38000
Expand Down Expand Up @@ -36,7 +37,8 @@ func (s *PrivateTxBundleAPI) SimulateGaslessBundle(_ context.Context, args types
for _, encodedTx := range args.Txs {
tx := new(types.Transaction)
if err := tx.UnmarshalBinary(encodedTx); err != nil {
return nil, err
log.Error("failed to unmarshal gasless tx", "err", err)
continue
}
txs = append(txs, tx)
}
Expand Down
21 changes: 9 additions & 12 deletions miner/worker_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,31 +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
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.Warn("fail to simulate gasless bundle, skipped", "txHash", tx.Hash(), "err", err)
log.Error("fail to simulate gasless tx, skipped", "hash", tx.Hash(), "err", err)
} else {
txIdx++
}

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

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

0 comments on commit 957523e

Please sign in to comment.