@@ -109,6 +109,38 @@ impl Extension {
109109 }
110110 }
111111
112+ fn send_status ( & mut self , id : & NodeId ) {
113+ let chain_info = self . client . chain_info ( ) ;
114+ self . api . send (
115+ id,
116+ Arc :: new (
117+ Message :: Status {
118+ total_score : chain_info. best_proposal_score ,
119+ best_hash : chain_info. best_proposal_block_hash ,
120+ genesis_hash : chain_info. genesis_hash ,
121+ }
122+ . rlp_bytes ( ) ,
123+ ) ,
124+ ) ;
125+ }
126+
127+ fn send_status_broadcast ( & mut self ) {
128+ let chain_info = self . client . chain_info ( ) ;
129+ for id in self . connected_nodes . iter ( ) {
130+ self . api . send (
131+ id,
132+ Arc :: new (
133+ Message :: Status {
134+ total_score : chain_info. best_proposal_score ,
135+ best_hash : chain_info. best_proposal_block_hash ,
136+ genesis_hash : chain_info. genesis_hash ,
137+ }
138+ . rlp_bytes ( ) ,
139+ ) ,
140+ ) ;
141+ }
142+ }
143+
112144 fn send_header_request ( & mut self , id : & NodeId , request : RequestMessage ) {
113145 if let Some ( requests) = self . requests . get_mut ( id) {
114146 ctrace ! ( SYNC , "Send header request to {}" , id) ;
@@ -212,18 +244,8 @@ impl NetworkExtension<Event> for Extension {
212244
213245 fn on_node_added ( & mut self , id : & NodeId , _version : u64 ) {
214246 cinfo ! ( SYNC , "New peer detected #{}" , id) ;
215- let chain_info = self . client . chain_info ( ) ;
216- self . api . send (
217- id,
218- Arc :: new (
219- Message :: Status {
220- total_score : chain_info. best_proposal_score ,
221- best_hash : chain_info. best_proposal_block_hash ,
222- genesis_hash : chain_info. genesis_hash ,
223- }
224- . rlp_bytes ( ) ,
225- ) ,
226- ) ;
247+ self . send_status ( id) ;
248+
227249 let t = self . connected_nodes . insert ( * id) ;
228250 debug_assert ! ( t, "{} is already added to peer list" , id) ;
229251
@@ -420,22 +442,7 @@ impl Extension {
420442 self . body_downloader . remove_target ( & imported) ;
421443 self . body_downloader . remove_target ( & invalid) ;
422444
423-
424- let chain_info = self . client . chain_info ( ) ;
425-
426- for id in & self . connected_nodes {
427- self . api . send (
428- id,
429- Arc :: new (
430- Message :: Status {
431- total_score : chain_info. best_proposal_score ,
432- best_hash : chain_info. best_proposal_block_hash ,
433- genesis_hash : chain_info. genesis_hash ,
434- }
435- . rlp_bytes ( ) ,
436- ) ,
437- ) ;
438- }
445+ self . send_status_broadcast ( ) ;
439446 }
440447}
441448
0 commit comments