Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
275 changes: 138 additions & 137 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,23 +153,20 @@ pub fn run() -> Result<()> {
service::new_chain_ops::<
service::kusama_runtime::RuntimeApi,
service::KusamaExecutor,
service::kusama_runtime::UncheckedExtrinsic,
>(config)
)
} else if chain_spec.is_westend() {
runner.run_subcommand(subcommand, |config|
service::new_chain_ops::<
service::westend_runtime::RuntimeApi,
service::WestendExecutor,
service::westend_runtime::UncheckedExtrinsic,
>(config)
)
} else {
runner.run_subcommand(subcommand, |config|
service::new_chain_ops::<
service::polkadot_runtime::RuntimeApi,
service::PolkadotExecutor,
service::polkadot_runtime::UncheckedExtrinsic,
>(config)
)
}
Expand Down
15 changes: 5 additions & 10 deletions collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,16 @@ pub trait BuildParachainContext {
type ParachainContext: self::ParachainContext;

/// Build the `ParachainContext`.
fn build<Client, SP, Extrinsic>(
fn build<Client, SP>(
self,
client: Arc<Client>,
spawner: SP,
network: impl Network + Clone + 'static,
) -> Result<Self::ParachainContext, ()>
where
Client: ProvideRuntimeApi<Block> + HeaderBackend<Block> + BlockchainEvents<Block> + Send + Sync + 'static,
Client::Api: RuntimeApiCollection<Extrinsic>,
Client::Api: RuntimeApiCollection,
<Client::Api as ApiExt<Block>>::StateBackend: StateBackend<HashFor<Block>>,
Extrinsic: codec::Codec + Send + Sync + 'static,
SP: SpawnNamed + Clone + Send + Sync + 'static;
}

Expand Down Expand Up @@ -203,7 +202,7 @@ pub async fn collate<P>(
}

#[cfg(feature = "service-rewr")]
fn build_collator_service<SP, P, C, R, Extrinsic>(
fn build_collator_service<SP, P, C, R>(
_spawner: SP,
_handles: FullNodeHandles,
_client: Arc<C>,
Expand All @@ -224,22 +223,20 @@ fn build_collator_service<SP, P, C, R, Extrinsic>(
StateBackend = <service::TFullBackend<service::Block> as service::Backend<service::Block>>::State,
>
+ RuntimeApiCollection<
Extrinsic,
StateBackend = <service::TFullBackend<service::Block> as service::Backend<service::Block>>::State,
>
+ Sync + Send,
P: BuildParachainContext,
P::ParachainContext: Send + 'static,
<P::ParachainContext as ParachainContext>::ProduceCandidate: Send,
Extrinsic: service::Codec + Send + Sync + 'static,
SP: SpawnNamed + Clone + Send + Sync + 'static,
{
Err("Collator is not functional with the new service yet".into())
}


#[cfg(not(feature = "service-rewr"))]
fn build_collator_service<P, C, R, Extrinsic>(
fn build_collator_service<P, C, R>(
spawner: SpawnTaskHandle,
handles: FullNodeHandles,
client: Arc<C>,
Expand All @@ -260,14 +257,12 @@ fn build_collator_service<P, C, R, Extrinsic>(
StateBackend = <service::TFullBackend<service::Block> as service::Backend<service::Block>>::State,
>
+ RuntimeApiCollection<
Extrinsic,
StateBackend = <service::TFullBackend<service::Block> as service::Backend<service::Block>>::State,
>
+ Sync + Send,
P: BuildParachainContext,
P::ParachainContext: Send + 'static,
<P::ParachainContext as ParachainContext>::ProduceCandidate: Send,
Extrinsic: service::Codec + Send + Sync + 'static,
{
let polkadot_network = handles.polkadot_network
.ok_or_else(|| "Collator cannot run when Polkadot-specific networking has not been started")?;
Expand Down Expand Up @@ -497,7 +492,7 @@ mod tests {
impl BuildParachainContext for BuildDummyParachainContext {
type ParachainContext = DummyParachainContext;

fn build<C, SP, Extrinsic>(
fn build<C, SP>(
self,
_: Arc<C>,
_: SP,
Expand Down
58 changes: 24 additions & 34 deletions node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,23 @@ native_executor_instance!(
);

/// A set of APIs that polkadot-like runtimes must implement.
pub trait RuntimeApiCollection<Extrinsic: codec::Codec + Send + Sync + 'static>:
pub trait RuntimeApiCollection:
sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
+ sp_api::ApiExt<Block, Error = sp_blockchain::Error>
+ babe_primitives::BabeApi<Block>
+ grandpa_primitives::GrandpaApi<Block>
+ sp_block_builder::BlockBuilder<Block>
+ system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce>
+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance, Extrinsic>
+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>
+ sp_api::Metadata<Block>
+ sp_offchain::OffchainWorkerApi<Block>
+ sp_session::SessionKeys<Block>
+ authority_discovery_primitives::AuthorityDiscoveryApi<Block>
where
Extrinsic: RuntimeExtrinsic,
<Self as sp_api::ApiExt<Block>>::StateBackend: sp_api::StateBackend<HashFor<Block>>,
{}

impl<Api, Extrinsic> RuntimeApiCollection<Extrinsic> for Api
impl<Api> RuntimeApiCollection for Api
where
Api:
sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
Expand All @@ -104,19 +103,14 @@ where
+ grandpa_primitives::GrandpaApi<Block>
+ sp_block_builder::BlockBuilder<Block>
+ system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce>
+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance, Extrinsic>
+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>
+ sp_api::Metadata<Block>
+ sp_offchain::OffchainWorkerApi<Block>
+ sp_session::SessionKeys<Block>
+ authority_discovery_primitives::AuthorityDiscoveryApi<Block>,
Extrinsic: RuntimeExtrinsic,
<Self as sp_api::ApiExt<Block>>::StateBackend: sp_api::StateBackend<HashFor<Block>>,
{}

pub trait RuntimeExtrinsic: codec::Codec + Send + Sync + 'static {}

impl<E> RuntimeExtrinsic for E where E: codec::Codec + Send + Sync + 'static {}

/// Can be called for a `Configuration` to check if it is a configuration for the `Kusama` network.
pub trait IdentifyVariant {
/// Returns if this is a configuration for the `Kusama` network.
Expand Down Expand Up @@ -157,7 +151,7 @@ type LightClient<RuntimeApi, Executor> =
service::TLightClientWithBackend<Block, RuntimeApi, Executor, LightBackend>;

#[cfg(feature = "full-node")]
fn new_partial<RuntimeApi, Executor, Extrinsic>(config: &mut Configuration) -> Result<
fn new_partial<RuntimeApi, Executor>(config: &mut Configuration) -> Result<
service::PartialComponents<
FullClient<RuntimeApi, Executor>, FullBackend, FullSelectChain,
consensus_common::DefaultImportQueue<Block, FullClient<RuntimeApi, Executor>>,
Expand All @@ -179,9 +173,8 @@ fn new_partial<RuntimeApi, Executor, Extrinsic>(config: &mut Configuration) -> R
where
RuntimeApi: ConstructRuntimeApi<Block, FullClient<RuntimeApi, Executor>> + Send + Sync + 'static,
RuntimeApi::RuntimeApi:
RuntimeApiCollection<Extrinsic, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,
RuntimeApiCollection<StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,
Executor: NativeExecutionDispatch + 'static,
Extrinsic: RuntimeExtrinsic,
{
set_prometheus_registry(config)?;

Expand Down Expand Up @@ -303,7 +296,7 @@ fn real_overseer<S: SpawnNamed>(
}

#[cfg(feature = "full-node")]
fn new_full<RuntimeApi, Executor, Extrinsic>(
fn new_full<RuntimeApi, Executor>(
mut config: Configuration,
collating_for: Option<(CollatorId, ParaId)>,
_max_block_data_size: Option<u64>,
Expand All @@ -317,9 +310,8 @@ fn new_full<RuntimeApi, Executor, Extrinsic>(
where
RuntimeApi: ConstructRuntimeApi<Block, FullClient<RuntimeApi, Executor>> + Send + Sync + 'static,
RuntimeApi::RuntimeApi:
RuntimeApiCollection<Extrinsic, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,
RuntimeApiCollection<StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,
Executor: NativeExecutionDispatch + 'static,
Extrinsic: RuntimeExtrinsic,
{
use sc_client_api::ExecutorProvider;
use sp_core::traits::BareCryptoStorePtr;
Expand All @@ -335,8 +327,8 @@ fn new_full<RuntimeApi, Executor, Extrinsic>(
client, backend, mut task_manager, keystore, select_chain, import_queue, transaction_pool,
inherent_data_providers,
other: (rpc_extensions_builder, import_setup, rpc_setup)
} = new_partial::<RuntimeApi, Executor, Extrinsic>(&mut config)?;
} = new_partial::<RuntimeApi, Executor>(&mut config)?;

let prometheus_registry = config.prometheus_registry().cloned();

let finality_proof_provider =
Expand Down Expand Up @@ -525,13 +517,12 @@ fn new_full<RuntimeApi, Executor, Extrinsic>(
pub struct FullNodeHandles;

/// Builds a new service for a light client.
fn new_light<Runtime, Dispatch, Extrinsic>(mut config: Configuration) -> Result<TaskManager, Error>
fn new_light<Runtime, Dispatch>(mut config: Configuration) -> Result<TaskManager, Error>
where
Runtime: 'static + Send + Sync + ConstructRuntimeApi<Block, LightClient<Runtime, Dispatch>>,
<Runtime as ConstructRuntimeApi<Block, LightClient<Runtime, Dispatch>>>::RuntimeApi:
RuntimeApiCollection<Extrinsic, StateBackend = sc_client_api::StateBackendFor<LightBackend, Block>>,
RuntimeApiCollection<StateBackend = sc_client_api::StateBackendFor<LightBackend, Block>>,
Dispatch: NativeExecutionDispatch + 'static,
Extrinsic: RuntimeExtrinsic,
{
crate::set_prometheus_registry(&mut config)?;
use sc_client_api::backend::RemoteBackend;
Expand Down Expand Up @@ -594,7 +585,7 @@ fn new_light<Runtime, Dispatch, Extrinsic>(mut config: Configuration) -> Result<
finality_proof_request_builder: Some(finality_proof_request_builder),
finality_proof_provider: Some(finality_proof_provider),
})?;

if config.offchain_worker.enabled {
service::build_offchain_workers(
&config, backend.clone(), task_manager.spawn_handle(), client.clone(), network.clone(),
Expand All @@ -610,7 +601,7 @@ fn new_light<Runtime, Dispatch, Extrinsic>(mut config: Configuration) -> Result<

let rpc_extensions = polkadot_rpc::create_light(light_deps);

service::spawn_tasks(service::SpawnTasksParams {
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)),
Expand All @@ -619,13 +610,13 @@ fn new_light<Runtime, Dispatch, Extrinsic>(mut config: Configuration) -> Result<
config, keystore, backend, transaction_pool, client, network, network_status_sinks,
system_rpc_tx,
})?;

Ok(task_manager)
}

/// Builds a new object suitable for chain operations.
#[cfg(feature = "full-node")]
pub fn new_chain_ops<Runtime, Dispatch, Extrinsic>(mut config: Configuration) -> Result<
pub fn new_chain_ops<Runtime, Dispatch>(mut config: Configuration) -> Result<
(
Arc<FullClient<Runtime, Dispatch>>,
Arc<FullBackend>,
Expand All @@ -637,13 +628,12 @@ pub fn new_chain_ops<Runtime, Dispatch, Extrinsic>(mut config: Configuration) ->
where
Runtime: ConstructRuntimeApi<Block, FullClient<Runtime, Dispatch>> + Send + Sync + 'static,
Runtime::RuntimeApi:
RuntimeApiCollection<Extrinsic, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,
RuntimeApiCollection<StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,
Dispatch: NativeExecutionDispatch + 'static,
Extrinsic: RuntimeExtrinsic,
{
config.keystore = service::config::KeystoreConfig::InMemory;
let service::PartialComponents { client, backend, import_queue, task_manager, .. }
= new_partial::<Runtime, Dispatch, Extrinsic>(&mut config)?;
= new_partial::<Runtime, Dispatch>(&mut config)?;
Ok((client, backend, import_queue, task_manager))
}

Expand All @@ -667,7 +657,7 @@ pub fn polkadot_new_full(
FullNodeHandles,
), ServiceError>
{
let (components, client) = new_full::<polkadot_runtime::RuntimeApi, PolkadotExecutor, _>(
let (components, client) = new_full::<polkadot_runtime::RuntimeApi, PolkadotExecutor>(
config,
collating_for,
max_block_data_size,
Expand Down Expand Up @@ -699,7 +689,7 @@ pub fn kusama_new_full(
FullNodeHandles,
), ServiceError>
{
let (components, client) = new_full::<kusama_runtime::RuntimeApi, KusamaExecutor, _>(
let (components, client) = new_full::<kusama_runtime::RuntimeApi, KusamaExecutor>(
config,
collating_for,
max_block_data_size,
Expand Down Expand Up @@ -731,7 +721,7 @@ pub fn westend_new_full(
FullNodeHandles,
), ServiceError>
{
let (components, client) = new_full::<westend_runtime::RuntimeApi, WestendExecutor, _>(
let (components, client) = new_full::<westend_runtime::RuntimeApi, WestendExecutor>(
config,
collating_for,
max_block_data_size,
Expand All @@ -746,17 +736,17 @@ pub fn westend_new_full(
/// Create a new Polkadot service for a light client.
pub fn polkadot_new_light(config: Configuration) -> Result<TaskManager, ServiceError>
{
new_light::<polkadot_runtime::RuntimeApi, PolkadotExecutor, _>(config)
new_light::<polkadot_runtime::RuntimeApi, PolkadotExecutor>(config)
}

/// Create a new Kusama service for a light client.
pub fn kusama_new_light(config: Configuration) -> Result<TaskManager, ServiceError>
{
new_light::<kusama_runtime::RuntimeApi, KusamaExecutor, _>(config)
new_light::<kusama_runtime::RuntimeApi, KusamaExecutor>(config)
}

/// Create a new Westend service for a light client.
pub fn westend_new_light(config: Configuration, ) -> Result<TaskManager, ServiceError>
{
new_light::<westend_runtime::RuntimeApi, KusamaExecutor, _>(config)
new_light::<westend_runtime::RuntimeApi, KusamaExecutor>(config)
}
2 changes: 1 addition & 1 deletion node/test-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn polkadot_test_new_full(
ServiceError,
> {
let (task_manager, client, handles, network, rpc_handlers) =
new_full::<polkadot_test_runtime::RuntimeApi, PolkadotTestExecutor, _>(
new_full::<polkadot_test_runtime::RuntimeApi, PolkadotTestExecutor>(
config,
collating_for,
max_block_data_size,
Expand Down
2 changes: 1 addition & 1 deletion parachain/test-parachains/adder/collator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl ParachainContext for AdderContext {
impl BuildParachainContext for AdderContext {
type ParachainContext = Self;

fn build<Client, SP, Extrinsic>(
fn build<Client, SP>(
self,
_: Arc<Client>,
_: SP,
Expand Down
10 changes: 4 additions & 6 deletions rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,15 @@ pub struct FullDeps<C, P, SC> {
}

/// Instantiate all RPC extensions.
pub fn create_full<C, P, UE, SC>(deps: FullDeps<C, P, SC>) -> RpcExtension where
pub fn create_full<C, P, SC>(deps: FullDeps<C, P, SC>) -> RpcExtension where
C: ProvideRuntimeApi<Block>,
C: HeaderBackend<Block> + HeaderMetadata<Block, Error=BlockChainError>,
C: Send + Sync + 'static,
C::Api: frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance, UE>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BabeApi<Block>,
C::Api: BlockBuilder<Block>,
P: TransactionPool + Sync + Send + 'static,
UE: codec::Codec + Send + Sync + 'static,
SC: SelectChain<Block> + 'static,
{
use frame_rpc_system::{FullSystem, SystemApi};
Expand Down Expand Up @@ -145,16 +144,15 @@ pub fn create_full<C, P, UE, SC>(deps: FullDeps<C, P, SC>) -> RpcExtension where
}

/// Instantiate all RPC extensions for light node.
pub fn create_light<C, P, F, UE>(deps: LightDeps<C, F, P>) -> RpcExtension
pub fn create_light<C, P, F>(deps: LightDeps<C, F, P>) -> RpcExtension
where
C: ProvideRuntimeApi<Block>,
C: HeaderBackend<Block>,
C: Send + Sync + 'static,
C::Api: frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance, UE>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
P: TransactionPool + Sync + Send + 'static,
F: Fetcher<Block> + 'static,
UE: codec::Codec + Send + Sync + 'static,
{
use frame_rpc_system::{LightSystem, SystemApi};

Expand Down
3 changes: 1 addition & 2 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1254,9 +1254,8 @@ sp_api::impl_runtime_apis! {
impl transaction_payment_rpc_runtime_api::TransactionPaymentApi<
Block,
Balance,
UncheckedExtrinsic,
> for Runtime {
fn query_info(uxt: UncheckedExtrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {
fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {
TransactionPayment::query_info(uxt, len)
}
}
Expand Down
3 changes: 1 addition & 2 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1394,9 +1394,8 @@ sp_api::impl_runtime_apis! {
impl transaction_payment_rpc_runtime_api::TransactionPaymentApi<
Block,
Balance,
UncheckedExtrinsic,
> for Runtime {
fn query_info(uxt: UncheckedExtrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {
fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {
TransactionPayment::query_info(uxt, len)
}
}
Expand Down
Loading