From 2fa5e6255a2259647881ac46ad84933fd7203611 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 1 Oct 2024 18:38:25 +0700 Subject: [PATCH] add method descriptors. add DropAllTxs to subpool interface. clean up the impls a bit --- core/txpool/blobpool/blobpool.go | 42 +++++++++++++++------------- core/txpool/legacypool/legacypool.go | 34 ++++++++++++---------- core/txpool/subpool.go | 3 ++ 3 files changed, 44 insertions(+), 35 deletions(-) diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index 838640fbf9..921b1950c6 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -325,26 +325,6 @@ type BlobPool struct { lock sync.RWMutex // Mutex protecting the pool during reorg handling } -func (p *BlobPool) DropAllTxs() { - p.lock.Lock() - defer p.lock.Unlock() - - for _, entry := range p.lookup { - if err := p.store.Delete(entry); err != nil { - log.Warn("failed to delete blob tx from backing store", "err", err) - } - } - p.lookup = make(map[common.Hash]uint64) - p.index = make(map[common.Address][]*blobTxMeta) - p.spent = make(map[common.Address]*uint256.Int) - - var ( - basefee = uint256.MustFromBig(eip1559.CalcBaseFee(p.chain.Config(), p.head)) - blobfee = uint256.NewInt(params.BlobTxMinBlobGasprice) - ) - p.evict = newPriceHeap(basefee, blobfee, p.index) -} - // New creates a new blob transaction pool to gather, sort and filter inbound // blob transactions from the network. func New(config Config, chain BlockChain) *BlobPool { @@ -1734,3 +1714,25 @@ func (p *BlobPool) Status(hash common.Hash) txpool.TxStatus { } return txpool.TxStatusUnknown } + +// DropAllTxs implements txpool.SubPool, removing all tracked transactions +// from the blob pool and persistent store. +func (p *BlobPool) DropAllTxs() { + p.lock.Lock() + defer p.lock.Unlock() + + for _, entry := range p.lookup { + if err := p.store.Delete(entry); err != nil { + log.Warn("failed to delete blob tx from backing store", "err", err) + } + } + p.lookup = make(map[common.Hash]uint64) + p.index = make(map[common.Address][]*blobTxMeta) + p.spent = make(map[common.Address]*uint256.Int) + + var ( + basefee = uint256.MustFromBig(eip1559.CalcBaseFee(p.chain.Config(), p.head)) + blobfee = uint256.NewInt(params.BlobTxMinBlobGasprice) + ) + p.evict = newPriceHeap(basefee, blobfee, p.index) +} diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index a2e932fc3b..5469b6c580 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -239,21 +239,6 @@ type txpoolResetRequest struct { oldHead, newHead *types.Header } -func (p *LegacyPool) DropAllTxs() { - p.mu.Lock() - defer p.mu.Unlock() - p.all = newLookup() - p.priced = newPricedList(p.all) - p.pending = make(map[common.Address]*list) - p.queue = make(map[common.Address]*list) - if !p.config.NoLocals && p.config.Journal != "" { - p.journal = newTxJournal(p.config.Journal) - if err := p.journal.rotate(p.local()); err != nil { - log.Warn("Failed to rotate transaction journal", "err", err) - } - } -} - // New creates a new transaction pool to gather, sort and filter inbound // transactions from the network. func New(config Config, chain BlockChain) *LegacyPool { @@ -1976,3 +1961,22 @@ func (t *lookup) RemotesBelowTip(threshold *big.Int) types.Transactions { func numSlots(tx *types.Transaction) int { return int((tx.Size() + txSlotSize - 1) / txSlotSize) } + +// DropAllTxs implements txpool.SubPool, removing all tracked txs from the pool +// and rotating the journal. +func (p *LegacyPool) DropAllTxs() { + p.mu.Lock() + defer p.mu.Unlock() + + p.all = newLookup() + p.priced = newPricedList(p.all) + p.pending = make(map[common.Address]*list) + p.queue = make(map[common.Address]*list) + + if !p.config.NoLocals && p.config.Journal != "" { + p.journal = newTxJournal(p.config.Journal) + if err := p.journal.rotate(p.local()); err != nil { + log.Warn("Failed to rotate transaction journal", "err", err) + } + } +} diff --git a/core/txpool/subpool.go b/core/txpool/subpool.go index 180facd217..c8d676c1b2 100644 --- a/core/txpool/subpool.go +++ b/core/txpool/subpool.go @@ -168,4 +168,7 @@ type SubPool interface { // Status returns the known status (unknown/pending/queued) of a transaction // identified by their hashes. Status(hash common.Hash) TxStatus + + // DropAllTxs removes all tracked transactions from the pool + DropAllTxs() }