diff --git a/core/txpool/bundlepool/bundlepool.go b/core/txpool/bundlepool/bundlepool.go index 08bb64e4bf..94fdebc5cf 100644 --- a/core/txpool/bundlepool/bundlepool.go +++ b/core/txpool/bundlepool/bundlepool.go @@ -125,14 +125,15 @@ func (p *BundlePool) AddBundle(bundle *types.Bundle) error { if err != nil { return err } + + p.mu.Lock() + defer p.mu.Unlock() + if price.Cmp(p.minimalBundleGasPrice()) < 0 && p.slots+numSlots(bundle) > p.config.GlobalSlots { return ErrBundleGasPriceLow } bundle.Price = price - p.mu.Lock() - defer p.mu.Unlock() - hash := bundle.Hash() if _, ok := p.bundles[hash]; ok { return ErrBundleAlreadyExist @@ -326,8 +327,6 @@ func (p *BundlePool) deleteBundle(hash common.Hash) { // drop removes the bundle with the lowest gas price from the pool. func (p *BundlePool) drop() { - p.mu.Lock() - defer p.mu.Unlock() for len(p.bundleHeap) > 0 { // Pop the bundle with the lowest gas price // the min element in the heap may not exist in the pool as it may be pruned