mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-07 14:46:44 +00:00
[NOD-669] Fix startSync sending a blockLocatorMsg with a zeroHash insead of the peer's selectedTip (#592)
* [NOD-669] Fix startSync sending a blockLocatorMsg with a zeroHash instead of the peer's selectedTip. * [NOD-669] Rename bestPeer to syncPeer. * [NOD-669] Fix comments.
This commit is contained in:
parent
045984e6b9
commit
38b4749f20
@ -153,7 +153,7 @@ type SyncManager struct {
|
|||||||
peerStates map[*peerpkg.Peer]*peerSyncState
|
peerStates map[*peerpkg.Peer]*peerSyncState
|
||||||
}
|
}
|
||||||
|
|
||||||
// startSync will choose the best peer among the available candidate peers to
|
// startSync will choose the sync peer among the available candidate peers to
|
||||||
// download/sync the blockDAG from. When syncing is already running, it
|
// download/sync the blockDAG from. When syncing is already running, it
|
||||||
// simply returns. It also examines the candidates for any which are no longer
|
// simply returns. It also examines the candidates for any which are no longer
|
||||||
// candidates and removes them as needed.
|
// candidates and removes them as needed.
|
||||||
@ -163,7 +163,7 @@ func (sm *SyncManager) startSync() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var bestPeer *peerpkg.Peer
|
var syncPeer *peerpkg.Peer
|
||||||
for peer, state := range sm.peerStates {
|
for peer, state := range sm.peerStates {
|
||||||
if !state.syncCandidate {
|
if !state.syncCandidate {
|
||||||
continue
|
continue
|
||||||
@ -174,23 +174,23 @@ func (sm *SyncManager) startSync() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(davec): Use a better algorithm to choose the best peer.
|
// TODO(davec): Use a better algorithm to choose the sync peer.
|
||||||
// For now, just pick the first available candidate.
|
// For now, just pick the first available candidate.
|
||||||
bestPeer = peer
|
syncPeer = peer
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start syncing from the best peer if one was selected.
|
// Start syncing from the sync peer if one was selected.
|
||||||
if bestPeer != nil {
|
if syncPeer != nil {
|
||||||
// Clear the requestedBlocks if the sync peer changes, otherwise
|
// Clear the requestedBlocks if the sync peer changes, otherwise
|
||||||
// we may ignore blocks we need that the last sync peer failed
|
// we may ignore blocks we need that the last sync peer failed
|
||||||
// to send.
|
// to send.
|
||||||
sm.requestedBlocks = make(map[daghash.Hash]struct{})
|
sm.requestedBlocks = make(map[daghash.Hash]struct{})
|
||||||
|
|
||||||
log.Infof("Syncing to block %s from peer %s",
|
log.Infof("Syncing to block %s from peer %s",
|
||||||
bestPeer.SelectedTip(), bestPeer.Addr())
|
syncPeer.SelectedTip(), syncPeer.Addr())
|
||||||
|
|
||||||
bestPeer.PushGetBlockLocatorMsg(&daghash.ZeroHash, sm.dagParams.GenesisHash)
|
syncPeer.PushGetBlockLocatorMsg(syncPeer.SelectedTip(), sm.dagParams.GenesisHash)
|
||||||
sm.syncPeer = bestPeer
|
sm.syncPeer = syncPeer
|
||||||
} else {
|
} else {
|
||||||
log.Warnf("No sync peer candidates available")
|
log.Warnf("No sync peer candidates available")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user