From f44e4b3d4851a0cd68c339a2a2436dcfaaff9a8a Mon Sep 17 00:00:00 2001
From: Liu-Cheng Xu <xuliuchengxlc@gmail.com>
Date: Thu, 28 Jul 2022 23:31:47 +0800
Subject: [PATCH] Enrich the sync log on handling the block request (#11747)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Add more info to the log to help debug the issue like
https://github.com/paritytech/substrate/issues/11732.

Co-authored-by: Bastian Köcher <info@kchr.de>
---
 .../network/sync/src/block_request_handler.rs | 28 +++++++++++++------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/substrate/client/network/sync/src/block_request_handler.rs b/substrate/client/network/sync/src/block_request_handler.rs
index 2a847a8bf36..30cbb32289d 100644
--- a/substrate/client/network/sync/src/block_request_handler.rs
+++ b/substrate/client/network/sync/src/block_request_handler.rs
@@ -226,16 +226,13 @@ where
 
 		debug!(
 			target: LOG_TARGET,
-			"Handling block request from {}: Starting at `{:?}` with maximum blocks \
-			 of `{}`, direction `{:?}` and attributes `{:?}`.",
-			peer,
-			from_block_id,
-			max_blocks,
-			direction,
-			attributes,
+			"Handling block request from {peer}: Starting at `{from_block_id:?}` with \
+			maximum blocks of `{max_blocks}`, reputation_change: `{reputation_change:?}`, \
+			small_request `{small_request:?}`, direction `{direction:?}` and \
+			attributes `{attributes:?}`.",
 		);
 
-		let result = if reputation_change.is_none() || small_request {
+		let maybe_block_response = if reputation_change.is_none() || small_request {
 			let block_response = self.get_block_response(
 				attributes,
 				from_block_id,
@@ -259,9 +256,22 @@ where
 				}
 			}
 
+			Some(block_response)
+		} else {
+			None
+		};
+
+		debug!(
+			target: LOG_TARGET,
+			"Sending result of block request from {peer} starting at `{from_block_id:?}`: \
+			blocks: {:?}, data: {:?}",
+			maybe_block_response.as_ref().map(|res| res.blocks.len()),
+			maybe_block_response.as_ref().map(|res| res.encoded_len()),
+		);
+
+		let result = if let Some(block_response) = maybe_block_response {
 			let mut data = Vec::with_capacity(block_response.encoded_len());
 			block_response.encode(&mut data)?;
-
 			Ok(data)
 		} else {
 			Err(())
-- 
GitLab