Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.0] Support throttling block syncing to peers #1741

Merged
merged 54 commits into from
Oct 10, 2023

Conversation

jgiszczak
Copy link
Contributor

Peer to peer listen ports may now apply a block sync throttle. Each occurrence of p2p-listen-endpoint has an independent throttle specification. Here's the updated help text:

--p2p-listen-endpoint arg (=0.0.0.0:9876:0)
                                        The actual host:port[:<rate-cap>] used
                                        to listen for incoming p2p connections.
                                        May be used multiple times.   The
                                        optional rate cap will limit block sync
                                        bandwidth to the specified rate.  A
                                        number alone will be interpreted as
                                        bytes per second.  The number may be
                                        suffixed with units.  Supported units
                                        are:   'B/s', 'KB/s', 'MB/s, 'GB/s',
                                        'TB/s', 'KiB/s', 'MiB/s', 'GiB/s',
                                        'TiB/s'.  Transactions and blocks
                                        outside of sync mode are not throttled.
                                          Examples:
                                            192.168.0.100:9876:1MiB/s
                                            node.eos.io:9876:1512KB/s
                                            node.eos.io:9876:0.5GB/s
                                            [2001:db8:85a3:8d3:1319:8a2e:370:7348]:9876:250KB/s

Parsing of the rate cap accepts fractional numbers expressed as decimals. The throttle rate is in bytes per second. Per the help text, shorthand suffixes are supported, and transactions and blocks being propagated across the peer to peer network between synchronized nodes are not throttled. Only blocks transmitted to a syncing node are throttled. A throttle of 0 or 0B/s means unthrottled, and is the default.

The limit for specifying a rate cap is 30 characters, including the colon field separator. This is sufficient characters to specify any value in the 64 bit range of size_t with room left for a suffix. If the rate cap does not parse or the value multiplied by the suffix exceeds 18,446,744,073,709,551,615 an exception will be thrown and the node will not start.

IPv6 addresses are supported for listen endpoints. They must be in square bracket format: [<ipv6 address>]:port optionally followed by :<rate-cap>.

Note

Inbound connections from IPs which are configured p2p-peer-addresses are exempt from throttle rate caps. Care should be taken in NAT environments to avoid inadvertently exempting connections due to overlapping subnets.

Throttling is stable even at exceptionally low byterates, but of course on a busy network if the throttle is less than the average block size on the network, clients using that listen port will never catch up to the head block. Such configurations are allowed but not recommended.

Suggested network topology

Together with #1411 which allows multiple listen endpoints, an edge node for public peering might be configured as follows:
Leap Throttle Sample Network Diagram (truncated)

Resolves #1295.

Retargetting #1540 to release/5.0.

jgiszczak and others added 30 commits August 22, 2023 03:16
Add necessary custom topology for p2p_sync_throttle_test.
Clarify variable names in p2p throttled sync test and tweak numbers.
Fix p2p throttled test to actually function (waitForBlock has a hidden
default timeout).
Bump up timeout in block_log_util_test.
Remove exponential backoff in throttle and utilize existing retry
mechanism.
Fix parsing and overflow problems and address peer review comments.
Extend throttle test to add another throttle prefix.
Added additional code comments.
Addressed peer review comment.
Update connections_manager::add method.
Clean up cruft and rename connection data structure back to
'connections'.
Address peer review comments.
Add mock_connection constructor required by clang14.
oschwaldp-oci and others added 5 commits October 4, 2023 08:07
Remove dependency on python requests package.
Remove locale-aware parsing of sync throttle rate.
Prevent transmitting peer from throttling while not in sync mode.
Add timeouts to throttle sync test.
@heifner heifner changed the title Support throttling block syncing to peers 5.0. [5.0] Support throttling block syncing to peers Oct 10, 2023
@heifner heifner requested a review from dimas1185 October 10, 2023 17:40
@heifner heifner added the OCI Work exclusive to OCI team label Oct 10, 2023
@heifner heifner linked an issue Oct 10, 2023 that may be closed by this pull request
@jgiszczak jgiszczak merged commit 1498a04 into release/5.0 Oct 10, 2023
26 of 36 checks passed
@jgiszczak jgiszczak deleted the p2p-peer-throttle-5.0 branch October 10, 2023 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCI Work exclusive to OCI team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

P2P: Ability to limit peer bandwidth consumption
4 participants