-
Notifications
You must be signed in to change notification settings - Fork 990
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
Conversation
Related bitcoin/bitcoin#5315
|
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
There was a problem hiding this 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
2309890
to
0b5a0f6
Compare
…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
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 -
max_diff
across all connected peers (inbound and outbound)diff >= max_diff
diff >= max_diff
This means we prefer outbound peers when syncing. And we sync against inbound peers only when necessary.