From 0fa2024bdab5e8a8396bf776f7a4f4c12f139952 Mon Sep 17 00:00:00 2001 From: andyzhang2023 Date: Sat, 11 Jan 2025 13:32:18 +0800 Subject: [PATCH 1/2] fix concurrent map read/write issue --- core/txpool/legacypool/legacypool.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index 740ffffd1..e2c2ade56 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -1496,7 +1496,7 @@ func (pool *LegacyPool) runReorg(done chan struct{}, reset *txpoolResetRequest, resetPromoteTimer.Update(promoteDur) resetFeedTimer.Update(sendfeedDur) - pending, queued := pool.stats() + pending, queued := pool.Stats() if reset.newHead != nil && reset.oldHead != nil { log.Info("Transaction pool reorged", "from", reset.oldHead.Number.Uint64(), "to", reset.newHead.Number.Uint64(), "reorgCost", reorgCost, "waittime", waittime, "promoted", len(promoted), "demoted", demoted, "sendFeed", sendFeed, "pending", pending, "queued", queued, From c2a2dfffe3267811379fd96c4ddce3ad4d7f39e8 Mon Sep 17 00:00:00 2001 From: andyzhang2023 Date: Sat, 11 Jan 2025 13:36:15 +0800 Subject: [PATCH 2/2] improve performance of txpool.stats() --- core/txpool/legacypool/legacypool.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index e2c2ade56..0c6c93f6b 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -609,15 +609,7 @@ func (pool *LegacyPool) Stats() (int, int) { // stats retrieves the current pool stats, namely the number of pending and the // number of queued (non-executable) transactions. func (pool *LegacyPool) stats() (int, int) { - pending := 0 - for _, list := range pool.pending { - pending += list.Len() - } - queued := 0 - for _, list := range pool.queue { - queued += list.Len() - } - return pending, queued + return pool.pendingCounter, pool.queueCounter } // Content retrieves the data content of the transaction pool, returning all the