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 dc3c294 commit 5e6a1d6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/txpool/bundlepool/bundlepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (p *BundlePool) AddBundle(bundle *types.Bundle) error {
return ErrBundleAlreadyExist
}
for p.slots+numSlots(bundle) > p.config.GlobalSlots {
p.drop()
p.drop() // deadlock
}
p.bundles[hash] = bundle
heap.Push(&p.bundleHeap, bundle)
Expand Down
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
15 changes: 10 additions & 5 deletions miner/worker_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,10 @@ 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()
valid = true
gasUsed uint64 = 0
)

receipt, err := core.ApplyTransaction(w.chainConfig, w.chain, &w.coinbase, env.gasPool, env.state, env.header, tx,
Expand All @@ -514,14 +515,18 @@ func (w *worker) simulateGaslessBundle(env *environment, bundle *types.Bundle) (
env.state.RevertToSnapshot(snap)
env.gasPool.SetGas(gp)
valid = false
log.Warn("fail to simulate gasless bundle, skipped", "txHash", tx.Hash(), "err", err)
log.Info("fail to simulate gasless bundle, skipped", "txHash", tx.Hash(), "err", err)
} else {
txIdx++
}

if receipt != nil {
gasUsed = receipt.GasUsed
}

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

0 comments on commit 5e6a1d6

Please sign in to comment.