mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-10 13:09:24 +00:00
Provide a way to create the machine
The BasicQueue returned obscures the TendermintImport struct. Accordingly, a Future scoped with access is returned upwards, which when awaited will create the machine. This makes creating the machine optional while maintaining scope boundaries. Is sufficient to create a 1-node net which produces and finalizes blocks.
This commit is contained in:
@@ -60,23 +60,23 @@ pub fn run() -> sc_cli::Result<()> {
|
||||
|
||||
Some(Subcommand::CheckBlock(cmd)) => cli.create_runner(cmd)?.async_run(|config| {
|
||||
let PartialComponents { client, task_manager, import_queue, .. } =
|
||||
service::new_partial(&config)?;
|
||||
service::new_partial(&config)?.1;
|
||||
Ok((cmd.run(client, import_queue), task_manager))
|
||||
}),
|
||||
|
||||
Some(Subcommand::ExportBlocks(cmd)) => cli.create_runner(cmd)?.async_run(|config| {
|
||||
let PartialComponents { client, task_manager, .. } = service::new_partial(&config)?;
|
||||
let PartialComponents { client, task_manager, .. } = service::new_partial(&config)?.1;
|
||||
Ok((cmd.run(client, config.database), task_manager))
|
||||
}),
|
||||
|
||||
Some(Subcommand::ExportState(cmd)) => cli.create_runner(cmd)?.async_run(|config| {
|
||||
let PartialComponents { client, task_manager, .. } = service::new_partial(&config)?;
|
||||
let PartialComponents { client, task_manager, .. } = service::new_partial(&config)?.1;
|
||||
Ok((cmd.run(client, config.chain_spec), task_manager))
|
||||
}),
|
||||
|
||||
Some(Subcommand::ImportBlocks(cmd)) => cli.create_runner(cmd)?.async_run(|config| {
|
||||
let PartialComponents { client, task_manager, import_queue, .. } =
|
||||
service::new_partial(&config)?;
|
||||
service::new_partial(&config)?.1;
|
||||
Ok((cmd.run(client, import_queue), task_manager))
|
||||
}),
|
||||
|
||||
@@ -85,14 +85,15 @@ pub fn run() -> sc_cli::Result<()> {
|
||||
}
|
||||
|
||||
Some(Subcommand::Revert(cmd)) => cli.create_runner(cmd)?.async_run(|config| {
|
||||
let PartialComponents { client, task_manager, backend, .. } = service::new_partial(&config)?;
|
||||
let PartialComponents { client, task_manager, backend, .. } =
|
||||
service::new_partial(&config)?.1;
|
||||
Ok((cmd.run(client, backend, None), task_manager))
|
||||
}),
|
||||
|
||||
Some(Subcommand::Benchmark(cmd)) => cli.create_runner(cmd)?.sync_run(|config| match cmd {
|
||||
BenchmarkCmd::Pallet(cmd) => cmd.run::<Block, service::ExecutorDispatch>(config),
|
||||
|
||||
BenchmarkCmd::Block(cmd) => cmd.run(service::new_partial(&config)?.client),
|
||||
BenchmarkCmd::Block(cmd) => cmd.run(service::new_partial(&config)?.1.client),
|
||||
|
||||
#[cfg(not(feature = "runtime-benchmarks"))]
|
||||
BenchmarkCmd::Storage(_) => {
|
||||
@@ -101,12 +102,12 @@ pub fn run() -> sc_cli::Result<()> {
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
BenchmarkCmd::Storage(cmd) => {
|
||||
let PartialComponents { client, backend, .. } = service::new_partial(&config)?;
|
||||
let PartialComponents { client, backend, .. } = service::new_partial(&config)?.1;
|
||||
cmd.run(config, client, backend.expose_db(), backend.expose_storage())
|
||||
}
|
||||
|
||||
BenchmarkCmd::Overhead(cmd) => {
|
||||
let client = service::new_partial(&config)?.client;
|
||||
let client = service::new_partial(&config)?.1.client;
|
||||
cmd.run(
|
||||
config,
|
||||
client.clone(),
|
||||
@@ -117,7 +118,7 @@ pub fn run() -> sc_cli::Result<()> {
|
||||
}
|
||||
|
||||
BenchmarkCmd::Extrinsic(cmd) => {
|
||||
let client = service::new_partial(&config)?.client;
|
||||
let client = service::new_partial(&config)?.1.client;
|
||||
cmd.run(
|
||||
client.clone(),
|
||||
inherent_benchmark_data()?,
|
||||
@@ -134,7 +135,7 @@ pub fn run() -> sc_cli::Result<()> {
|
||||
}
|
||||
|
||||
None => cli.create_runner(&cli.run)?.run_node_until_exit(|config| async {
|
||||
service::new_full(config).map_err(sc_cli::Error::Service)
|
||||
service::new_full(config).await.map_err(sc_cli::Error::Service)
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::sync::Arc;
|
||||
use std::{sync::Arc, future::Future};
|
||||
|
||||
use sc_service::{error::Error as ServiceError, Configuration, TaskManager};
|
||||
use sc_executor::NativeElseWasmExecutor;
|
||||
@@ -19,7 +19,9 @@ type PartialComponents = sc_service::PartialComponents<
|
||||
Option<Telemetry>,
|
||||
>;
|
||||
|
||||
pub fn new_partial(config: &Configuration) -> Result<PartialComponents, ServiceError> {
|
||||
pub fn new_partial(
|
||||
config: &Configuration,
|
||||
) -> Result<(impl Future<Output = ()>, PartialComponents), ServiceError> {
|
||||
if config.keystore_remote.is_some() {
|
||||
return Err(ServiceError::Other("Remote Keystores are not supported".to_string()));
|
||||
}
|
||||
@@ -63,38 +65,44 @@ pub fn new_partial(config: &Configuration) -> Result<PartialComponents, ServiceE
|
||||
client.clone(),
|
||||
);
|
||||
|
||||
let import_queue = serai_consensus::import_queue(
|
||||
let (authority, import_queue) = serai_consensus::import_queue(
|
||||
&task_manager,
|
||||
client.clone(),
|
||||
transaction_pool.clone(),
|
||||
config.prometheus_registry(),
|
||||
)?;
|
||||
);
|
||||
|
||||
let select_chain = serai_consensus::TendermintSelectChain::new(backend.clone());
|
||||
|
||||
Ok(sc_service::PartialComponents {
|
||||
client,
|
||||
backend,
|
||||
task_manager,
|
||||
import_queue,
|
||||
keystore_container,
|
||||
select_chain,
|
||||
transaction_pool,
|
||||
other: telemetry,
|
||||
})
|
||||
Ok((
|
||||
authority,
|
||||
sc_service::PartialComponents {
|
||||
client,
|
||||
backend,
|
||||
task_manager,
|
||||
import_queue,
|
||||
keystore_container,
|
||||
select_chain,
|
||||
transaction_pool,
|
||||
other: telemetry,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
|
||||
let sc_service::PartialComponents {
|
||||
client,
|
||||
backend,
|
||||
mut task_manager,
|
||||
import_queue,
|
||||
keystore_container,
|
||||
select_chain: _,
|
||||
other: mut telemetry,
|
||||
transaction_pool,
|
||||
} = new_partial(&config)?;
|
||||
pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
|
||||
let (
|
||||
authority,
|
||||
sc_service::PartialComponents {
|
||||
client,
|
||||
backend,
|
||||
mut task_manager,
|
||||
import_queue,
|
||||
keystore_container,
|
||||
select_chain: _,
|
||||
other: mut telemetry,
|
||||
transaction_pool,
|
||||
},
|
||||
) = new_partial(&config)?;
|
||||
|
||||
let (network, system_rpc_tx, tx_handler_controller, network_starter) =
|
||||
sc_service::build_network(sc_service::BuildNetworkParams {
|
||||
@@ -116,9 +124,6 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
|
||||
);
|
||||
}
|
||||
|
||||
let role = config.role.clone();
|
||||
let prometheus_registry = config.prometheus_registry().cloned();
|
||||
|
||||
let rpc_extensions_builder = {
|
||||
let client = client.clone();
|
||||
let pool = transaction_pool.clone();
|
||||
@@ -133,6 +138,8 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
|
||||
})
|
||||
};
|
||||
|
||||
let is_authority = config.role.is_authority();
|
||||
|
||||
sc_service::spawn_tasks(sc_service::SpawnTasksParams {
|
||||
network: network.clone(),
|
||||
client: client.clone(),
|
||||
@@ -147,14 +154,8 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
|
||||
telemetry: telemetry.as_mut(),
|
||||
})?;
|
||||
|
||||
if role.is_authority() {
|
||||
serai_consensus::authority(
|
||||
&task_manager,
|
||||
client,
|
||||
network,
|
||||
transaction_pool,
|
||||
prometheus_registry.as_ref(),
|
||||
);
|
||||
if is_authority {
|
||||
authority.await;
|
||||
}
|
||||
|
||||
network_starter.start_network();
|
||||
|
||||
Reference in New Issue
Block a user