@@ -27,7 +27,7 @@ use crate::{
2727use bytes:: Bytes ;
2828use ethereum_types:: H256 ;
2929use fastmap:: H256FastSet ;
30- use network:: { PeerId , client_version:: ClientCapabilities } ;
30+ use network:: { client_version:: ClientCapabilities , Error , PeerId } ;
3131use rand:: RngCore ;
3232use rlp:: RlpStream ;
3333
@@ -77,10 +77,12 @@ impl ChainSync {
7777 self . statistics
7878 . log_propagated_block ( io, * peer_id, blocks. len ( ) , rlp. len ( ) ) ;
7979
80- ChainSync :: send_packet ( io, * peer_id, NewBlockPacket , rlp. clone ( ) ) ;
80+ let send_result = ChainSync :: send_packet ( io, * peer_id, NewBlockPacket , rlp. clone ( ) ) ;
8181
82- if let Some ( ref mut peer) = self . peers . get_mut ( peer_id) {
83- peer. latest_hash = chain_info. best_block_hash . clone ( ) ;
82+ if send_result. is_ok ( ) {
83+ if let Some ( ref mut peer) = self . peers . get_mut ( peer_id) {
84+ peer. latest_hash = chain_info. best_block_hash . clone ( ) ;
85+ }
8486 }
8587 }
8688 } ;
@@ -122,7 +124,7 @@ impl ChainSync {
122124 if let Some ( ref mut peer) = self . peers . get_mut ( peer_id) {
123125 peer. latest_hash = best_block_hash;
124126 }
125- ChainSync :: send_packet ( io, * peer_id, NewBlockHashesPacket , rlp. clone ( ) ) ;
127+ let _ = ChainSync :: send_packet ( io, * peer_id, NewBlockHashesPacket , rlp. clone ( ) ) ;
126128 }
127129 sent
128130 }
@@ -200,13 +202,8 @@ impl ChainSync {
200202 rlp : Bytes | {
201203 let size = rlp. len ( ) ;
202204
203- if is_hashes {
204- stats. log_propagated_hashes ( sent, size) ;
205- } else {
206- stats. log_propagated_transactions ( sent, size) ;
207- }
208205
209- ChainSync :: send_packet (
206+ let send_result = ChainSync :: send_packet (
210207 io,
211208 peer_id,
212209 if is_hashes {
@@ -216,7 +213,18 @@ impl ChainSync {
216213 } ,
217214 rlp,
218215 ) ;
219- trace ! ( target: "sync" , "{:02} <- {} ({} entries; {} bytes)" , peer_id, if is_hashes { "NewPooledTransactionHashes" } else { "Transactions" } , sent, size) ;
216+
217+
218+
219+ if send_result. is_ok ( ) {
220+ if is_hashes {
221+ stats. log_propagated_hashes ( sent, size) ;
222+ } else {
223+ stats. log_propagated_transactions ( sent, size) ;
224+ }
225+ trace ! ( target: "sync" , "{:02} <- {} ({} entries; {} bytes)" , peer_id, if is_hashes { "NewPooledTransactionHashes" } else { "Transactions" } , sent, size) ;
226+ }
227+
220228 } ;
221229
222230 let mut sent_to_peers = HashSet :: new ( ) ;
@@ -385,7 +393,7 @@ impl ChainSync {
385393 // more about: https://github.com/DMDcoin/diamond-node/issues/61
386394 let rlp = ChainSync :: create_block_rlp ( block, io. chain ( ) . chain_info ( ) . total_difficulty ) ;
387395 for peer_id in & peers {
388- ChainSync :: send_packet ( io, * peer_id, NewBlockPacket , rlp. clone ( ) ) ;
396+ let _ = ChainSync :: send_packet ( io, * peer_id, NewBlockPacket , rlp. clone ( ) ) ;
389397 }
390398 }
391399 }
@@ -398,7 +406,11 @@ impl ChainSync {
398406 self . statistics
399407 . log_consensus_broadcast ( lucky_peers. len ( ) , packet. len ( ) ) ;
400408 for peer_id in lucky_peers {
401- ChainSync :: send_packet ( io, peer_id, ConsensusDataPacket , packet. clone ( ) ) ;
409+ let send_result = ChainSync :: send_packet ( io, peer_id, ConsensusDataPacket , packet. clone ( ) ) ;
410+
411+ if let Err ( e) = send_result {
412+ info ! ( target: "sync" , "Error broadcast consensus packet to peer {}: {:?}" , peer_id, e) ;
413+ }
402414 }
403415 }
404416
@@ -407,9 +419,18 @@ impl ChainSync {
407419 io : & mut dyn SyncIo ,
408420 packet : Bytes ,
409421 peer_id : usize ,
410- ) {
411- self . statistics . log_consensus ( peer_id, packet. len ( ) ) ;
412- ChainSync :: send_packet ( io, peer_id, ConsensusDataPacket , packet) ;
422+ ) -> Result < ( ) , Error > {
423+ let packet_len = packet. len ( ) ;
424+ let send_result = ChainSync :: send_packet ( io, peer_id, ConsensusDataPacket , packet. clone ( ) ) ;
425+ match & send_result {
426+ Ok ( _) => {
427+ self . statistics . log_consensus ( peer_id, packet_len) ;
428+ } ,
429+ Err ( e) => {
430+ warn ! ( target: "sync" , "Error sending consensus packet to peer {}: {:?}" , peer_id, e) ;
431+ } ,
432+ }
433+ return send_result;
413434 }
414435
415436 fn select_peers_for_transactions < F > ( & self , filter : F , are_new : bool ) -> Vec < PeerId >
@@ -444,11 +465,14 @@ impl ChainSync {
444465 peer_id : PeerId ,
445466 packet_id : SyncPacket ,
446467 packet : Bytes ,
447- ) {
448- if let Err ( e) = sync. send ( peer_id, packet_id, packet) {
468+ ) -> Result < ( ) , Error > {
469+ let result = sync. send ( peer_id, packet_id, packet) ;
470+ if let Err ( e) = & result {
449471 debug ! ( target: "sync" , "Error sending packet: {:?}" , e) ;
450472 sync. disconnect_peer ( peer_id) ;
451473 }
474+
475+ return result;
452476 }
453477
454478 /// propagates new transactions to all peers
0 commit comments