Truncate inbound Peers
response further
#3007
Merged
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.
Motivation
We want to truncate the number of peers we return to a
Peers
request by a fraction of available peer addresses.Closes #1889
Solution
Truncate to whatever is smaller: The bitcoin constant(1000) or 1/3 of the number of available peers. We use
ceil()
instead offloor()
to cover edge cases of 1 and 2.Review
Anyone can review. A test could be possible, i made one. It was a mix of what https://github.com/ZcashFoundation/zebra/blob/main/zebra-network/src/peer_set/initialize/tests/vectors.rs and https://github.com/ZcashFoundation/zebra/blob/main/zebrad/src/components/inbound/tests.rs. There is some work to be done so we don't duplicate code, some files will have to change into public (which requires documentation), etc. I think doesn't worth it, just to see if we are truncating in a good manner.