@@ -494,24 +494,18 @@ impl SyncProtocolHandler {
494494 let mut sync_io = NetSyncIo :: new ( nc, & * self . chain , & * self . snapshot_service , & self . overlay ) ;
495495
496496 for node_id in pub_keys. iter ( ) {
497- if let Some ( peer_id) = nc. node_id_to_peer_id ( * node_id) {
497+ if let Some ( peer_id) = nc. node_id_to_peer_id ( node_id) {
498498 let found_peers = self . sync . peer_info ( & [ peer_id] ) ;
499499 if let Some ( peer_info) = found_peers. first ( ) {
500500 if let Some ( _) = peer_info {
501- self . send_cached_consensus_messages_for ( & mut sync_io, node_id, peer_id ) ;
501+ self . send_cached_consensus_messages_for ( & mut sync_io, node_id) ;
502502 }
503503 }
504504 }
505505 }
506506 }
507507
508- fn send_cached_consensus_messages_for (
509- & self ,
510- sync_io : & mut dyn SyncIo ,
511- node_id : & NodeId ,
512- peer_id : PeerId ,
513- ) {
514-
508+ fn send_cached_consensus_messages_for ( & self , sync_io : & mut dyn SyncIo , node_id : & NodeId ) {
515509 // now since we are connected, lets send any cached messages
516510 if let Some ( vec_msg) = self . message_cache . write ( ) . remove ( & Some ( * node_id) ) {
517511 trace ! ( target: "consensus" , "Cached Messages: Trying to send cached messages to {:?}" , node_id) ;
@@ -521,17 +515,18 @@ impl SyncProtocolHandler {
521515 for msg in vec_msg {
522516 match msg {
523517 ChainMessageType :: Consensus ( message) => {
524- let send_consensus_result = self
525- . sync
526- . write ( )
527- . send_consensus_packet ( sync_io, message. clone ( ) , peer_id) ;
518+ let send_consensus_result = self . sync . write ( ) . send_consensus_packet (
519+ sync_io,
520+ message. clone ( ) ,
521+ node_id,
522+ ) ;
528523
529524 match send_consensus_result {
530- Ok ( _) => { } ,
525+ Ok ( _) => { }
531526 Err ( e) => {
532- info ! ( target: "consensus" , "Error sending cached consensus message to peer (re-adding) {:?}: {:?}" , peer_id , e) ;
527+ info ! ( target: "consensus" , "Error sending cached consensus message to peer (re-adding) {:?}: {:?}" , node_id , e) ;
533528 failed_messages. push ( ChainMessageType :: Consensus ( message) ) ;
534- } ,
529+ }
535530 }
536531 }
537532 }
@@ -540,7 +535,9 @@ impl SyncProtocolHandler {
540535 if !failed_messages. is_empty ( ) {
541536 // If we failed to send some messages, cache them for later
542537 let mut lock = self . message_cache . write ( ) ;
543- lock. entry ( Some ( * node_id) ) . or_default ( ) . extend ( failed_messages) ;
538+ lock. entry ( Some ( * node_id) )
539+ . or_default ( )
540+ . extend ( failed_messages) ;
544541 } else {
545542 trace ! ( target: "consensus" , "Cached Messages: Successfully sent all cached messages to {:?}" , node_id) ;
546543 }
@@ -736,41 +733,21 @@ impl ChainNotify for EthSync {
736733 } ) ;
737734 }
738735
739- fn send ( & self , message_type : ChainMessageType , node_id : Option < H512 > ) {
736+ fn send ( & self , message_type : ChainMessageType , node_id : & H512 ) {
740737 self . network . with_context ( PAR_PROTOCOL , |context| {
741- let peer_ids = self . network . connected_peers ( ) ;
742- let target_peer_id = peer_ids. into_iter ( ) . find ( |p| {
743- match context. session_info ( * p) {
744- Some ( session_info) => {
745- session_info. id == node_id
746- } ,
747- None => { warn ! ( target: "sync" , "No session exists for peerId {:?} Node: {:?}" , p, node_id) ; false } ,
748- }
749- } ) ;
750-
751- let my_peer_id = match target_peer_id {
752- None => {
753- trace ! ( target: "consensus" , "Cached Messages: peer {:?} not connected, caching message..." , node_id) ;
754- let mut lock = self . eth_handler . message_cache . write ( ) ;
755- lock. entry ( node_id. clone ( ) ) . or_default ( ) . push ( message_type) ;
756- return ;
757- }
758- Some ( n) => n,
759- } ;
760-
761738 let mut sync_io = NetSyncIo :: new ( context,
762739 & * self . eth_handler . chain ,
763740 & * self . eth_handler . snapshot_service ,
764741 & self . eth_handler . overlay ) ;
765742
766743 match message_type {
767744 ChainMessageType :: Consensus ( message) => {
768- let send_result = self . eth_handler . sync . write ( ) . send_consensus_packet ( & mut sync_io, message. clone ( ) , my_peer_id ) ;
745+ let send_result = self . eth_handler . sync . write ( ) . send_consensus_packet ( & mut sync_io, message. clone ( ) , node_id ) ;
769746 if let Err ( e) = send_result {
770- info ! ( target: "consensus" , "Error sending consensus message to peer - caching message {:?}: {:?}" , my_peer_id , e) ;
747+ info ! ( target: "consensus" , "Error sending consensus message to peer - caching message {:?}: {:?}" , node_id , e) ;
771748 // If we failed to send the message, cache it for later
772749 let mut lock = self . eth_handler . message_cache . write ( ) ;
773- lock. entry ( node_id. clone ( ) ) . or_default ( ) . push ( ChainMessageType :: Consensus ( message) ) ;
750+ lock. entry ( Some ( node_id. clone ( ) ) ) . or_default ( ) . push ( ChainMessageType :: Consensus ( message) ) ;
774751 }
775752 } ,
776753 }
0 commit comments