Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polkadot-parachain: Add omni-node variant with u64 block number #5269

Merged
merged 12 commits into from
Aug 28, 2024
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ sc-consensus = { workspace = true, default-features = true }
frame-support = { optional = true, workspace = true, default-features = true }
sc-cli = { workspace = true, default-features = true }
sc-client-api = { workspace = true, default-features = true }
sc-client-db = { workspace = true, default-features = true }
sc-executor = { workspace = true, default-features = true }
sc-service = { workspace = true, default-features = true }
sc-telemetry = { workspace = true, default-features = true }
Expand Down Expand Up @@ -105,6 +106,7 @@ runtime-benchmarks = [
"parachains-common/runtime-benchmarks",
"polkadot-cli/runtime-benchmarks",
"polkadot-primitives/runtime-benchmarks",
"sc-client-db/runtime-benchmarks",
"sc-service/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
Expand Down
39 changes: 26 additions & 13 deletions cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

#[cfg(feature = "runtime-benchmarks")]
use crate::service::Block;
use crate::{
cli::{Cli, RelayChainCli, Subcommand},
common::{
Expand All @@ -24,20 +22,19 @@ use crate::{
AuraConsensusId, Consensus, Runtime, RuntimeResolver as RuntimeResolverT,
RuntimeResolver,
},
spec::DynNodeSpec,
types::{Block, CustomBlock},
NodeExtraArgs,
},
fake_runtime_api::{
asset_hub_polkadot_aura::RuntimeApi as AssetHubPolkadotRuntimeApi,
aura::RuntimeApi as AuraRuntimeApi,
},
service::{new_aura_node_spec, DynNodeSpec, ShellNode},
fake_runtime_api,
runtime::BlockNumber,
service::{new_aura_node_spec, ShellNode},
};
#[cfg(feature = "runtime-benchmarks")]
use cumulus_client_service::storage_proof_size::HostFunctions as ReclaimHostFunctions;
use cumulus_primitives_core::ParaId;
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
use log::info;
use parachains_common::{AssetHubPolkadotAuraId, AuraId};
use sc_cli::{Result, SubstrateCli};
use sp_runtime::traits::AccountIdConversion;
#[cfg(feature = "runtime-benchmarks")]
Expand All @@ -59,11 +56,27 @@ fn new_node_spec(

Ok(match runtime {
Runtime::Shell => Box::new(ShellNode),
Runtime::Omni(consensus) => match consensus {
Consensus::Aura(AuraConsensusId::Sr25519) =>
new_aura_node_spec::<AuraRuntimeApi, AuraId>(extra_args),
Consensus::Aura(AuraConsensusId::Ed25519) =>
new_aura_node_spec::<AssetHubPolkadotRuntimeApi, AssetHubPolkadotAuraId>(extra_args),
Runtime::Omni(block_number, consensus) => match (block_number, consensus) {
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
(BlockNumber::U32, Consensus::Aura(AuraConsensusId::Sr25519)) => new_aura_node_spec::<
Block,
fake_runtime_api::u32_block::aura_sr25519::RuntimeApi,
sp_consensus_aura::sr25519::AuthorityId,
>(extra_args),
(BlockNumber::U32, Consensus::Aura(AuraConsensusId::Ed25519)) => new_aura_node_spec::<
Block,
fake_runtime_api::u32_block::aura_ed25519::RuntimeApi,
sp_consensus_aura::ed25519::AuthorityId,
>(extra_args),
(BlockNumber::U64, Consensus::Aura(AuraConsensusId::Sr25519)) => new_aura_node_spec::<
CustomBlock<u64>,
fake_runtime_api::u64_block::aura_sr25519::RuntimeApi,
sp_consensus_aura::sr25519::AuthorityId,
>(extra_args),
(BlockNumber::U64, Consensus::Aura(AuraConsensusId::Ed25519)) => new_aura_node_spec::<
CustomBlock<u64>,
fake_runtime_api::u64_block::aura_ed25519::RuntimeApi,
sp_consensus_aura::ed25519::AuthorityId,
>(extra_args),
},
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Cumulus.

// Cumulus is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Cumulus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

use crate::common::spec::NodeSpec;
use cumulus_client_cli::ExportGenesisHeadCommand;
use frame_benchmarking_cli::BlockCmd;
#[cfg(any(feature = "runtime-benchmarks"))]
use frame_benchmarking_cli::StorageCmd;
use sc_cli::{CheckBlockCmd, ExportBlocksCmd, ExportStateCmd, ImportBlocksCmd, RevertCmd};
use sc_service::{Configuration, TaskManager};
use std::{future::Future, pin::Pin};

type SyncCmdResult = sc_cli::Result<()>;

type AsyncCmdResult<'a> =
sc_cli::Result<(Pin<Box<dyn Future<Output = SyncCmdResult> + 'a>>, TaskManager)>;

pub trait NodeCommandRunner {
fn prepare_check_block_cmd(
self: Box<Self>,
config: Configuration,
cmd: &CheckBlockCmd,
) -> AsyncCmdResult<'_>;

fn prepare_export_blocks_cmd(
self: Box<Self>,
config: Configuration,
cmd: &ExportBlocksCmd,
) -> AsyncCmdResult<'_>;

fn prepare_export_state_cmd(
self: Box<Self>,
config: Configuration,
cmd: &ExportStateCmd,
) -> AsyncCmdResult<'_>;

fn prepare_import_blocks_cmd(
self: Box<Self>,
config: Configuration,
cmd: &ImportBlocksCmd,
) -> AsyncCmdResult<'_>;

fn prepare_revert_cmd(
self: Box<Self>,
config: Configuration,
cmd: &RevertCmd,
) -> AsyncCmdResult<'_>;

fn run_export_genesis_head_cmd(
self: Box<Self>,
config: Configuration,
cmd: &ExportGenesisHeadCommand,
) -> SyncCmdResult;

fn run_benchmark_block_cmd(
self: Box<Self>,
config: Configuration,
cmd: &BlockCmd,
) -> SyncCmdResult;

#[cfg(any(feature = "runtime-benchmarks"))]
fn run_benchmark_storage_cmd(
self: Box<Self>,
config: Configuration,
cmd: &StorageCmd,
) -> SyncCmdResult;
}

impl<T> NodeCommandRunner for T
where
T: NodeSpec,
{
fn prepare_check_block_cmd(
self: Box<Self>,
config: Configuration,
cmd: &CheckBlockCmd,
) -> AsyncCmdResult<'_> {
let partial = T::new_partial(&config).map_err(sc_cli::Error::Service)?;
Ok((Box::pin(cmd.run(partial.client, partial.import_queue)), partial.task_manager))
}

fn prepare_export_blocks_cmd(
self: Box<Self>,
config: Configuration,
cmd: &ExportBlocksCmd,
) -> AsyncCmdResult<'_> {
let partial = T::new_partial(&config).map_err(sc_cli::Error::Service)?;
Ok((Box::pin(cmd.run(partial.client, config.database)), partial.task_manager))
}

fn prepare_export_state_cmd(
self: Box<Self>,
config: Configuration,
cmd: &ExportStateCmd,
) -> AsyncCmdResult<'_> {
let partial = T::new_partial(&config).map_err(sc_cli::Error::Service)?;
Ok((Box::pin(cmd.run(partial.client, config.chain_spec)), partial.task_manager))
}

fn prepare_import_blocks_cmd(
self: Box<Self>,
config: Configuration,
cmd: &ImportBlocksCmd,
) -> AsyncCmdResult<'_> {
let partial = T::new_partial(&config).map_err(sc_cli::Error::Service)?;
Ok((Box::pin(cmd.run(partial.client, partial.import_queue)), partial.task_manager))
}

fn prepare_revert_cmd(
self: Box<Self>,
config: Configuration,
cmd: &RevertCmd,
) -> AsyncCmdResult<'_> {
let partial = T::new_partial(&config).map_err(sc_cli::Error::Service)?;
Ok((Box::pin(cmd.run(partial.client, partial.backend, None)), partial.task_manager))
}

fn run_export_genesis_head_cmd(
self: Box<Self>,
config: Configuration,
cmd: &ExportGenesisHeadCommand,
) -> SyncCmdResult {
let partial = T::new_partial(&config).map_err(sc_cli::Error::Service)?;
cmd.run(partial.client)
}

fn run_benchmark_block_cmd(
self: Box<Self>,
config: Configuration,
cmd: &BlockCmd,
) -> SyncCmdResult {
let partial = T::new_partial(&config).map_err(sc_cli::Error::Service)?;
cmd.run(partial.client)
}

#[cfg(any(feature = "runtime-benchmarks"))]
fn run_benchmark_storage_cmd(
self: Box<Self>,
config: Configuration,
cmd: &StorageCmd,
) -> SyncCmdResult {
let partial = T::new_partial(&config).map_err(sc_cli::Error::Service)?;
let db = partial.backend.expose_db();
let storage = partial.backend.expose_storage();

cmd.run(config, partial.client, db, storage)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,43 @@

pub(crate) mod aura;
pub mod chain_spec;
pub mod command;
pub mod rpc;
pub mod runtime;
pub mod spec;
pub mod types;

use cumulus_primitives_core::CollectCollationInfo;
use sc_client_db::DbHash;
use sp_api::{ApiExt, CallApiAt, ConstructRuntimeApi, Metadata};
use sp_block_builder::BlockBuilder;
use sp_runtime::traits::Block as BlockT;
use sp_runtime::{
traits::{Block as BlockT, BlockNumber, Header as HeaderT, NumberFor},
OpaqueExtrinsic,
};
use sp_session::SessionKeys;
use sp_transaction_pool::runtime_api::TaggedTransactionQueue;
use std::path::PathBuf;
use std::{fmt::Debug, path::PathBuf, str::FromStr};

pub trait NodeBlock:
BlockT<Extrinsic = OpaqueExtrinsic, Header = Self::BoundedHeader, Hash = DbHash>
+ for<'de> serde::Deserialize<'de>
{
type BoundedFromStrErr: Debug;
type BoundedNumber: FromStr<Err = Self::BoundedFromStrErr> + BlockNumber;
type BoundedHeader: HeaderT<Number = Self::BoundedNumber> + Unpin;
}

impl<T> NodeBlock for T
where
T: BlockT<Extrinsic = OpaqueExtrinsic, Hash = DbHash> + for<'de> serde::Deserialize<'de>,
<T as BlockT>::Header: Unpin,
<NumberFor<T> as FromStr>::Err: Debug,
{
type BoundedFromStrErr = <NumberFor<T> as FromStr>::Err;
type BoundedNumber = NumberFor<T>;
type BoundedHeader = <T as BlockT>::Header;
}

/// Convenience trait that defines the basic bounds for the `RuntimeApi` of a parachain node.
pub trait NodeRuntimeApi<Block: BlockT>:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@

#![warn(missing_docs)]

use crate::{
common::ConstructNodeRuntimeApi,
service::{ParachainBackend, ParachainClient},
use crate::common::{
types::{AccountId, Balance, Nonce, ParachainBackend, ParachainClient},
ConstructNodeRuntimeApi,
};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use parachains_common::{AccountId, Balance, Block, Nonce};
use sc_rpc::{
dev::{Dev, DevApiServer},
DenyUnsafe,
};
use sp_runtime::traits::Block as BlockT;
use std::{marker::PhantomData, sync::Arc};
use substrate_frame_rpc_system::{System, SystemApiServer};
use substrate_state_trie_migration_rpc::{StateMigration, StateMigrationApiServer};
Expand All @@ -44,45 +44,47 @@ pub(crate) trait BuildRpcExtensions<Client, Backend, Pool> {
) -> sc_service::error::Result<RpcExtension>;
}

pub(crate) struct BuildEmptyRpcExtensions<RuntimeApi>(PhantomData<RuntimeApi>);
pub(crate) struct BuildEmptyRpcExtensions<Block, RuntimeApi>(PhantomData<(Block, RuntimeApi)>);

impl<RuntimeApi>
impl<Block: BlockT, RuntimeApi>
BuildRpcExtensions<
ParachainClient<RuntimeApi>,
ParachainBackend,
sc_transaction_pool::FullPool<Block, ParachainClient<RuntimeApi>>,
> for BuildEmptyRpcExtensions<RuntimeApi>
ParachainClient<Block, RuntimeApi>,
ParachainBackend<Block>,
sc_transaction_pool::FullPool<Block, ParachainClient<Block, RuntimeApi>>,
> for BuildEmptyRpcExtensions<Block, RuntimeApi>
where
RuntimeApi: ConstructNodeRuntimeApi<Block, ParachainClient<RuntimeApi>> + Send + Sync + 'static,
RuntimeApi:
ConstructNodeRuntimeApi<Block, ParachainClient<Block, RuntimeApi>> + Send + Sync + 'static,
{
fn build_rpc_extensions(
_deny_unsafe: DenyUnsafe,
_client: Arc<ParachainClient<RuntimeApi>>,
_backend: Arc<ParachainBackend>,
_pool: Arc<sc_transaction_pool::FullPool<Block, ParachainClient<RuntimeApi>>>,
_client: Arc<ParachainClient<Block, RuntimeApi>>,
_backend: Arc<ParachainBackend<Block>>,
_pool: Arc<sc_transaction_pool::FullPool<Block, ParachainClient<Block, RuntimeApi>>>,
) -> sc_service::error::Result<RpcExtension> {
Ok(RpcExtension::new(()))
}
}

pub(crate) struct BuildParachainRpcExtensions<RuntimeApi>(PhantomData<RuntimeApi>);
pub(crate) struct BuildParachainRpcExtensions<Block, RuntimeApi>(PhantomData<(Block, RuntimeApi)>);

impl<RuntimeApi>
impl<Block: BlockT, RuntimeApi>
BuildRpcExtensions<
ParachainClient<RuntimeApi>,
ParachainBackend,
sc_transaction_pool::FullPool<Block, ParachainClient<RuntimeApi>>,
> for BuildParachainRpcExtensions<RuntimeApi>
ParachainClient<Block, RuntimeApi>,
ParachainBackend<Block>,
sc_transaction_pool::FullPool<Block, ParachainClient<Block, RuntimeApi>>,
> for BuildParachainRpcExtensions<Block, RuntimeApi>
where
RuntimeApi: ConstructNodeRuntimeApi<Block, ParachainClient<RuntimeApi>> + Send + Sync + 'static,
RuntimeApi:
ConstructNodeRuntimeApi<Block, ParachainClient<Block, RuntimeApi>> + Send + Sync + 'static,
RuntimeApi::RuntimeApi: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
{
fn build_rpc_extensions(
deny_unsafe: DenyUnsafe,
client: Arc<ParachainClient<RuntimeApi>>,
backend: Arc<ParachainBackend>,
pool: Arc<sc_transaction_pool::FullPool<Block, ParachainClient<RuntimeApi>>>,
client: Arc<ParachainClient<Block, RuntimeApi>>,
backend: Arc<ParachainBackend<Block>>,
pool: Arc<sc_transaction_pool::FullPool<Block, ParachainClient<Block, RuntimeApi>>>,
) -> sc_service::error::Result<RpcExtension> {
let build = || -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>> {
let mut module = RpcExtension::new(());
Expand Down
Loading
Loading