mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 17:31:05 +00:00
Split polkadot-service (#310)
* Substrate service * Splitting polkadot service * Specialised components * Specialised components * Docs and style * Docs and style * Final touches * Added db key assertion
This commit is contained in:
committed by
Gav Wood
parent
ee31955969
commit
b8216372c7
@@ -39,10 +39,10 @@ pub enum ChainSpec {
|
||||
impl ChainSpec {
|
||||
pub(crate) fn load(self) -> Result<service::ChainSpec, String> {
|
||||
Ok(match self {
|
||||
ChainSpec::PoC1Testnet => service::ChainSpec::poc_1_testnet_config()?,
|
||||
ChainSpec::Development => service::ChainSpec::development_config(),
|
||||
ChainSpec::LocalTestnet => service::ChainSpec::local_testnet_config(),
|
||||
ChainSpec::StagingTestnet => service::ChainSpec::staging_testnet_config(),
|
||||
ChainSpec::PoC1Testnet => service::chain_spec::poc_1_testnet_config()?,
|
||||
ChainSpec::Development => service::chain_spec::development_config(),
|
||||
ChainSpec::LocalTestnet => service::chain_spec::local_testnet_config(),
|
||||
ChainSpec::StagingTestnet => service::chain_spec::staging_testnet_config(),
|
||||
ChainSpec::Custom(f) => service::ChainSpec::from_json_file(PathBuf::from(f))?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ use service::{Service, Components};
|
||||
use tokio::runtime::TaskExecutor;
|
||||
use tokio::timer::Interval;
|
||||
use network::{SyncState, SyncProvider};
|
||||
use polkadot_primitives::Block;
|
||||
use state_machine;
|
||||
use client::{self, BlockchainEvents};
|
||||
use client::BlockchainEvents;
|
||||
use runtime_primitives::traits::{Header, As};
|
||||
use substrate_extrinsic_pool::api::ExtrinsicPool;
|
||||
|
||||
const TIMER_INTERVAL_MS: u64 = 5000;
|
||||
|
||||
@@ -32,13 +32,12 @@ const TIMER_INTERVAL_MS: u64 = 5000;
|
||||
pub fn start<C>(service: &Service<C>, exit: ::exit_future::Exit, handle: TaskExecutor)
|
||||
where
|
||||
C: Components,
|
||||
client::error::Error: From<<<<C as Components>::Backend as client::backend::Backend<Block>>::State as state_machine::Backend>::Error>,
|
||||
{
|
||||
let interval = Interval::new(Instant::now(), Duration::from_millis(TIMER_INTERVAL_MS));
|
||||
|
||||
let network = service.network();
|
||||
let client = service.client();
|
||||
let txpool = service.transaction_pool();
|
||||
let txpool = service.extrinsic_pool();
|
||||
|
||||
let display_notifications = interval.map_err(|e| debug!("Timer error: {:?}", e)).for_each(move |_| {
|
||||
let sync_status = network.status();
|
||||
@@ -52,8 +51,9 @@ pub fn start<C>(service: &Service<C>, exit: ::exit_future::Exit, handle: TaskExe
|
||||
(SyncState::Downloading, Some(n)) => format!("Syncing, target=#{}", n),
|
||||
};
|
||||
let txpool_status = txpool.light_status();
|
||||
info!(target: "polkadot", "{} ({} peers), best: #{} ({})", status, sync_status.num_peers, best_block.number, hash);
|
||||
telemetry!("system.interval"; "status" => status, "peers" => num_peers, "height" => best_block.number, "best" => ?hash, "txcount" => txpool_status.transaction_count);
|
||||
let best_number: u64 = best_block.number().as_();
|
||||
info!(target: "polkadot", "{} ({} peers), best: #{} ({})", status, sync_status.num_peers, best_number, hash);
|
||||
telemetry!("system.interval"; "status" => status, "peers" => num_peers, "height" => best_number, "best" => ?hash, "txcount" => txpool_status.transaction_count);
|
||||
} else {
|
||||
warn!("Error getting best block information");
|
||||
}
|
||||
@@ -66,7 +66,7 @@ pub fn start<C>(service: &Service<C>, exit: ::exit_future::Exit, handle: TaskExe
|
||||
Ok(())
|
||||
});
|
||||
|
||||
let txpool = service.transaction_pool();
|
||||
let txpool = service.extrinsic_pool();
|
||||
let display_txpool_import = txpool.import_notification_stream().for_each(move |_| {
|
||||
let status = txpool.light_status();
|
||||
telemetry!("txpool.import"; "mem_usage" => status.mem_usage, "count" => status.transaction_count, "sender" => status.senders);
|
||||
|
||||
@@ -41,6 +41,8 @@ extern crate substrate_rpc;
|
||||
extern crate substrate_rpc_servers as rpc;
|
||||
extern crate substrate_runtime_primitives as runtime_primitives;
|
||||
extern crate substrate_state_machine as state_machine;
|
||||
extern crate substrate_extrinsic_pool;
|
||||
extern crate substrate_service;
|
||||
extern crate polkadot_primitives;
|
||||
extern crate polkadot_runtime;
|
||||
extern crate polkadot_service as service;
|
||||
@@ -76,7 +78,7 @@ use std::fs::File;
|
||||
use std::net::SocketAddr;
|
||||
use std::path::{Path, PathBuf};
|
||||
use substrate_telemetry::{init_telemetry, TelemetryConfig};
|
||||
use polkadot_primitives::{Block, BlockId};
|
||||
use polkadot_primitives::BlockId;
|
||||
use codec::Slicable;
|
||||
use client::BlockOrigin;
|
||||
use runtime_primitives::generic::SignedBlock;
|
||||
@@ -141,8 +143,7 @@ pub trait Worker {
|
||||
fn exit_only(self) -> Self::Exit;
|
||||
|
||||
/// Do work and schedule exit.
|
||||
fn work<C: ServiceComponents>(self, service: &Service<C>) -> Self::Work
|
||||
where ClientError: From<<<<C as ServiceComponents>::Backend as ClientBackend<PolkadotBlock>>::State as StateMachineBackend>::Error>;
|
||||
fn work<C: ServiceComponents>(self, service: &Service<C>) -> Self::Work;
|
||||
}
|
||||
|
||||
/// Parse command line arguments and start the node.
|
||||
@@ -441,7 +442,6 @@ fn run_until_exit<C, W>(
|
||||
where
|
||||
C: service::Components,
|
||||
W: Worker,
|
||||
client::error::Error: From<<<<C as service::Components>::Backend as client::backend::Backend<Block>>::State as state_machine::Backend>::Error>,
|
||||
{
|
||||
let (exit_send, exit) = exit_future::signal();
|
||||
|
||||
@@ -453,10 +453,11 @@ fn run_until_exit<C, W>(
|
||||
let ws_address = parse_address("127.0.0.1:9944", "ws-port", matches)?;
|
||||
|
||||
let handler = || {
|
||||
let chain = rpc::apis::chain::Chain::new(service.client(), executor.clone());
|
||||
let author = rpc::apis::author::Author::new(service.client(), service.transaction_pool());
|
||||
rpc::rpc_handler::<Block, _, _, _, _>(
|
||||
service.client(),
|
||||
let client = (&service as &substrate_service::Service<C>).client();
|
||||
let chain = rpc::apis::chain::Chain::new(client.clone(), executor.clone());
|
||||
let author = rpc::apis::author::Author::new(client.clone(), service.extrinsic_pool());
|
||||
rpc::rpc_handler::<service::ComponentBlock<C>, _, _, _, _>(
|
||||
client,
|
||||
chain,
|
||||
author,
|
||||
sys_conf.clone(),
|
||||
|
||||
Reference in New Issue
Block a user