Skip to content

Commit

Permalink
fix: concurrent map read in bundlepool (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
irrun authored Jan 16, 2025
1 parent fadd748 commit a320daf
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions core/txpool/bundlepool/bundlepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,11 @@ func (p *BundlePool) AddBundle(bundle *types.Bundle) error {
return err
}
bundle.Price = price

hash := bundle.Hash()

p.mu.Lock()
defer p.mu.Unlock()

if _, ok := p.bundles[hash]; ok {
return ErrBundleAlreadyExist
}
Expand All @@ -162,22 +165,20 @@ func (p *BundlePool) AddBundle(bundle *types.Bundle) error {
return ErrBundleGasPriceLow
}

p.mu.Lock()
for p.slots+numSlots(bundle) > p.config.GlobalSlots {
p.drop()
}
p.bundles[hash] = bundle
heap.Push(&p.bundleHeap, bundle)
p.slots += numSlots(bundle)
p.mu.Unlock()

bundleGauge.Update(int64(len(p.bundles)))
slotsGauge.Update(int64(p.slots))

p.bundleMetricsMu.Lock()
defer p.bundleMetricsMu.Unlock()
currentHeaderNumber := p.blockchain.CurrentBlock().Number.Int64()
p.bundleMetrics[currentHeaderNumber] = append(p.bundleMetrics[currentHeaderNumber], bundle.TxHashes())
p.bundleMetricsMu.Unlock()

return nil
}
Expand Down

0 comments on commit a320daf

Please sign in to comment.