From d26ba44f3af0dd74ea34a3353f14650ac592de61 Mon Sep 17 00:00:00 2001 From: andyzhang2023 Date: Thu, 9 May 2024 18:22:50 +0800 Subject: [PATCH] update pending cache within a minimal duration --- core/txpool/legacypool/legacypool.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index be3f3ebd6f..1b70451252 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -54,6 +54,9 @@ const ( // txReannoMaxNum is the maximum number of transactions a reannounce action can include. txReannoMaxNum = 1024 + + // minPendingCacheDuration is the minimum duration between two pending cache updates. + minPendingCacheDuration = 250 * time.Millisecond ) var ( @@ -263,6 +266,8 @@ type LegacyPool struct { changesSinceReorg int // A counter for how many drops we've performed in-between reorg. l1CostFn txpool.L1CostFunc // To apply L1 costs as rollup, optional field, may be nil. + + lastPendingCacheTime time.Time // Last time pending cache was updated } type txpoolResetRequest struct { @@ -1376,6 +1381,11 @@ func (pool *LegacyPool) runReorg(done chan struct{}, reset *txpoolResetRequest, } pool.pendingNonces.setAll(nonces) } + // keep updating pending cache in a minimal frequency + if reset == nil && time.Since(pool.lastPendingCacheTime) > minPendingCacheDuration { + pool.lastPendingCacheTime = time.Now() + go pool.pendingCache.dump(pool, pool.gasTip.Load(), pool.priced.urgent.baseFee) + } // Ensure pool.queue and pool.pending sizes stay within the configured limits. pool.truncatePending() pool.truncateQueue()