Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip incorrect tx in simulate gasless bundle #44

Merged
merged 3 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading