@@ -666,7 +666,7 @@ impl<N: Network> BlockSync<N> {
666666 /// This function does **not** check
667667 /// that the block locators are consistent with the peer's previous block locators or other peers' block locators.
668668 pub fn update_peer_locators ( & self , peer_ip : SocketAddr , locators : & BlockLocators < N > ) -> Result < ( ) > {
669- // Update the locators entry for the given peer IP.
669+ // -- First, update the locators entry for the given peer IP. --
670670 // We perform this update atomically, and drop the lock as soon as we are done with the update.
671671 match self . locators . write ( ) . entry ( peer_ip) {
672672 hash_map:: Entry :: Occupied ( mut e) => {
@@ -688,7 +688,7 @@ impl<N: Network> BlockSync<N> {
688688 }
689689 }
690690
691- // Compute the common ancestor with this node.
691+ // -- Second, compute the common ancestor with this node. --
692692 let new_local_ancestor = {
693693 let mut ancestor = 0 ;
694694 // Attention: Please do not optimize this loop, as it performs fork-detection. In addition,
@@ -699,7 +699,7 @@ impl<N: Network> BlockSync<N> {
699699 match ledger_hash == hash {
700700 true => ancestor = height,
701701 false => {
702- debug ! ( "Detected fork with peer \" {peer_ip}\" at height {height}" ) ;
702+ warn ! ( "Detected fork between this node and peer \" {peer_ip}\" at height {height}" ) ;
703703 break ;
704704 }
705705 }
@@ -708,7 +708,7 @@ impl<N: Network> BlockSync<N> {
708708 ancestor
709709 } ;
710710
711- // Compute the common ancestor with every other peer.
711+ // -- Third, compute the common ancestor with every other peer, and determine if this peer is forked from others. --
712712 // Do not hold write lock to `common_ancestors` here, because this can take a while with many peers.
713713 let ancestor_updates: Vec < _ > = self
714714 . locators
@@ -739,7 +739,7 @@ impl<N: Network> BlockSync<N> {
739739 } )
740740 . collect ( ) ;
741741
742- // Update the map of common ancestors.
742+ // -- Forth, update the map of common ancestors. --
743743 // Scope the lock, so it is dropped before locking `sync_state`.
744744 {
745745 let mut common_ancestors = self . common_ancestors . write ( ) ;
@@ -750,14 +750,14 @@ impl<N: Network> BlockSync<N> {
750750 }
751751 }
752752
753- // Update sync state, because the greatest peer height may have decreased.
753+ // -- Finally, update sync state and notify the sync loop about the change. --
754754 if let Some ( greatest_peer_height) = self . locators . read ( ) . values ( ) . map ( |l| l. latest_locator_height ( ) ) . max ( ) {
755755 self . sync_state . write ( ) . set_greatest_peer_height ( greatest_peer_height) ;
756756 } else {
757757 error ! ( "Got new block locators but greatest peer height is zero." ) ;
758758 }
759-
760- // Notify the sync loop that something changed .
759+ // Even if the greatest peer height did not change, we still received new block locators
760+ // that the sync loop might need to proceed .
761761 self . peer_notify . notify_one ( ) ;
762762
763763 Ok ( ( ) )
0 commit comments