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

feat: same geo peering #111

Closed
wants to merge 72 commits into from
Closed

Conversation

czarcas7ic
Copy link
Member

@czarcas7ic czarcas7ic commented Jun 20, 2024

This PR introduces a new config section of p2p:

# If region_aware is set to true, the defined percent_peers_in_same_region of the max_num_inbound_peers and
# max_num_outbound_peers must be from the same region as this node.
# The percent can be at max 0.9 (90%), as we hardcode this max to allow cross-geo connectivity.
# E.g. if max_num_inbound_peers and max_num_inbound_peers are both set to 10, and percent_peers_in_same_region
# is set to 0.9 (90%), then 9 peers must be from the same region as this node, and 1 peer must be from a different region.
region_aware = false
percent_peers_in_same_region = 0.9
# The amount of times we can query a region for a peer in a given ensurePeers period.
# E.g. The current peer query period is hard coded to 30 seconds. If our API rate limits us to 40 queries per minute,
# then we can set this value to 20, preventing us from hitting the rate limit.
region_queries_per_peer_query_period = 20

If region_aware is set to false, all previous logic for peer dialing should be exactly the same (the ONLY diff was a small change I snuck in, where in the current live logic, if toDial is 1, the max dial attempts we make are 3*1. I instead created a floor of 5, as finding that last peer tends to take a while.)

If region_aware is set to true, the following new logic occurs:

  • We determine our own region via an IP API service and store this region
  • When populating our addressbook via ensurePeers, we query and store the region of the peer in our addrbook (note: this stores it in the addrbook.json as well. If you revert back to an old version, the addrbook.json just flushes the region field and works like normal out of the box!)
  • Instead of a single toDial category, we have a toDial in our own region category, and a toDial in other regions category.
    • If percent_peers_in_same_region is 0.9 and we have inbound and outbound peers set to 10, we will connect to 9 inbound/outbound peers in our own region, and 1 inbound/outbound peer outside of our region.
    • This number cannot go higher than 0.9, to mandate cross-geo connectivity (we can change this max higher or lower)

You can test this feature out for yourself, but setting these values in config.toml, starting the node up, waiting a few minutes and running the following one-liner:

curl -s localhost:26657/net_info? | jq '{
     Outbound: [.result.peers[] | select(.is_outbound == true) | .remote_ip],
      Inbound: [.result.peers[] | select(.is_outbound == false) | .remote_ip]
}'

You can then manually use this link (http://ip-api.com/json/X.X.X.X) to check that the region for the peers you are connected to follow the constraints.


PR checklist

  • Tests written/updated
  • Changelog entry added in .changelog (we use unclog to manage our changelog)
  • Updated relevant documentation (docs/ or spec/) and code comments

Copy link

github-actions bot commented Jul 6, 2024

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label Jul 6, 2024
@github-actions github-actions bot closed this Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant