Unverified Commit c8649e59 authored by Cecile Tonglet's avatar Cecile Tonglet Committed by GitHub
Browse files

Polkadot companion for #8143 (#2535)

Companion for https://github.com/paritytech/substrate/pull/8143
parent c0474d2c
Pipeline #127856 passed with stages
in 35 minutes and 19 seconds
This diff is collapsed.
......@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use browser_utils::{browser_configuration, init_logging_and_telemetry, set_console_error_panic_hook, Client};
use browser_utils::{browser_configuration, init_logging, set_console_error_panic_hook, Client};
use log::info;
use wasm_bindgen::prelude::*;
......@@ -26,12 +26,11 @@ pub async fn start_client(chain_spec: String, log_level: String) -> Result<Clien
async fn start_inner(chain_spec: String, log_directives: String) -> Result<Client, Box<dyn std::error::Error>> {
set_console_error_panic_hook();
let telemetry_worker = init_logging_and_telemetry(&log_directives)?;
init_logging(&log_directives)?;
let chain_spec =
service::PolkadotChainSpec::from_json_bytes(chain_spec.as_bytes().to_vec()).map_err(|e| format!("{:?}", e))?;
let telemetry_handle = telemetry_worker.handle();
let config = browser_configuration(chain_spec, Some(telemetry_handle)).await?;
let config = browser_configuration(chain_spec).await?;
info!("Polkadot browser node");
info!(" version {}", config.impl_version);
......@@ -41,9 +40,7 @@ async fn start_inner(chain_spec: String, log_directives: String) -> Result<Clien
info!("👤 Role: {}", config.display_role());
// Create the service. This is the most heavy initialization step.
let (task_manager, rpc_handlers, _) = service::build_light(config).map_err(|e| format!("{:?}", e))?;
task_manager.spawn_handle().spawn("telemetry", telemetry_worker.run());
let (task_manager, rpc_handlers) = service::build_light(config).map_err(|e| format!("{:?}", e))?;
Ok(browser_utils::start_client(task_manager, rpc_handlers))
}
......@@ -170,12 +170,13 @@ pub fn run() -> Result<()> {
let role = config.role.clone();
let task_manager = match role {
Role::Light => service::build_light(config).map(|(task_manager, _, _)| task_manager),
Role::Light => service::build_light(config).map(|(task_manager, _)| task_manager),
_ => service::build_full(
config,
service::IsCollator::No,
grandpa_pause,
jaeger_agent,
None,
).map(|full| full.task_manager)
}?;
Ok::<_, Error>(task_manager)
......
......@@ -14,6 +14,7 @@ polkadot-primitives = { path = "../../../primitives" }
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-block-builder = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-telemetry = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" }
......
......@@ -29,6 +29,7 @@ use polkadot_primitives::v1::{
Block, Hash, Header,
};
use sc_block_builder::{BlockBuilderApi, BlockBuilderProvider};
use sc_telemetry::TelemetryHandle;
use sp_core::traits::SpawnNamed;
use sp_api::{ApiExt, ProvideRuntimeApi};
use sp_blockchain::HeaderBackend;
......@@ -55,6 +56,7 @@ impl<TxPool, Backend, Client> ProposerFactory<TxPool, Backend, Client> {
transaction_pool: Arc<TxPool>,
overseer: OverseerHandler,
prometheus: Option<&PrometheusRegistry>,
telemetry: Option<TelemetryHandle>,
) -> Self {
ProposerFactory {
inner: sc_basic_authorship::ProposerFactory::new(
......@@ -62,6 +64,7 @@ impl<TxPool, Backend, Client> ProposerFactory<TxPool, Backend, Client> {
client,
transaction_pool,
prometheus,
telemetry,
),
overseer,
}
......
......@@ -54,7 +54,7 @@ use std::sync::Arc;
use prometheus_endpoint::Registry;
use sc_executor::native_executor_instance;
use service::RpcHandlers;
use telemetry::{TelemetryConnectionNotifier, TelemetrySpan};
use telemetry::{Telemetry, TelemetryWorker, TelemetryWorkerHandle};
pub use self::client::{AbstractClient, Client, ClientHandle, ExecuteWithClient, RuntimeApiCollection};
pub use chain_spec::{PolkadotChainSpec, KusamaChainSpec, WestendChainSpec, RococoChainSpec};
......@@ -129,6 +129,9 @@ pub enum Error {
#[error(transparent)]
Prometheus(#[from] prometheus_endpoint::PrometheusError),
#[error(transparent)]
Telemetry(#[from] telemetry::Error),
#[error(transparent)]
Jaeger(#[from] polkadot_subsystem::jaeger::JaegerError),
......@@ -206,7 +209,11 @@ type LightClient<RuntimeApi, Executor> =
service::TLightClientWithBackend<Block, RuntimeApi, Executor, LightBackend>;
#[cfg(feature = "full-node")]
fn new_partial<RuntimeApi, Executor>(config: &mut Configuration, jaeger_agent: Option<std::net::SocketAddr>) -> Result<
fn new_partial<RuntimeApi, Executor>(
config: &mut Configuration,
jaeger_agent: Option<std::net::SocketAddr>,
telemetry_worker_handle: Option<TelemetryWorkerHandle>,
) -> Result<
service::PartialComponents<
FullClient<RuntimeApi, Executor>, FullBackend, FullSelectChain,
consensus_common::DefaultImportQueue<Block, FullClient<RuntimeApi, Executor>>,
......@@ -225,6 +232,7 @@ fn new_partial<RuntimeApi, Executor>(config: &mut Configuration, jaeger_agent: O
),
grandpa::SharedVoterState,
u64, // slot-duration
Option<Telemetry>,
)
>,
Error
......@@ -240,10 +248,36 @@ fn new_partial<RuntimeApi, Executor>(config: &mut Configuration, jaeger_agent: O
let inherent_data_providers = inherents::InherentDataProviders::new();
let telemetry = config.telemetry_endpoints.clone()
.filter(|x| !x.is_empty())
.map(move |endpoints| -> Result<_, telemetry::Error> {
let (worker, mut worker_handle) = if let Some(worker_handle) = telemetry_worker_handle {
(None, worker_handle)
} else {
let worker = TelemetryWorker::new(16)?;
let worker_handle = worker.handle();
(Some(worker), worker_handle)
};
let telemetry = worker_handle.new_telemetry(endpoints);
Ok((worker, telemetry))
})
.transpose()?;
let (client, backend, keystore_container, task_manager) =
service::new_full_parts::<Block, RuntimeApi, Executor>(&config)?;
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)| {
if let Some(worker) = worker {
task_manager.spawn_handle().spawn("telemetry", worker.run());
}
telemetry
});
jaeger_launch_collector_with_agent(task_manager.spawn_handle(), &*config, jaeger_agent)?;
let select_chain = sc_consensus::LongestChain::new(backend.clone());
......@@ -268,6 +302,7 @@ fn new_partial<RuntimeApi, Executor>(config: &mut Configuration, jaeger_agent: O
&(client.clone() as Arc<_>),
select_chain.clone(),
grandpa_hard_forks,
telemetry.as_ref().map(|x| x.handle()),
)?;
let justification_import = grandpa_block_import.clone();
......@@ -289,6 +324,7 @@ fn new_partial<RuntimeApi, Executor>(config: &mut Configuration, jaeger_agent: O
&task_manager.spawn_essential_handle(),
config.prometheus_registry(),
consensus_common::CanAuthorWithNativeVersion::new(client.executor().clone()),
telemetry.as_ref().map(|x| x.handle()),
)?;
let justification_stream = grandpa_link.justification_stream();
......@@ -346,7 +382,7 @@ fn new_partial<RuntimeApi, Executor>(config: &mut Configuration, jaeger_agent: O
import_queue,
transaction_pool,
inherent_data_providers,
other: (rpc_extensions_builder, import_setup, rpc_setup, slot_duration)
other: (rpc_extensions_builder, import_setup, rpc_setup, slot_duration, telemetry)
})
}
......@@ -566,6 +602,7 @@ pub fn new_full<RuntimeApi, Executor>(
grandpa_pause: Option<(u32, u32)>,
jaeger_agent: Option<std::net::SocketAddr>,
isolation_strategy: IsolationStrategy,
telemetry_worker_handle: Option<TelemetryWorkerHandle>,
) -> Result<NewFull<Arc<FullClient<RuntimeApi, Executor>>>, Error>
where
RuntimeApi: ConstructRuntimeApi<Block, FullClient<RuntimeApi, Executor>> + Send + Sync + 'static,
......@@ -576,9 +613,6 @@ pub fn new_full<RuntimeApi, Executor>(
#[cfg(feature = "real-overseer")]
info!("real-overseer feature is ENABLED");
let telemetry_span = TelemetrySpan::new();
let _telemetry_span_entered = telemetry_span.enter();
let role = config.role.clone();
let force_authoring = config.force_authoring;
let backoff_authoring_blocks =
......@@ -600,8 +634,8 @@ pub fn new_full<RuntimeApi, Executor>(
import_queue,
transaction_pool,
inherent_data_providers,
other: (rpc_extensions_builder, import_setup, rpc_setup, slot_duration)
} = new_partial::<RuntimeApi, Executor>(&mut config, jaeger_agent)?;
other: (rpc_extensions_builder, import_setup, rpc_setup, slot_duration, mut telemetry)
} = new_partial::<RuntimeApi, Executor>(&mut config, jaeger_agent, telemetry_worker_handle)?;
let prometheus_registry = config.prometheus_registry().cloned();
......@@ -705,7 +739,7 @@ pub fn new_full<RuntimeApi, Executor>(
cache_size: None, // default is fine.
};
let (rpc_handlers, telemetry_connection_notifier) = service::spawn_tasks(service::SpawnTasksParams {
let rpc_handlers = service::spawn_tasks(service::SpawnTasksParams {
config,
backend: backend.clone(),
client: client.clone(),
......@@ -718,7 +752,7 @@ pub fn new_full<RuntimeApi, Executor>(
remote_blockchain: None,
network_status_sinks: network_status_sinks.clone(),
system_rpc_tx,
telemetry_span: Some(telemetry_span.clone()),
telemetry: telemetry.as_mut(),
})?;
let (block_import, link_half, babe_link) = import_setup;
......@@ -830,6 +864,7 @@ pub fn new_full<RuntimeApi, Executor>(
transaction_pool,
overseer_handler.as_ref().ok_or(Error::AuthoritiesRequireRealOverseer)?.clone(),
prometheus_registry.as_ref(),
telemetry.as_ref().map(|x| x.handle()),
);
let babe_config = babe::BabeParams {
......@@ -845,6 +880,7 @@ pub fn new_full<RuntimeApi, Executor>(
babe_link,
can_author_with,
block_proposal_slot_portion: babe::SlotProportion::new(2f32 / 3f32),
telemetry: telemetry.as_ref().map(|x| x.handle()),
};
let babe = babe::start_babe(babe_config)?;
......@@ -867,6 +903,7 @@ pub fn new_full<RuntimeApi, Executor>(
observer_enabled: false,
keystore: keystore_opt,
is_authority: role.is_authority(),
telemetry: telemetry.as_ref().map(|x| x.handle()),
};
let enable_grandpa = !disable_grandpa;
......@@ -914,10 +951,10 @@ pub fn new_full<RuntimeApi, Executor>(
config,
link: link_half,
network: network.clone(),
telemetry_on_connect: telemetry_connection_notifier.map(|x| x.on_connect_stream()),
voting_rule,
prometheus_registry: prometheus_registry.clone(),
shared_voter_state,
telemetry: telemetry.as_ref().map(|x| x.handle()),
};
task_manager.spawn_essential_handle().spawn_blocking(
......@@ -943,7 +980,6 @@ pub fn new_full<RuntimeApi, Executor>(
fn new_light<Runtime, Dispatch>(mut config: Configuration) -> Result<(
TaskManager,
RpcHandlers,
Option<TelemetryConnectionNotifier>,
), Error>
where
Runtime: 'static + Send + Sync + ConstructRuntimeApi<Block, LightClient<Runtime, Dispatch>>,
......@@ -954,8 +990,26 @@ fn new_light<Runtime, Dispatch>(mut config: Configuration) -> Result<(
set_prometheus_registry(&mut config)?;
use sc_client_api::backend::RemoteBackend;
let telemetry = config.telemetry_endpoints.clone()
.filter(|x| !x.is_empty())
.map(|endpoints| -> Result<_, telemetry::Error> {
let worker = TelemetryWorker::new(16)?;
let telemetry = worker.handle().new_telemetry(endpoints);
Ok((worker, telemetry))
})
.transpose()?;
let (client, backend, keystore_container, mut task_manager, on_demand) =
service::new_light_parts::<Block, Runtime, Dispatch>(&config)?;
service::new_light_parts::<Block, Runtime, Dispatch>(
&config,
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
)?;
let mut telemetry = telemetry
.map(|(worker, telemetry)| {
task_manager.spawn_handle().spawn("telemetry", worker.run());
telemetry
});
let select_chain = sc_consensus::LongestChain::new(backend.clone());
......@@ -971,6 +1025,7 @@ fn new_light<Runtime, Dispatch>(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();
......@@ -993,6 +1048,7 @@ fn new_light<Runtime, Dispatch>(mut config: Configuration) -> Result<(
&task_manager.spawn_essential_handle(),
config.prometheus_registry(),
consensus_common::NeverCanAuthor,
telemetry.as_ref().map(|x| x.handle()),
)?;
let (network, network_status_sinks, system_rpc_tx, network_starter) =
......@@ -1024,10 +1080,7 @@ fn new_light<Runtime, Dispatch>(mut config: Configuration) -> Result<(
let rpc_extensions = polkadot_rpc::create_light(light_deps);
let telemetry_span = TelemetrySpan::new();
let _telemetry_span_entered = telemetry_span.enter();
let (rpc_handlers, telemetry_connection_notifier) = service::spawn_tasks(service::SpawnTasksParams {
let rpc_handlers = service::spawn_tasks(service::SpawnTasksParams {
on_demand: Some(on_demand),
remote_blockchain: Some(backend.remote_blockchain()),
rpc_extensions_builder: Box::new(service::NoopRpcExtensionBuilder(rpc_extensions)),
......@@ -1040,17 +1093,20 @@ fn new_light<Runtime, Dispatch>(mut config: Configuration) -> Result<(
network,
network_status_sinks,
system_rpc_tx,
telemetry_span: Some(telemetry_span.clone()),
telemetry: telemetry.as_mut(),
})?;
network_starter.start_network();
Ok((task_manager, rpc_handlers, telemetry_connection_notifier))
Ok((task_manager, rpc_handlers))
}
/// Builds a new object suitable for chain operations.
#[cfg(feature = "full-node")]
pub fn new_chain_ops(mut config: &mut Configuration, jaeger_agent: Option<std::net::SocketAddr>) -> Result<
pub fn new_chain_ops(
mut config: &mut Configuration,
jaeger_agent: Option<std::net::SocketAddr>,
) -> Result<
(
Arc<Client>,
Arc<FullBackend>,
......@@ -1063,19 +1119,19 @@ pub fn new_chain_ops(mut config: &mut Configuration, jaeger_agent: Option<std::n
config.keystore = service::config::KeystoreConfig::InMemory;
if config.chain_spec.is_rococo() {
let service::PartialComponents { client, backend, import_queue, task_manager, .. }
= new_partial::<rococo_runtime::RuntimeApi, RococoExecutor>(config, jaeger_agent)?;
= new_partial::<rococo_runtime::RuntimeApi, RococoExecutor>(config, jaeger_agent, None)?;
Ok((Arc::new(Client::Rococo(client)), backend, import_queue, task_manager))
} else if config.chain_spec.is_kusama() {
let service::PartialComponents { client, backend, import_queue, task_manager, .. }
= new_partial::<kusama_runtime::RuntimeApi, KusamaExecutor>(config, jaeger_agent)?;
= new_partial::<kusama_runtime::RuntimeApi, KusamaExecutor>(config, jaeger_agent, None)?;
Ok((Arc::new(Client::Kusama(client)), backend, import_queue, task_manager))
} else if config.chain_spec.is_westend() {
let service::PartialComponents { client, backend, import_queue, task_manager, .. }
= new_partial::<westend_runtime::RuntimeApi, WestendExecutor>(config, jaeger_agent)?;
= new_partial::<westend_runtime::RuntimeApi, WestendExecutor>(config, jaeger_agent, None)?;
Ok((Arc::new(Client::Westend(client)), backend, import_queue, task_manager))
} else {
let service::PartialComponents { client, backend, import_queue, task_manager, .. }
= new_partial::<polkadot_runtime::RuntimeApi, PolkadotExecutor>(config, jaeger_agent)?;
= new_partial::<polkadot_runtime::RuntimeApi, PolkadotExecutor>(config, jaeger_agent, None)?;
Ok((Arc::new(Client::Polkadot(client)), backend, import_queue, task_manager))
}
}
......@@ -1084,7 +1140,6 @@ pub fn new_chain_ops(mut config: &mut Configuration, jaeger_agent: Option<std::n
pub fn build_light(config: Configuration) -> Result<(
TaskManager,
RpcHandlers,
Option<TelemetryConnectionNotifier>,
), Error> {
if config.chain_spec.is_rococo() {
new_light::<rococo_runtime::RuntimeApi, RococoExecutor>(config)
......@@ -1103,6 +1158,7 @@ pub fn build_full(
is_collator: IsCollator,
grandpa_pause: Option<(u32, u32)>,
jaeger_agent: Option<std::net::SocketAddr>,
telemetry_worker_handle: Option<TelemetryWorkerHandle>,
) -> Result<NewFull<Client>, Error> {
let isolation_strategy = {
#[cfg(not(any(target_os = "android", target_os = "unknown")))]
......@@ -1124,6 +1180,7 @@ pub fn build_full(
grandpa_pause,
jaeger_agent,
isolation_strategy,
telemetry_worker_handle,
).map(|full| full.with_client(Client::Rococo))
} else if config.chain_spec.is_kusama() {
new_full::<kusama_runtime::RuntimeApi, KusamaExecutor>(
......@@ -1132,6 +1189,7 @@ pub fn build_full(
grandpa_pause,
jaeger_agent,
isolation_strategy,
telemetry_worker_handle,
).map(|full| full.with_client(Client::Kusama))
} else if config.chain_spec.is_westend() {
new_full::<westend_runtime::RuntimeApi, WestendExecutor>(
......@@ -1140,6 +1198,7 @@ pub fn build_full(
grandpa_pause,
jaeger_agent,
isolation_strategy,
telemetry_worker_handle,
).map(|full| full.with_client(Client::Westend))
} else {
new_full::<polkadot_runtime::RuntimeApi, PolkadotExecutor>(
......@@ -1148,6 +1207,7 @@ pub fn build_full(
grandpa_pause,
jaeger_agent,
isolation_strategy,
telemetry_worker_handle,
).map(|full| full.with_client(Client::Polkadot))
}
}
......@@ -83,6 +83,7 @@ pub fn new_full(
None,
None,
polkadot_parachain::wasm_executor::IsolationStrategy::InProcess,
None,
)
}
......@@ -198,7 +199,6 @@ pub fn node_config(
base_path: Some(base_path),
informant_output_format: Default::default(),
disable_log_reloading: false,
telemetry_handle: None,
}
}
......
......@@ -63,6 +63,7 @@ fn main() -> Result<()> {
polkadot_service::IsCollator::Yes(collator.collator_id()),
None,
None,
None,
).map_err(|e| e.to_string())?;
let mut overseer_handler = full_node
.overseer_handler
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment