Allow multiple concurrent allocations per peer per context#9599
Draft
Allow multiple concurrent allocations per peer per context#9599
Conversation
…le limit - Added MaxAllocationsPerPeerPerContext config parameter (default: 2) - Modified PeerInfo to track allocation counts per context instead of binary flags - Updated allocation/free logic to increment/decrement counts - Updated tests to reflect new behavior where peers can be allocated multiple times - This allows peers to serve multiple requests during latency periods, improving efficiency Co-authored-by: asdacap <1841324+asdacap@users.noreply.github.com>
Co-authored-by: asdacap <1841324+asdacap@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Allow allocating to the same peer multiple times
Allow multiple concurrent allocations per peer per context
Oct 30, 2025
asdacap
reviewed
Oct 30, 2025
| SyncPeerAllocation allocation1 = await ctx.Pool.Allocate(new BySpeedStrategy(TransferSpeedType.Headers, true)); | ||
| SyncPeerAllocation allocation2 = await ctx.Pool.Allocate(new BySpeedStrategy(TransferSpeedType.Headers, true)); | ||
| Assert.That(allocation2.Current, Is.Not.SameAs(allocation1.Current), "first"); | ||
| // With multiple allocations per peer, both may point to same PeerInfo or different - both are valid |
| [ConfigItem(Description = "_Technical._ Estimated max size of blocks in block processing queue before stop downloading.", DefaultValue = "200000000", HiddenFromDocs = true)] | ||
| long ForwardSyncBlockProcessingQueueMemoryBudget { get; set; } | ||
|
|
||
| [ConfigItem(Description = "The maximum number of concurrent allocations per peer per allocation context. Allows a peer to serve multiple requests simultaneously during request latency periods.", DefaultValue = "2")] |
Contributor
There was a problem hiding this comment.
Remove the mention of "request latency periods", its weird.
Contributor
Author
There was a problem hiding this comment.
Done in a1c3297. Simplified description to "Allows a peer to serve multiple requests simultaneously."
| Assert.That(allocation2.HasPeer, Is.True); | ||
| Assert.That(allocation3.HasPeer, Is.False); | ||
| // With 2 awake peers and max 2 allocations per peer, we can have up to 4 allocations, so third allocation succeeds | ||
| Assert.That(allocation3.HasPeer, Is.True); |
Contributor
There was a problem hiding this comment.
@copilot a sleeping peer cannot allocate even if it has slot.
Contributor
Author
There was a problem hiding this comment.
Fixed in a1c3297. Updated test to allocate 4 times (maxing out the 2 awake peers) and then verify the 5th allocation fails, confirming sleeping peers cannot be allocated even with available slots.
- Remove mention of "request latency periods" from config description - Add more allocations in Can_borrow_many test to fully test 2 slots per peer - Fix Does_not_allocate_sleeping_peers test to properly verify sleeping peers cannot be allocated Co-authored-by: asdacap <1841324+asdacap@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements support for allocating the same peer multiple times per allocation context, allowing peers to serve multiple concurrent requests.
Changes Made
MaxAllocationsPerPeerPerContextconfiguration parameter (default: 2) in ISyncConfig and SyncConfigBenefits
✅ Peers can serve multiple requests simultaneously
✅ Improves sync efficiency for low-peer networks (e.g., base-mainnet)
✅ Configurable limit allows network-specific tuning
✅ Backward compatible (set to 1 to restore old behavior)
Technical Details
The implementation uses a per-context allocation counter instead of binary flags. When allocating:
When freeing:
This allows the same peer to be allocated up to
maxAllocationsPerContexttimes for each context (Headers, Bodies, Receipts, etc.), significantly improving throughput.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.