From e6acbc5a5885a5a0bfc3ef91b2f3732e2e8a7d36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Mon, 23 Jul 2018 14:42:08 +0100 Subject: [PATCH] rpc: fix is_major_importing sync state condition (#9112) * rpc: fix is_major_importing sync state condition * rpc: fix informant printout when waiting for peers --- parity/informant.rs | 14 +++++++------- rpc/src/lib.rs | 2 +- rpc/src/v1/helpers/block_import.rs | 13 ++++++++++--- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/parity/informant.rs b/parity/informant.rs index 6f1227592..d3489a52f 100644 --- a/parity/informant.rs +++ b/parity/informant.rs @@ -35,7 +35,7 @@ use io::{TimerToken, IoContext, IoHandler}; use light::Cache as LightDataCache; use light::client::{LightChainClient, LightChainNotify}; use number_prefix::{binary_prefix, Standalone, Prefixed}; -use parity_rpc::{is_major_importing}; +use parity_rpc::is_major_importing_or_waiting; use parity_rpc::informant::RpcStats; use ethereum_types::H256; use bytes::Bytes; @@ -128,7 +128,7 @@ impl InformantData for FullNodeInformantData { fn is_major_importing(&self) -> bool { let state = self.sync.as_ref().map(|sync| sync.status().state); - is_major_importing(state, self.client.queue_info()) + is_major_importing_or_waiting(state, self.client.queue_info(), false) } fn report(&self) -> Report { @@ -142,7 +142,8 @@ impl InformantData for FullNodeInformantData { cache_sizes.insert("queue", queue_info.mem_used); cache_sizes.insert("chain", blockchain_cache_info.total()); - let (importing, sync_info) = match (self.sync.as_ref(), self.net.as_ref()) { + let importing = self.is_major_importing(); + let sync_info = match (self.sync.as_ref(), self.net.as_ref()) { (Some(sync), Some(net)) => { let status = sync.status(); let num_peers_range = net.num_peers_range(); @@ -150,16 +151,15 @@ impl InformantData for FullNodeInformantData { cache_sizes.insert("sync", status.mem_used); - let importing = is_major_importing(Some(status.state), queue_info.clone()); - (importing, Some(SyncInfo { + Some(SyncInfo { last_imported_block_number: status.last_imported_block_number.unwrap_or(chain_info.best_block_number), last_imported_old_block_number: status.last_imported_old_block_number, num_peers: status.num_peers, max_peers: status.current_max_peers(num_peers_range.start, num_peers_range.end - 1), snapshot_sync: status.is_snapshot_syncing(), - })) + }) } - _ => (is_major_importing(self.sync.as_ref().map(|s| s.status().state), queue_info.clone()), None), + _ => None }; Report { diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index e748b840c..96926700c 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -118,7 +118,7 @@ pub use http::{ }; pub use v1::{NetworkSettings, Metadata, Origin, informant, dispatch, signer}; -pub use v1::block_import::is_major_importing; +pub use v1::block_import::{is_major_importing, is_major_importing_or_waiting}; pub use v1::extractors::{RpcExtractor, WsExtractor, WsStats, WsDispatcher}; pub use authcodes::{AuthCodes, TimeProvider}; pub use http_common::HttpMetaExtractor; diff --git a/rpc/src/v1/helpers/block_import.rs b/rpc/src/v1/helpers/block_import.rs index 9e947e5ba..50a4ed8e0 100644 --- a/rpc/src/v1/helpers/block_import.rs +++ b/rpc/src/v1/helpers/block_import.rs @@ -19,16 +19,23 @@ use ethcore::client::BlockQueueInfo; use sync::SyncState; -/// Check if client is during major sync or during block import. -pub fn is_major_importing(sync_state: Option, queue_info: BlockQueueInfo) -> bool { +/// Check if client is during major sync or during block import and allows defining whether 'waiting for peers' should +/// be considered a syncing state. +pub fn is_major_importing_or_waiting(sync_state: Option, queue_info: BlockQueueInfo, waiting_is_syncing_state: bool) -> bool { let is_syncing_state = sync_state.map_or(false, |s| match s { - SyncState::Idle | SyncState::NewBlocks | SyncState::WaitingPeers => false, + SyncState::Idle | SyncState::NewBlocks => false, + SyncState::WaitingPeers if !waiting_is_syncing_state => false, _ => true, }); let is_verifying = queue_info.unverified_queue_size + queue_info.verified_queue_size > 3; is_verifying || is_syncing_state } +/// Check if client is during major sync or during block import. +pub fn is_major_importing(sync_state: Option, queue_info: BlockQueueInfo) -> bool { + is_major_importing_or_waiting(sync_state, queue_info, true) +} + #[cfg(test)] mod tests { use ethcore::client::BlockQueueInfo;