Skip to content

Commit

Permalink
update pending cache within a minimal duration
Browse files Browse the repository at this point in the history
  • Loading branch information
andyzhang2023 committed May 9, 2024
1 parent f5d5a11 commit d26ba44
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/txpool/legacypool/legacypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit d26ba44

Please sign in to comment.