|
|
|
@@ -33,7 +33,7 @@ use sp_runtime::traits::Block as BlockT;
|
|
|
|
|
use futures::prelude::*;
|
|
|
|
|
use sc_client_api::{ExecutorProvider, RemoteBackend};
|
|
|
|
|
use node_executor::Executor;
|
|
|
|
|
use sc_telemetry::{TelemetryConnectionNotifier, TelemetrySpan};
|
|
|
|
|
use sc_telemetry::{Telemetry, TelemetryWorker};
|
|
|
|
|
use sc_consensus_babe::SlotProportion;
|
|
|
|
|
|
|
|
|
|
type FullClient = sc_service::TFullClient<Block, RuntimeApi, Executor>;
|
|
|
|
@@ -43,7 +43,9 @@ type FullGrandpaBlockImport =
|
|
|
|
|
grandpa::GrandpaBlockImport<FullBackend, Block, FullClient, FullSelectChain>;
|
|
|
|
|
type LightClient = sc_service::TLightClient<Block, RuntimeApi, Executor>;
|
|
|
|
|
|
|
|
|
|
pub fn new_partial(config: &Configuration) -> Result<sc_service::PartialComponents<
|
|
|
|
|
pub fn new_partial(
|
|
|
|
|
config: &Configuration,
|
|
|
|
|
) -> Result<sc_service::PartialComponents<
|
|
|
|
|
FullClient, FullBackend, FullSelectChain,
|
|
|
|
|
sp_consensus::DefaultImportQueue<Block, FullClient>,
|
|
|
|
|
sc_transaction_pool::FullPool<Block, FullClient>,
|
|
|
|
@@ -58,12 +60,31 @@ pub fn new_partial(config: &Configuration) -> Result<sc_service::PartialComponen
|
|
|
|
|
sc_consensus_babe::BabeLink<Block>,
|
|
|
|
|
),
|
|
|
|
|
grandpa::SharedVoterState,
|
|
|
|
|
Option<Telemetry>,
|
|
|
|
|
)
|
|
|
|
|
>, ServiceError> {
|
|
|
|
|
let telemetry = config.telemetry_endpoints.clone()
|
|
|
|
|
.filter(|x| !x.is_empty())
|
|
|
|
|
.map(|endpoints| -> Result<_, sc_telemetry::Error> {
|
|
|
|
|
let worker = TelemetryWorker::new(16)?;
|
|
|
|
|
let telemetry = worker.handle().new_telemetry(endpoints);
|
|
|
|
|
Ok((worker, telemetry))
|
|
|
|
|
})
|
|
|
|
|
.transpose()?;
|
|
|
|
|
|
|
|
|
|
let (client, backend, keystore_container, task_manager) =
|
|
|
|
|
sc_service::new_full_parts::<Block, RuntimeApi, Executor>(&config)?;
|
|
|
|
|
sc_service::new_full_parts::<Block, RuntimeApi, Executor>(
|
|
|
|
|
&config,
|
|
|
|
|
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
|
|
|
|
|
)?;
|
|
|
|
|
let client = Arc::new(client);
|
|
|
|
|
|
|
|
|
|
let telemetry = telemetry
|
|
|
|
|
.map(|(worker, telemetry)| {
|
|
|
|
|
task_manager.spawn_handle().spawn("telemetry", worker.run());
|
|
|
|
|
telemetry
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let select_chain = sc_consensus::LongestChain::new(backend.clone());
|
|
|
|
|
|
|
|
|
|
let transaction_pool = sc_transaction_pool::BasicPool::new_full(
|
|
|
|
@@ -75,7 +96,10 @@ pub fn new_partial(config: &Configuration) -> Result<sc_service::PartialComponen
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let (grandpa_block_import, grandpa_link) = grandpa::block_import(
|
|
|
|
|
client.clone(), &(client.clone() as Arc<_>), select_chain.clone(),
|
|
|
|
|
client.clone(),
|
|
|
|
|
&(client.clone() as Arc<_>),
|
|
|
|
|
select_chain.clone(),
|
|
|
|
|
telemetry.as_ref().map(|x| x.handle()),
|
|
|
|
|
)?;
|
|
|
|
|
let justification_import = grandpa_block_import.clone();
|
|
|
|
|
|
|
|
|
@@ -97,6 +121,7 @@ pub fn new_partial(config: &Configuration) -> Result<sc_service::PartialComponen
|
|
|
|
|
&task_manager.spawn_essential_handle(),
|
|
|
|
|
config.prometheus_registry(),
|
|
|
|
|
sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()),
|
|
|
|
|
telemetry.as_ref().map(|x| x.handle()),
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
|
let import_setup = (block_import, grandpa_link, babe_link);
|
|
|
|
@@ -159,7 +184,7 @@ pub fn new_partial(config: &Configuration) -> Result<sc_service::PartialComponen
|
|
|
|
|
import_queue,
|
|
|
|
|
transaction_pool,
|
|
|
|
|
inherent_data_providers,
|
|
|
|
|
other: (rpc_extensions_builder, import_setup, rpc_setup),
|
|
|
|
|
other: (rpc_extensions_builder, import_setup, rpc_setup, telemetry),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -189,7 +214,7 @@ pub fn new_full_base(
|
|
|
|
|
select_chain,
|
|
|
|
|
transaction_pool,
|
|
|
|
|
inherent_data_providers,
|
|
|
|
|
other: (rpc_extensions_builder, import_setup, rpc_setup),
|
|
|
|
|
other: (rpc_extensions_builder, import_setup, rpc_setup, mut telemetry),
|
|
|
|
|
} = new_partial(&config)?;
|
|
|
|
|
|
|
|
|
|
let shared_voter_state = rpc_setup;
|
|
|
|
@@ -231,10 +256,7 @@ pub fn new_full_base(
|
|
|
|
|
let enable_grandpa = !config.disable_grandpa;
|
|
|
|
|
let prometheus_registry = config.prometheus_registry().cloned();
|
|
|
|
|
|
|
|
|
|
let telemetry_span = TelemetrySpan::new();
|
|
|
|
|
let _telemetry_span_entered = telemetry_span.enter();
|
|
|
|
|
|
|
|
|
|
let (_rpc_handlers, telemetry_connection_notifier) = sc_service::spawn_tasks(
|
|
|
|
|
let _rpc_handlers = sc_service::spawn_tasks(
|
|
|
|
|
sc_service::SpawnTasksParams {
|
|
|
|
|
config,
|
|
|
|
|
backend: backend.clone(),
|
|
|
|
@@ -248,7 +270,7 @@ pub fn new_full_base(
|
|
|
|
|
remote_blockchain: None,
|
|
|
|
|
network_status_sinks: network_status_sinks.clone(),
|
|
|
|
|
system_rpc_tx,
|
|
|
|
|
telemetry_span: Some(telemetry_span.clone()),
|
|
|
|
|
telemetry: telemetry.as_mut(),
|
|
|
|
|
},
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
@@ -262,6 +284,7 @@ pub fn new_full_base(
|
|
|
|
|
client.clone(),
|
|
|
|
|
transaction_pool.clone(),
|
|
|
|
|
prometheus_registry.as_ref(),
|
|
|
|
|
telemetry.as_ref().map(|x| x.handle()),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let can_author_with =
|
|
|
|
@@ -280,6 +303,7 @@ pub fn new_full_base(
|
|
|
|
|
babe_link,
|
|
|
|
|
can_author_with,
|
|
|
|
|
block_proposal_slot_portion: SlotProportion::new(0.5),
|
|
|
|
|
telemetry: telemetry.as_ref().map(|x| x.handle()),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let babe = sc_consensus_babe::start_babe(babe_config)?;
|
|
|
|
@@ -323,6 +347,7 @@ pub fn new_full_base(
|
|
|
|
|
observer_enabled: false,
|
|
|
|
|
keystore,
|
|
|
|
|
is_authority: role.is_authority(),
|
|
|
|
|
telemetry: telemetry.as_ref().map(|x| x.handle()),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if enable_grandpa {
|
|
|
|
@@ -336,7 +361,7 @@ pub fn new_full_base(
|
|
|
|
|
config,
|
|
|
|
|
link: grandpa_link,
|
|
|
|
|
network: network.clone(),
|
|
|
|
|
telemetry_on_connect: telemetry_connection_notifier.map(|x| x.on_connect_stream()),
|
|
|
|
|
telemetry: telemetry.as_ref().map(|x| x.handle()),
|
|
|
|
|
voting_rule: grandpa::VotingRulesBuilder::default().build(),
|
|
|
|
|
prometheus_registry,
|
|
|
|
|
shared_voter_state,
|
|
|
|
@@ -362,20 +387,50 @@ pub fn new_full_base(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Builds a new service for a full client.
|
|
|
|
|
pub fn new_full(config: Configuration)
|
|
|
|
|
-> Result<TaskManager, ServiceError> {
|
|
|
|
|
pub fn new_full(
|
|
|
|
|
config: Configuration,
|
|
|
|
|
) -> Result<TaskManager, ServiceError> {
|
|
|
|
|
new_full_base(config, |_, _| ()).map(|NewFullBase { task_manager, .. }| {
|
|
|
|
|
task_manager
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn new_light_base(mut config: Configuration) -> Result<(
|
|
|
|
|
TaskManager, RpcHandlers, Option<TelemetryConnectionNotifier>, Arc<LightClient>,
|
|
|
|
|
pub fn new_light_base(
|
|
|
|
|
mut config: Configuration,
|
|
|
|
|
) -> Result<(
|
|
|
|
|
TaskManager,
|
|
|
|
|
RpcHandlers,
|
|
|
|
|
Arc<LightClient>,
|
|
|
|
|
Arc<NetworkService<Block, <Block as BlockT>::Hash>>,
|
|
|
|
|
Arc<sc_transaction_pool::LightPool<Block, LightClient, sc_network::config::OnDemand<Block>>>
|
|
|
|
|
), ServiceError> {
|
|
|
|
|
let telemetry = config.telemetry_endpoints.clone()
|
|
|
|
|
.filter(|x| !x.is_empty())
|
|
|
|
|
.map(|endpoints| -> Result<_, sc_telemetry::Error> {
|
|
|
|
|
#[cfg(feature = "browser")]
|
|
|
|
|
let transport = Some(
|
|
|
|
|
sc_telemetry::ExtTransport::new(libp2p_wasm_ext::ffi::websocket_transport())
|
|
|
|
|
);
|
|
|
|
|
#[cfg(not(feature = "browser"))]
|
|
|
|
|
let transport = None;
|
|
|
|
|
|
|
|
|
|
let worker = TelemetryWorker::with_transport(16, transport)?;
|
|
|
|
|
let telemetry = worker.handle().new_telemetry(endpoints);
|
|
|
|
|
Ok((worker, telemetry))
|
|
|
|
|
})
|
|
|
|
|
.transpose()?;
|
|
|
|
|
|
|
|
|
|
let (client, backend, keystore_container, mut task_manager, on_demand) =
|
|
|
|
|
sc_service::new_light_parts::<Block, RuntimeApi, Executor>(&config)?;
|
|
|
|
|
sc_service::new_light_parts::<Block, RuntimeApi, Executor>(
|
|
|
|
|
&config,
|
|
|
|
|
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
|
let mut telemetry = telemetry
|
|
|
|
|
.map(|(worker, telemetry)| {
|
|
|
|
|
task_manager.spawn_handle().spawn("telemetry", worker.run());
|
|
|
|
|
telemetry
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
config.network.extra_sets.push(grandpa::grandpa_peers_set_config());
|
|
|
|
|
|
|
|
|
@@ -393,6 +448,7 @@ pub fn new_light_base(mut config: Configuration) -> Result<(
|
|
|
|
|
client.clone(),
|
|
|
|
|
&(client.clone() as Arc<_>),
|
|
|
|
|
select_chain.clone(),
|
|
|
|
|
telemetry.as_ref().map(|x| x.handle()),
|
|
|
|
|
)?;
|
|
|
|
|
let justification_import = grandpa_block_import.clone();
|
|
|
|
|
|
|
|
|
@@ -414,6 +470,7 @@ pub fn new_light_base(mut config: Configuration) -> Result<(
|
|
|
|
|
&task_manager.spawn_essential_handle(),
|
|
|
|
|
config.prometheus_registry(),
|
|
|
|
|
sp_consensus::NeverCanAuthor,
|
|
|
|
|
telemetry.as_ref().map(|x| x.handle()),
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
|
let (network, network_status_sinks, system_rpc_tx, network_starter) =
|
|
|
|
@@ -443,10 +500,7 @@ pub fn new_light_base(mut config: Configuration) -> Result<(
|
|
|
|
|
|
|
|
|
|
let rpc_extensions = node_rpc::create_light(light_deps);
|
|
|
|
|
|
|
|
|
|
let telemetry_span = TelemetrySpan::new();
|
|
|
|
|
let _telemetry_span_entered = telemetry_span.enter();
|
|
|
|
|
|
|
|
|
|
let (rpc_handlers, telemetry_connection_notifier) =
|
|
|
|
|
let rpc_handlers =
|
|
|
|
|
sc_service::spawn_tasks(sc_service::SpawnTasksParams {
|
|
|
|
|
on_demand: Some(on_demand),
|
|
|
|
|
remote_blockchain: Some(backend.remote_blockchain()),
|
|
|
|
@@ -457,13 +511,12 @@ pub fn new_light_base(mut config: Configuration) -> Result<(
|
|
|
|
|
config, backend, network_status_sinks, system_rpc_tx,
|
|
|
|
|
network: network.clone(),
|
|
|
|
|
task_manager: &mut task_manager,
|
|
|
|
|
telemetry_span: Some(telemetry_span.clone()),
|
|
|
|
|
telemetry: telemetry.as_mut(),
|
|
|
|
|
})?;
|
|
|
|
|
|
|
|
|
|
Ok((
|
|
|
|
|
task_manager,
|
|
|
|
|
rpc_handlers,
|
|
|
|
|
telemetry_connection_notifier,
|
|
|
|
|
client,
|
|
|
|
|
network,
|
|
|
|
|
transaction_pool,
|
|
|
|
@@ -471,8 +524,10 @@ pub fn new_light_base(mut config: Configuration) -> Result<(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Builds a new service for a light client.
|
|
|
|
|
pub fn new_light(config: Configuration) -> Result<TaskManager, ServiceError> {
|
|
|
|
|
new_light_base(config).map(|(task_manager, _, _, _, _, _)| {
|
|
|
|
|
pub fn new_light(
|
|
|
|
|
config: Configuration,
|
|
|
|
|
) -> Result<TaskManager, ServiceError> {
|
|
|
|
|
new_light_base(config).map(|(task_manager, _, _, _, _)| {
|
|
|
|
|
task_manager
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
@@ -553,7 +608,7 @@ mod tests {
|
|
|
|
|
Ok((node, (inherent_data_providers, setup_handles.unwrap())))
|
|
|
|
|
},
|
|
|
|
|
|config| {
|
|
|
|
|
let (keep_alive, _, _, client, network, transaction_pool) = new_light_base(config)?;
|
|
|
|
|
let (keep_alive, _, client, network, transaction_pool) = new_light_base(config)?;
|
|
|
|
|
Ok(sc_service_test::TestNetComponents::new(keep_alive, client, network, transaction_pool))
|
|
|
|
|
},
|
|
|
|
|
|service, &mut (ref inherent_data_providers, (ref mut block_import, ref babe_link))| {
|
|
|
|
@@ -580,6 +635,7 @@ mod tests {
|
|
|
|
|
service.client(),
|
|
|
|
|
service.transaction_pool(),
|
|
|
|
|
None,
|
|
|
|
|
None,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let epoch_descriptor = babe_link.epoch_changes().lock().epoch_descriptor_for_child_of(
|
|
|
|
@@ -708,7 +764,7 @@ mod tests {
|
|
|
|
|
Ok(sc_service_test::TestNetComponents::new(task_manager, client, network, transaction_pool))
|
|
|
|
|
},
|
|
|
|
|
|config| {
|
|
|
|
|
let (keep_alive, _, _, client, network, transaction_pool) = new_light_base(config)?;
|
|
|
|
|
let (keep_alive, _, client, network, transaction_pool) = new_light_base(config)?;
|
|
|
|
|
Ok(sc_service_test::TestNetComponents::new(keep_alive, client, network, transaction_pool))
|
|
|
|
|
},
|
|
|
|
|
vec![
|
|
|
|
|