Skip to content

Commit 8a45116

Browse files
authored
Expand LRU size comment
1 parent 60f92ee commit 8a45116

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

op-node/rollup/derive/batch_authenticator.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,16 @@ type BatchAuthCaches struct {
3838

3939
// NewBatchAuthCaches creates caches sized for the BatchAuthLookbackWindow.
4040
func NewBatchAuthCaches() *BatchAuthCaches {
41-
// BatchAuthLookbackWindow past blocks + 1 current block + 1 LRU overhead.
41+
// The lookback window covers 101 blocks (the ref block plus 100 ancestors),
42+
// so 101 entries are live during any single traversal. We add +2 (not +1)
43+
// because the traversal reads newest-to-oldest: the ref block is touched
44+
// first and so becomes the LRU entry. With exactly 101 slots, inserting the
45+
// next block's ref would evict the previous ref (its parent) — the very block
46+
// we're about to read — triggering a cascade of evict-and-refetch through the
47+
// whole window. The extra slot leaves room for the 101 new window entries plus
48+
// one stale entry (the block that just fell out of the lookback window). That
49+
// stale entry, untouched in the current traversal, is the LRU and gets evicted
50+
// instead, so no cascade occurs.
4251
// lru.New only errors on size <= 0.
4352
size := int(BatchAuthLookbackWindow) + 2
4453
authCache, _ := lru.New[common.Hash, map[common.Hash]common.Address](size)

0 commit comments

Comments
 (0)