From b6554880a9330570d3f466f08b77e8a749dcbc79 Mon Sep 17 00:00:00 2001 From: irrun Date: Tue, 13 Aug 2024 14:49:10 +0800 Subject: [PATCH] fix: deadlock when add bundle into bundlepool (#46) --- core/txpool/bundlepool/bundlepool.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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