Skip to content

Commit

Permalink
Merge branch 'i73-is-major-syncing' into dev_0_9_4
Browse files Browse the repository at this point in the history
  • Loading branch information
SurfingNerd committed Nov 6, 2023
2 parents ffab76b + 5b1ce14 commit 920e0cd
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
12 changes: 12 additions & 0 deletions bin/oe/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ use node_filter::NodeFilter;
use parity_rpc::{informant, is_major_importing, NetworkSettings};
use parity_runtime::Runtime;
use parity_version::version;
use sync::SyncState;

// How often we attempt to take a snapshot: only snapshot on blocknumbers that are multiples of this.
const SNAPSHOT_PERIOD: u64 = 20000;
Expand Down Expand Up @@ -160,6 +161,17 @@ impl ChainSyncing for SyncProviderWrapper {
None => true,
}
}

/// are we syncing in any means ?
fn is_syncing(&self) -> bool {
match self.sync_provider.upgrade() {
Some(sync_arc) => {
return sync_arc.status().state != SyncState::Idle;
}
// We also indicate the "syncing" state when the SyncProvider has already been destroyed.
None => true,
}
}
}

/// Executes the given run command.
Expand Down
21 changes: 18 additions & 3 deletions crates/ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2886,6 +2886,16 @@ impl BlockChainClient for Client {
}
}

fn is_syncing(&self) -> bool {
// so far we know, this lock cannot result into a deadlock.
match &*self.sync_provider.lock() {
Some(sync_provider) => sync_provider.is_syncing(),
// We also indicate the "syncing" state when the SyncProvider has not been set,
// which usually only happens when the client is not fully configured yet.
None => true,
}
}

fn next_nonce(&self, address: &Address) -> U256 {
self.importer.miner.next_nonce(self, address)
}
Expand Down Expand Up @@ -3652,9 +3662,14 @@ impl PrometheusMetrics for Client {
chain.best_block_number as i64,
);

let is_syncing_val: i64 = self.is_major_syncing() as i64;
// 0 or 1 if we are syncing.
r.register_gauge("is_major_syncing", "syncing, boolean", is_syncing_val);
// 0 or 1 if we are major syncing.
r.register_gauge(
"is_major_syncing",
"syncing, boolean",
self.is_major_syncing() as i64,
);

r.register_gauge("is_syncing", "syncing, boolean", self.is_syncing() as i64);

// prunning info
let prunning = self.pruning_info();
Expand Down
4 changes: 4 additions & 0 deletions crates/ethcore/src/client/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,10 @@ impl BlockChainClient for TestBlockChainClient {
false
}

fn is_syncing(&self) -> bool {
false
}

fn next_nonce(&self, address: &Address) -> U256 {
self.miner.next_nonce(self, address)
}
Expand Down
8 changes: 7 additions & 1 deletion crates/ethcore/src/client/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ pub trait EngineInfo {

/// Provides information about the chain sync state.
pub trait ChainSyncing: Send + Sync {
/// are we syncing?
fn is_syncing(&self) -> bool;

/// are we in the middle of a major sync?
fn is_major_syncing(&self) -> bool;
}
Expand Down Expand Up @@ -524,9 +527,12 @@ pub trait BlockChainClient:
/// Used by engines to queue transactions without causing deadlocks due to re-entrant calls.
fn transact_silently(&self, tx_request: TransactionRequest) -> Result<(), transaction::Error>;

/// Returns true if the chain is currently syncing.
/// Returns true if the chain is currently syncing in major states.
fn is_major_syncing(&self) -> bool;

// Returns true if the chain is currently syncing.
fn is_syncing(&self) -> bool;

/// Returns the next nonce for the given address, taking the transaction queue into account.
fn next_nonce(&self, address: &Address) -> U256;

Expand Down
2 changes: 1 addition & 1 deletion crates/ethcore/src/engines/hbbft/hbbft_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ impl HoneyBadgerBFT {

fn is_syncing(&self, client: &Arc<dyn EngineClient>) -> bool {
match client.as_full_client() {
Some(full_client) => full_client.is_major_syncing(),
Some(full_client) => full_client.is_syncing(),
// We only support full clients at this point.
None => true,
}
Expand Down

0 comments on commit 920e0cd

Please sign in to comment.