1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Cumulus.
3// SPDX-License-Identifier: Apache-2.0
45// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
1617//! Cumulus parachain collator primitives.
1819#![warn(missing_docs)]
2021pub(crate) mod aura;
22pub mod chain_spec;
23pub mod command;
24pub mod rpc;
25pub mod runtime;
26pub mod spec;
27pub(crate) mod statement_store;
28pub mod types;
2930use crate::cli::AuthoringPolicy;
3132use cumulus_primitives_core::{
33 CollectCollationInfo, GetCoreSelectorApi, GetParachainInfo, RelayParentOffsetApi,
34};
35use sc_client_db::DbHash;
36use sc_offchain::OffchainWorkerApi;
37use serde::de::DeserializeOwned;
38use sp_api::{ApiExt, CallApiAt, ConstructRuntimeApi, Metadata};
39use sp_block_builder::BlockBuilder;
40use sp_runtime::{
41 traits::{Block as BlockT, BlockNumber, Header as HeaderT, NumberFor},
42 OpaqueExtrinsic,
43};
44use sp_session::SessionKeys;
45use sp_statement_store::runtime_api::ValidateStatement;
46use sp_transaction_pool::runtime_api::TaggedTransactionQueue;
47use std::{fmt::Debug, path::PathBuf, str::FromStr};
4849pub trait NodeBlock:
50 BlockT<Extrinsic = OpaqueExtrinsic, Header = Self::BoundedHeader, Hash = DbHash> + DeserializeOwned
51{
52type BoundedFromStrErr: Debug;
53type BoundedNumber: FromStr<Err = Self::BoundedFromStrErr> + BlockNumber;
54type BoundedHeader: HeaderT<Number = Self::BoundedNumber, Hash = DbHash> + Unpin;
55}
5657impl<T> NodeBlock for T
58where
59T: BlockT<Extrinsic = OpaqueExtrinsic, Hash = DbHash> + DeserializeOwned,
60 <T as BlockT>::Header: Unpin,
61 <NumberFor<T> as FromStr>::Err: Debug,
62{
63type BoundedFromStrErr = <NumberFor<T> as FromStr>::Err;
64type BoundedNumber = NumberFor<T>;
65type BoundedHeader = <T as BlockT>::Header;
66}
6768/// Convenience trait that defines the basic bounds for the `RuntimeApi` of a parachain node.
69pub trait NodeRuntimeApi<Block: BlockT>:
70 ApiExt<Block>
71 + Metadata<Block>
72 + SessionKeys<Block>
73 + BlockBuilder<Block>
74 + TaggedTransactionQueue<Block>
75 + OffchainWorkerApi<Block>
76 + CollectCollationInfo<Block>
77 + GetCoreSelectorApi<Block>
78 + ValidateStatement<Block>
79 + GetParachainInfo<Block>
80 + RelayParentOffsetApi<Block>
81 + Sized
82{
83}
8485impl<T, Block: BlockT> NodeRuntimeApi<Block> for T where
86T: ApiExt<Block>
87 + Metadata<Block>
88 + SessionKeys<Block>
89 + BlockBuilder<Block>
90 + TaggedTransactionQueue<Block>
91 + OffchainWorkerApi<Block>
92 + GetCoreSelectorApi<Block>
93 + RelayParentOffsetApi<Block>
94 + CollectCollationInfo<Block>
95 + ValidateStatement<Block>
96 + GetParachainInfo<Block>
97{
98}
99100/// Convenience trait that defines the basic bounds for the `ConstructRuntimeApi` of a parachain
101/// node.
102pub trait ConstructNodeRuntimeApi<Block: BlockT, C: CallApiAt<Block>>:
103 ConstructRuntimeApi<Block, C, RuntimeApi = Self::BoundedRuntimeApi> + Send + Sync + 'static
104{
105/// Basic bounds for the `RuntimeApi` of a parachain node.
106type BoundedRuntimeApi: NodeRuntimeApi<Block>;
107}
108109impl<T, Block: BlockT, C: CallApiAt<Block>> ConstructNodeRuntimeApi<Block, C> for T
110where
111T: ConstructRuntimeApi<Block, C> + Send + Sync + 'static,
112 T::RuntimeApi: NodeRuntimeApi<Block>,
113{
114type BoundedRuntimeApi = T::RuntimeApi;
115}
116117/// Extra args that are passed when creating a new node spec.
118pub struct NodeExtraArgs {
119/// The authoring policy to use.
120 ///
121 /// Can be used to influence details of block production.
122pub authoring_policy: AuthoringPolicy,
123124/// If set, each `PoV` build by the node will be exported to this folder.
125pub export_pov: Option<PathBuf>,
126127/// The maximum percentage of the maximum PoV size that the collator can use.
128 /// It will be removed once <https://github.com/paritytech/polkadot-sdk/issues/6020> is fixed.
129pub max_pov_percentage: Option<u32>,
130131/// If true then the statement store will be enabled.
132pub enable_statement_store: bool,
133}