Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
rpc: fix detection of major importing state
Browse files Browse the repository at this point in the history
  • Loading branch information
andresilva committed Sep 18, 2018
1 parent 6d06c7a commit f128ce8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
4 changes: 2 additions & 2 deletions parity/informant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_or_waiting;
use parity_rpc::is_major_importing;
use parity_rpc::informant::RpcStats;
use ethereum_types::H256;
use bytes::Bytes;
Expand Down Expand Up @@ -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_or_waiting(state, self.client.queue_info(), false)
is_major_importing(state, self.client.queue_info())
}

fn report(&self) -> Report {
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub use http::{
};

pub use v1::{NetworkSettings, Metadata, Origin, informant, dispatch, signer};
pub use v1::block_import::{is_major_importing, is_major_importing_or_waiting};
pub use v1::block_import::is_major_importing;
pub use v1::extractors::{RpcExtractor, WsExtractor, WsStats, WsDispatcher};
pub use authcodes::{AuthCodes, TimeProvider};
pub use http_common::HttpMetaExtractor;
Expand Down
11 changes: 2 additions & 9 deletions rpc/src/v1/helpers/block_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,16 @@
use ethcore::client::BlockQueueInfo;
use sync::SyncState;

/// 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<SyncState>, queue_info: BlockQueueInfo, waiting_is_syncing_state: bool) -> bool {
/// Check if client is during major sync or during block import.
pub fn is_major_importing(sync_state: Option<SyncState>, queue_info: BlockQueueInfo) -> bool {
let is_syncing_state = sync_state.map_or(false, |s| match s {
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<SyncState>, queue_info: BlockQueueInfo) -> bool {
is_major_importing_or_waiting(sync_state, queue_info, true)
}

#[cfg(test)]
mod tests {
use ethcore::client::BlockQueueInfo;
Expand Down

0 comments on commit f128ce8

Please sign in to comment.