fix(chunk-post): key sorted-peer memo by set, not length#804
Conversation
getSortedChunkPostPeers memoized its weighted peer ordering with a normalizer of `eligiblePeers.length`, so two *different* eligible-peer sets of equal size shared one cached ordering for the full CHUNK_POST_SORTED_PEERS_CACHE_DURATION_MS window (10s default). That quietly narrowed chunk-POST seeding diversity: a churning-but-same-size peer set kept reusing the first set's ordering. Key by the set of peer ids instead (order-independent sort+join). Still cheap — a sort+join over the bounded postChunk peer set, far less than the weighted selection it guards — and the 10s maxAge still absorbs gradual weight drift. Extracted as the pure, exported `chunkPostPeersCacheKey` so the keying is unit-tested directly (distinct same-length sets ⇒ distinct keys; order- independent; no input mutation; empty set). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XQPK4TXcVoXoyFp6sNW2Lr
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds an exported Peer memoization key fix
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #804 +/- ##
===========================================
+ Coverage 78.65% 78.76% +0.11%
===========================================
Files 132 132
Lines 49980 50109 +129
Branches 3763 3781 +18
===========================================
+ Hits 39312 39470 +158
+ Misses 10620 10591 -29
Partials 48 48 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Superseded by #812 — consolidated into the |
What
ArweaveCompositeClient.getSortedChunkPostPeersmemoizes its weighted peer ordering with a normalizer ofeligiblePeers.length. Two different eligible-peer sets of equal size therefore share one cached ordering for the fullCHUNK_POST_SORTED_PEERS_CACHE_DURATION_MSwindow (10s default).This keys the memo by the set of peer ids instead (order-independent
slice().sort().join()).Why it matters
The length-only key quietly narrows chunk-POST seeding diversity: a churning-but-same-size peer set keeps reusing the first set's ordering, so the same peers get prioritized for up to 10s even as the eligible set changes. For a gateway whose job is to be a good seeding target, fanout diversity is exactly what we don't want to silently pin.
Surfaced during an architecture review of chunk fanout (the broader durability work concluded the gateway should optimize fanout quality, not duplicate the bundler's durability engine — this is one of those quality fixes).
Cost
Still cheap: one sort+join over the bounded
postChunkpeer set (tens–low hundreds of entries), far less than the weightedselectPeers+ filtering the memo guards. The 10smaxAgestill absorbs gradual weight drift. Does not mutate the caller's array.Tests
Extracted the keying as the pure, exported
chunkPostPeersCacheKeyand unit-tested it directly:yarn test:file src/arweave/composite-client.test.ts→ 15/15 pass; eslint clean.🤖 Generated with Claude Code