From 692834ec7a117d2fd610f425374dd6549819a1b2 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 1 Oct 2024 17:32:24 +0700 Subject: [PATCH 01/10] wip: DropAllTxs for legacypool --- core/txpool/legacypool/legacypool.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index f7495dd39f8a..7953c1b8cdd4 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -239,6 +239,19 @@ 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 != "" { + // TODO: do we need to truncate the existing journal here? + p.journal = newTxJournal(p.config.Journal) + } +} + // New creates a new transaction pool to gather, sort and filter inbound // transactions from the network. func New(config Config, chain BlockChain) *LegacyPool { From 0209e9515edade2b99643799d16a3e669155bc43 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 1 Oct 2024 17:45:54 +0700 Subject: [PATCH 02/10] rotate journal upon DropAllTxs --- core/txpool/legacypool/legacypool.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index 7953c1b8cdd4..a2e932fc3b44 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -247,8 +247,10 @@ func (p *LegacyPool) DropAllTxs() { p.pending = make(map[common.Address]*list) p.queue = make(map[common.Address]*list) if !p.config.NoLocals && p.config.Journal != "" { - // TODO: do we need to truncate the existing journal here? p.journal = newTxJournal(p.config.Journal) + if err := p.journal.rotate(p.local()); err != nil { + log.Warn("Failed to rotate transaction journal", "err", err) + } } } From 4fa5629f31caecd4dc9de826c6e5a58af9defe13 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 1 Oct 2024 18:30:57 +0700 Subject: [PATCH 03/10] implement DropAllTxs for blob pool --- core/txpool/blobpool/blobpool.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index 0352ea978394..838640fbf9e0 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -325,6 +325,26 @@ 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 { From 2fa5e6255a2259647881ac46ad84933fd7203611 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 1 Oct 2024 18:38:25 +0700 Subject: [PATCH 04/10] 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 838640fbf9e0..921b1950c6fb 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 a2e932fc3b44..5469b6c580e9 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 180facd217f7..c8d676c1b295 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() } From 8827b3a5cb93eb7b20b0c3d602d576245451c9fb Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 1 Oct 2024 18:48:07 +0700 Subject: [PATCH 05/10] rename DropAllTxs -> DropTransactions for consistency. Add to txpool interface. Make simulated beacon rollback use the new method, fix old hack --- core/txpool/blobpool/blobpool.go | 4 ++-- core/txpool/legacypool/legacypool.go | 4 ++-- core/txpool/subpool.go | 4 ++-- core/txpool/txpool.go | 7 +++++++ eth/catalyst/simulated_beacon.go | 9 +-------- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index 921b1950c6fb..9737d6cdc7fa 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -1715,9 +1715,9 @@ func (p *BlobPool) Status(hash common.Hash) txpool.TxStatus { return txpool.TxStatusUnknown } -// DropAllTxs implements txpool.SubPool, removing all tracked transactions +// DropTransactions implements txpool.SubPool, removing all tracked transactions // from the blob pool and persistent store. -func (p *BlobPool) DropAllTxs() { +func (p *BlobPool) DropTransactions() { p.lock.Lock() defer p.lock.Unlock() diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index 5469b6c580e9..94fe84637115 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -1962,9 +1962,9 @@ func numSlots(tx *types.Transaction) int { return int((tx.Size() + txSlotSize - 1) / txSlotSize) } -// DropAllTxs implements txpool.SubPool, removing all tracked txs from the pool +// DropTransactions implements txpool.SubPool, removing all tracked txs from the pool // and rotating the journal. -func (p *LegacyPool) DropAllTxs() { +func (p *LegacyPool) DropTransactions() { p.mu.Lock() defer p.mu.Unlock() diff --git a/core/txpool/subpool.go b/core/txpool/subpool.go index c8d676c1b295..f9312a101b57 100644 --- a/core/txpool/subpool.go +++ b/core/txpool/subpool.go @@ -169,6 +169,6 @@ type SubPool interface { // identified by their hashes. Status(hash common.Hash) TxStatus - // DropAllTxs removes all tracked transactions from the pool - DropAllTxs() + // DropTransactions removes all tracked transactions from the pool + DropTransactions() } diff --git a/core/txpool/txpool.go b/core/txpool/txpool.go index 54ae3be56948..90058d15bd2e 100644 --- a/core/txpool/txpool.go +++ b/core/txpool/txpool.go @@ -497,3 +497,10 @@ func (p *TxPool) Sync() error { return errors.New("pool already terminated") } } + +// DropTransactions removes all tracked txs from the subpools. +func (p *TxPool) DropTransactions() { + for _, subpool := range p.subpools { + subpool.DropTransactions() + } +} diff --git a/eth/catalyst/simulated_beacon.go b/eth/catalyst/simulated_beacon.go index db46afc30d63..056ab633a536 100644 --- a/eth/catalyst/simulated_beacon.go +++ b/eth/catalyst/simulated_beacon.go @@ -21,7 +21,6 @@ import ( "crypto/sha256" "errors" "fmt" - "math/big" "sync" "time" @@ -34,7 +33,6 @@ import ( "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/node" - "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rpc" ) @@ -287,12 +285,7 @@ func (c *SimulatedBeacon) Commit() common.Hash { // Rollback un-sends previously added transactions. func (c *SimulatedBeacon) Rollback() { - // Flush all transactions from the transaction pools - maxUint256 := new(big.Int).Sub(new(big.Int).Lsh(common.Big1, 256), common.Big1) - c.eth.TxPool().SetGasTip(maxUint256) - // Set the gas tip back to accept new transactions - // TODO (Marius van der Wijden): set gas tip to parameter passed by config - c.eth.TxPool().SetGasTip(big.NewInt(params.GWei)) + c.eth.TxPool().DropTransactions() } // Fork sets the head to the provided hash. From 673898778651b9fb701642ec512f93d23cda85f5 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 1 Oct 2024 19:43:46 +0700 Subject: [PATCH 06/10] add comment about suboptimal-ness of the billy deletion iteration. --- core/txpool/blobpool/blobpool.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index 9737d6cdc7fa..2d4298d726be 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -1721,6 +1721,9 @@ func (p *BlobPool) DropTransactions() { p.lock.Lock() defer p.lock.Unlock() + // manually iterating and deleting every entry is super sub-optimal + // However, DropTransactions is not currently used in production so + // performance is not critical at the moment. 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) From 5842b1db622b11d0092af82c264fab9bfbada5f3 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 1 Oct 2024 21:28:07 +0700 Subject: [PATCH 07/10] rename DropTransactions -> Clear --- core/txpool/blobpool/blobpool.go | 6 +++--- core/txpool/legacypool/legacypool.go | 4 ++-- core/txpool/subpool.go | 4 ++-- core/txpool/txpool.go | 6 +++--- eth/catalyst/simulated_beacon.go | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index 2d4298d726be..16bad1e922e5 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -1715,14 +1715,14 @@ func (p *BlobPool) Status(hash common.Hash) txpool.TxStatus { return txpool.TxStatusUnknown } -// DropTransactions implements txpool.SubPool, removing all tracked transactions +// Clear implements txpool.SubPool, removing all tracked transactions // from the blob pool and persistent store. -func (p *BlobPool) DropTransactions() { +func (p *BlobPool) Clear() { p.lock.Lock() defer p.lock.Unlock() // manually iterating and deleting every entry is super sub-optimal - // However, DropTransactions is not currently used in production so + // However, Clear is not currently used in production so // performance is not critical at the moment. for _, entry := range p.lookup { if err := p.store.Delete(entry); err != nil { diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index 94fe84637115..7e3f40f31a85 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -1962,9 +1962,9 @@ func numSlots(tx *types.Transaction) int { return int((tx.Size() + txSlotSize - 1) / txSlotSize) } -// DropTransactions implements txpool.SubPool, removing all tracked txs from the pool +// Clear implements txpool.SubPool, removing all tracked txs from the pool // and rotating the journal. -func (p *LegacyPool) DropTransactions() { +func (p *LegacyPool) Clear() { p.mu.Lock() defer p.mu.Unlock() diff --git a/core/txpool/subpool.go b/core/txpool/subpool.go index f9312a101b57..9ee0a69c0be9 100644 --- a/core/txpool/subpool.go +++ b/core/txpool/subpool.go @@ -169,6 +169,6 @@ type SubPool interface { // identified by their hashes. Status(hash common.Hash) TxStatus - // DropTransactions removes all tracked transactions from the pool - DropTransactions() + // Clear removes all tracked transactions from the pool + Clear() } diff --git a/core/txpool/txpool.go b/core/txpool/txpool.go index 90058d15bd2e..ce455e806e50 100644 --- a/core/txpool/txpool.go +++ b/core/txpool/txpool.go @@ -498,9 +498,9 @@ func (p *TxPool) Sync() error { } } -// DropTransactions removes all tracked txs from the subpools. -func (p *TxPool) DropTransactions() { +// Clear removes all tracked txs from the subpools. +func (p *TxPool) Clear() { for _, subpool := range p.subpools { - subpool.DropTransactions() + subpool.Clear() } } diff --git a/eth/catalyst/simulated_beacon.go b/eth/catalyst/simulated_beacon.go index 056ab633a536..a24ff5210119 100644 --- a/eth/catalyst/simulated_beacon.go +++ b/eth/catalyst/simulated_beacon.go @@ -285,7 +285,7 @@ func (c *SimulatedBeacon) Commit() common.Hash { // Rollback un-sends previously added transactions. func (c *SimulatedBeacon) Rollback() { - c.eth.TxPool().DropTransactions() + c.eth.TxPool().Clear() } // Fork sets the head to the provided hash. From 8d241f04753c9a3782b6173db065cad79c38c601 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Wed, 2 Oct 2024 16:30:44 +0700 Subject: [PATCH 08/10] clear address reservations inside subpools, with explanation for why it's not done at the TxPool level. --- core/txpool/blobpool/blobpool.go | 17 +++++++++++++++++ core/txpool/legacypool/legacypool.go | 22 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index 16bad1e922e5..8eb49121bfd9 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -1729,6 +1729,23 @@ func (p *BlobPool) Clear() { log.Warn("failed to delete blob tx from backing store", "err", err) } } + // unreserve each tracked account. Ideally, we could just clear the + // reservation map in the parent txpool context. However, if we clear in + // parent context, to avoid exposing the subpool lock, we have to lock the + // reservations and then lock each subpool. + // + // This creates the potential for a deadlock situation: + // + // * TxPool.Clear locks the reservations + // * a new transaction is received which locks the subpool mutex + // * TxPool.Clear attempts to lock subpool mutex + // + // The transaction addition may attempt to reserve the sender addr which + // can't happen until Clear releases the reservation lock. Clear cannot + // acquire the subpool lock until the transaction addition is completed. + for acct, _ := range p.index { + p.reserve(acct, false) + } p.lookup = make(map[common.Hash]uint64) p.index = make(map[common.Address][]*blobTxMeta) p.spent = make(map[common.Address]*uint256.Int) diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index 7e3f40f31a85..c971ece9a86e 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -1968,6 +1968,28 @@ func (p *LegacyPool) Clear() { p.mu.Lock() defer p.mu.Unlock() + // unreserve each tracked account. Ideally, we could just clear the + // reservation map in the parent txpool context. However, if we clear in + // parent context, to avoid exposing the subpool lock, we have to lock the + // reservations and then lock each subpool. + // + // This creates the potential for a deadlock situation: + // + // * TxPool.Clear locks the reservations + // * a new transaction is received which locks the subpool mutex + // * TxPool.Clear attempts to lock subpool mutex + // + // The transaction addition may attempt to reserve the sender addr which + // can't happen until Clear releases the reservation lock. Clear cannot + // acquire the subpool lock until the transaction addition is completed. + for _, tx := range p.all.remotes { + senderAddr, _ := types.Sender(p.signer, tx) + p.reserve(senderAddr, false) + } + for localSender, _ := range p.locals.accounts { + p.reserve(localSender, false) + } + p.all = newLookup() p.priced = newPricedList(p.all) p.pending = make(map[common.Address]*list) From fbc98ae50e1e2b4f18ba1b1a9b8fb59b066577d3 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 13 Nov 2024 11:11:13 +0100 Subject: [PATCH 09/10] core/txpool/legacypool: change receiver name --- core/txpool/legacypool/legacypool.go | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index c971ece9a86e..89ff86df0221 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -1964,9 +1964,9 @@ func numSlots(tx *types.Transaction) int { // Clear implements txpool.SubPool, removing all tracked txs from the pool // and rotating the journal. -func (p *LegacyPool) Clear() { - p.mu.Lock() - defer p.mu.Unlock() +func (pool *LegacyPool) Clear() { + pool.mu.Lock() + defer pool.mu.Unlock() // unreserve each tracked account. Ideally, we could just clear the // reservation map in the parent txpool context. However, if we clear in @@ -1982,22 +1982,22 @@ func (p *LegacyPool) Clear() { // The transaction addition may attempt to reserve the sender addr which // can't happen until Clear releases the reservation lock. Clear cannot // acquire the subpool lock until the transaction addition is completed. - for _, tx := range p.all.remotes { - senderAddr, _ := types.Sender(p.signer, tx) - p.reserve(senderAddr, false) + for _, tx := range pool.all.remotes { + senderAddr, _ := types.Sender(pool.signer, tx) + pool.reserve(senderAddr, false) } - for localSender, _ := range p.locals.accounts { - p.reserve(localSender, false) + for localSender, _ := range pool.locals.accounts { + pool.reserve(localSender, false) } - p.all = newLookup() - p.priced = newPricedList(p.all) - p.pending = make(map[common.Address]*list) - p.queue = make(map[common.Address]*list) + pool.all = newLookup() + pool.priced = newPricedList(pool.all) + pool.pending = make(map[common.Address]*list) + pool.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 { + if !pool.config.NoLocals && pool.config.Journal != "" { + pool.journal = newTxJournal(pool.config.Journal) + if err := pool.journal.rotate(pool.local()); err != nil { log.Warn("Failed to rotate transaction journal", "err", err) } } From e4e0c453e15b5f198ae5ae12b8e1c4fa18303426 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 13 Nov 2024 11:38:35 +0100 Subject: [PATCH 10/10] core/txpool/blobpool: fix rebase --- core/txpool/blobpool/blobpool.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index 8eb49121bfd9..02d339f99c2d 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -1724,11 +1724,19 @@ func (p *BlobPool) Clear() { // manually iterating and deleting every entry is super sub-optimal // However, Clear is not currently used in production so // performance is not critical at the moment. - for _, entry := range p.lookup { - if err := p.store.Delete(entry); err != nil { + for hash := range p.lookup.txIndex { + id, _ := p.lookup.storeidOfTx(hash) + if err := p.store.Delete(id); err != nil { log.Warn("failed to delete blob tx from backing store", "err", err) } } + for hash := range p.lookup.blobIndex { + id, _ := p.lookup.storeidOfBlob(hash) + if err := p.store.Delete(id); err != nil { + log.Warn("failed to delete blob from backing store", "err", err) + } + } + // unreserve each tracked account. Ideally, we could just clear the // reservation map in the parent txpool context. However, if we clear in // parent context, to avoid exposing the subpool lock, we have to lock the @@ -1746,7 +1754,7 @@ func (p *BlobPool) Clear() { for acct, _ := range p.index { p.reserve(acct, false) } - p.lookup = make(map[common.Hash]uint64) + p.lookup = newLookup() p.index = make(map[common.Address][]*blobTxMeta) p.spent = make(map[common.Address]*uint256.Int)