mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-06 06:06:49 +00:00

* [NOD-669] Remove the "get" from getBlueBlocksBetween. * [NOD-669] Remove the "Get" from GetBlueBlocksHeadersBetween. * [NOD-669] In blueBlocksBetween, rename startHash to lowHash and stopHash to highHash. * [NOD-669] Rename startHash to lowHash and stopHash to highHash in blockLocator logic. * [NOD-669] Remove zeroHash logic in blockLocator. * [NOD-669] Finish renaming startHash and stopHash in blockdag. * [NOD-669] Rename startHash and stopHash in blockdag where I previously missed it. * [NOD-669] Rename startHash and stopHash in blockdag where I previously missed it some more. * [NOD-669] Rename startHash and stopHash in blockdag where I previously missed it some more some more. * [NOD-669] Fix bad grammar in method names. * [NOD-669] Rename lowHash to blockHash in SelectedParentChain. * [NOD-669] Fix a comment.
50 lines
1.7 KiB
Go
50 lines
1.7 KiB
Go
package p2p
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/peer"
|
|
"github.com/kaspanet/kaspad/wire"
|
|
)
|
|
|
|
// OnBlockLocator is invoked when a peer receives a locator kaspa
|
|
// message.
|
|
func (sp *Peer) OnBlockLocator(_ *peer.Peer, msg *wire.MsgBlockLocator) {
|
|
// Find the highest known shared block between the peers, and asks
|
|
// the block and its future from the peer. If the block is not
|
|
// found, create a lower resolution block locator and send it to
|
|
// the peer in order to find it in the next iteration.
|
|
dag := sp.server.DAG
|
|
if len(msg.BlockLocatorHashes) == 0 {
|
|
peerLog.Warnf("Got empty block locator from peer %s",
|
|
sp)
|
|
return
|
|
}
|
|
// If the first hash of the block locator is known, it means we found
|
|
// the highest shared block.
|
|
highHash := msg.BlockLocatorHashes[0]
|
|
if dag.BlockExists(highHash) {
|
|
if dag.IsKnownFinalizedBlock(highHash) {
|
|
peerLog.Debugf("Cannot sync with peer %s because the highest"+
|
|
" shared chain block (%s) is below the finality point", sp, highHash)
|
|
sp.server.SyncManager.RemoveFromSyncCandidates(sp.Peer)
|
|
return
|
|
}
|
|
|
|
// We send the highHash as the GetBlockInvsMsg's lowHash here.
|
|
// This is not a mistake. The invs we desire start from the highest
|
|
// hash that we know of and end at the highest hash that the peer
|
|
// knows of.
|
|
err := sp.Peer.PushGetBlockInvsMsg(highHash, sp.Peer.SelectedTip())
|
|
if err != nil {
|
|
peerLog.Errorf("Failed pushing get blocks message for peer %s: %s",
|
|
sp, err)
|
|
return
|
|
}
|
|
return
|
|
}
|
|
highHash, lowHash := dag.FindNextLocatorBoundaries(msg.BlockLocatorHashes)
|
|
if highHash == nil {
|
|
panic("Couldn't find any unknown hashes in the block locator.")
|
|
}
|
|
sp.PushGetBlockLocatorMsg(highHash, lowHash)
|
|
}
|