diff --git a/cumulus/parachain-template/node/src/service.rs b/cumulus/parachain-template/node/src/service.rs index 43d16ee0d5b7..830b6e82f969 100644 --- a/cumulus/parachain-template/node/src/service.rs +++ b/cumulus/parachain-template/node/src/service.rs @@ -59,23 +59,21 @@ type ParachainBackend = TFullBackend; type ParachainBlockImport = TParachainBlockImport, ParachainBackend>; +/// Assembly of PartialComponents (enough to run chain ops subcommands) +pub type Service = PartialComponents< + ParachainClient, + ParachainBackend, + (), + sc_consensus::DefaultImportQueue, + sc_transaction_pool::FullPool, + (ParachainBlockImport, Option, Option), +>; + /// Starts a `ServiceBuilder` for a full service. /// /// Use this macro if you don't actually need the full service, but just the builder in order to /// be able to perform chain operations. -pub fn new_partial( - config: &Configuration, -) -> Result< - PartialComponents< - ParachainClient, - ParachainBackend, - (), - sc_consensus::DefaultImportQueue, - sc_transaction_pool::FullPool, - (ParachainBlockImport, Option, Option), - >, - sc_service::Error, -> { +pub fn new_partial(config: &Configuration) -> Result { let telemetry = config .telemetry_endpoints .clone() diff --git a/cumulus/polkadot-parachain/src/service.rs b/cumulus/polkadot-parachain/src/service.rs index 77978a49f561..d5c120178593 100644 --- a/cumulus/polkadot-parachain/src/service.rs +++ b/cumulus/polkadot-parachain/src/service.rs @@ -216,6 +216,16 @@ impl sc_executor::NativeExecutionDispatch for PeopleRococoRuntimeExecutor { } } +/// Assembly of PartialComponents (enough to run chain ops subcommands) +pub type Service = PartialComponents< + ParachainClient, + ParachainBackend, + (), + sc_consensus::DefaultImportQueue, + sc_transaction_pool::FullPool>, + (ParachainBlockImport, Option, Option), +>; + /// Starts a `ServiceBuilder` for a full service. /// /// Use this macro if you don't actually need the full service, but just the builder in order to @@ -223,17 +233,7 @@ impl sc_executor::NativeExecutionDispatch for PeopleRococoRuntimeExecutor { pub fn new_partial( config: &Configuration, build_import_queue: BIQ, -) -> Result< - PartialComponents< - ParachainClient, - ParachainBackend, - (), - sc_consensus::DefaultImportQueue, - sc_transaction_pool::FullPool>, - (ParachainBlockImport, Option, Option), - >, - sc_service::Error, -> +) -> Result, sc_service::Error> where RuntimeApi: ConstructRuntimeApi> + Send + Sync + 'static, RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue diff --git a/cumulus/test/service/src/lib.rs b/cumulus/test/service/src/lib.rs index 586c4603c76a..eca65dd4ca0f 100644 --- a/cumulus/test/service/src/lib.rs +++ b/cumulus/test/service/src/lib.rs @@ -183,6 +183,16 @@ impl RecoveryHandle for FailingRecoveryHandle { } } +/// Assembly of PartialComponents (enough to run chain ops subcommands) +pub type Service = PartialComponents< + Client, + Backend, + (), + sc_consensus::import_queue::BasicQueue, + sc_transaction_pool::FullPool, + ParachainBlockImport, +>; + /// Starts a `ServiceBuilder` for a full service. /// /// Use this macro if you don't actually need the full service, but just the builder in order to @@ -190,17 +200,7 @@ impl RecoveryHandle for FailingRecoveryHandle { pub fn new_partial( config: &mut Configuration, enable_import_proof_record: bool, -) -> Result< - PartialComponents< - Client, - Backend, - (), - sc_consensus::import_queue::BasicQueue, - sc_transaction_pool::FullPool, - ParachainBlockImport, - >, - sc_service::Error, -> { +) -> Result { let heap_pages = config .default_heap_pages .map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |h| HeapAllocStrategy::Static { extra_pages: h as _ }); diff --git a/prdoc/pr_2767.prdoc b/prdoc/pr_2767.prdoc new file mode 100644 index 000000000000..c2cd466c0097 --- /dev/null +++ b/prdoc/pr_2767.prdoc @@ -0,0 +1,17 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: Extract PartialComponents into type alias `Service` + +doc: + - audience: Node Dev + description: | + Simplifies service definitions by extraction of a complicated type into a type alias. No breaking changes. + +crates: + - name: "sc-service" + - name: "node-template" + - name: "minimal-node" + - name: "cumulus-test-service" + - name: "polkadot-parachain-bin" + - name: "parachain-template-node" diff --git a/substrate/bin/minimal/node/src/service.rs b/substrate/bin/minimal/node/src/service.rs index b6369c44dda9..08db8b593614 100644 --- a/substrate/bin/minimal/node/src/service.rs +++ b/substrate/bin/minimal/node/src/service.rs @@ -38,19 +38,17 @@ pub(crate) type FullClient = type FullBackend = sc_service::TFullBackend; type FullSelectChain = sc_consensus::LongestChain; -pub fn new_partial( - config: &Configuration, -) -> Result< - sc_service::PartialComponents< - FullClient, - FullBackend, - FullSelectChain, - sc_consensus::DefaultImportQueue, - sc_transaction_pool::FullPool, - Option, - >, - ServiceError, -> { +/// Assembly of PartialComponents (enough to run chain ops subcommands) +pub type Service = sc_service::PartialComponents< + FullClient, + FullBackend, + FullSelectChain, + sc_consensus::DefaultImportQueue, + sc_transaction_pool::FullPool, + Option, +>; + +pub fn new_partial(config: &Configuration) -> Result { let telemetry = config .telemetry_endpoints .clone() diff --git a/substrate/bin/node-template/node/src/service.rs b/substrate/bin/node-template/node/src/service.rs index c4a2b2f39d21..25cd65117841 100644 --- a/substrate/bin/node-template/node/src/service.rs +++ b/substrate/bin/node-template/node/src/service.rs @@ -23,29 +23,20 @@ type FullSelectChain = sc_consensus::LongestChain; /// imported and generated. const GRANDPA_JUSTIFICATION_PERIOD: u32 = 512; -#[allow(clippy::type_complexity)] -pub fn new_partial( - config: &Configuration, -) -> Result< - sc_service::PartialComponents< - FullClient, - FullBackend, - FullSelectChain, - sc_consensus::DefaultImportQueue, - sc_transaction_pool::FullPool, - ( - sc_consensus_grandpa::GrandpaBlockImport< - FullBackend, - Block, - FullClient, - FullSelectChain, - >, - sc_consensus_grandpa::LinkHalf, - Option, - ), - >, - ServiceError, -> { +pub type Service = sc_service::PartialComponents< + FullClient, + FullBackend, + FullSelectChain, + sc_consensus::DefaultImportQueue, + sc_transaction_pool::FullPool, + ( + sc_consensus_grandpa::GrandpaBlockImport, + sc_consensus_grandpa::LinkHalf, + Option, + ), +>; + +pub fn new_partial(config: &Configuration) -> Result { let telemetry = config .telemetry_endpoints .clone()