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

prefer outbound peers when syncing #3521

Merged
merged 1 commit into from
Dec 15, 2020

Conversation

antiochp
Copy link
Member

@antiochp antiochp commented Dec 11, 2020

Resolves #3518

This PR fixes an edge case that we appear to be hitting on testnet due to low number of nodes and overall network health.

There was an inconsistency during sync where we would see a max_diff on an inbound peer that would trigger sync but then we would attempt to sync against a randomly chosen outbound peer. But it is possible that no outbound peers have sufficient difficulty to handle the sync request.

When checking for known max_diff we need to ensure we check against a set of peers that is consistent with those that we will actually sync from.

We want to prioritize syncing against outbound peers whenever possible.
But we we also want to handle the case where an inbound peer advertises more work than any other connected peers - in this case we will sync against that inbound peer, but only if no outbound peers are known to have the same total work.

Outbound peers are considered more reliable as they are more likely to be long lived (and likely with faster connections and more bandwidth).
Related discussion - bitcoin/bitcoin#5315 (comment)

Rules are as follows -

  • find max_diff across all connected peers (inbound and outbound)
  • randomly choose an outbound peer with diff >= max_diff
  • if no outbound peer then randomly choose inbound peer with diff >= max_diff

This means we prefer outbound peers when syncing. And we sync against inbound peers only when necessary.

@antiochp antiochp changed the title [WIP] prefer outbound peers when syncing prefer outbound peers when syncing Dec 12, 2020
@antiochp antiochp marked this pull request as ready for review December 12, 2020 09:52
@antiochp antiochp added this to the 5.0.0 milestone Dec 12, 2020
@antiochp
Copy link
Member Author

Related bitcoin/bitcoin#5315
Specifically bitcoin/bitcoin#5315 (comment)

It's not a strong guarantee, but typically large block chain fetches come from incoming and not from outgoing connections.

@antiochp antiochp requested a review from j01tz December 14, 2020 17:03
Copy link
Member

@j01tz j01tz left a comment

Choose a reason for hiding this comment

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

👍 on the concept and initial review. Tested for a quick sync but not likely under the troublesome conditions. As mentioned elsewhere, we probably want to revisit this area after the HF to ensure we have a clear big-picture robustness with good edge case security wrt rules around incoming/outgoing peer connections.

.connected()
.count();
let peers_iter = || peers.iter().connected();
let peers_count = peers_iter().count();
Copy link
Member

Choose a reason for hiding this comment

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

The change to using empty closures here and in other files when iterating peers is just a rust convenience thing?

Copy link
Member Author

Choose a reason for hiding this comment

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

We need to build a couple of instances of the same (or similar) iterator.
And the closure just makes this a lot easier to keep them consistent.

Copy link
Member

@quentinlesceller quentinlesceller left a comment

Choose a reason for hiding this comment

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

Looking good. Minor comment regarding the logs. Just synced with it.

servers/src/grin/sync/body_sync.rs Outdated Show resolved Hide resolved
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.

Looks good. Don't have anything to add that wasn't mentioned before.

but use inbound peer for header and body sync if necessary
sync state from inbound peer if no outbound peers to sync from
@antiochp antiochp merged commit 1baa59c into mimblewimble:master Dec 15, 2020
@antiochp antiochp deleted the most_work_peer_fix branch December 15, 2020 19:11
@antiochp antiochp mentioned this pull request May 6, 2021
bayk added a commit to mwcproject/mwc-node that referenced this pull request Jun 11, 2024
…imblewimble#3521)

but use inbound peer for header and body sync if necessary sync state from inbound peer if no outbound peers to sync from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

no peers available, disabling sync (finally explained, inbound vs outbound inconsistency)
4 participants