diff --git a/substrate/client/network/src/protocol.rs b/substrate/client/network/src/protocol.rs index b3c08320f9..0450818e7a 100644 --- a/substrate/client/network/src/protocol.rs +++ b/substrate/client/network/src/protocol.rs @@ -533,9 +533,9 @@ impl Protocol { self.sync.status().queued_blocks } - /// Number of processed blocks. - pub fn num_processed_blocks(&self) -> usize { - self.sync.num_processed_blocks() + /// Number of downloaded blocks. + pub fn num_downloaded_blocks(&self) -> usize { + self.sync.num_downloaded_blocks() } /// Number of active sync requests. diff --git a/substrate/client/network/src/protocol/sync.rs b/substrate/client/network/src/protocol/sync.rs index e08fcf4e9b..781d410fff 100644 --- a/substrate/client/network/src/protocol/sync.rs +++ b/substrate/client/network/src/protocol/sync.rs @@ -189,8 +189,8 @@ pub struct ChainSync { block_announce_validator: Box + Send>, /// Maximum number of peers to ask the same blocks in parallel. max_parallel_downloads: u32, - /// Total number of processed blocks (imported or failed). - processed_blocks: usize, + /// Total number of downloaded blocks. + downloaded_blocks: usize, } /// All the data we have about a Peer that we are trying to sync with @@ -375,7 +375,7 @@ impl ChainSync { pending_requests: Default::default(), block_announce_validator, max_parallel_downloads, - processed_blocks: 0, + downloaded_blocks: 0, } } @@ -415,9 +415,9 @@ impl ChainSync { self.fork_targets.len() } - /// Number of processed blocks. - pub fn num_processed_blocks(&self) -> usize { - self.processed_blocks + /// Number of downloaded blocks. + pub fn num_downloaded_blocks(&self) -> usize { + self.downloaded_blocks } /// Handle a new connected peer. @@ -719,6 +719,7 @@ impl ChainSync { request: Option>, response: BlockResponse ) -> Result, BadPeer> { + self.downloaded_blocks += response.blocks.len(); let mut new_blocks: Vec> = if let Some(peer) = self.peers.get_mut(who) { let mut blocks = response.blocks; @@ -1004,8 +1005,6 @@ impl ChainSync { for (_, hash) in &results { self.queue_blocks.remove(&hash); } - self.processed_blocks += results.len(); - for (result, hash) in results { if has_error { continue; @@ -1274,7 +1273,6 @@ impl ChainSync { /// Restart the sync process. fn restart<'a>(&'a mut self) -> impl Iterator), BadPeer>> + 'a { - self.processed_blocks = 0; self.blocks.clear(); let info = self.client.info(); self.best_queued_hash = info.best_hash; diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index c4b6d97909..8263d78c35 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -390,9 +390,9 @@ impl NetworkWorker { self.network_service.user_protocol().num_queued_blocks() } - /// Returns the number of processed blocks. - pub fn num_processed_blocks(&self) -> usize { - self.network_service.user_protocol().num_processed_blocks() + /// Returns the number of downloaded blocks. + pub fn num_downloaded_blocks(&self) -> usize { + self.network_service.user_protocol().num_downloaded_blocks() } /// Number of active sync requests. diff --git a/substrate/client/network/test/src/lib.rs b/substrate/client/network/test/src/lib.rs index 3ce28c261f..a3e644558b 100644 --- a/substrate/client/network/test/src/lib.rs +++ b/substrate/client/network/test/src/lib.rs @@ -221,9 +221,9 @@ impl Peer { self.network.num_connected_peers() } - /// Returns the number of processed blocks. - pub fn num_processed_blocks(&self) -> usize { - self.network.num_processed_blocks() + /// Returns the number of downloaded blocks. + pub fn num_downloaded_blocks(&self) -> usize { + self.network.num_downloaded_blocks() } /// Returns true if we have no peer. diff --git a/substrate/client/network/test/src/sync.rs b/substrate/client/network/test/src/sync.rs index 13d04a8c4e..0269eb3562 100644 --- a/substrate/client/network/test/src/sync.rs +++ b/substrate/client/network/test/src/sync.rs @@ -673,12 +673,12 @@ fn imports_stale_once() { // check that NEW block is imported from announce message let new_hash = net.peer(0).push_blocks(1, false); import_with_announce(&mut net, new_hash); - assert_eq!(net.peer(1).num_processed_blocks(), 1); + assert_eq!(net.peer(1).num_downloaded_blocks(), 1); // check that KNOWN STALE block is imported from announce message let known_stale_hash = net.peer(0).push_blocks_at(BlockId::Number(0), 1, true); import_with_announce(&mut net, known_stale_hash); - assert_eq!(net.peer(1).num_processed_blocks(), 2); + assert_eq!(net.peer(1).num_downloaded_blocks(), 2); } #[test]