func (pool *BlockPool) UpdatePeer(peerID p2p.ID, height int64) error {

	peer := pool.peers[peerID]

	if peer == nil {
		if height < pool.Height {
			pool.logger.Info("Peer height too small",
				"peer", peerID, "height", height, "fsm_height", pool.Height)
			return errPeerTooShort
		}
		// Add new peer.
		peer = NewBpPeer(peerID, height, pool.toBcR.sendPeerError, nil)
		peer.SetLogger(pool.logger.With("peer", peerID))
		pool.peers[peerID] = peer
		pool.logger.Info("added peer", "peerID", peerID, "height", height, "num_peers", len(pool.peers))
	} else {
		// Check if peer is lowering its height. This is not allowed.
		if height < peer.Height {
			pool.RemovePeer(peerID, errPeerLowersItsHeight)
			return errPeerLowersItsHeight
		}
		// Update existing peer.
		peer.Height = height
	}

	// Update the pool's MaxPeerHeight if needed.
	pool.updateMaxPeerHeight()

	return nil
}
// UpdatePeer adds a new peer or updates an existing peer with a new height.
// If a peer is short it is not added.
UpdatePeer adds a new peer or updates an existing peer with a new height.
If a peer is short it is not added.
// UpdatePeer adds a new peer or updates an existing peer with a new height . // If a peer is short it is not added .
func (pool *BlockPool) UpdatePeer(peerID p2p.ID, height int64) error {
	peer := pool.peers[peerID]
	if peer == nil {
		if height < pool.Height {
			pool.logger.Info("Peer height too small",
				"peer", peerID, "height", height, "fsm_height", pool.Height)
			return errPeerTooShort
		}
		peer = NewBpPeer(peerID, height, pool.toBcR.sendPeerError, nil)
		peer.SetLogger(pool.logger.With("peer", peerID))
		pool.peers[peerID] = peer
		pool.logger.Info("added peer", "peerID", peerID, "height", height, "num_peers", len(pool.peers))
	} else {
		if height < peer.Height {
			pool.RemovePeer(peerID, errPeerLowersItsHeight)
			return errPeerLowersItsHeight
		}
		peer.Height = height
	}
	pool.updateMaxPeerHeight()
	return nil
}
func ( pool * BlockPool ) UpdatePeer ( peerID p2p . ID , height int64 ) error { peer := pool . peers [ peerID ] if peer == nil { if height < pool . Height { pool . logger . Info ( " " , " " , peerID , " " , height , " " , pool . Height ) return errPeerTooShort } peer = NewBpPeer ( peerID , height , pool . toBcR . sendPeerError , nil ) peer . SetLogger ( pool . logger . With ( " " , peerID ) ) pool . peers [ peerID ] = peer pool . logger . Info ( " " , " " , peerID , " " , height , " " , len ( pool . peers ) ) } else { if height < peer . Height { pool . RemovePeer ( peerID , errPeerLowersItsHeight ) return errPeerLowersItsHeight } peer . Height = height } pool . updateMaxPeerHeight ( ) return nil }
UpdatePeer adds a new peer or updates an existing peer with a new height.
UpdatePeer adds a new peer or updates an existing peer with a new height .
// Add new peer. // Check if peer is lowering its height. This is not allowed. // Update existing peer. // Update the pool's MaxPeerHeight if needed.