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
This commit is contained in:
parent
8dd4db5d85
commit
e6acbc5a58
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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<SyncState>, 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<SyncState>, 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<SyncState>, queue_info: BlockQueueInfo) -> bool {
|
||||
is_major_importing_or_waiting(sync_state, queue_info, true)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ethcore::client::BlockQueueInfo;
|
||||
|
Loading…
Reference in New Issue
Block a user