@@ -64,9 +64,9 @@ const TICK_TIMEOUT: time::Duration = time::Duration::from_millis(1100);
6464const PROPAGATE_TIMEOUT : time:: Duration = time:: Duration :: from_millis ( 2900 ) ;
6565
6666/// Current protocol version.
67- pub ( crate ) const CURRENT_VERSION : u32 = 3 ;
67+ pub ( crate ) const CURRENT_VERSION : u32 = 4 ;
6868/// Lowest version we support
69- pub ( crate ) const MIN_VERSION : u32 = 2 ;
69+ pub ( crate ) const MIN_VERSION : u32 = 3 ;
7070
7171// Maximum allowed entries in `BlockResponse`
7272const MAX_BLOCK_DATA_RESPONSE : u32 = 128 ;
@@ -1028,14 +1028,33 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
10281028 return ;
10291029 }
10301030
1031- let hash = header. hash ( ) ;
1031+ let is_best = self . context_data . chain . info ( ) . chain . best_hash == hash;
1032+ debug ! ( target: "sync" , "Reannouncing block {:?}" , hash) ;
1033+ self . send_announcement ( & header, is_best, true )
1034+ }
10321035
1033- let message = GenericMessage :: BlockAnnounce ( message:: BlockAnnounce { header : header. clone ( ) } ) ;
1036+ fn send_announcement ( & mut self , header : & B :: Header , is_best : bool , force : bool ) {
1037+ let hash = header. hash ( ) ;
10341038
10351039 for ( who, ref mut peer) in self . context_data . peers . iter_mut ( ) {
1036- trace ! ( target: "sync" , "Reannouncing block {:?} to {}" , hash, who) ;
1037- peer. known_blocks . insert ( hash) ;
1038- self . behaviour . send_packet ( who, message. clone ( ) )
1040+ trace ! ( target: "sync" , "Announcing block {:?} to {}" , hash, who) ;
1041+ let inserted = peer. known_blocks . insert ( hash) ;
1042+ if inserted || force {
1043+ let message = GenericMessage :: BlockAnnounce ( message:: BlockAnnounce {
1044+ header : header. clone ( ) ,
1045+ state : if peer. info . protocol_version >= 4 {
1046+ if is_best {
1047+ Some ( message:: BlockState :: Best )
1048+ } else {
1049+ Some ( message:: BlockState :: Normal )
1050+ }
1051+ } else {
1052+ None
1053+ }
1054+ } ) ;
1055+
1056+ self . behaviour . send_packet ( who, message)
1057+ }
10391058 }
10401059 }
10411060
@@ -1072,7 +1091,12 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
10721091 peerset : self . peerset_handle . clone ( ) ,
10731092 } , who. clone ( ) , * header. number ( ) ) ;
10741093
1075- match self . sync . on_block_announce ( who. clone ( ) , hash, & header) {
1094+ let is_their_best = match announce. state . unwrap_or ( message:: BlockState :: Best ) {
1095+ message:: BlockState :: Best => true ,
1096+ message:: BlockState :: Normal => false ,
1097+ } ;
1098+
1099+ match self . sync . on_block_announce ( who. clone ( ) , hash, & header, is_their_best) {
10761100 sync:: OnBlockAnnounce :: Request ( peer, req) => {
10771101 self . send_message ( peer, GenericMessage :: BlockRequest ( req) ) ;
10781102 return CustomMessageOutcome :: None
@@ -1132,8 +1156,10 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
11321156
11331157 /// Call this when a block has been imported in the import queue and we should announce it on
11341158 /// the network.
1135- pub fn on_block_imported ( & mut self , hash : B :: Hash , header : & B :: Header ) {
1136- self . sync . update_chain_info ( header) ;
1159+ pub fn on_block_imported ( & mut self , hash : B :: Hash , header : & B :: Header , is_best : bool ) {
1160+ if is_best {
1161+ self . sync . update_chain_info ( header) ;
1162+ }
11371163 self . specialization . on_block_imported (
11381164 & mut ProtocolContext :: new ( & mut self . context_data , & mut self . behaviour , & self . peerset_handle ) ,
11391165 hash. clone ( ) ,
@@ -1146,15 +1172,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
11461172 }
11471173
11481174 // send out block announcements
1149-
1150- let message = GenericMessage :: BlockAnnounce ( message:: BlockAnnounce { header : header. clone ( ) } ) ;
1151-
1152- for ( who, ref mut peer) in self . context_data . peers . iter_mut ( ) {
1153- if peer. known_blocks . insert ( hash. clone ( ) ) {
1154- trace ! ( target: "sync" , "Announcing block {:?} to {}" , hash, who) ;
1155- self . behaviour . send_packet ( who, message. clone ( ) )
1156- }
1157- }
1175+ self . send_announcement ( & header, is_best, false ) ;
11581176 }
11591177
11601178 /// Call this when a block has been finalized. The sync layer may have some additional
0 commit comments