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

Flexible peer filtering #3458

Merged
merged 8 commits into from
Oct 27, 2020

Conversation

antiochp
Copy link
Member

@antiochp antiochp commented Oct 1, 2020

Takes inspiration from #3021 replacing custom cursor impl with impl Iterator.

As part of the PIBD work we will want to run nodes on the network that support various different sync strategies. some nodes may support PIBD while others only support "legacy" txhashset downloads.
So we need more flexible peer management and filtering of connected peers. This PR is a step toward this.


Introduce PeersIter so we can return iterator via "newtype iterator delegation".

pub fn peers_iter(&self) -> PeersIter<impl Iterator<Item = Arc<Peer>>> {
    ...
}

Then expose various filters and operators on PeersIter so we can chain them in various flexible ways -

self
    .peers_iter()
    .outbound()
    .connected()
    .count()

  • moved the random sorting/shuffle out of the api and into a simpler choose_random() filter on PeersIter
  • flexible with_difficulty() filtering to filter based on minimum difficulty
  • flexible with_capabilities() filtering that can be combined with other chain-able filters

The following fns have all been replaced with the flexible with_difficulty() filter -

  • more_work_peers()
  • more_or_same_work_peers()
  • more_work_peer()
  • most_work_peers()
  • most_work_peer()

Note: As part of this PR the sync process has been modified slightly.
During sync (both header_sync and state_sync) we now sync explicitly against outbound peers.
This makes the sync process more consistent across "public" and "private" nodes. We no longer attempt to sync against inbound nodes regardless of whether we accept incoming connections or not.

@antiochp antiochp force-pushed the most_work_peers_capabilities branch 2 times, most recently from 60a5eac to 74523f4 Compare October 8, 2020 15:50
@antiochp antiochp marked this pull request as ready for review October 19, 2020 15:29
@antiochp antiochp added this to the 5.0.0 milestone Oct 19, 2020
@antiochp antiochp self-assigned this Oct 22, 2020
Copy link
Contributor

@jaspervdm jaspervdm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the delay in review. I really like the approach here 👍 Just have a few small comments

p2p/src/peers.rs Show resolved Hide resolved
p2p/src/peers.rs Outdated Show resolved Hide resolved
api/src/handlers/server_api.rs Show resolved Hide resolved
@antiochp antiochp merged commit 25fcefa into mimblewimble:master Oct 27, 2020
@antiochp antiochp deleted the most_work_peers_capabilities branch October 27, 2020 12:36
@antiochp antiochp mentioned this pull request Nov 26, 2020
bayk added a commit to mwcproject/mwc-node that referenced this pull request Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants