From a5f41e51af6a9f8d535947902f4f4aa826b7112d Mon Sep 17 00:00:00 2001 From: agwab Date: Mon, 27 Apr 2026 00:04:28 +0900 Subject: [PATCH] core/txpool/blobpool: defer underpriced delete out of SetGasTip --- core/txpool/blobpool/blobpool.go | 18 +++++++++++------- core/txpool/blobpool/blobpool_test.go | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index 02cb5d971e..19d0a51c4c 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -1165,8 +1165,9 @@ func (p *BlobPool) reinject(addr common.Address, txhash common.Hash) error { // SetGasTip implements txpool.SubPool, allowing the blob pool's gas requirements // to be kept in sync with the main transaction pool's gas requirements. func (p *BlobPool) SetGasTip(tip *big.Int) { + var dropped []uint64 + p.lock.Lock() - defer p.lock.Unlock() // Store the new minimum gas tip old := p.gasTip.Load() @@ -1209,15 +1210,10 @@ func (p *BlobPool) SetGasTip(tip *big.Int) { heap.Remove(p.evict, p.evict.index[addr]) p.reserver.Release(addr) } - // Clear out the transactions from the data store log.Warn("Dropping underpriced blob transaction", "from", addr, "rejected", tx.nonce, "tip", tx.execTipCap, "want", tip, "drop", nonces, "ids", ids) dropUnderpricedMeter.Mark(int64(len(ids))) - for _, id := range ids { - if err := p.store.Delete(id); err != nil { - log.Error("Failed to delete dropped transaction", "id", id, "err", err) - } - } + dropped = append(dropped, ids...) break } } @@ -1225,6 +1221,14 @@ func (p *BlobPool) SetGasTip(tip *big.Int) { } log.Debug("Blobpool tip threshold updated", "tip", tip) pooltipGauge.Update(tip.Int64()) + p.lock.Unlock() + + // Flush the dropped transactions to disk without holding the pool lock. + for _, id := range dropped { + if err := p.store.Delete(id); err != nil { + log.Error("Failed to delete dropped transaction", "id", id, "err", err) + } + } p.updateStorageMetrics() } diff --git a/core/txpool/blobpool/blobpool_test.go b/core/txpool/blobpool/blobpool_test.go index 507e759f4c..86626f29af 100644 --- a/core/txpool/blobpool/blobpool_test.go +++ b/core/txpool/blobpool/blobpool_test.go @@ -2235,3 +2235,20 @@ func BenchmarkWriteUnderReaderLoad(b *testing.B) { close(stop) wg.Wait() } + +// BenchmarkSetGasTipDrop times a SetGasTip call that drops every tx in a +// freshly populated pool of numTxs blob transactions whose tips fall below +// the new threshold. +func BenchmarkSetGasTipDrop(b *testing.B) { + const numTxs = 256 + + for i := 0; i < b.N; i++ { + b.StopTimer() + pool, _, _ := setupGetBenchPool(b, numTxs) + b.StartTimer() + // Any tip far above the per-tx execTipCap (10) drops everything. + pool.SetGasTip(big.NewInt(1_000_000_000)) + b.StopTimer() + pool.Close() + } +}