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::Cache as LightDataCache;
|
||||||
use light::client::{LightChainClient, LightChainNotify};
|
use light::client::{LightChainClient, LightChainNotify};
|
||||||
use number_prefix::{binary_prefix, Standalone, Prefixed};
|
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 parity_rpc::informant::RpcStats;
|
||||||
use ethereum_types::H256;
|
use ethereum_types::H256;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
@ -128,7 +128,7 @@ impl InformantData for FullNodeInformantData {
|
|||||||
|
|
||||||
fn is_major_importing(&self) -> bool {
|
fn is_major_importing(&self) -> bool {
|
||||||
let state = self.sync.as_ref().map(|sync| sync.status().state);
|
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 {
|
fn report(&self) -> Report {
|
||||||
@ -142,7 +142,8 @@ impl InformantData for FullNodeInformantData {
|
|||||||
cache_sizes.insert("queue", queue_info.mem_used);
|
cache_sizes.insert("queue", queue_info.mem_used);
|
||||||
cache_sizes.insert("chain", blockchain_cache_info.total());
|
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)) => {
|
(Some(sync), Some(net)) => {
|
||||||
let status = sync.status();
|
let status = sync.status();
|
||||||
let num_peers_range = net.num_peers_range();
|
let num_peers_range = net.num_peers_range();
|
||||||
@ -150,16 +151,15 @@ impl InformantData for FullNodeInformantData {
|
|||||||
|
|
||||||
cache_sizes.insert("sync", status.mem_used);
|
cache_sizes.insert("sync", status.mem_used);
|
||||||
|
|
||||||
let importing = is_major_importing(Some(status.state), queue_info.clone());
|
Some(SyncInfo {
|
||||||
(importing, Some(SyncInfo {
|
|
||||||
last_imported_block_number: status.last_imported_block_number.unwrap_or(chain_info.best_block_number),
|
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,
|
last_imported_old_block_number: status.last_imported_old_block_number,
|
||||||
num_peers: status.num_peers,
|
num_peers: status.num_peers,
|
||||||
max_peers: status.current_max_peers(num_peers_range.start, num_peers_range.end - 1),
|
max_peers: status.current_max_peers(num_peers_range.start, num_peers_range.end - 1),
|
||||||
snapshot_sync: status.is_snapshot_syncing(),
|
snapshot_sync: status.is_snapshot_syncing(),
|
||||||
}))
|
})
|
||||||
}
|
}
|
||||||
_ => (is_major_importing(self.sync.as_ref().map(|s| s.status().state), queue_info.clone()), None),
|
_ => None
|
||||||
};
|
};
|
||||||
|
|
||||||
Report {
|
Report {
|
||||||
|
@ -118,7 +118,7 @@ pub use http::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub use v1::{NetworkSettings, Metadata, Origin, informant, dispatch, signer};
|
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 v1::extractors::{RpcExtractor, WsExtractor, WsStats, WsDispatcher};
|
||||||
pub use authcodes::{AuthCodes, TimeProvider};
|
pub use authcodes::{AuthCodes, TimeProvider};
|
||||||
pub use http_common::HttpMetaExtractor;
|
pub use http_common::HttpMetaExtractor;
|
||||||
|
@ -19,16 +19,23 @@
|
|||||||
use ethcore::client::BlockQueueInfo;
|
use ethcore::client::BlockQueueInfo;
|
||||||
use sync::SyncState;
|
use sync::SyncState;
|
||||||
|
|
||||||
/// Check if client is during major sync or during block import.
|
/// Check if client is during major sync or during block import and allows defining whether 'waiting for peers' should
|
||||||
pub fn is_major_importing(sync_state: Option<SyncState>, queue_info: BlockQueueInfo) -> bool {
|
/// 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 {
|
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,
|
_ => true,
|
||||||
});
|
});
|
||||||
let is_verifying = queue_info.unverified_queue_size + queue_info.verified_queue_size > 3;
|
let is_verifying = queue_info.unverified_queue_size + queue_info.verified_queue_size > 3;
|
||||||
is_verifying || is_syncing_state
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use ethcore::client::BlockQueueInfo;
|
use ethcore::client::BlockQueueInfo;
|
||||||
|
Loading…
Reference in New Issue
Block a user