From c7a1e6acae4a03babaf038a99712e2a067b4a483 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Mon, 11 Nov 2024 15:48:43 +0100 Subject: [PATCH] Rebase onto stable2409 --- Cargo.lock | 46 ++ Cargo.toml | 2 + .../testing/yet-another-parachain/Cargo.toml | 120 ++++ .../testing/yet-another-parachain/build.rs | 22 + .../testing/yet-another-parachain/src/lib.rs | 549 ++++++++++++++++++ cumulus/polkadot-parachain/Cargo.toml | 5 + .../polkadot-parachain/src/chain_spec/mod.rs | 22 + .../src/chain_spec/yet_another_parachain.rs | 101 ++++ 8 files changed, 867 insertions(+) create mode 100644 cumulus/parachains/runtimes/testing/yet-another-parachain/Cargo.toml create mode 100644 cumulus/parachains/runtimes/testing/yet-another-parachain/build.rs create mode 100644 cumulus/parachains/runtimes/testing/yet-another-parachain/src/lib.rs create mode 100644 cumulus/polkadot-parachain/src/chain_spec/yet_another_parachain.rs diff --git a/Cargo.lock b/Cargo.lock index 01db3951f95d..55676056fd00 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13890,6 +13890,7 @@ dependencies = [ "contracts-rococo-runtime", "coretime-rococo-runtime", "coretime-westend-runtime", + "cumulus-client-consensus-aura", "cumulus-primitives-core", "glutton-westend-runtime", "hex-literal", @@ -13909,9 +13910,11 @@ dependencies = [ "shell-runtime", "sp-core", "sp-genesis-builder", + "sp-keyring", "staging-xcm", "substrate-build-script-utils", "testnet-parachains-constants", + "yet-another-parachain-runtime", ] [[package]] @@ -24245,6 +24248,49 @@ dependencies = [ "time", ] +[[package]] +name = "yet-another-parachain-runtime" +version = "0.6.0" +dependencies = [ + "cumulus-pallet-aura-ext", + "cumulus-pallet-parachain-system", + "cumulus-primitives-aura", + "cumulus-primitives-core", + "cumulus-primitives-storage-weight-reclaim", + "cumulus-primitives-utility", + "frame-benchmarking", + "frame-executive", + "frame-support", + "frame-system", + "frame-system-rpc-runtime-api", + "pallet-assets", + "pallet-aura", + "pallet-balances", + "pallet-sudo", + "pallet-timestamp", + "pallet-transaction-payment", + "pallet-transaction-payment-rpc-runtime-api", + "parachains-common", + "parity-scale-codec", + "polkadot-parachain-primitives", + "polkadot-runtime-common", + "scale-info", + "sp-api", + "sp-block-builder", + "sp-consensus-aura", + "sp-core", + "sp-genesis-builder", + "sp-inherents", + "sp-offchain", + "sp-runtime", + "sp-session", + "sp-transaction-pool", + "sp-version", + "staging-parachain-info", + "substrate-wasm-builder", + "testnet-parachains-constants", +] + [[package]] name = "zerocopy" version = "0.7.32" diff --git a/Cargo.toml b/Cargo.toml index 2aa614f7aaa1..4eab11a191e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -135,6 +135,7 @@ members = [ "cumulus/parachains/runtimes/test-utils", "cumulus/parachains/runtimes/testing/penpal", "cumulus/parachains/runtimes/testing/rococo-parachain", + "cumulus/parachains/runtimes/testing/yet-another-parachain", "cumulus/polkadot-parachain", "cumulus/polkadot-parachain/polkadot-parachain-lib", "cumulus/primitives/aura", @@ -1363,6 +1364,7 @@ xcm-executor = { path = "polkadot/xcm/xcm-executor", default-features = false, p xcm-procedural = { path = "polkadot/xcm/procedural", default-features = false, version = "10.1.0" } xcm-runtime-apis = { path = "polkadot/xcm/xcm-runtime-apis", default-features = false, version = "0.4.0" } xcm-simulator = { path = "polkadot/xcm/xcm-simulator", default-features = false, version = "17.0.0" } +yet-another-parachain-runtime = { path = "cumulus/parachains/runtimes/testing/yet-another-parachain", version = "0.6.0" } zeroize = { version = "1.7.0", default-features = false } zstd = { version = "0.12.4", default-features = false } diff --git a/cumulus/parachains/runtimes/testing/yet-another-parachain/Cargo.toml b/cumulus/parachains/runtimes/testing/yet-another-parachain/Cargo.toml new file mode 100644 index 000000000000..b10db4774b71 --- /dev/null +++ b/cumulus/parachains/runtimes/testing/yet-another-parachain/Cargo.toml @@ -0,0 +1,120 @@ +[package] +name = "yet-another-parachain-runtime" +version = "0.6.0" +authors.workspace = true +edition.workspace = true +description = "Simple runtime used by the testing parachain(s)" +license = "Apache-2.0" + +[lints] +workspace = true + +[dependencies] +codec = { features = ["derive"], workspace = true } +scale-info = { features = ["derive"], workspace = true } + +# Substrate +frame-benchmarking = { optional = true, workspace = true } +frame-executive = { workspace = true } +frame-support = { workspace = true } +frame-system = { workspace = true } +frame-system-rpc-runtime-api = { workspace = true } +pallet-assets = { workspace = true } +pallet-aura = { workspace = true } +pallet-balances = { workspace = true } +pallet-sudo = { workspace = true } +pallet-timestamp = { workspace = true } +pallet-transaction-payment = { workspace = true } +pallet-transaction-payment-rpc-runtime-api = { workspace = true } +sp-api = { workspace = true } +sp-block-builder = { workspace = true } +sp-consensus-aura = { workspace = true } +sp-core = { workspace = true } +sp-genesis-builder = { workspace = true } +sp-inherents = { workspace = true } +sp-offchain = { workspace = true } +sp-runtime = { workspace = true } +sp-session = { workspace = true } +sp-transaction-pool = { workspace = true } +sp-version = { workspace = true } + +# Polkadot +polkadot-parachain-primitives = { workspace = true } +polkadot-runtime-common = { workspace = true } + +# Cumulus +cumulus-pallet-aura-ext = { workspace = true } +cumulus-pallet-parachain-system = { workspace = true } +cumulus-primitives-aura = { workspace = true } +cumulus-primitives-core = { workspace = true } +cumulus-primitives-storage-weight-reclaim = { workspace = true } +cumulus-primitives-utility = { workspace = true } +parachains-common = { workspace = true } +testnet-parachains-constants = { features = ["rococo"], workspace = true } +parachain-info = { workspace = true } + +[build-dependencies] +substrate-wasm-builder = { optional = true, workspace = true, default-features = true } + +[features] +default = ["std"] +std = [ + "codec/std", + "cumulus-pallet-aura-ext/std", + "cumulus-pallet-parachain-system/std", + "cumulus-primitives-aura/std", + "cumulus-primitives-core/std", + "cumulus-primitives-storage-weight-reclaim/std", + "cumulus-primitives-utility/std", + "frame-benchmarking?/std", + "frame-executive/std", + "frame-support/std", + "frame-system-rpc-runtime-api/std", + "frame-system/std", + "pallet-assets/std", + "pallet-aura/std", + "pallet-balances/std", + "pallet-sudo/std", + "pallet-timestamp/std", + "pallet-transaction-payment-rpc-runtime-api/std", + "pallet-transaction-payment/std", + "parachain-info/std", + "parachains-common/std", + "polkadot-parachain-primitives/std", + "polkadot-runtime-common/std", + "scale-info/std", + "sp-api/std", + "sp-block-builder/std", + "sp-consensus-aura/std", + "sp-core/std", + "sp-genesis-builder/std", + "sp-inherents/std", + "sp-offchain/std", + "sp-runtime/std", + "sp-session/std", + "sp-transaction-pool/std", + "sp-version/std", + "substrate-wasm-builder", + "testnet-parachains-constants/std", +] +runtime-benchmarks = [ + "cumulus-pallet-parachain-system/runtime-benchmarks", + "cumulus-primitives-core/runtime-benchmarks", + "cumulus-primitives-utility/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "pallet-assets/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-sudo/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", + "parachains-common/runtime-benchmarks", + "polkadot-parachain-primitives/runtime-benchmarks", + "polkadot-runtime-common/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", +] + +# A feature that should be enabled when the runtime should be built for on-chain +# deployment. This will disable stuff that shouldn't be part of the on-chain wasm +# to make it smaller, like logging for example. +on-chain-release-build = [] diff --git a/cumulus/parachains/runtimes/testing/yet-another-parachain/build.rs b/cumulus/parachains/runtimes/testing/yet-another-parachain/build.rs new file mode 100644 index 000000000000..239ccac19ec7 --- /dev/null +++ b/cumulus/parachains/runtimes/testing/yet-another-parachain/build.rs @@ -0,0 +1,22 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[cfg(feature = "std")] +fn main() { + substrate_wasm_builder::WasmBuilder::build_using_defaults(); +} + +#[cfg(not(feature = "std"))] +fn main() {} diff --git a/cumulus/parachains/runtimes/testing/yet-another-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/yet-another-parachain/src/lib.rs new file mode 100644 index 000000000000..ee1175c9f62e --- /dev/null +++ b/cumulus/parachains/runtimes/testing/yet-another-parachain/src/lib.rs @@ -0,0 +1,549 @@ +// 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 . + +#![cfg_attr(not(feature = "std"), no_std)] +// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. +#![recursion_limit = "256"] + +// Make the WASM binary available. +#[cfg(feature = "std")] +include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); + +extern crate alloc; + +use alloc::{vec, vec::Vec}; +use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; +use sp_api::impl_runtime_apis; +use sp_core::OpaqueMetadata; +use sp_runtime::{ + create_runtime_str, generic, impl_opaque_keys, + traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, Hash as HashT}, + transaction_validity::{TransactionSource, TransactionValidity}, + ApplyExtrinsicResult, +}; +#[cfg(feature = "std")] +use sp_version::NativeVersion; +use sp_version::RuntimeVersion; + +// A few exports that help ease life for downstream crates. +pub use frame_support::{ + construct_runtime, derive_impl, + dispatch::DispatchClass, + genesis_builder_helper::{build_state, get_preset}, + parameter_types, + traits::{ + AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, ConstU8, Contains, EitherOfDiverse, + Everything, HandleMessage, IsInVec, Nothing, QueueFootprint, Randomness, + }, + weights::{ + constants::{ + BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND, + }, + ConstantMultiplier, IdentityFee, Weight, + }, + BoundedSlice, StorageValue, +}; +use frame_system::limits::{BlockLength, BlockWeights}; +pub use pallet_balances::Call as BalancesCall; +pub use pallet_timestamp::Call as TimestampCall; +pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; +#[cfg(any(feature = "std", test))] +pub use sp_runtime::BuildStorage; +pub use sp_runtime::{Perbill, Permill}; + +use cumulus_primitives_core::AggregateMessageOrigin; //, ClaimQueueOffset, CoreSelector}; +use parachains_common::{AccountId, Signature}; + +pub type SessionHandlers = (); + +impl_opaque_keys! { + pub struct SessionKeys { + pub aura: Aura, + } +} + +/// This runtime version. +#[sp_version::runtime_version] +pub const VERSION: RuntimeVersion = RuntimeVersion { + spec_name: create_runtime_str!("yet-another-parachain"), + impl_name: create_runtime_str!("yet-another-parachain"), + authoring_version: 1, + spec_version: 1_001_001, + impl_version: 0, + apis: RUNTIME_API_VERSIONS, + transaction_version: 6, + state_version: 1, +}; + +pub const MILLISECS_PER_BLOCK: u64 = 6000; + +pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; + +pub const EPOCH_DURATION_IN_BLOCKS: u32 = 10 * MINUTES; + +// These time units are defined in number of blocks. +pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); +pub const HOURS: BlockNumber = MINUTES * 60; +pub const DAYS: BlockNumber = HOURS * 24; + +pub const YAP: Balance = 1_000_000_000_000; +pub const MILLIYAP: Balance = 1_000_000_000; +pub const MICROYAP: Balance = 1_000_000; + +// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks. +pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4); + +/// The version information used to identify this runtime when compiled natively. +#[cfg(feature = "std")] +pub fn native_version() -> NativeVersion { + NativeVersion { runtime_version: VERSION, can_author_with: Default::default() } +} + +/// We assume that ~10% of the block weight is consumed by `on_initialize` handlers. +/// This is used to limit the maximal weight of a single extrinsic. +const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10); +/// We allow `Normal` extrinsics to fill up the block up to 95%, the rest can be used +/// by Operational extrinsics. +const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(95); +/// We allow for 2 seconds of compute with a 6 second average block time. +const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts( + WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2), + cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64, +); + +/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included +/// into the relay chain. +const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3; +/// How many parachain blocks are processed by the relay chain per parent. Limits the +/// number of blocks authored per slot. +const BLOCK_PROCESSING_VELOCITY: u32 = 2; +/// Relay chain slot duration, in milliseconds. +const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000; + +parameter_types! { + pub const BlockHashCount: BlockNumber = 250; + pub const Version: RuntimeVersion = VERSION; + pub RuntimeBlockLength: BlockLength = + BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); + pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder() + .base_block(BlockExecutionWeight::get()) + .for_class(DispatchClass::all(), |weights| { + weights.base_extrinsic = ExtrinsicBaseWeight::get(); + }) + .for_class(DispatchClass::Normal, |weights| { + weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT); + }) + .for_class(DispatchClass::Operational, |weights| { + weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT); + // Operational transactions have some extra reserved space, so that they + // are included even if block reached `MAXIMUM_BLOCK_WEIGHT`. + weights.reserved = Some( + MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT + ); + }) + .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO) + .build_or_panic(); + pub const SS58Prefix: u8 = 42; +} + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] +impl frame_system::Config for Runtime { + /// The identifier used to distinguish between accounts. + type AccountId = AccountId; + /// The aggregated dispatch type that is available for extrinsics. + type RuntimeCall = RuntimeCall; + /// The lookup mechanism to get account ID from whatever is passed in dispatchers. + type Lookup = AccountIdLookup; + /// The index type for storing how many extrinsics an account has signed. + type Nonce = Nonce; + /// The type for hashing blocks and tries. + type Hash = Hash; + /// The hashing algorithm used. + type Hashing = BlakeTwo256; + /// The block type. + type Block = Block; + /// The ubiquitous event type. + type RuntimeEvent = RuntimeEvent; + /// The ubiquitous origin type. + type RuntimeOrigin = RuntimeOrigin; + /// Maximum number of block number to block hash mappings to keep (oldest pruned first). + type BlockHashCount = BlockHashCount; + /// Runtime version. + type Version = Version; + /// Converts a module to an index of this module in the runtime. + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type DbWeight = RocksDbWeight; + type BaseCallFilter = frame_support::traits::Everything; + type SystemWeightInfo = (); + type BlockWeights = RuntimeBlockWeights; + type BlockLength = RuntimeBlockLength; + type SS58Prefix = SS58Prefix; + type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; + type MaxConsumers = frame_support::traits::ConstU32<16>; +} + +impl pallet_timestamp::Config for Runtime { + /// A timestamp: milliseconds since the unix epoch. + type Moment = u64; + type OnTimestampSet = Aura; + type MinimumPeriod = ConstU64<0>; + type WeightInfo = (); +} + +parameter_types! { + pub const ExistentialDeposit: u128 = MILLIYAP; + pub const TransferFee: u128 = MILLIYAP; + pub const CreationFee: u128 = MILLIYAP; + pub const TransactionByteFee: u128 = MICROYAP; +} + +impl pallet_balances::Config for Runtime { + /// The type for recording an account's balance. + type Balance = Balance; + type DustRemoval = (); + /// The ubiquitous event type. + type RuntimeEvent = RuntimeEvent; + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxLocks = ConstU32<50>; + type MaxReserves = ConstU32<50>; + type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = RuntimeHoldReason; + type RuntimeFreezeReason = RuntimeFreezeReason; + type FreezeIdentifier = (); + type MaxFreezes = ConstU32<0>; +} + +impl pallet_transaction_payment::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter; + type WeightToFee = IdentityFee; + type LengthToFee = ConstantMultiplier; + type FeeMultiplierUpdate = (); + type OperationalFeeMultiplier = ConstU8<5>; +} + +impl pallet_sudo::Config for Runtime { + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type WeightInfo = pallet_sudo::weights::SubstrateWeight; +} + +parameter_types! { + pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); + pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); + pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent; +} + +type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< + Runtime, + RELAY_CHAIN_SLOT_DURATION_MILLIS, + BLOCK_PROCESSING_VELOCITY, + UNINCLUDED_SEGMENT_CAPACITY, +>; + +pub struct DmpSink; +impl HandleMessage for DmpSink { + type MaxMessageLen = ConstU32<16>; + + fn handle_message(_msg: BoundedSlice) {} + + fn handle_messages<'a>(_: impl Iterator>) { + unimplemented!() + } + + fn sweep_queue() { + unimplemented!() + } + + fn footprint() -> QueueFootprint { + unimplemented!() + } +} + +impl cumulus_pallet_parachain_system::Config for Runtime { + type WeightInfo = (); + type RuntimeEvent = RuntimeEvent; + type OnSystemEvent = (); + type SelfParaId = parachain_info::Pallet; + type OutboundXcmpMessageSource = (); + type DmpQueue = DmpSink; + type ReservedDmpWeight = (); + type XcmpMessageHandler = (); + type ReservedXcmpWeight = (); + type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases; + type ConsensusHook = ConsensusHook; +} + +impl parachain_info::Config for Runtime {} + +impl cumulus_pallet_aura_ext::Config for Runtime {} + +impl pallet_aura::Config for Runtime { + type AuthorityId = AuraId; + type DisabledValidators = (); + type MaxAuthorities = ConstU32<100_000>; + type AllowMultipleBlocksPerSlot = ConstBool; + type SlotDuration = ConstU64; +} + +construct_runtime! { + pub enum Runtime + { + System: frame_system, + Timestamp: pallet_timestamp, + Sudo: pallet_sudo, + TransactionPayment: pallet_transaction_payment, + + ParachainSystem: cumulus_pallet_parachain_system = 20, + ParachainInfo: parachain_info = 21, + + Balances: pallet_balances = 30, + + Aura: pallet_aura, + AuraExt: cumulus_pallet_aura_ext, + } +} + +/// Balance of an account. +pub type Balance = u128; +/// Index of a transaction in the chain. +pub type Nonce = u32; +/// A hash of some data used by the chain. +pub type Hash = ::Output; +/// An index to a block. +pub type BlockNumber = u32; +/// The address format for describing accounts. +pub type Address = sp_runtime::MultiAddress; +/// Block header type as expected by this runtime. +pub type Header = generic::Header; +/// Block type as expected by this runtime. +pub type Block = generic::Block; +/// A Block signed with a Justification +pub type SignedBlock = generic::SignedBlock; +/// BlockId type as expected by this runtime. +pub type BlockId = generic::BlockId; +/// The SignedExtension to the basic transaction logic. +pub type SignedExtra = ( + frame_system::CheckNonZeroSender, + frame_system::CheckSpecVersion, + frame_system::CheckTxVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + frame_system::CheckWeight, + pallet_transaction_payment::ChargeTransactionPayment, + cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim, +); +/// Unchecked extrinsic type as expected by this runtime. +pub type UncheckedExtrinsic = + generic::UncheckedExtrinsic; +/// Executive: handles dispatch to the various modules. +pub type Executive = frame_executive::Executive< + Runtime, + Block, + frame_system::ChainContext, + Runtime, + AllPalletsWithSystem, + RemoveCollectiveFlip, +>; + +pub struct RemoveCollectiveFlip; +impl frame_support::traits::OnRuntimeUpgrade for RemoveCollectiveFlip { + fn on_runtime_upgrade() -> Weight { + use frame_support::storage::migration; + // Remove the storage value `RandomMaterial` from removed pallet `RandomnessCollectiveFlip` + #[allow(deprecated)] + migration::remove_storage_prefix(b"RandomnessCollectiveFlip", b"RandomMaterial", b""); + ::DbWeight::get().writes(1) + } +} + +impl_runtime_apis! { + impl sp_api::Core for Runtime { + fn version() -> RuntimeVersion { + VERSION + } + + fn execute_block(block: Block) { + Executive::execute_block(block); + } + + fn initialize_block(header: &::Header) -> sp_runtime::ExtrinsicInclusionMode { + Executive::initialize_block(header) + } + } + + impl sp_api::Metadata for Runtime { + fn metadata() -> OpaqueMetadata { + OpaqueMetadata::new(Runtime::metadata().into()) + } + + fn metadata_at_version(version: u32) -> Option { + Runtime::metadata_at_version(version) + } + + fn metadata_versions() -> alloc::vec::Vec { + Runtime::metadata_versions() + } + } + + impl sp_block_builder::BlockBuilder for Runtime { + fn apply_extrinsic( + extrinsic: ::Extrinsic, + ) -> ApplyExtrinsicResult { + Executive::apply_extrinsic(extrinsic) + } + + fn finalize_block() -> ::Header { + Executive::finalize_block() + } + + fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<::Extrinsic> { + data.create_extrinsics() + } + + fn check_inherents(block: Block, data: sp_inherents::InherentData) -> sp_inherents::CheckInherentsResult { + data.check_extrinsics(&block) + } + } + + impl sp_transaction_pool::runtime_api::TaggedTransactionQueue for Runtime { + fn validate_transaction( + source: TransactionSource, + tx: ::Extrinsic, + block_hash: ::Hash, + ) -> TransactionValidity { + Executive::validate_transaction(source, tx, block_hash) + } + } + + impl sp_offchain::OffchainWorkerApi for Runtime { + fn offchain_worker(header: &::Header) { + Executive::offchain_worker(header) + } + } + + impl sp_session::SessionKeys for Runtime { + fn decode_session_keys( + encoded: Vec, + ) -> Option, sp_core::crypto::KeyTypeId)>> { + SessionKeys::decode_into_raw_public_keys(&encoded) + } + + fn generate_session_keys(seed: Option>) -> Vec { + SessionKeys::generate(seed) + } + } + + impl sp_consensus_aura::AuraApi for Runtime { + fn slot_duration() -> sp_consensus_aura::SlotDuration { + sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration()) + } + + fn authorities() -> Vec { + pallet_aura::Authorities::::get().into_inner() + } + } + + impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { + fn account_nonce(account: AccountId) -> Nonce { + System::account_nonce(account) + } + } + + impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi for Runtime { + fn query_info( + uxt: ::Extrinsic, + len: u32, + ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo { + TransactionPayment::query_info(uxt, len) + } + fn query_fee_details( + uxt: ::Extrinsic, + len: u32, + ) -> pallet_transaction_payment::FeeDetails { + TransactionPayment::query_fee_details(uxt, len) + } + fn query_weight_to_fee(weight: Weight) -> Balance { + TransactionPayment::weight_to_fee(weight) + } + fn query_length_to_fee(length: u32) -> Balance { + TransactionPayment::length_to_fee(length) + } + } + + impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi + for Runtime + { + fn query_call_info( + call: RuntimeCall, + len: u32, + ) -> pallet_transaction_payment::RuntimeDispatchInfo { + TransactionPayment::query_call_info(call, len) + } + fn query_call_fee_details( + call: RuntimeCall, + len: u32, + ) -> pallet_transaction_payment::FeeDetails { + TransactionPayment::query_call_fee_details(call, len) + } + fn query_weight_to_fee(weight: Weight) -> Balance { + TransactionPayment::weight_to_fee(weight) + } + fn query_length_to_fee(length: u32) -> Balance { + TransactionPayment::length_to_fee(length) + } + } + + impl cumulus_primitives_core::CollectCollationInfo for Runtime { + fn collect_collation_info(header: &::Header) -> cumulus_primitives_core::CollationInfo { + ParachainSystem::collect_collation_info(header) + } + } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) + } + + fn get_preset(id: &Option) -> Option> { + get_preset::(id, |_| None) + } + + fn preset_names() -> Vec { + vec![] + } + } + + impl cumulus_primitives_aura::AuraUnincludedSegmentApi for Runtime { + fn can_build_upon( + included_hash: ::Hash, + slot: cumulus_primitives_aura::Slot, + ) -> bool { + ConsensusHook::can_build_upon(included_hash, slot) + } + } +} + +cumulus_pallet_parachain_system::register_validate_block! { + Runtime = Runtime, + BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::, +} diff --git a/cumulus/polkadot-parachain/Cargo.toml b/cumulus/polkadot-parachain/Cargo.toml index 8c0f723d3f5c..2780599b74bb 100644 --- a/cumulus/polkadot-parachain/Cargo.toml +++ b/cumulus/polkadot-parachain/Cargo.toml @@ -53,12 +53,15 @@ sc-chain-spec.workspace = true sc-chain-spec.default-features = true sp-genesis-builder.workspace = true sp-genesis-builder.default-features = true +sp-keyring.workspace = true xcm.workspace = true xcm.default-features = true cumulus-primitives-core.workspace = true cumulus-primitives-core.default-features = true bp-messages.workspace = true bp-messages.default-features = true +cumulus-client-consensus-aura.workspace = true +yet-another-parachain-runtime.workspace = true [build-dependencies] substrate-build-script-utils.workspace = true @@ -85,6 +88,7 @@ runtime-benchmarks = [ "people-rococo-runtime/runtime-benchmarks", "people-westend-runtime/runtime-benchmarks", "rococo-parachain-runtime/runtime-benchmarks", + "yet-another-parachain-runtime/runtime-benchmarks", ] try-runtime = [ "polkadot-parachain-lib/try-runtime", @@ -109,3 +113,4 @@ fast-runtime = [ "coretime-rococo-runtime/fast-runtime", "coretime-westend-runtime/fast-runtime", ] +full-pov-size = ["cumulus-client-consensus-aura/full-pov-size"] diff --git a/cumulus/polkadot-parachain/src/chain_spec/mod.rs b/cumulus/polkadot-parachain/src/chain_spec/mod.rs index adb3eb2c0e04..1a03ad392b9f 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/mod.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/mod.rs @@ -25,6 +25,8 @@ use polkadot_parachain_lib::{ }, }; use sc_chain_spec::ChainSpec; +use sc_service::ChainType; +use yet_another_parachain::yet_another_parachain_config; pub mod asset_hubs; pub mod bridge_hubs; @@ -36,6 +38,7 @@ pub mod people; pub mod rococo_parachain; pub mod seedling; pub mod shell; +pub mod yet_another_parachain; /// The default XCM version to set in genesis config. const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; @@ -178,6 +181,25 @@ impl LoadSpec for ChainSpecLoader { )) }, + id if id.starts_with("yap-") => { + let tok: Vec = id.split('-').map(|s| s.to_owned()).collect(); + assert!( + tok.len() == 4, + "Invalid YAP chain id, should be 'yap---'" + ); + let relay = if &tok[2] == "live" { tok[1].clone() } else { tok[1..=2].join("-") }; + let chain_type = match tok[2].as_str() { + "local" => ChainType::Local, + "dev" => ChainType::Development, + "live" => ChainType::Live, + _ => unimplemented!("Unknown chain type {}", tok[2]), + }; + let para_id: u32 = + tok[3].parse().expect(&format!("Illegal para id '{}' provided", tok[3])); + + Box::new(yet_another_parachain_config(relay, chain_type, para_id)) + }, + // -- People people_like_id if people_like_id.starts_with(people::PeopleRuntimeType::ID_PREFIX) => people_like_id diff --git a/cumulus/polkadot-parachain/src/chain_spec/yet_another_parachain.rs b/cumulus/polkadot-parachain/src/chain_spec/yet_another_parachain.rs new file mode 100644 index 000000000000..f8085fbd4ec5 --- /dev/null +++ b/cumulus/polkadot-parachain/src/chain_spec/yet_another_parachain.rs @@ -0,0 +1,101 @@ +// 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 . + +//! ChainSpecs dedicated to parachain setups for testing and example purposes + +use polkadot_parachain_lib::chain_spec::{Extensions, GenericChainSpec}; +use sc_chain_spec::ChainType; +use sp_core::{sr25519::Pair as SrPair, Pair}; +use sp_keyring::Sr25519Keyring as Keyring; +use yet_another_parachain_runtime::AuraId; + +const NUM_ACCOUNT_PAIRS: usize = 16000; + +fn derive_accounts(n: usize, seed: String) -> Vec { + let t = std::cmp::min( + n, + std::thread::available_parallelism().unwrap_or(1usize.try_into().unwrap()).get(), + ); + + let mut tn = (0..t).cycle(); + let mut tranges: Vec<_> = (0..t).map(|_| Vec::new()).collect(); + (0..n).for_each(|i| tranges[tn.next().unwrap()].push(i)); + let mut threads = Vec::new(); + + tranges.into_iter().for_each(|chunk| { + let seed = seed.clone(); + threads.push(std::thread::spawn(move || { + chunk + .into_iter() + .map(move |i| { + let derivation = format!("{seed}/{i}"); + ::from_string(&derivation, None).unwrap() + }) + .collect::>() + })); + }); + + threads + .into_iter() + .map(|h| h.join().unwrap()) + .flatten() + // .map(|p| (p, funds)) + .collect() +} + +pub fn yet_another_parachain_config( + relay: impl Into, + chain_type: ChainType, + para_id: u32, +) -> GenericChainSpec { + let mut endowed_accounts = vec![ + Keyring::Alice.to_account_id(), + Keyring::Bob.to_account_id(), + Keyring::AliceStash.to_account_id(), + Keyring::BobStash.to_account_id(), + ]; + + endowed_accounts.extend( + derive_accounts(NUM_ACCOUNT_PAIRS, "//Sender".into()) + .into_iter() + .map(|k| k.public().into()), + ); + endowed_accounts.extend( + derive_accounts(NUM_ACCOUNT_PAIRS, "//Receiver".into()) + .into_iter() + .map(|k| k.public().into()), + ); + + GenericChainSpec::builder( + yet_another_parachain_runtime::WASM_BINARY + .expect("WASM binary was not built, please build it!"), + Extensions { relay_chain: relay.into(), para_id }, + ) + .with_name("Yet Another Parachain") + .with_id("yet_another_parachain") + .with_chain_type(chain_type) + .with_genesis_config_patch(serde_json::json!({ + "balances": { + "balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::>(), + }, + "sudo": { "key": Some(Keyring::Alice.to_account_id()) }, + "parachainInfo": { + "parachainId": para_id, + }, + "aura": { "authorities": vec![Into::::into(Keyring::Alice.public()), Keyring::Bob.public().into()] }, + })) + .build() +}