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

Peer/sync manager improvements #470

Merged
merged 2 commits into from
May 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions netsync/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ func (sm *SyncManager) startSync() {
bestPeers := []*peerpkg.Peer{}
okPeers := []*peerpkg.Peer{}
for peer, state := range sm.peerStates {
// Check if this node is a sync candidate. These nodes will be used
// when determining switching sync peers. See 'medianSyncPeerCandidateBlockHeight'.
state.syncCandidate = sm.isSyncCandidate(peer)
if !state.syncCandidate {
continue
}
Expand Down Expand Up @@ -455,7 +458,14 @@ func (sm *SyncManager) isSyncCandidate(peer *peerpkg.Peer) bool {
// Typically a peer is not a candidate for sync if it's not a full node,
// however regression test is special in that the regression tool is
// not a full node and still needs to be considered a sync candidate.
if sm.chainParams == &chaincfg.RegressionNetParams && !sm.regTestSyncAnyHost {
if sm.chainParams != &chaincfg.RegressionNetParams {
// The peer is not a candidate for sync if it's not a full
// node.
nodeServices := peer.Services()
return nodeServices&wire.SFNodeNetwork == wire.SFNodeNetwork
}

if !sm.regTestSyncAnyHost {
// The peer is not a candidate if it's not coming from localhost
// or the hostname can't be determined for some reason.
host, _, err := net.SplitHostPort(peer.Addr())
Expand All @@ -466,13 +476,6 @@ func (sm *SyncManager) isSyncCandidate(peer *peerpkg.Peer) bool {
if host != "127.0.0.1" && host != "localhost" {
return false
}
} else {
// The peer is not a candidate for sync if it's not a full
// node.
nodeServices := peer.Services()
if nodeServices&wire.SFNodeNetwork != wire.SFNodeNetwork {
return false
}
}

// Candidate if all checks passed.
Expand Down