mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 22:11:06 +00:00
Expose system health via RPC and REST (#1269)
* Implement health endpoint. * Expose health API.
This commit is contained in:
@@ -19,17 +19,17 @@
|
||||
use std::{sync::Arc, net::SocketAddr, marker::PhantomData, ops::Deref, ops::DerefMut};
|
||||
use serde::{Serialize, de::DeserializeOwned};
|
||||
use tokio::runtime::TaskExecutor;
|
||||
use chain_spec::{ChainSpec, Properties};
|
||||
use chain_spec::ChainSpec;
|
||||
use client_db;
|
||||
use client::{self, Client, runtime_api::{Metadata, TaggedTransactionQueue}};
|
||||
use {error, Service, RpcConfig, maybe_start_server};
|
||||
use {error, Service, maybe_start_server};
|
||||
use network::{self, OnDemand, import_queue::ImportQueue};
|
||||
use substrate_executor::{NativeExecutor, NativeExecutionDispatch};
|
||||
use transaction_pool::txpool::{self, Options as TransactionPoolOptions, Pool as TransactionPool};
|
||||
use runtime_primitives::{BuildStorage, traits::{Block as BlockT, Header as HeaderT, ProvideRuntimeApi}, generic::{BlockId, SignedBlock}};
|
||||
use config::Configuration;
|
||||
use primitives::{Blake2Hasher, H256};
|
||||
use rpc;
|
||||
use rpc::{self, apis::system::SystemInfo};
|
||||
use parking_lot::Mutex;
|
||||
|
||||
// Type aliases.
|
||||
@@ -123,12 +123,11 @@ pub trait StartRPC<C: Components> {
|
||||
|
||||
fn start_rpc(
|
||||
client: Arc<ComponentClient<C>>,
|
||||
chain_name: String,
|
||||
impl_name: &'static str,
|
||||
impl_version: &'static str,
|
||||
network: Arc<network::SyncProvider<ComponentBlock<C>>>,
|
||||
should_have_peers: bool,
|
||||
system_info: SystemInfo,
|
||||
rpc_http: Option<SocketAddr>,
|
||||
rpc_ws: Option<SocketAddr>,
|
||||
properties: Properties,
|
||||
task_executor: TaskExecutor,
|
||||
transaction_pool: Arc<TransactionPool<C::TransactionPoolApi>>,
|
||||
) -> error::Result<Self::ServersHandle>;
|
||||
@@ -142,17 +141,14 @@ impl<C: Components> StartRPC<Self> for C where
|
||||
|
||||
fn start_rpc(
|
||||
client: Arc<ComponentClient<C>>,
|
||||
chain_name: String,
|
||||
impl_name: &'static str,
|
||||
impl_version: &'static str,
|
||||
network: Arc<network::SyncProvider<ComponentBlock<C>>>,
|
||||
should_have_peers: bool,
|
||||
rpc_system_info: SystemInfo,
|
||||
rpc_http: Option<SocketAddr>,
|
||||
rpc_ws: Option<SocketAddr>,
|
||||
properties: Properties,
|
||||
task_executor: TaskExecutor,
|
||||
transaction_pool: Arc<TransactionPool<C::TransactionPoolApi>>,
|
||||
) -> error::Result<Self::ServersHandle> {
|
||||
let rpc_config = RpcConfig { properties, chain_name, impl_name, impl_version };
|
||||
|
||||
let handler = || {
|
||||
let client = client.clone();
|
||||
let subscriptions = rpc::apis::Subscriptions::new(task_executor.clone());
|
||||
@@ -161,11 +157,14 @@ impl<C: Components> StartRPC<Self> for C where
|
||||
let author = rpc::apis::author::Author::new(
|
||||
client.clone(), transaction_pool.clone(), subscriptions
|
||||
);
|
||||
let system = rpc::apis::system::System::new(
|
||||
rpc_system_info.clone(), network.clone(), should_have_peers
|
||||
);
|
||||
rpc::rpc_handler::<ComponentBlock<C>, ComponentExHash<C>, _, _, _, _>(
|
||||
state,
|
||||
chain,
|
||||
author,
|
||||
rpc_config.clone(),
|
||||
system,
|
||||
)
|
||||
};
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ extern crate substrate_client as client;
|
||||
extern crate substrate_client_db as client_db;
|
||||
extern crate parity_codec as codec;
|
||||
extern crate substrate_transaction_pool as transaction_pool;
|
||||
extern crate substrate_rpc;
|
||||
extern crate substrate_rpc_servers as rpc;
|
||||
extern crate target_info;
|
||||
extern crate tokio;
|
||||
@@ -189,6 +188,7 @@ impl<Components: components::Components> Service<Components> {
|
||||
protocol_id
|
||||
};
|
||||
|
||||
let has_bootnodes = !network_params.network_config.boot_nodes.is_empty();
|
||||
let network = network::Service::new(
|
||||
network_params,
|
||||
protocol_id,
|
||||
@@ -240,10 +240,14 @@ impl<Components: components::Components> Service<Components> {
|
||||
|
||||
|
||||
// RPC
|
||||
let system_info = rpc::apis::system::SystemInfo {
|
||||
chain_name: config.chain_spec.name().into(),
|
||||
impl_name: config.impl_name.into(),
|
||||
impl_version: config.impl_version.into(),
|
||||
properties: config.chain_spec.properties(),
|
||||
};
|
||||
let rpc = Components::RPC::start_rpc(
|
||||
client.clone(), config.chain_spec.name().to_string(), config.impl_name,
|
||||
config.impl_version, config.rpc_http, config.rpc_ws, config.chain_spec.properties(),
|
||||
task_executor.clone(), transaction_pool.clone()
|
||||
client.clone(), network.clone(), has_bootnodes, system_info, config.rpc_http, config.rpc_ws, task_executor.clone(), transaction_pool.clone(),
|
||||
)?;
|
||||
|
||||
// Telemetry
|
||||
@@ -358,32 +362,6 @@ fn maybe_start_server<T, F>(address: Option<SocketAddr>, start: F) -> Result<Opt
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct RpcConfig {
|
||||
chain_name: String,
|
||||
properties: Properties,
|
||||
impl_name: &'static str,
|
||||
impl_version: &'static str,
|
||||
}
|
||||
|
||||
impl substrate_rpc::system::SystemApi for RpcConfig {
|
||||
fn system_name(&self) -> substrate_rpc::system::error::Result<String> {
|
||||
Ok(self.impl_name.into())
|
||||
}
|
||||
|
||||
fn system_version(&self) -> substrate_rpc::system::error::Result<String> {
|
||||
Ok(self.impl_version.into())
|
||||
}
|
||||
|
||||
fn system_chain(&self) -> substrate_rpc::system::error::Result<String> {
|
||||
Ok(self.chain_name.clone())
|
||||
}
|
||||
|
||||
fn system_properties(&self) -> substrate_rpc::system::error::Result<Properties> {
|
||||
Ok(self.properties.clone())
|
||||
}
|
||||
}
|
||||
|
||||
/// Transaction pool adapter.
|
||||
pub struct TransactionPoolAdapter<C: Components> {
|
||||
imports_external_transactions: bool,
|
||||
|
||||
Reference in New Issue
Block a user