diff --git a/Cargo.lock b/Cargo.lock index e9756cfd539e..a3947013ded0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4732,6 +4732,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-transaction-pool", + "sp-trie", "substrate-prometheus-endpoint", "westend-runtime", ] @@ -4792,6 +4793,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-transaction-pool", + "sp-trie", "substrate-prometheus-endpoint", "westend-runtime", ] diff --git a/collator/src/lib.rs b/collator/src/lib.rs index 51f3255a745b..7e3e0bd3420c 100644 --- a/collator/src/lib.rs +++ b/collator/src/lib.rs @@ -373,12 +373,15 @@ fn build_collator_service( /// Async function that will run the collator node with the given `RelayChainContext` and `ParachainContext` /// built by the given `BuildParachainContext` and arguments to the underlying polkadot node. -pub async fn start_collator

( +pub fn start_collator

( build_parachain_context: P, para_id: ParaId, key: Arc, config: Configuration, -) -> Result<(), polkadot_service::Error> +) -> Result< + (Pin + Send>>, sc_service::TaskManager), + polkadot_service::Error +> where P: 'static + BuildParachainContext, P::ParachainContext: Send + 'static, @@ -400,14 +403,15 @@ where None, )?; let spawn_handle = task_manager.spawn_handle(); - build_collator_service( + let future = build_collator_service( spawn_handle, handlers, client, para_id, key, build_parachain_context - )?.await; + )?; + Ok((future.boxed(), task_manager)) } else if config.chain_spec.is_westend() { let (task_manager, client, handlers) = service::westend_new_full( config, @@ -418,14 +422,15 @@ where None, )?; let spawn_handle = task_manager.spawn_handle(); - build_collator_service( + let future = build_collator_service( spawn_handle, handlers, client, para_id, key, build_parachain_context - )?.await; + )?; + Ok((future.boxed(), task_manager)) } else { let (task_manager, client, handles) = service::polkadot_new_full( config, @@ -436,17 +441,16 @@ where None, )?; let spawn_handle = task_manager.spawn_handle(); - build_collator_service( + let future = build_collator_service( spawn_handle, handles, client, para_id, key, - build_parachain_context, - )?.await; + build_parachain_context + )?; + Ok((future.boxed(), task_manager)) } - - Ok(()) } #[cfg(not(feature = "service-rewr"))] @@ -506,7 +510,7 @@ mod tests { fn check_send(_: T) {} let cli = Cli::from_iter(&["-dev"]); - let task_executor = |_, _| unimplemented!(); + let task_executor = |_, _| {}; let config = cli.create_configuration(&cli.run.base, task_executor.into()).unwrap(); check_send(start_collator( diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index f1a56acfad95..1036cff494a2 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -31,6 +31,7 @@ sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "mas sc-executor = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" } consensus_common = { package = "sp-consensus", git = "https://github.com/paritytech/substrate", branch = "master" } grandpa = { package = "sc-finality-grandpa", git = "https://github.com/paritytech/substrate", branch = "master" } grandpa_primitives = { package = "sp-finality-grandpa", git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index c798d3e9aa71..c478e007545a 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -34,10 +34,11 @@ use polkadot_subsystem::{ Subsystem, SubsystemContext, SpawnedSubsystem, messages::{CandidateValidationMessage, CandidateBackingMessage}, }; +use sp_trie::PrefixedMemoryDB; pub use service::{ Role, PruningMode, TransactionPoolOptions, Error, RuntimeGenesis, TFullClient, TLightClient, TFullBackend, TLightBackend, TFullCallExecutor, TLightCallExecutor, - Configuration, ChainSpec, ServiceBuilderCommand, ServiceComponents, TaskManager, + Configuration, ChainSpec, ServiceComponents, TaskManager, }; pub use service::config::{DatabaseConfig, PrometheusConfig}; pub use sc_executor::NativeExecutionDispatch; @@ -576,18 +577,25 @@ macro_rules! new_light { } /// Builds a new object suitable for chain operations. -pub fn new_chain_ops(mut config: Configuration) - -> Result, ServiceError> +pub fn new_chain_ops(mut config: Configuration) -> Result< + ( + Arc>, + Arc>, + consensus_common::import_queue::BasicQueue>, + TaskManager, + ), + ServiceError +> where Runtime: ConstructRuntimeApi> + Send + Sync + 'static, Runtime::RuntimeApi: RuntimeApiCollection, Block>>, Dispatch: NativeExecutionDispatch + 'static, Extrinsic: RuntimeExtrinsic, - >::StateBackend: sp_api::StateBackend, { config.keystore = service::config::KeystoreConfig::InMemory; - Ok(new_full_start!(config, Runtime, Dispatch).0) + let (builder, _, _, _) = new_full_start!(config, Runtime, Dispatch); + Ok(builder.to_chain_ops_parts()) } /// Create a new Polkadot service for a full node. diff --git a/parachain/test-parachains/adder/collator/src/main.rs b/parachain/test-parachains/adder/collator/src/main.rs index 326549fda713..42c3c824004a 100644 --- a/parachain/test-parachains/adder/collator/src/main.rs +++ b/parachain/test-parachains/adder/collator/src/main.rs @@ -28,7 +28,7 @@ use primitives::{ }; use collator::{ParachainContext, Network, BuildParachainContext, Cli, SubstrateCli}; use parking_lot::Mutex; -use futures::future::{Ready, ready, TryFutureExt}; +use futures::future::{Ready, ready, FutureExt}; const GENESIS: AdderHead = AdderHead { number: 0, @@ -135,12 +135,14 @@ fn main() -> Result<(), Box> { let cli = Cli::from_iter(&["-dev"]); let runner = cli.create_runner(&cli.run.base)?; runner.async_run(|config| { - collator::start_collator( + let (future, task_manager) = collator::start_collator( context, id, key, config, - ).map_err(|e| e.into()) + )?; + + Ok((future.map(Ok), task_manager)) })?; Ok(()) diff --git a/service/Cargo.toml b/service/Cargo.toml index 5eb47ec8875c..8d816dac1adb 100644 --- a/service/Cargo.toml +++ b/service/Cargo.toml @@ -31,6 +31,7 @@ sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "mas sc-executor = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" } consensus_common = { package = "sp-consensus", git = "https://github.com/paritytech/substrate", branch = "master" } grandpa = { package = "sc-finality-grandpa", git = "https://github.com/paritytech/substrate", branch = "master" } grandpa_primitives = { package = "sp-finality-grandpa", git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/service/src/lib.rs b/service/src/lib.rs index 5cf371ebec84..70d04df6301f 100644 --- a/service/src/lib.rs +++ b/service/src/lib.rs @@ -29,10 +29,11 @@ use service::{error::Error as ServiceError, ServiceBuilder}; use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider}; use sc_executor::native_executor_instance; use log::info; +use sp_trie::PrefixedMemoryDB; pub use service::{ Role, PruningMode, TransactionPoolOptions, Error, RuntimeGenesis, RpcHandlers, TFullClient, TLightClient, TFullBackend, TLightBackend, TFullCallExecutor, TLightCallExecutor, - Configuration, ChainSpec, ServiceBuilderCommand, ServiceComponents, TaskManager, + Configuration, ChainSpec, ServiceComponents, TaskManager, }; pub use service::config::{DatabaseConfig, PrometheusConfig}; pub use sc_executor::NativeExecutionDispatch; @@ -634,18 +635,25 @@ macro_rules! new_light { } /// Builds a new object suitable for chain operations. -pub fn new_chain_ops(mut config: Configuration) - -> Result, ServiceError> +pub fn new_chain_ops(mut config: Configuration) -> Result< + ( + Arc>, + Arc>, + consensus_common::import_queue::BasicQueue>, + TaskManager, + ), + ServiceError +> where Runtime: ConstructRuntimeApi> + Send + Sync + 'static, Runtime::RuntimeApi: RuntimeApiCollection, Block>>, Dispatch: NativeExecutionDispatch + 'static, Extrinsic: RuntimeExtrinsic, - >::StateBackend: sp_api::StateBackend, { config.keystore = service::config::KeystoreConfig::InMemory; - Ok(new_full_start!(config, Runtime, Dispatch).0) + let (builder, _, _, _) = new_full_start!(config, Runtime, Dispatch); + Ok(builder.to_chain_ops_parts()) } /// Create a new Polkadot service for a full node.