referrerpolicy=no-referrer-when-downgrade

polkadot_omni_node_lib/common/
mod.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Cumulus.
3// SPDX-License-Identifier: Apache-2.0
4
5// 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.
16
17//! Cumulus parachain collator primitives.
18
19#![warn(missing_docs)]
20
21pub(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;
29
30use crate::cli::AuthoringPolicy;
31
32use cumulus_primitives_core::{CollectCollationInfo, GetParachainInfo, RelayParentOffsetApi};
33use sc_client_db::DbHash;
34use sc_offchain::OffchainWorkerApi;
35use serde::de::DeserializeOwned;
36use sp_api::{ApiExt, CallApiAt, ConstructRuntimeApi, Metadata};
37use sp_block_builder::BlockBuilder;
38use sp_runtime::{
39	traits::{Block as BlockT, BlockNumber, Header as HeaderT, NumberFor},
40	OpaqueExtrinsic,
41};
42use sp_session::SessionKeys;
43use sp_statement_store::runtime_api::ValidateStatement;
44use sp_transaction_pool::runtime_api::TaggedTransactionQueue;
45use std::{fmt::Debug, path::PathBuf, str::FromStr};
46
47pub trait NodeBlock:
48	BlockT<Extrinsic = OpaqueExtrinsic, Header = Self::BoundedHeader, Hash = DbHash> + DeserializeOwned
49{
50	type BoundedFromStrErr: Debug;
51	type BoundedNumber: FromStr<Err = Self::BoundedFromStrErr> + BlockNumber;
52	type BoundedHeader: HeaderT<Number = Self::BoundedNumber, Hash = DbHash> + Unpin;
53}
54
55impl<T> NodeBlock for T
56where
57	T: BlockT<Extrinsic = OpaqueExtrinsic, Hash = DbHash> + DeserializeOwned,
58	<T as BlockT>::Header: Unpin,
59	<NumberFor<T> as FromStr>::Err: Debug,
60{
61	type BoundedFromStrErr = <NumberFor<T> as FromStr>::Err;
62	type BoundedNumber = NumberFor<T>;
63	type BoundedHeader = <T as BlockT>::Header;
64}
65
66/// Convenience trait that defines the basic bounds for the `RuntimeApi` of a parachain node.
67pub trait NodeRuntimeApi<Block: BlockT>:
68	ApiExt<Block>
69	+ Metadata<Block>
70	+ SessionKeys<Block>
71	+ BlockBuilder<Block>
72	+ TaggedTransactionQueue<Block>
73	+ OffchainWorkerApi<Block>
74	+ CollectCollationInfo<Block>
75	+ ValidateStatement<Block>
76	+ GetParachainInfo<Block>
77	+ RelayParentOffsetApi<Block>
78	+ Sized
79{
80}
81
82impl<T, Block: BlockT> NodeRuntimeApi<Block> for T where
83	T: ApiExt<Block>
84		+ Metadata<Block>
85		+ SessionKeys<Block>
86		+ BlockBuilder<Block>
87		+ TaggedTransactionQueue<Block>
88		+ OffchainWorkerApi<Block>
89		+ RelayParentOffsetApi<Block>
90		+ CollectCollationInfo<Block>
91		+ ValidateStatement<Block>
92		+ GetParachainInfo<Block>
93{
94}
95
96/// Convenience trait that defines the basic bounds for the `ConstructRuntimeApi` of a parachain
97/// node.
98pub trait ConstructNodeRuntimeApi<Block: BlockT, C: CallApiAt<Block>>:
99	ConstructRuntimeApi<Block, C, RuntimeApi = Self::BoundedRuntimeApi> + Send + Sync + 'static
100{
101	/// Basic bounds for the `RuntimeApi` of a parachain node.
102	type BoundedRuntimeApi: NodeRuntimeApi<Block>;
103}
104
105impl<T, Block: BlockT, C: CallApiAt<Block>> ConstructNodeRuntimeApi<Block, C> for T
106where
107	T: ConstructRuntimeApi<Block, C> + Send + Sync + 'static,
108	T::RuntimeApi: NodeRuntimeApi<Block>,
109{
110	type BoundedRuntimeApi = T::RuntimeApi;
111}
112
113/// Extra args that are passed when creating a new node spec.
114pub struct NodeExtraArgs {
115	/// The authoring policy to use.
116	///
117	/// Can be used to influence details of block production.
118	pub authoring_policy: AuthoringPolicy,
119
120	/// If set, each `PoV` build by the node will be exported to this folder.
121	pub export_pov: Option<PathBuf>,
122
123	/// The maximum percentage of the maximum PoV size that the collator can use.
124	/// It will be removed once <https://github.com/paritytech/polkadot-sdk/issues/6020> is fixed.
125	pub max_pov_percentage: Option<u32>,
126
127	/// If true then the statement store will be enabled.
128	pub enable_statement_store: bool,
129}