RPC: Implements eth_subscribe("syncing") (#10311)
* implement eth_subscibe syncing * fix imports * add is_major_syncing to SyncProvider * add eth_subscribe(syncing) support for light clients * tests * fix TestSyncClient * correct LightFetch impl * added currentBlock, startingBlock, highestBlock to PubSubSyncStatus * fixed tests * fix PR grumbles * improve code style * is_syncing -> syncing * code style * use ethereum types
This commit is contained in:
committed by
Talha Cross
parent
288d73789a
commit
fba63de974
@@ -24,7 +24,7 @@ use std::time::{Instant, Duration};
|
||||
|
||||
use atty;
|
||||
use ethcore::client::{
|
||||
BlockId, BlockChainClient, ChainInfo, BlockInfo, BlockChainInfo,
|
||||
BlockId, ChainInfo, BlockInfo, BlockChainInfo, BlockChainClient,
|
||||
BlockQueueInfo, ChainNotify, NewBlocks, ClientReport, Client, ClientIoMessage
|
||||
};
|
||||
use types::BlockNumber;
|
||||
|
||||
@@ -20,6 +20,7 @@ use ethcore::client::BlockChainClient;
|
||||
use sync::{self, AttachedProtocol, SyncConfig, NetworkConfiguration, Params, ConnectionFilter};
|
||||
use ethcore::snapshot::SnapshotService;
|
||||
use light::Provider;
|
||||
use parity_runtime::Executor;
|
||||
|
||||
pub use sync::{EthSync, SyncProvider, ManageNetwork, PrivateTxHandler};
|
||||
pub use ethcore::client::ChainNotify;
|
||||
@@ -34,6 +35,7 @@ pub type SyncModules = (
|
||||
|
||||
pub fn sync(
|
||||
config: SyncConfig,
|
||||
executor: Executor,
|
||||
network_config: NetworkConfiguration,
|
||||
chain: Arc<BlockChainClient>,
|
||||
snapshot_service: Arc<SnapshotService>,
|
||||
@@ -45,6 +47,7 @@ pub fn sync(
|
||||
) -> Result<SyncModules, sync::Error> {
|
||||
let eth_sync = EthSync::new(Params {
|
||||
config,
|
||||
executor,
|
||||
chain,
|
||||
provider,
|
||||
snapshot_service,
|
||||
|
||||
@@ -25,6 +25,8 @@ use account_utils::{self, AccountProvider};
|
||||
use ethcore::client::Client;
|
||||
use ethcore::miner::Miner;
|
||||
use ethcore::snapshot::SnapshotService;
|
||||
use ethcore::client::BlockChainClient;
|
||||
use sync::SyncState;
|
||||
use ethcore_logger::RotatingLogger;
|
||||
use ethcore_private_tx::Provider as PrivateTransactionManager;
|
||||
use ethcore_service::PrivateTxService;
|
||||
@@ -320,8 +322,22 @@ impl FullDependencies {
|
||||
}
|
||||
Api::EthPubSub => {
|
||||
if !for_generic_pubsub {
|
||||
let client =
|
||||
let mut client =
|
||||
EthPubSubClient::new(self.client.clone(), self.executor.clone());
|
||||
let weak_client = Arc::downgrade(&self.client);
|
||||
|
||||
client.add_sync_notifier(self.sync.sync_notification(), move |state| {
|
||||
let client = weak_client.upgrade()?;
|
||||
let queue_info = client.queue_info();
|
||||
|
||||
let is_syncing_state = match state { SyncState::Idle | SyncState::NewBlocks => false, _ => true };
|
||||
let is_verifying = queue_info.unverified_queue_size + queue_info.verified_queue_size > 3;
|
||||
|
||||
Some(PubSubSyncStatus {
|
||||
syncing: is_verifying || is_syncing_state,
|
||||
})
|
||||
});
|
||||
|
||||
let h = client.handler();
|
||||
self.miner
|
||||
.add_transactions_listener(Box::new(move |hashes| {
|
||||
@@ -553,7 +569,7 @@ impl<C: LightChainClient + 'static> LightDependencies<C> {
|
||||
}
|
||||
}
|
||||
Api::EthPubSub => {
|
||||
let client = EthPubSubClient::light(
|
||||
let mut client = EthPubSubClient::light(
|
||||
self.client.clone(),
|
||||
self.on_demand.clone(),
|
||||
self.sync.clone(),
|
||||
@@ -561,6 +577,21 @@ impl<C: LightChainClient + 'static> LightDependencies<C> {
|
||||
self.executor.clone(),
|
||||
self.gas_price_percentile,
|
||||
);
|
||||
|
||||
let weak_client = Arc::downgrade(&self.client);
|
||||
|
||||
client.add_sync_notifier(self.sync.sync_notification(), move |state| {
|
||||
let client = weak_client.upgrade()?;
|
||||
let queue_info = client.queue_info();
|
||||
|
||||
let is_syncing_state = match state { SyncState::Idle | SyncState::NewBlocks => false, _ => true };
|
||||
let is_verifying = queue_info.unverified_queue_size + queue_info.verified_queue_size > 3;
|
||||
|
||||
Some(PubSubSyncStatus {
|
||||
syncing: is_verifying || is_syncing_state,
|
||||
})
|
||||
});
|
||||
|
||||
self.client.add_listener(client.handler() as Weak<_>);
|
||||
let h = client.handler();
|
||||
self.transaction_queue
|
||||
|
||||
@@ -41,7 +41,7 @@ use node_filter::NodeFilter;
|
||||
use parity_runtime::Runtime;
|
||||
use sync::{self, SyncConfig, PrivateTxHandler};
|
||||
use parity_rpc::{
|
||||
Origin, Metadata, NetworkSettings, informant, is_major_importing, PubSubSession, FutureResult, FutureResponse, FutureOutput
|
||||
Origin, Metadata, NetworkSettings, informant, PubSubSession, FutureResult, FutureResponse, FutureOutput
|
||||
};
|
||||
use updater::{UpdatePolicy, Updater};
|
||||
use parity_version::version;
|
||||
@@ -661,6 +661,7 @@ fn execute_impl<Cr, Rr>(cmd: RunCmd, logger: Arc<RotatingLogger>, on_client_rq:
|
||||
// create sync object
|
||||
let (sync_provider, manage_network, chain_notify, priority_tasks) = modules::sync(
|
||||
sync_config,
|
||||
runtime.executor(),
|
||||
net_conf.clone().into(),
|
||||
client.clone(),
|
||||
snapshot_service.clone(),
|
||||
@@ -815,10 +816,9 @@ fn execute_impl<Cr, Rr>(cmd: RunCmd, logger: Arc<RotatingLogger>, on_client_rq:
|
||||
true => None,
|
||||
false => {
|
||||
let sync = sync_provider.clone();
|
||||
let client = client.clone();
|
||||
let watcher = Arc::new(snapshot::Watcher::new(
|
||||
service.client(),
|
||||
move || is_major_importing(Some(sync.status().state), client.queue_info()),
|
||||
move || sync.is_major_syncing(),
|
||||
service.io().channel(),
|
||||
SNAPSHOT_PERIOD,
|
||||
SNAPSHOT_HISTORY,
|
||||
|
||||
Reference in New Issue
Block a user