Skip to content

Commit

Permalink
fix: oom caused by non-discarded mev simulation env (#2430)
Browse files Browse the repository at this point in the history
  • Loading branch information
irrun authored Apr 28, 2024
1 parent ba67263 commit 9e17097
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions miner/bid_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ func (b *bidSimulator) SetBestBid(prevBlockHash common.Hash, bid *BidRuntime) {
b.bestBidMu.Lock()
defer b.bestBidMu.Unlock()

// must discard the environment of the last best bid, otherwise it will cause memory leak
last := b.bestBid[prevBlockHash]
if last != nil && last.env != nil {
last.env.discard()
}

b.bestBid[prevBlockHash] = bid
}

Expand Down Expand Up @@ -623,11 +629,6 @@ func (b *bidSimulator) simBid(interruptCh chan int32, bidRuntime *BidRuntime) {
if b.config.GreedyMergeTx {
delay := b.engine.Delay(b.chain, bidRuntime.env.header, &b.delayLeftOver)
if delay != nil && *delay > 0 {
log.Debug("BidSimulator: greedy merge stopTimer", "block", bidRuntime.env.header.Number,
"builder", bidRuntime.bid.Builder,
"header time", time.Until(time.Unix(int64(bidRuntime.env.header.Time), 0)),
"commit delay", *delay, "DelayLeftOver", b.delayLeftOver)

stopTimer := time.NewTimer(*delay)

bidTxsSet := mapset.NewSet[common.Hash]()
Expand All @@ -636,7 +637,7 @@ func (b *bidSimulator) simBid(interruptCh chan int32, bidRuntime *BidRuntime) {
}

fillErr := b.bidWorker.fillTransactions(interruptCh, bidRuntime.env, stopTimer, bidTxsSet)
log.Info("BidSimulator: greedy merge stopped", "block", bidRuntime.env.header.Number,
log.Trace("BidSimulator: greedy merge stopped", "block", bidRuntime.env.header.Number,
"builder", bidRuntime.bid.Builder, "tx count", bidRuntime.env.tcount-bidTxLen+1, "err", fillErr)

// recalculate the packed reward
Expand Down

0 comments on commit 9e17097

Please sign in to comment.