diff --git a/core/txpool/bundlepool/bundlepool.go b/core/txpool/bundlepool/bundlepool.go index 6188e13186..f69fd7dae0 100644 --- a/core/txpool/bundlepool/bundlepool.go +++ b/core/txpool/bundlepool/bundlepool.go @@ -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 } @@ -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 }