From 5113d3151be099b446867088f19622641a83a3a8 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Tue, 8 Oct 2024 12:42:15 +0300 Subject: [PATCH 01/12] pallet-parachain-template --- Cargo.lock | 7 +-- .../parachain/pallets/template/Cargo.toml | 47 ++++--------------- .../pallets/template/src/benchmarking.rs | 2 +- .../parachain/pallets/template/src/lib.rs | 17 +++---- .../parachain/pallets/template/src/mock.rs | 11 +++-- .../parachain/pallets/template/src/tests.rs | 2 +- .../parachain/pallets/template/src/weights.rs | 3 +- 7 files changed, 31 insertions(+), 58 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 34e30d79e98b..a97f4ad3b15c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12176,14 +12176,9 @@ dependencies = [ name = "pallet-parachain-template" version = "0.0.0" dependencies = [ - "frame-benchmarking", - "frame-support", - "frame-system", "parity-scale-codec", + "polkadot-sdk", "scale-info", - "sp-core 28.0.0", - "sp-io 30.0.0", - "sp-runtime 31.0.1", ] [[package]] diff --git a/templates/parachain/pallets/template/Cargo.toml b/templates/parachain/pallets/template/Cargo.toml index dde863101372..c79dfc309a9b 100644 --- a/templates/parachain/pallets/template/Cargo.toml +++ b/templates/parachain/pallets/template/Cargo.toml @@ -13,45 +13,16 @@ publish = false targets = ["x86_64-unknown-linux-gnu"] [dependencies] -codec = { features = [ - "derive", -], workspace = true } -scale-info = { features = [ - "derive", -], workspace = true } +codec = { features = ["derive"], workspace = true } +scale-info = { features = ["derive"], workspace = true } -# frame deps -frame-benchmarking = { optional = true, workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } - -# primitive deps -sp-runtime = { workspace = true } - -[dev-dependencies] -sp-core = { workspace = true, default-features = true } -sp-io = { workspace = true, default-features = true } +polkadot-sdk = { workspace = true, default-features = false, features = [ + "experimental", + "runtime", +] } [features] default = ["std"] -runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", -] -std = [ - "codec/std", - "scale-info/std", - - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", - - "sp-runtime/std", -] -try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", - "sp-runtime/try-runtime", -] +runtime-benchmarks = ["polkadot-sdk/runtime-benchmarks"] +std = ["codec/std", "polkadot-sdk/std", "scale-info/std"] +try-runtime = ["polkadot-sdk/try-runtime"] diff --git a/templates/parachain/pallets/template/src/benchmarking.rs b/templates/parachain/pallets/template/src/benchmarking.rs index 29572c3ff609..8ceb9186e677 100644 --- a/templates/parachain/pallets/template/src/benchmarking.rs +++ b/templates/parachain/pallets/template/src/benchmarking.rs @@ -1,7 +1,7 @@ //! Benchmarking setup for pallet-template use super::*; -use frame_benchmarking::v2::*; +use polkadot_sdk::{frame_benchmarking::v2::*, frame_system}; #[benchmarks] mod benchmarks { diff --git a/templates/parachain/pallets/template/src/lib.rs b/templates/parachain/pallets/template/src/lib.rs index 6bfb98972aed..44ef53a44267 100644 --- a/templates/parachain/pallets/template/src/lib.rs +++ b/templates/parachain/pallets/template/src/lib.rs @@ -66,18 +66,19 @@ mod benchmarking; // To see a full list of `pallet` macros and their use cases, see: // // -#[frame_support::pallet] +#[polkadot_sdk::frame_support::pallet] pub mod pallet { - use frame_support::{dispatch::DispatchResultWithPostInfo, pallet_prelude::*, DefaultNoBound}; - use frame_system::pallet_prelude::*; - use sp_runtime::traits::{CheckedAdd, One}; + use polkadot_sdk::{ + frame_support::{dispatch::DispatchResultWithPostInfo, pallet_prelude::*, DefaultNoBound}, + frame_system::pallet_prelude::*, + sp_runtime::traits::{CheckedAdd, One}, + }; /// Configure the pallet by specifying the parameters and types on which it depends. #[pallet::config] - pub trait Config: frame_system::Config { - /// Because this pallet emits events, it depends on the runtime's definition of an event. - /// - type RuntimeEvent: From> + IsType<::RuntimeEvent>; + pub trait Config: polkadot_sdk::frame_system::Config { + type RuntimeEvent: From> + + IsType<::RuntimeEvent>; /// A type representing the weights required by the dispatchables of this pallet. type WeightInfo: crate::weights::WeightInfo; diff --git a/templates/parachain/pallets/template/src/mock.rs b/templates/parachain/pallets/template/src/mock.rs index b8c730b6eb5d..ce5eeab661bd 100644 --- a/templates/parachain/pallets/template/src/mock.rs +++ b/templates/parachain/pallets/template/src/mock.rs @@ -1,6 +1,11 @@ -use frame_support::{derive_impl, weights::constants::RocksDbWeight}; -use frame_system::{mocking::MockBlock, GenesisConfig}; -use sp_runtime::{traits::ConstU64, BuildStorage}; +use polkadot_sdk::{ + frame_support, + frame_support::{derive_impl, weights::constants::RocksDbWeight}, + frame_system, + frame_system::{mocking::MockBlock, GenesisConfig}, + sp_io, + sp_runtime::{traits::ConstU64, BuildStorage}, +}; // Configure a mock runtime to test the pallet. #[frame_support::runtime] diff --git a/templates/parachain/pallets/template/src/tests.rs b/templates/parachain/pallets/template/src/tests.rs index 2f641ce08fbb..7bb3634c1d08 100644 --- a/templates/parachain/pallets/template/src/tests.rs +++ b/templates/parachain/pallets/template/src/tests.rs @@ -1,5 +1,5 @@ use crate::{mock::*, Error, Something}; -use frame_support::{assert_noop, assert_ok}; +use polkadot_sdk::frame_support::{assert_noop, assert_ok}; #[test] fn it_works_for_default_value() { diff --git a/templates/parachain/pallets/template/src/weights.rs b/templates/parachain/pallets/template/src/weights.rs index 4b4522429c6c..1853d8023791 100644 --- a/templates/parachain/pallets/template/src/weights.rs +++ b/templates/parachain/pallets/template/src/weights.rs @@ -29,7 +29,8 @@ #![allow(unused_parens)] #![allow(unused_imports)] -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use polkadot_sdk::frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use polkadot_sdk::frame_system; use core::marker::PhantomData; /// Weight functions needed for pallet_template. From 98001732f3315759206606a35f0aff20a96688d6 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Tue, 8 Oct 2024 15:25:41 +0300 Subject: [PATCH 02/12] parachain-template-runtime --- Cargo.lock | 46 +---- templates/parachain/runtime/Cargo.toml | 168 ++++-------------- templates/parachain/runtime/src/apis.rs | 44 +++-- templates/parachain/runtime/src/benchmarks.rs | 2 +- .../parachain/runtime/src/configs/mod.rs | 58 +++--- .../runtime/src/configs/xcm_config.rs | 41 +++-- .../runtime/src/genesis_config_presets.rs | 12 +- templates/parachain/runtime/src/lib.rs | 49 +++-- .../runtime/src/weights/block_weights.rs | 4 +- .../runtime/src/weights/extrinsic_weights.rs | 4 +- .../runtime/src/weights/paritydb_weights.rs | 4 +- .../runtime/src/weights/rocksdb_weights.rs | 4 +- 12 files changed, 169 insertions(+), 267 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a97f4ad3b15c..0a7aa3a6604e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13098,60 +13098,16 @@ dependencies = [ name = "parachain-template-runtime" version = "0.0.0" dependencies = [ - "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", - "cumulus-pallet-session-benchmarking", - "cumulus-pallet-xcm", - "cumulus-pallet-xcmp-queue", - "cumulus-primitives-aura", - "cumulus-primitives-core", - "cumulus-primitives-storage-weight-reclaim", - "cumulus-primitives-utility", "docify", - "frame-benchmarking", - "frame-executive", - "frame-metadata-hash-extension", - "frame-support", - "frame-system", - "frame-system-benchmarking", - "frame-system-rpc-runtime-api", - "frame-try-runtime", "hex-literal", "log", - "pallet-aura", - "pallet-authorship", - "pallet-balances", - "pallet-collator-selection", - "pallet-message-queue", "pallet-parachain-template", - "pallet-session", - "pallet-sudo", - "pallet-timestamp", - "pallet-transaction-payment", - "pallet-transaction-payment-rpc-runtime-api", - "pallet-xcm", - "parachains-common", "parity-scale-codec", - "polkadot-parachain-primitives", - "polkadot-runtime-common", + "polkadot-sdk", "scale-info", "serde_json", "smallvec", - "sp-api 26.0.0", - "sp-block-builder", - "sp-consensus-aura", - "sp-core 28.0.0", - "sp-genesis-builder", - "sp-inherents", - "sp-offchain", - "sp-runtime 31.0.1", - "sp-session", - "sp-transaction-pool", - "sp-version 29.0.0", - "staging-parachain-info", - "staging-xcm", - "staging-xcm-builder", - "staging-xcm-executor", "substrate-wasm-builder", ] diff --git a/templates/parachain/runtime/Cargo.toml b/templates/parachain/runtime/Cargo.toml index 236b7c048632..a51e42d55ead 100644 --- a/templates/parachain/runtime/Cargo.toml +++ b/templates/parachain/runtime/Cargo.toml @@ -32,168 +32,68 @@ serde_json = { workspace = true, default-features = false, features = ["alloc"] # Local pallet-parachain-template = { workspace = true } -# Substrate / FRAME -frame-benchmarking = { optional = true, workspace = true } -frame-executive = { workspace = true } -frame-metadata-hash-extension = { workspace = true } -frame-support = { features = ["experimental"], workspace = true } -frame-system = { workspace = true } -frame-system-benchmarking = { optional = true, workspace = true } -frame-system-rpc-runtime-api = { workspace = true } -frame-try-runtime = { optional = true, workspace = true } +polkadot-sdk = { workspace = true, default-features = false, features = [ + "experimental", -# FRAME Pallets -pallet-aura = { workspace = true } -pallet-authorship = { workspace = true } -pallet-balances = { workspace = true } -pallet-message-queue = { workspace = true } -pallet-session = { workspace = true } -pallet-sudo = { workspace = true } -pallet-timestamp = { workspace = true } -pallet-transaction-payment = { workspace = true } -pallet-transaction-payment-rpc-runtime-api = { workspace = true } + "pallet-aura", + "pallet-authorship", + "pallet-balances", + "pallet-message-queue", + "pallet-session", + "pallet-sudo", + "pallet-timestamp", + "pallet-transaction-payment", + "pallet-transaction-payment-rpc-runtime-api", -# Substrate Primitives -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 } + "pallet-xcm", + "polkadot-parachain-primitives", + "polkadot-runtime-common", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", -# Polkadot -pallet-xcm = { workspace = true } -polkadot-parachain-primitives = { workspace = true } -polkadot-runtime-common = { workspace = true } -xcm = { workspace = true } -xcm-builder = { workspace = true } -xcm-executor = { workspace = true } + "cumulus-pallet-aura-ext", + "cumulus-pallet-session-benchmarking", + "cumulus-pallet-xcm", + "cumulus-pallet-xcmp-queue", + "cumulus-primitives-aura", + "cumulus-primitives-core", + "cumulus-primitives-storage-weight-reclaim", + "cumulus-primitives-utility", + "pallet-collator-selection", + "parachains-common", + "staging-parachain-info", + + "runtime", +] } # Cumulus -cumulus-pallet-aura-ext = { workspace = true } cumulus-pallet-parachain-system = { workspace = true } -cumulus-pallet-session-benchmarking = { workspace = true } -cumulus-pallet-xcm = { workspace = true } -cumulus-pallet-xcmp-queue = { workspace = true } -cumulus-primitives-aura = { workspace = true } -cumulus-primitives-core = { workspace = true } -cumulus-primitives-utility = { workspace = true } -cumulus-primitives-storage-weight-reclaim = { workspace = true } -pallet-collator-selection = { workspace = true } -parachains-common = { workspace = true } -parachain-info = { workspace = true } [features] default = ["std"] std = [ "codec/std", - "cumulus-pallet-aura-ext/std", "cumulus-pallet-parachain-system/std", - "cumulus-pallet-session-benchmarking/std", - "cumulus-pallet-xcm/std", - "cumulus-pallet-xcmp-queue/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-metadata-hash-extension/std", - "frame-support/std", - "frame-system-benchmarking?/std", - "frame-system-rpc-runtime-api/std", - "frame-system/std", - "frame-try-runtime?/std", "log/std", - "pallet-aura/std", - "pallet-authorship/std", - "pallet-balances/std", - "pallet-collator-selection/std", - "pallet-message-queue/std", "pallet-parachain-template/std", - "pallet-session/std", - "pallet-sudo/std", - "pallet-timestamp/std", - "pallet-transaction-payment-rpc-runtime-api/std", - "pallet-transaction-payment/std", - "pallet-xcm/std", - "parachain-info/std", - "parachains-common/std", - "polkadot-parachain-primitives/std", - "polkadot-runtime-common/std", + "polkadot-sdk/std", "scale-info/std", "serde_json/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", - "xcm-builder/std", - "xcm-executor/std", - "xcm/std", ] runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", - "cumulus-pallet-session-benchmarking/runtime-benchmarks", - "cumulus-pallet-xcmp-queue/runtime-benchmarks", - "cumulus-primitives-core/runtime-benchmarks", - "cumulus-primitives-utility/runtime-benchmarks", - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system-benchmarking/runtime-benchmarks", - "frame-system/runtime-benchmarks", "hex-literal", - "pallet-balances/runtime-benchmarks", - "pallet-collator-selection/runtime-benchmarks", - "pallet-message-queue/runtime-benchmarks", "pallet-parachain-template/runtime-benchmarks", - "pallet-sudo/runtime-benchmarks", - "pallet-timestamp/runtime-benchmarks", - "pallet-xcm/runtime-benchmarks", - "parachains-common/runtime-benchmarks", - "polkadot-parachain-primitives/runtime-benchmarks", - "polkadot-runtime-common/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", - "xcm-builder/runtime-benchmarks", - "xcm-executor/runtime-benchmarks", + "polkadot-sdk/runtime-benchmarks", ] try-runtime = [ - "cumulus-pallet-aura-ext/try-runtime", "cumulus-pallet-parachain-system/try-runtime", - "cumulus-pallet-xcm/try-runtime", - "cumulus-pallet-xcmp-queue/try-runtime", - "frame-executive/try-runtime", - "frame-support/try-runtime", - "frame-system/try-runtime", - "frame-try-runtime/try-runtime", - "pallet-aura/try-runtime", - "pallet-authorship/try-runtime", - "pallet-balances/try-runtime", - "pallet-collator-selection/try-runtime", - "pallet-message-queue/try-runtime", "pallet-parachain-template/try-runtime", - "pallet-session/try-runtime", - "pallet-sudo/try-runtime", - "pallet-timestamp/try-runtime", - "pallet-transaction-payment/try-runtime", - "pallet-xcm/try-runtime", - "parachain-info/try-runtime", - "polkadot-runtime-common/try-runtime", - "sp-runtime/try-runtime", + "polkadot-sdk/try-runtime", ] # Enable the metadata hash generation. diff --git a/templates/parachain/runtime/src/apis.rs b/templates/parachain/runtime/src/apis.rs index 243db1b6dde0..1995b4027319 100644 --- a/templates/parachain/runtime/src/apis.rs +++ b/templates/parachain/runtime/src/apis.rs @@ -25,20 +25,34 @@ // External crates imports use alloc::vec::Vec; -use frame_support::{ - genesis_builder_helper::{build_state, get_preset}, - weights::Weight, +#[cfg(feature = "try-runtime")] +use polkadot_sdk::frame_try_runtime; +#[cfg(feature = "runtime-benchmarks")] +use polkadot_sdk::{ + cumulus_pallet_session_benchmarking, frame_benchmarking, frame_system_benchmarking, }; -use pallet_aura::Authorities; -use sp_api::impl_runtime_apis; -use sp_consensus_aura::sr25519::AuthorityId as AuraId; -use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; -use sp_runtime::{ - traits::Block as BlockT, - transaction_validity::{TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, +use polkadot_sdk::{ + cumulus_primitives_aura, cumulus_primitives_core, + frame_support::{ + genesis_builder_helper::{build_state, get_preset}, + weights::Weight, + }, + frame_system_rpc_runtime_api, + pallet_aura::Authorities, + pallet_transaction_payment, pallet_transaction_payment_rpc_runtime_api, + sp_api::{self, impl_runtime_apis}, + sp_block_builder, sp_consensus_aura, + sp_consensus_aura::sr25519::AuthorityId as AuraId, + sp_core::{crypto::KeyTypeId, OpaqueMetadata}, + sp_genesis_builder, sp_inherents, sp_offchain, sp_runtime, + sp_runtime::{ + traits::Block as BlockT, + transaction_validity::{TransactionSource, TransactionValidity}, + ApplyExtrinsicResult, + }, + sp_session, sp_transaction_pool, + sp_version::RuntimeVersion, }; -use sp_version::RuntimeVersion; // Local module imports use super::{ @@ -241,10 +255,10 @@ impl_runtime_apis! { impl frame_benchmarking::Benchmark for Runtime { fn benchmark_metadata(extra: bool) -> ( Vec, - Vec, + Vec, ) { use frame_benchmarking::{Benchmarking, BenchmarkList}; - use frame_support::traits::StorageInfoTrait; + use polkadot_sdk::frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; use super::*; @@ -277,7 +291,7 @@ impl_runtime_apis! { use cumulus_pallet_session_benchmarking::Pallet as SessionBench; impl cumulus_pallet_session_benchmarking::Config for Runtime {} - use frame_support::traits::WhitelistedStorageKeys; + use polkadot_sdk::frame_support::traits::WhitelistedStorageKeys; let whitelist = AllPalletsWithSystem::whitelisted_storage_keys(); let mut batches = Vec::::new(); diff --git a/templates/parachain/runtime/src/benchmarks.rs b/templates/parachain/runtime/src/benchmarks.rs index 9fbf1ad82bdb..aae50e7258c0 100644 --- a/templates/parachain/runtime/src/benchmarks.rs +++ b/templates/parachain/runtime/src/benchmarks.rs @@ -23,7 +23,7 @@ // // For more information, please refer to -frame_benchmarking::define_benchmarks!( +polkadot_sdk::frame_benchmarking::define_benchmarks!( [frame_system, SystemBench::] [pallet_balances, Balances] [pallet_session, SessionBench::] diff --git a/templates/parachain/runtime/src/configs/mod.rs b/templates/parachain/runtime/src/configs/mod.rs index 43ab63bd0b67..41af9e9097e5 100644 --- a/templates/parachain/runtime/src/configs/mod.rs +++ b/templates/parachain/runtime/src/configs/mod.rs @@ -27,30 +27,44 @@ mod xcm_config; // Substrate and Polkadot dependencies use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; -use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; -use frame_support::{ - derive_impl, - dispatch::DispatchClass, - parameter_types, - traits::{ - ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, TransformOrigin, VariantCountOf, +#[cfg(feature = "runtime-benchmarks")] +use polkadot_sdk::cumulus_primitives_core; +use polkadot_sdk::{ + cumulus_pallet_aura_ext, cumulus_pallet_xcmp_queue, + cumulus_primitives_core::{AggregateMessageOrigin, ParaId}, + frame_support::{ + self, derive_impl, + dispatch::DispatchClass, + parameter_types, + traits::{ + ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, TransformOrigin, + VariantCountOf, + }, + weights::{ConstantMultiplier, Weight}, + PalletId, }, - weights::{ConstantMultiplier, Weight}, - PalletId, -}; -use frame_system::{ - limits::{BlockLength, BlockWeights}, - EnsureRoot, -}; -use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; -use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}; -use polkadot_runtime_common::{ - xcm_sender::NoPriceForMessageDelivery, BlockHashCount, SlowAdjustingFeeUpdate, + frame_system::{ + self, + limits::{BlockLength, BlockWeights}, + EnsureRoot, + }, + pallet_aura, pallet_authorship, pallet_balances, pallet_collator_selection, + pallet_message_queue, pallet_session, pallet_sudo, pallet_timestamp, + pallet_transaction_payment, + pallet_xcm::{EnsureXcm, IsVoiceOfBody}, + parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}, + polkadot_runtime_common::{ + xcm_sender::NoPriceForMessageDelivery, BlockHashCount, SlowAdjustingFeeUpdate, + }, + sp_consensus_aura::sr25519::AuthorityId as AuraId, + sp_core, sp_runtime, + sp_runtime::Perbill, + sp_version::RuntimeVersion, + staging_parachain_info as parachain_info, + staging_xcm::latest::prelude::BodyId, }; -use sp_consensus_aura::sr25519::AuthorityId as AuraId; -use sp_runtime::Perbill; -use sp_version::RuntimeVersion; -use xcm::latest::prelude::BodyId; +#[cfg(not(feature = "runtime-benchmarks"))] +use polkadot_sdk::{staging_xcm_builder as xcm_builder, staging_xcm_executor as xcm_executor}; // Local module imports use super::{ diff --git a/templates/parachain/runtime/src/configs/xcm_config.rs b/templates/parachain/runtime/src/configs/xcm_config.rs index e162bcbf8868..6bd234ca3e80 100644 --- a/templates/parachain/runtime/src/configs/xcm_config.rs +++ b/templates/parachain/runtime/src/configs/xcm_config.rs @@ -2,25 +2,30 @@ use crate::{ AccountId, AllPalletsWithSystem, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, }; -use frame_support::{ - parameter_types, - traits::{ConstU32, Contains, Everything, Nothing}, - weights::Weight, +use polkadot_sdk::{ + cumulus_pallet_xcm, cumulus_primitives_utility, + frame_support::{ + parameter_types, + traits::{ConstU32, Contains, Everything, Nothing}, + weights::Weight, + }, + frame_system::EnsureRoot, + pallet_xcm, + pallet_xcm::XcmPassthrough, + polkadot_parachain_primitives::primitives::Sibling, + polkadot_runtime_common::impls::ToAuthor, + staging_xcm::latest::prelude::*, + staging_xcm_builder::{ + AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, + DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds, + FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, ParentIsPreset, + RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, + TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, + WithUniqueTopic, + }, + staging_xcm_executor::{self as xcm_executor, XcmExecutor}, }; -use frame_system::EnsureRoot; -use pallet_xcm::XcmPassthrough; -use polkadot_parachain_primitives::primitives::Sibling; -use polkadot_runtime_common::impls::ToAuthor; -use xcm::latest::prelude::*; -use xcm_builder::{ - AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, - DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds, - FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, ParentIsPreset, - RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, - SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, - TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic, -}; -use xcm_executor::XcmExecutor; parameter_types! { pub const RelayLocation: Location = Location::parent(); diff --git a/templates/parachain/runtime/src/genesis_config_presets.rs b/templates/parachain/runtime/src/genesis_config_presets.rs index fec53d17394c..ed9f2736aa18 100644 --- a/templates/parachain/runtime/src/genesis_config_presets.rs +++ b/templates/parachain/runtime/src/genesis_config_presets.rs @@ -1,14 +1,16 @@ -use cumulus_primitives_core::ParaId; - use crate::{ AccountId, BalancesConfig, CollatorSelectionConfig, ParachainInfoConfig, PolkadotXcmConfig, RuntimeGenesisConfig, SessionConfig, SessionKeys, SudoConfig, EXISTENTIAL_DEPOSIT, }; use alloc::{vec, vec::Vec}; -use parachains_common::{genesis_config_helpers::*, AuraId}; +use polkadot_sdk::{ + cumulus_primitives_core::ParaId, + parachains_common::{genesis_config_helpers::*, AuraId}, + sp_core::sr25519, + sp_genesis_builder::{self, PresetId}, + staging_xcm as xcm, +}; use serde_json::Value; -use sp_core::sr25519; -use sp_genesis_builder::PresetId; /// The default XCM version to set in genesis config. const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; diff --git a/templates/parachain/runtime/src/lib.rs b/templates/parachain/runtime/src/lib.rs index ccec648ce4c1..8d0e6102405c 100644 --- a/templates/parachain/runtime/src/lib.rs +++ b/templates/parachain/runtime/src/lib.rs @@ -16,25 +16,37 @@ mod weights; extern crate alloc; use alloc::vec::Vec; use smallvec::smallvec; -use sp_runtime::{ - create_runtime_str, generic, impl_opaque_keys, - traits::{BlakeTwo256, IdentifyAccount, Verify}, - MultiSignature, -}; +#[cfg(any(feature = "std", test))] +pub use polkadot_sdk::sp_runtime::BuildStorage; #[cfg(feature = "std")] -use sp_version::NativeVersion; -use sp_version::RuntimeVersion; - -use frame_support::weights::{ - constants::WEIGHT_REF_TIME_PER_SECOND, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, - WeightToFeePolynomial, +use polkadot_sdk::sp_version::NativeVersion; +use polkadot_sdk::{ + cumulus_pallet_aura_ext, cumulus_pallet_xcm, cumulus_pallet_xcmp_queue, + cumulus_primitives_core, cumulus_primitives_storage_weight_reclaim, frame_executive, + frame_metadata_hash_extension, + frame_support::{ + self, + weights::{ + constants::WEIGHT_REF_TIME_PER_SECOND, Weight, WeightToFeeCoefficient, + WeightToFeeCoefficients, WeightToFeePolynomial, + }, + }, + frame_system, pallet_aura, pallet_authorship, pallet_balances, pallet_collator_selection, + pallet_message_queue, pallet_session, pallet_sudo, pallet_timestamp, + pallet_transaction_payment, pallet_xcm, sp_core, + sp_runtime::{ + create_runtime_str, generic, impl_opaque_keys, + traits::{BlakeTwo256, IdentifyAccount, Verify}, + MultiSignature, + }, + sp_version::{self, RuntimeVersion}, + staging_parachain_info as parachain_info, +}; +pub use polkadot_sdk::{ + sp_consensus_aura::sr25519::AuthorityId as AuraId, + sp_runtime::{MultiAddress, Perbill, Permill}, }; -pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; -pub use sp_runtime::{MultiAddress, Perbill, Permill}; - -#[cfg(any(feature = "std", test))] -pub use sp_runtime::BuildStorage; use weights::ExtrinsicBaseWeight; @@ -140,13 +152,12 @@ impl WeightToFeePolynomial for WeightToFee { /// to even the core data structures. pub mod opaque { use super::*; - use sp_runtime::{ + pub use polkadot_sdk::sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic; + use polkadot_sdk::sp_runtime::{ generic, traits::{BlakeTwo256, Hash as HashT}, }; - pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic; - /// Opaque block header type. pub type Header = generic::Header; /// Opaque block type. diff --git a/templates/parachain/runtime/src/weights/block_weights.rs b/templates/parachain/runtime/src/weights/block_weights.rs index e7fdb2aae2a0..75be7639ed0a 100644 --- a/templates/parachain/runtime/src/weights/block_weights.rs +++ b/templates/parachain/runtime/src/weights/block_weights.rs @@ -16,7 +16,7 @@ // limitations under the License. pub mod constants { - use frame_support::{ + use polkadot_sdk::frame_support::{ parameter_types, weights::{constants, Weight}, }; @@ -29,7 +29,7 @@ pub mod constants { #[cfg(test)] mod test_weights { - use frame_support::weights::constants; + use polkadot_sdk::frame_support::weights::constants; /// Checks that the weight exists and is sane. // NOTE: If this test fails but you are sure that the generated values are fine, diff --git a/templates/parachain/runtime/src/weights/extrinsic_weights.rs b/templates/parachain/runtime/src/weights/extrinsic_weights.rs index 1a4adb968bb7..ff2d9f087f5a 100644 --- a/templates/parachain/runtime/src/weights/extrinsic_weights.rs +++ b/templates/parachain/runtime/src/weights/extrinsic_weights.rs @@ -16,7 +16,7 @@ // limitations under the License. pub mod constants { - use frame_support::{ + use polkadot_sdk::frame_support::{ parameter_types, weights::{constants, Weight}, }; @@ -29,7 +29,7 @@ pub mod constants { #[cfg(test)] mod test_weights { - use frame_support::weights::constants; + use polkadot_sdk::frame_support::weights::constants; /// Checks that the weight exists and is sane. // NOTE: If this test fails but you are sure that the generated values are fine, diff --git a/templates/parachain/runtime/src/weights/paritydb_weights.rs b/templates/parachain/runtime/src/weights/paritydb_weights.rs index 25679703831a..f02b03f13752 100644 --- a/templates/parachain/runtime/src/weights/paritydb_weights.rs +++ b/templates/parachain/runtime/src/weights/paritydb_weights.rs @@ -16,7 +16,7 @@ // limitations under the License. pub mod constants { - use frame_support::{ + use polkadot_sdk::frame_support::{ parameter_types, weights::{constants, RuntimeDbWeight}, }; @@ -33,7 +33,7 @@ pub mod constants { #[cfg(test)] mod test_db_weights { use super::constants::ParityDbWeight as W; - use frame_support::weights::constants; + use polkadot_sdk::frame_support::weights::constants; /// Checks that all weights exist and have sane values. // NOTE: If this test fails but you are sure that the generated values are fine, diff --git a/templates/parachain/runtime/src/weights/rocksdb_weights.rs b/templates/parachain/runtime/src/weights/rocksdb_weights.rs index 3dd817aa6f13..5d305b3cce0c 100644 --- a/templates/parachain/runtime/src/weights/rocksdb_weights.rs +++ b/templates/parachain/runtime/src/weights/rocksdb_weights.rs @@ -16,7 +16,7 @@ // limitations under the License. pub mod constants { - use frame_support::{ + use polkadot_sdk::frame_support::{ parameter_types, weights::{constants, RuntimeDbWeight}, }; @@ -33,7 +33,7 @@ pub mod constants { #[cfg(test)] mod test_db_weights { use super::constants::RocksDbWeight as W; - use frame_support::weights::constants; + use polkadot_sdk::frame_support::weights::constants; /// Checks that all weights exist and have sane values. // NOTE: If this test fails but you are sure that the generated values are fine, From 58869d00cf128126e0d7a8aedf79b5bc39bb9636 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Wed, 9 Oct 2024 10:11:02 +0300 Subject: [PATCH 03/12] parachain-template-node --- Cargo.lock | 43 +------------- templates/parachain/node/Cargo.toml | 68 +++------------------- templates/parachain/node/build.rs | 2 +- templates/parachain/node/src/chain_spec.rs | 7 ++- templates/parachain/node/src/cli.rs | 1 + templates/parachain/node/src/command.rs | 21 ++++--- templates/parachain/node/src/main.rs | 2 + templates/parachain/node/src/rpc.rs | 12 ++-- templates/parachain/node/src/service.rs | 54 +++++++++-------- 9 files changed, 70 insertions(+), 140 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0a7aa3a6604e..fb0ab77927b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13040,57 +13040,16 @@ version = "0.0.0" dependencies = [ "clap 4.5.13", "color-print", - "cumulus-client-cli", - "cumulus-client-collator", - "cumulus-client-consensus-aura", - "cumulus-client-consensus-common", - "cumulus-client-consensus-proposer", - "cumulus-client-service", - "cumulus-primitives-core", - "cumulus-primitives-parachain-inherent", - "cumulus-relay-chain-interface", "docify", - "frame-benchmarking", - "frame-benchmarking-cli", "futures", "jsonrpsee 0.24.3", "log", - "pallet-transaction-payment-rpc", "parachain-template-runtime", "parity-scale-codec", - "polkadot-cli", - "polkadot-primitives", - "sc-basic-authorship", - "sc-chain-spec", - "sc-cli", - "sc-client-api", - "sc-consensus", - "sc-executor 0.32.0", - "sc-network", - "sc-network-sync", - "sc-offchain", - "sc-rpc", - "sc-service", - "sc-sysinfo", - "sc-telemetry", + "polkadot-sdk", "sc-tracing", - "sc-transaction-pool", - "sc-transaction-pool-api", "serde", "serde_json", - "sp-api 26.0.0", - "sp-block-builder", - "sp-blockchain", - "sp-consensus-aura", - "sp-core 28.0.0", - "sp-genesis-builder", - "sp-io 30.0.0", - "sp-keystore 0.34.0", - "sp-runtime 31.0.1", - "sp-timestamp", - "staging-xcm", - "substrate-build-script-utils", - "substrate-frame-rpc-system", "substrate-prometheus-endpoint", ] diff --git a/templates/parachain/node/Cargo.toml b/templates/parachain/node/Cargo.toml index c0c81d8222a4..eada504f45f8 100644 --- a/templates/parachain/node/Cargo.toml +++ b/templates/parachain/node/Cargo.toml @@ -10,9 +10,6 @@ edition.workspace = true publish = false build = "build.rs" -# [[bin]] -# name = "parachain-template-node" - [dependencies] clap = { features = ["derive"], workspace = true } log = { workspace = true, default-features = true } @@ -22,82 +19,31 @@ jsonrpsee = { features = ["server"], workspace = true } futures = { workspace = true } serde_json = { workspace = true, default-features = true } docify = { workspace = true } +color-print = { workspace = true } + +polkadot-sdk = { workspace = true, features = ["experimental", "node"] } -# Local parachain-template-runtime = { workspace = true } # Substrate -frame-benchmarking = { workspace = true, default-features = true } -frame-benchmarking-cli = { workspace = true, default-features = true } -pallet-transaction-payment-rpc = { workspace = true, default-features = true } -sc-basic-authorship = { workspace = true, default-features = true } -sc-chain-spec = { workspace = true, default-features = true } -sc-cli = { workspace = true, default-features = true } -sc-client-api = { workspace = true, default-features = true } -sc-offchain = { workspace = true, default-features = true } -sc-consensus = { workspace = true, default-features = true } -sc-executor = { workspace = true, default-features = true } -sc-network = { workspace = true, default-features = true } -sc-network-sync = { workspace = true, default-features = true } -sc-rpc = { workspace = true, default-features = true } -sc-service = { workspace = true, default-features = true } -sc-sysinfo = { workspace = true, default-features = true } -sc-telemetry = { workspace = true, default-features = true } sc-tracing = { workspace = true, default-features = true } -sc-transaction-pool = { workspace = true, default-features = true } -sc-transaction-pool-api = { workspace = true, default-features = true } -sp-api = { workspace = true, default-features = true } -sp-block-builder = { workspace = true, default-features = true } -sp-blockchain = { workspace = true, default-features = true } -sp-consensus-aura = { workspace = true, default-features = true } -sp-core = { workspace = true, default-features = true } -sp-genesis-builder = { workspace = true, default-features = true } -sp-keystore = { workspace = true, default-features = true } -sp-io = { workspace = true, default-features = true } -sp-runtime = { workspace = true, default-features = true } -sp-timestamp = { workspace = true, default-features = true } -substrate-frame-rpc-system = { workspace = true, default-features = true } prometheus-endpoint = { workspace = true, default-features = true } -# Polkadot -polkadot-cli = { features = ["rococo-native"], workspace = true, default-features = true } -polkadot-primitives = { workspace = true, default-features = true } -xcm = { workspace = true } - -# Cumulus -cumulus-client-cli = { workspace = true, default-features = true } -cumulus-client-collator = { workspace = true, default-features = true } -cumulus-client-consensus-aura = { workspace = true, default-features = true } -cumulus-client-consensus-common = { workspace = true, default-features = true } -cumulus-client-consensus-proposer = { workspace = true, default-features = true } -cumulus-client-service = { workspace = true, default-features = true } -cumulus-primitives-core = { workspace = true, default-features = true } -cumulus-primitives-parachain-inherent = { workspace = true, default-features = true } -cumulus-relay-chain-interface = { workspace = true, default-features = true } -color-print = { workspace = true } - [build-dependencies] -substrate-build-script-utils = { workspace = true, default-features = true } +polkadot-sdk = { workspace = true, features = ["substrate-build-script-utils"] } [features] default = ["std"] std = [ "log/std", "parachain-template-runtime/std", - "xcm/std", + "polkadot-sdk/std", ] runtime-benchmarks = [ - "cumulus-primitives-core/runtime-benchmarks", - "frame-benchmarking-cli/runtime-benchmarks", - "frame-benchmarking/runtime-benchmarks", "parachain-template-runtime/runtime-benchmarks", - "polkadot-cli/runtime-benchmarks", - "polkadot-primitives/runtime-benchmarks", - "sc-service/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", + "polkadot-sdk/runtime-benchmarks", ] try-runtime = [ "parachain-template-runtime/try-runtime", - "polkadot-cli/try-runtime", - "sp-runtime/try-runtime", + "polkadot-sdk/try-runtime", ] diff --git a/templates/parachain/node/build.rs b/templates/parachain/node/build.rs index e3bfe3116bf2..8ee8f23d8548 100644 --- a/templates/parachain/node/build.rs +++ b/templates/parachain/node/build.rs @@ -1,4 +1,4 @@ -use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed}; +use polkadot_sdk::substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed}; fn main() { generate_cargo_keys(); diff --git a/templates/parachain/node/src/chain_spec.rs b/templates/parachain/node/src/chain_spec.rs index af82607bc8e4..e7e9c9d1d978 100644 --- a/templates/parachain/node/src/chain_spec.rs +++ b/templates/parachain/node/src/chain_spec.rs @@ -1,6 +1,9 @@ use parachain_template_runtime as runtime; -use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; -use sc_service::ChainType; +use polkadot_sdk::{ + sc_chain_spec::{self, ChainSpecExtension, ChainSpecGroup}, + sc_service::{self, ChainType}, + sp_genesis_builder, +}; use serde::{Deserialize, Serialize}; /// Specialized `ChainSpec` for the normal parachain runtime. diff --git a/templates/parachain/node/src/cli.rs b/templates/parachain/node/src/cli.rs index f008e856d99b..ade5e288a9ff 100644 --- a/templates/parachain/node/src/cli.rs +++ b/templates/parachain/node/src/cli.rs @@ -1,3 +1,4 @@ +use polkadot_sdk::{cumulus_client_cli, frame_benchmarking_cli, polkadot_cli, sc_cli, sc_service}; use std::path::PathBuf; /// Sub-commands supported by the collator. diff --git a/templates/parachain/node/src/command.rs b/templates/parachain/node/src/command.rs index 6b9deade1271..ea6e35d107f2 100644 --- a/templates/parachain/node/src/command.rs +++ b/templates/parachain/node/src/command.rs @@ -1,13 +1,20 @@ -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 parachain_template_runtime::Block; -use sc_cli::{ - ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, - NetworkParams, Result, RpcEndpoint, SharedParams, SubstrateCli, +use polkadot_sdk::{ + cumulus_client_service::storage_proof_size::HostFunctions as ReclaimHostFunctions, + cumulus_primitives_core::ParaId, + frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE}, + polkadot_cli, + sc_cli::{ + self, ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, + KeystoreParams, NetworkParams, Result, RpcEndpoint, SharedParams, SubstrateCli, + }, + sc_service::{ + self, + config::{BasePath, PrometheusConfig}, + }, + sc_sysinfo, sc_telemetry, sp_runtime, }; -use sc_service::config::{BasePath, PrometheusConfig}; use crate::{ chain_spec, diff --git a/templates/parachain/node/src/main.rs b/templates/parachain/node/src/main.rs index 12738a6793c0..3f231f4fab96 100644 --- a/templates/parachain/node/src/main.rs +++ b/templates/parachain/node/src/main.rs @@ -2,6 +2,8 @@ #![warn(missing_docs)] +use polkadot_sdk::sc_cli; + mod chain_spec; mod cli; mod command; diff --git a/templates/parachain/node/src/rpc.rs b/templates/parachain/node/src/rpc.rs index 4937469e11e2..bedc6700d152 100644 --- a/templates/parachain/node/src/rpc.rs +++ b/templates/parachain/node/src/rpc.rs @@ -9,10 +9,14 @@ use std::sync::Arc; use parachain_template_runtime::{opaque::Block, AccountId, Balance, Nonce}; -use sc_transaction_pool_api::TransactionPool; -use sp_api::ProvideRuntimeApi; -use sp_block_builder::BlockBuilder; -use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; +use polkadot_sdk::{ + pallet_transaction_payment_rpc, + sc_transaction_pool_api::TransactionPool, + sp_api::ProvideRuntimeApi, + sp_block_builder::BlockBuilder, + sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}, + substrate_frame_rpc_system, +}; /// A type representing all RPC extensions. pub type RpcExtension = jsonrpsee::RpcModule<()>; diff --git a/templates/parachain/node/src/service.rs b/templates/parachain/node/src/service.rs index 04e20be2bd40..98dc1e3e1cc0 100644 --- a/templates/parachain/node/src/service.rs +++ b/templates/parachain/node/src/service.rs @@ -3,42 +3,50 @@ // std use std::{sync::Arc, time::Duration}; -use cumulus_client_cli::CollatorOptions; // Local Runtime Types use parachain_template_runtime::{ apis::RuntimeApi, opaque::{Block, Hash}, }; -// Cumulus Imports -use cumulus_client_collator::service::CollatorService; #[docify::export(lookahead_collator)] -use cumulus_client_consensus_aura::collators::lookahead::{self as aura, Params as AuraParams}; -use cumulus_client_consensus_common::ParachainBlockImport as TParachainBlockImport; -use cumulus_client_consensus_proposer::Proposer; -use cumulus_client_service::{ - build_network, build_relay_chain_interface, prepare_node_config, start_relay_chain_tasks, - BuildNetworkParams, CollatorSybilResistance, DARecoveryProfile, ParachainHostFunctions, - StartRelayChainTasksParams, +use polkadot_sdk::cumulus_client_consensus_aura::collators::lookahead::{ + self as aura, Params as AuraParams, }; #[docify::export(cumulus_primitives)] -use cumulus_primitives_core::{ +use polkadot_sdk::cumulus_primitives_core::{ relay_chain::{CollatorPair, ValidationCode}, ParaId, }; -use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface}; - -// Substrate Imports -use frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE; +use polkadot_sdk::{ + cumulus_client_cli::CollatorOptions, + cumulus_client_collator::service::CollatorService, + cumulus_client_consensus_aura, + cumulus_client_consensus_common::ParachainBlockImport as TParachainBlockImport, + cumulus_client_consensus_proposer::Proposer, + cumulus_client_service::{ + build_network, build_relay_chain_interface, prepare_node_config, start_relay_chain_tasks, + BuildNetworkParams, CollatorSybilResistance, DARecoveryProfile, ParachainHostFunctions, + StartRelayChainTasksParams, + }, + cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface}, + frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE, + sc_basic_authorship, + sc_client_api::Backend, + sc_consensus::{self, ImportQueue}, + sc_executor::{HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY}, + sc_network::{self, NetworkBlock}, + sc_offchain, + sc_service::{self, Configuration, PartialComponents, TFullBackend, TFullClient, TaskManager}, + sc_sysinfo, + sc_telemetry::{self, Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}, + sc_transaction_pool, + sc_transaction_pool_api::OffchainTransactionPoolFactory, + sp_consensus_aura, + sp_keystore::KeystorePtr, + sp_timestamp, +}; use prometheus_endpoint::Registry; -use sc_client_api::Backend; -use sc_consensus::ImportQueue; -use sc_executor::{HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY}; -use sc_network::NetworkBlock; -use sc_service::{Configuration, PartialComponents, TFullBackend, TFullClient, TaskManager}; -use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}; -use sc_transaction_pool_api::OffchainTransactionPoolFactory; -use sp_keystore::KeystorePtr; #[docify::export(wasm_executor)] type ParachainExecutor = WasmExecutor; From 3a68ee834458d06db633f543b4182d1d6c24c93b Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Thu, 10 Oct 2024 15:09:25 +0300 Subject: [PATCH 04/12] Address CR comments --- Cargo.lock | 2 +- templates/parachain/node/src/chain_spec.rs | 9 ++- templates/parachain/node/src/cli.rs | 2 +- templates/parachain/node/src/command.rs | 23 +++---- templates/parachain/node/src/main.rs | 2 +- templates/parachain/node/src/rpc.rs | 14 ++--- templates/parachain/node/src/service.rs | 56 ++++++++--------- .../parachain/pallets/template/Cargo.toml | 8 +-- .../pallets/template/src/benchmarking.rs | 2 +- .../parachain/pallets/template/src/lib.rs | 14 ++--- .../parachain/pallets/template/src/mock.rs | 16 +++-- .../parachain/pallets/template/src/tests.rs | 2 +- .../parachain/pallets/template/src/weights.rs | 3 +- templates/parachain/runtime/src/apis.rs | 41 +++++-------- .../parachain/runtime/src/configs/mod.rs | 60 ++++++++----------- .../runtime/src/configs/xcm_config.rs | 44 +++++++------- .../runtime/src/genesis_config_presets.rs | 15 ++--- templates/parachain/runtime/src/lib.rs | 44 +++++--------- .../runtime/src/weights/block_weights.rs | 8 ++- .../runtime/src/weights/extrinsic_weights.rs | 8 ++- .../runtime/src/weights/paritydb_weights.rs | 8 ++- .../runtime/src/weights/rocksdb_weights.rs | 8 ++- 22 files changed, 176 insertions(+), 213 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fb0ab77927b2..51fca834629f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12177,7 +12177,7 @@ name = "pallet-parachain-template" version = "0.0.0" dependencies = [ "parity-scale-codec", - "polkadot-sdk", + "polkadot-sdk-frame", "scale-info", ] diff --git a/templates/parachain/node/src/chain_spec.rs b/templates/parachain/node/src/chain_spec.rs index e7e9c9d1d978..55a099dd022b 100644 --- a/templates/parachain/node/src/chain_spec.rs +++ b/templates/parachain/node/src/chain_spec.rs @@ -1,9 +1,8 @@ +use polkadot_sdk::*; + use parachain_template_runtime as runtime; -use polkadot_sdk::{ - sc_chain_spec::{self, ChainSpecExtension, ChainSpecGroup}, - sc_service::{self, ChainType}, - sp_genesis_builder, -}; +use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; +use sc_service::ChainType; use serde::{Deserialize, Serialize}; /// Specialized `ChainSpec` for the normal parachain runtime. diff --git a/templates/parachain/node/src/cli.rs b/templates/parachain/node/src/cli.rs index ade5e288a9ff..c8bdbc10d751 100644 --- a/templates/parachain/node/src/cli.rs +++ b/templates/parachain/node/src/cli.rs @@ -1,4 +1,4 @@ -use polkadot_sdk::{cumulus_client_cli, frame_benchmarking_cli, polkadot_cli, sc_cli, sc_service}; +use polkadot_sdk::*; use std::path::PathBuf; /// Sub-commands supported by the collator. diff --git a/templates/parachain/node/src/command.rs b/templates/parachain/node/src/command.rs index ea6e35d107f2..938bda837e0d 100644 --- a/templates/parachain/node/src/command.rs +++ b/templates/parachain/node/src/command.rs @@ -1,20 +1,15 @@ +use polkadot_sdk::*; + +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 parachain_template_runtime::Block; -use polkadot_sdk::{ - cumulus_client_service::storage_proof_size::HostFunctions as ReclaimHostFunctions, - cumulus_primitives_core::ParaId, - frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE}, - polkadot_cli, - sc_cli::{ - self, ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, - KeystoreParams, NetworkParams, Result, RpcEndpoint, SharedParams, SubstrateCli, - }, - sc_service::{ - self, - config::{BasePath, PrometheusConfig}, - }, - sc_sysinfo, sc_telemetry, sp_runtime, +use sc_cli::{ + ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, + NetworkParams, Result, RpcEndpoint, SharedParams, SubstrateCli, }; +use sc_service::config::{BasePath, PrometheusConfig}; use crate::{ chain_spec, diff --git a/templates/parachain/node/src/main.rs b/templates/parachain/node/src/main.rs index 3f231f4fab96..46ebcfd266d9 100644 --- a/templates/parachain/node/src/main.rs +++ b/templates/parachain/node/src/main.rs @@ -2,7 +2,7 @@ #![warn(missing_docs)] -use polkadot_sdk::sc_cli; +use polkadot_sdk::*; mod chain_spec; mod cli; diff --git a/templates/parachain/node/src/rpc.rs b/templates/parachain/node/src/rpc.rs index bedc6700d152..7549a5d090d7 100644 --- a/templates/parachain/node/src/rpc.rs +++ b/templates/parachain/node/src/rpc.rs @@ -9,14 +9,12 @@ use std::sync::Arc; use parachain_template_runtime::{opaque::Block, AccountId, Balance, Nonce}; -use polkadot_sdk::{ - pallet_transaction_payment_rpc, - sc_transaction_pool_api::TransactionPool, - sp_api::ProvideRuntimeApi, - sp_block_builder::BlockBuilder, - sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}, - substrate_frame_rpc_system, -}; +use polkadot_sdk::*; + +use sc_transaction_pool_api::TransactionPool; +use sp_api::ProvideRuntimeApi; +use sp_block_builder::BlockBuilder; +use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; /// A type representing all RPC extensions. pub type RpcExtension = jsonrpsee::RpcModule<()>; diff --git a/templates/parachain/node/src/service.rs b/templates/parachain/node/src/service.rs index 98dc1e3e1cc0..6729b9d7ef4f 100644 --- a/templates/parachain/node/src/service.rs +++ b/templates/parachain/node/src/service.rs @@ -9,44 +9,38 @@ use parachain_template_runtime::{ opaque::{Block, Hash}, }; +use polkadot_sdk::*; + +// Cumulus Imports +use cumulus_client_cli::CollatorOptions; +use cumulus_client_collator::service::CollatorService; #[docify::export(lookahead_collator)] -use polkadot_sdk::cumulus_client_consensus_aura::collators::lookahead::{ - self as aura, Params as AuraParams, +use cumulus_client_consensus_aura::collators::lookahead::{self as aura, Params as AuraParams}; +use cumulus_client_consensus_common::ParachainBlockImport as TParachainBlockImport; +use cumulus_client_consensus_proposer::Proposer; +use cumulus_client_service::{ + build_network, build_relay_chain_interface, prepare_node_config, start_relay_chain_tasks, + BuildNetworkParams, CollatorSybilResistance, DARecoveryProfile, ParachainHostFunctions, + StartRelayChainTasksParams, }; #[docify::export(cumulus_primitives)] -use polkadot_sdk::cumulus_primitives_core::{ +use cumulus_primitives_core::{ relay_chain::{CollatorPair, ValidationCode}, ParaId, }; -use polkadot_sdk::{ - cumulus_client_cli::CollatorOptions, - cumulus_client_collator::service::CollatorService, - cumulus_client_consensus_aura, - cumulus_client_consensus_common::ParachainBlockImport as TParachainBlockImport, - cumulus_client_consensus_proposer::Proposer, - cumulus_client_service::{ - build_network, build_relay_chain_interface, prepare_node_config, start_relay_chain_tasks, - BuildNetworkParams, CollatorSybilResistance, DARecoveryProfile, ParachainHostFunctions, - StartRelayChainTasksParams, - }, - cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface}, - frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE, - sc_basic_authorship, - sc_client_api::Backend, - sc_consensus::{self, ImportQueue}, - sc_executor::{HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY}, - sc_network::{self, NetworkBlock}, - sc_offchain, - sc_service::{self, Configuration, PartialComponents, TFullBackend, TFullClient, TaskManager}, - sc_sysinfo, - sc_telemetry::{self, Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}, - sc_transaction_pool, - sc_transaction_pool_api::OffchainTransactionPoolFactory, - sp_consensus_aura, - sp_keystore::KeystorePtr, - sp_timestamp, -}; +use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface}; + +// Substrate Imports +use frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE; use prometheus_endpoint::Registry; +use sc_client_api::Backend; +use sc_consensus::ImportQueue; +use sc_executor::{HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY}; +use sc_network::NetworkBlock; +use sc_service::{Configuration, PartialComponents, TFullBackend, TFullClient, TaskManager}; +use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}; +use sc_transaction_pool_api::OffchainTransactionPoolFactory; +use sp_keystore::KeystorePtr; #[docify::export(wasm_executor)] type ParachainExecutor = WasmExecutor; diff --git a/templates/parachain/pallets/template/Cargo.toml b/templates/parachain/pallets/template/Cargo.toml index c79dfc309a9b..dc1088cb33fe 100644 --- a/templates/parachain/pallets/template/Cargo.toml +++ b/templates/parachain/pallets/template/Cargo.toml @@ -16,13 +16,13 @@ targets = ["x86_64-unknown-linux-gnu"] codec = { features = ["derive"], workspace = true } scale-info = { features = ["derive"], workspace = true } -polkadot-sdk = { workspace = true, default-features = false, features = [ +frame = { workspace = true, default-features = false, features = [ "experimental", "runtime", ] } [features] default = ["std"] -runtime-benchmarks = ["polkadot-sdk/runtime-benchmarks"] -std = ["codec/std", "polkadot-sdk/std", "scale-info/std"] -try-runtime = ["polkadot-sdk/try-runtime"] +runtime-benchmarks = ["frame/runtime-benchmarks"] +std = ["codec/std", "frame/std", "scale-info/std"] +try-runtime = ["frame/try-runtime"] diff --git a/templates/parachain/pallets/template/src/benchmarking.rs b/templates/parachain/pallets/template/src/benchmarking.rs index 8ceb9186e677..9f2d09904f50 100644 --- a/templates/parachain/pallets/template/src/benchmarking.rs +++ b/templates/parachain/pallets/template/src/benchmarking.rs @@ -1,7 +1,7 @@ //! Benchmarking setup for pallet-template use super::*; -use polkadot_sdk::{frame_benchmarking::v2::*, frame_system}; +use frame::{deps::frame_benchmarking::v2::*, prelude::*}; #[benchmarks] mod benchmarks { diff --git a/templates/parachain/pallets/template/src/lib.rs b/templates/parachain/pallets/template/src/lib.rs index 44ef53a44267..09cebf87210a 100644 --- a/templates/parachain/pallets/template/src/lib.rs +++ b/templates/parachain/pallets/template/src/lib.rs @@ -66,19 +66,17 @@ mod benchmarking; // To see a full list of `pallet` macros and their use cases, see: // // -#[polkadot_sdk::frame_support::pallet] +#[frame::pallet] pub mod pallet { - use polkadot_sdk::{ - frame_support::{dispatch::DispatchResultWithPostInfo, pallet_prelude::*, DefaultNoBound}, - frame_system::pallet_prelude::*, - sp_runtime::traits::{CheckedAdd, One}, + use frame::{ + arithmetic::{CheckedAdd, One}, + prelude::*, }; /// Configure the pallet by specifying the parameters and types on which it depends. #[pallet::config] - pub trait Config: polkadot_sdk::frame_system::Config { - type RuntimeEvent: From> - + IsType<::RuntimeEvent>; + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; /// A type representing the weights required by the dispatchables of this pallet. type WeightInfo: crate::weights::WeightInfo; diff --git a/templates/parachain/pallets/template/src/mock.rs b/templates/parachain/pallets/template/src/mock.rs index ce5eeab661bd..b924428d4145 100644 --- a/templates/parachain/pallets/template/src/mock.rs +++ b/templates/parachain/pallets/template/src/mock.rs @@ -1,14 +1,12 @@ -use polkadot_sdk::{ - frame_support, - frame_support::{derive_impl, weights::constants::RocksDbWeight}, - frame_system, - frame_system::{mocking::MockBlock, GenesisConfig}, - sp_io, - sp_runtime::{traits::ConstU64, BuildStorage}, +use frame::{ + deps::{frame_support::weights::constants::RocksDbWeight, frame_system::GenesisConfig}, + prelude::*, + runtime::prelude::*, + testing_prelude::*, }; // Configure a mock runtime to test the pallet. -#[frame_support::runtime] +#[frame_construct_runtime] mod test_runtime { #[runtime::runtime] #[runtime::derive( @@ -44,6 +42,6 @@ impl crate::Config for Test { } // Build genesis storage according to the mock runtime. -pub fn new_test_ext() -> sp_io::TestExternalities { +pub fn new_test_ext() -> TestState { GenesisConfig::::default().build_storage().unwrap().into() } diff --git a/templates/parachain/pallets/template/src/tests.rs b/templates/parachain/pallets/template/src/tests.rs index 7bb3634c1d08..14609fd6dba7 100644 --- a/templates/parachain/pallets/template/src/tests.rs +++ b/templates/parachain/pallets/template/src/tests.rs @@ -1,5 +1,5 @@ use crate::{mock::*, Error, Something}; -use polkadot_sdk::frame_support::{assert_noop, assert_ok}; +use frame::testing_prelude::*; #[test] fn it_works_for_default_value() { diff --git a/templates/parachain/pallets/template/src/weights.rs b/templates/parachain/pallets/template/src/weights.rs index 1853d8023791..9295492bc20b 100644 --- a/templates/parachain/pallets/template/src/weights.rs +++ b/templates/parachain/pallets/template/src/weights.rs @@ -29,8 +29,7 @@ #![allow(unused_parens)] #![allow(unused_imports)] -use polkadot_sdk::frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use polkadot_sdk::frame_system; +use frame::{deps::frame_support::weights::constants::RocksDbWeight, prelude::*}; use core::marker::PhantomData; /// Weight functions needed for pallet_template. diff --git a/templates/parachain/runtime/src/apis.rs b/templates/parachain/runtime/src/apis.rs index 1995b4027319..eba9293a67ba 100644 --- a/templates/parachain/runtime/src/apis.rs +++ b/templates/parachain/runtime/src/apis.rs @@ -25,34 +25,23 @@ // External crates imports use alloc::vec::Vec; -#[cfg(feature = "try-runtime")] -use polkadot_sdk::frame_try_runtime; -#[cfg(feature = "runtime-benchmarks")] -use polkadot_sdk::{ - cumulus_pallet_session_benchmarking, frame_benchmarking, frame_system_benchmarking, + +use polkadot_sdk::*; + +use frame_support::{ + genesis_builder_helper::{build_state, get_preset}, + weights::Weight, }; -use polkadot_sdk::{ - cumulus_primitives_aura, cumulus_primitives_core, - frame_support::{ - genesis_builder_helper::{build_state, get_preset}, - weights::Weight, - }, - frame_system_rpc_runtime_api, - pallet_aura::Authorities, - pallet_transaction_payment, pallet_transaction_payment_rpc_runtime_api, - sp_api::{self, impl_runtime_apis}, - sp_block_builder, sp_consensus_aura, - sp_consensus_aura::sr25519::AuthorityId as AuraId, - sp_core::{crypto::KeyTypeId, OpaqueMetadata}, - sp_genesis_builder, sp_inherents, sp_offchain, sp_runtime, - sp_runtime::{ - traits::Block as BlockT, - transaction_validity::{TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, - }, - sp_session, sp_transaction_pool, - sp_version::RuntimeVersion, +use pallet_aura::Authorities; +use sp_api::impl_runtime_apis; +use sp_consensus_aura::sr25519::AuthorityId as AuraId; +use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; +use sp_runtime::{ + traits::Block as BlockT, + transaction_validity::{TransactionSource, TransactionValidity}, + ApplyExtrinsicResult, }; +use sp_version::RuntimeVersion; // Local module imports use super::{ diff --git a/templates/parachain/runtime/src/configs/mod.rs b/templates/parachain/runtime/src/configs/mod.rs index 41af9e9097e5..20236f5e37fa 100644 --- a/templates/parachain/runtime/src/configs/mod.rs +++ b/templates/parachain/runtime/src/configs/mod.rs @@ -25,46 +25,34 @@ mod xcm_config; +use polkadot_sdk::{staging_parachain_info as parachain_info, staging_xcm as xcm, *}; + // Substrate and Polkadot dependencies use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; -#[cfg(feature = "runtime-benchmarks")] -use polkadot_sdk::cumulus_primitives_core; -use polkadot_sdk::{ - cumulus_pallet_aura_ext, cumulus_pallet_xcmp_queue, - cumulus_primitives_core::{AggregateMessageOrigin, ParaId}, - frame_support::{ - self, derive_impl, - dispatch::DispatchClass, - parameter_types, - traits::{ - ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, TransformOrigin, - VariantCountOf, - }, - weights::{ConstantMultiplier, Weight}, - PalletId, - }, - frame_system::{ - self, - limits::{BlockLength, BlockWeights}, - EnsureRoot, - }, - pallet_aura, pallet_authorship, pallet_balances, pallet_collator_selection, - pallet_message_queue, pallet_session, pallet_sudo, pallet_timestamp, - pallet_transaction_payment, - pallet_xcm::{EnsureXcm, IsVoiceOfBody}, - parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}, - polkadot_runtime_common::{ - xcm_sender::NoPriceForMessageDelivery, BlockHashCount, SlowAdjustingFeeUpdate, +use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; +use frame_support::{ + derive_impl, + dispatch::DispatchClass, + parameter_types, + traits::{ + ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, TransformOrigin, VariantCountOf, }, - sp_consensus_aura::sr25519::AuthorityId as AuraId, - sp_core, sp_runtime, - sp_runtime::Perbill, - sp_version::RuntimeVersion, - staging_parachain_info as parachain_info, - staging_xcm::latest::prelude::BodyId, + weights::{ConstantMultiplier, Weight}, + PalletId, +}; +use frame_system::{ + limits::{BlockLength, BlockWeights}, + EnsureRoot, +}; +use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; +use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}; +use polkadot_runtime_common::{ + xcm_sender::NoPriceForMessageDelivery, BlockHashCount, SlowAdjustingFeeUpdate, }; -#[cfg(not(feature = "runtime-benchmarks"))] -use polkadot_sdk::{staging_xcm_builder as xcm_builder, staging_xcm_executor as xcm_executor}; +use sp_consensus_aura::sr25519::AuthorityId as AuraId; +use sp_runtime::Perbill; +use sp_version::RuntimeVersion; +use xcm::latest::prelude::BodyId; // Local module imports use super::{ diff --git a/templates/parachain/runtime/src/configs/xcm_config.rs b/templates/parachain/runtime/src/configs/xcm_config.rs index 6bd234ca3e80..3da3b711f4ff 100644 --- a/templates/parachain/runtime/src/configs/xcm_config.rs +++ b/templates/parachain/runtime/src/configs/xcm_config.rs @@ -2,30 +2,30 @@ use crate::{ AccountId, AllPalletsWithSystem, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, }; + use polkadot_sdk::{ - cumulus_pallet_xcm, cumulus_primitives_utility, - frame_support::{ - parameter_types, - traits::{ConstU32, Contains, Everything, Nothing}, - weights::Weight, - }, - frame_system::EnsureRoot, - pallet_xcm, - pallet_xcm::XcmPassthrough, - polkadot_parachain_primitives::primitives::Sibling, - polkadot_runtime_common::impls::ToAuthor, - staging_xcm::latest::prelude::*, - staging_xcm_builder::{ - AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, - DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds, - FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, ParentIsPreset, - RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, - SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, - TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, - WithUniqueTopic, - }, - staging_xcm_executor::{self as xcm_executor, XcmExecutor}, + staging_xcm as xcm, staging_xcm_builder as xcm_builder, staging_xcm_executor as xcm_executor, *, +}; + +use frame_support::{ + parameter_types, + traits::{ConstU32, Contains, Everything, Nothing}, + weights::Weight, +}; +use frame_system::EnsureRoot; +use pallet_xcm::XcmPassthrough; +use polkadot_parachain_primitives::primitives::Sibling; +use polkadot_runtime_common::impls::ToAuthor; +use xcm::latest::prelude::*; +use xcm_builder::{ + AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, + DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds, + FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, ParentIsPreset, + RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, + TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic, }; +use xcm_executor::XcmExecutor; parameter_types! { pub const RelayLocation: Location = Location::parent(); diff --git a/templates/parachain/runtime/src/genesis_config_presets.rs b/templates/parachain/runtime/src/genesis_config_presets.rs index ed9f2736aa18..ac2aef734f48 100644 --- a/templates/parachain/runtime/src/genesis_config_presets.rs +++ b/templates/parachain/runtime/src/genesis_config_presets.rs @@ -2,15 +2,16 @@ use crate::{ AccountId, BalancesConfig, CollatorSelectionConfig, ParachainInfoConfig, PolkadotXcmConfig, RuntimeGenesisConfig, SessionConfig, SessionKeys, SudoConfig, EXISTENTIAL_DEPOSIT, }; + use alloc::{vec, vec::Vec}; -use polkadot_sdk::{ - cumulus_primitives_core::ParaId, - parachains_common::{genesis_config_helpers::*, AuraId}, - sp_core::sr25519, - sp_genesis_builder::{self, PresetId}, - staging_xcm as xcm, -}; + +use polkadot_sdk::{staging_xcm as xcm, *}; + +use cumulus_primitives_core::ParaId; +use parachains_common::{genesis_config_helpers::*, AuraId}; use serde_json::Value; +use sp_core::sr25519; +use sp_genesis_builder::PresetId; /// The default XCM version to set in genesis config. const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; diff --git a/templates/parachain/runtime/src/lib.rs b/templates/parachain/runtime/src/lib.rs index 8d0e6102405c..cb30eb0e80d2 100644 --- a/templates/parachain/runtime/src/lib.rs +++ b/templates/parachain/runtime/src/lib.rs @@ -17,36 +17,24 @@ extern crate alloc; use alloc::vec::Vec; use smallvec::smallvec; -#[cfg(any(feature = "std", test))] -pub use polkadot_sdk::sp_runtime::BuildStorage; -#[cfg(feature = "std")] -use polkadot_sdk::sp_version::NativeVersion; -use polkadot_sdk::{ - cumulus_pallet_aura_ext, cumulus_pallet_xcm, cumulus_pallet_xcmp_queue, - cumulus_primitives_core, cumulus_primitives_storage_weight_reclaim, frame_executive, - frame_metadata_hash_extension, - frame_support::{ - self, - weights::{ - constants::WEIGHT_REF_TIME_PER_SECOND, Weight, WeightToFeeCoefficient, - WeightToFeeCoefficients, WeightToFeePolynomial, - }, - }, - frame_system, pallet_aura, pallet_authorship, pallet_balances, pallet_collator_selection, - pallet_message_queue, pallet_session, pallet_sudo, pallet_timestamp, - pallet_transaction_payment, pallet_xcm, sp_core, - sp_runtime::{ - create_runtime_str, generic, impl_opaque_keys, - traits::{BlakeTwo256, IdentifyAccount, Verify}, - MultiSignature, - }, - sp_version::{self, RuntimeVersion}, - staging_parachain_info as parachain_info, +use polkadot_sdk::{staging_parachain_info as parachain_info, *}; + +use sp_runtime::{ + create_runtime_str, generic, impl_opaque_keys, + traits::{BlakeTwo256, IdentifyAccount, Verify}, + MultiSignature, }; -pub use polkadot_sdk::{ - sp_consensus_aura::sr25519::AuthorityId as AuraId, - sp_runtime::{MultiAddress, Perbill, Permill}, + +#[cfg(feature = "std")] +use sp_version::NativeVersion; +use sp_version::RuntimeVersion; + +use frame_support::weights::{ + constants::WEIGHT_REF_TIME_PER_SECOND, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, + WeightToFeePolynomial, }; +pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; +pub use sp_runtime::{MultiAddress, Perbill, Permill}; use weights::ExtrinsicBaseWeight; diff --git a/templates/parachain/runtime/src/weights/block_weights.rs b/templates/parachain/runtime/src/weights/block_weights.rs index 75be7639ed0a..9e095a412ec2 100644 --- a/templates/parachain/runtime/src/weights/block_weights.rs +++ b/templates/parachain/runtime/src/weights/block_weights.rs @@ -16,7 +16,9 @@ // limitations under the License. pub mod constants { - use polkadot_sdk::frame_support::{ + use polkadot_sdk::*; + + use frame_support::{ parameter_types, weights::{constants, Weight}, }; @@ -29,7 +31,9 @@ pub mod constants { #[cfg(test)] mod test_weights { - use polkadot_sdk::frame_support::weights::constants; + use polkadot_sdk::*; + + use frame_support::weights::constants; /// Checks that the weight exists and is sane. // NOTE: If this test fails but you are sure that the generated values are fine, diff --git a/templates/parachain/runtime/src/weights/extrinsic_weights.rs b/templates/parachain/runtime/src/weights/extrinsic_weights.rs index ff2d9f087f5a..1a00a9cd0398 100644 --- a/templates/parachain/runtime/src/weights/extrinsic_weights.rs +++ b/templates/parachain/runtime/src/weights/extrinsic_weights.rs @@ -16,7 +16,9 @@ // limitations under the License. pub mod constants { - use polkadot_sdk::frame_support::{ + use polkadot_sdk::*; + + use frame_support::{ parameter_types, weights::{constants, Weight}, }; @@ -29,7 +31,9 @@ pub mod constants { #[cfg(test)] mod test_weights { - use polkadot_sdk::frame_support::weights::constants; + use polkadot_sdk::*; + + use frame_support::weights::constants; /// Checks that the weight exists and is sane. // NOTE: If this test fails but you are sure that the generated values are fine, diff --git a/templates/parachain/runtime/src/weights/paritydb_weights.rs b/templates/parachain/runtime/src/weights/paritydb_weights.rs index f02b03f13752..9071c58ec7f2 100644 --- a/templates/parachain/runtime/src/weights/paritydb_weights.rs +++ b/templates/parachain/runtime/src/weights/paritydb_weights.rs @@ -16,7 +16,9 @@ // limitations under the License. pub mod constants { - use polkadot_sdk::frame_support::{ + use polkadot_sdk::*; + + use frame_support::{ parameter_types, weights::{constants, RuntimeDbWeight}, }; @@ -32,8 +34,10 @@ pub mod constants { #[cfg(test)] mod test_db_weights { + use polkadot_sdk::*; + use super::constants::ParityDbWeight as W; - use polkadot_sdk::frame_support::weights::constants; + use frame_support::weights::constants; /// Checks that all weights exist and have sane values. // NOTE: If this test fails but you are sure that the generated values are fine, diff --git a/templates/parachain/runtime/src/weights/rocksdb_weights.rs b/templates/parachain/runtime/src/weights/rocksdb_weights.rs index 5d305b3cce0c..89e0b643aabe 100644 --- a/templates/parachain/runtime/src/weights/rocksdb_weights.rs +++ b/templates/parachain/runtime/src/weights/rocksdb_weights.rs @@ -16,7 +16,9 @@ // limitations under the License. pub mod constants { - use polkadot_sdk::frame_support::{ + use polkadot_sdk::*; + + use frame_support::{ parameter_types, weights::{constants, RuntimeDbWeight}, }; @@ -32,8 +34,10 @@ pub mod constants { #[cfg(test)] mod test_db_weights { + use polkadot_sdk::*; + use super::constants::RocksDbWeight as W; - use polkadot_sdk::frame_support::weights::constants; + use frame_support::weights::constants; /// Checks that all weights exist and have sane values. // NOTE: If this test fails but you are sure that the generated values are fine, From d0d0968fc7137e647a364de78c040c7719cff228 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Fri, 11 Oct 2024 10:40:43 +0300 Subject: [PATCH 05/12] Fix --- templates/parachain/runtime/src/configs/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/templates/parachain/runtime/src/configs/mod.rs b/templates/parachain/runtime/src/configs/mod.rs index 20236f5e37fa..7e2b4865bbb7 100644 --- a/templates/parachain/runtime/src/configs/mod.rs +++ b/templates/parachain/runtime/src/configs/mod.rs @@ -25,7 +25,10 @@ mod xcm_config; -use polkadot_sdk::{staging_parachain_info as parachain_info, staging_xcm as xcm, *}; +use polkadot_sdk::{ + staging_parachain_info as parachain_info, staging_xcm as xcm, + staging_xcm_builder as xcm_builder, staging_xcm_executor as xcm_executor, *, +}; // Substrate and Polkadot dependencies use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; From 551c0727cb77fdb3cff09019238b10a026f7cb49 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Fri, 11 Oct 2024 10:54:33 +0300 Subject: [PATCH 06/12] Fix warning --- templates/parachain/runtime/src/configs/mod.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/templates/parachain/runtime/src/configs/mod.rs b/templates/parachain/runtime/src/configs/mod.rs index 7e2b4865bbb7..0cf6497fd95e 100644 --- a/templates/parachain/runtime/src/configs/mod.rs +++ b/templates/parachain/runtime/src/configs/mod.rs @@ -25,10 +25,9 @@ mod xcm_config; -use polkadot_sdk::{ - staging_parachain_info as parachain_info, staging_xcm as xcm, - staging_xcm_builder as xcm_builder, staging_xcm_executor as xcm_executor, *, -}; +use polkadot_sdk::{staging_parachain_info as parachain_info, staging_xcm as xcm, *}; +#[cfg(not(feature = "runtime-benchmarks"))] +use polkadot_sdk::{staging_xcm_builder as xcm_builder, staging_xcm_executor as xcm_executor}; // Substrate and Polkadot dependencies use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; From abb88a660cc424f3aea2f7325231e64225282bd4 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Fri, 11 Oct 2024 21:51:43 +0300 Subject: [PATCH 07/12] Add traits to pallet_prelude --- substrate/frame/support/src/lib.rs | 2 +- templates/parachain/pallets/template/src/lib.rs | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs index 269867e38c51..443210cfab1a 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -915,7 +915,7 @@ pub mod pallet_prelude { pub use scale_info::TypeInfo; pub use sp_inherents::MakeFatalError; pub use sp_runtime::{ - traits::{MaybeSerializeDeserialize, Member, ValidateUnsigned}, + traits::{CheckedAdd, MaybeSerializeDeserialize, Member, One, ValidateUnsigned}, transaction_validity::{ InvalidTransaction, TransactionLongevity, TransactionPriority, TransactionSource, TransactionTag, TransactionValidity, TransactionValidityError, UnknownTransaction, diff --git a/templates/parachain/pallets/template/src/lib.rs b/templates/parachain/pallets/template/src/lib.rs index 09cebf87210a..211bef51aa86 100644 --- a/templates/parachain/pallets/template/src/lib.rs +++ b/templates/parachain/pallets/template/src/lib.rs @@ -68,10 +68,7 @@ mod benchmarking; // #[frame::pallet] pub mod pallet { - use frame::{ - arithmetic::{CheckedAdd, One}, - prelude::*, - }; + use frame::prelude::*; /// Configure the pallet by specifying the parameters and types on which it depends. #[pallet::config] From 0de030adf5203adc66603b1cc1c406e5c3d0675c Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Mon, 14 Oct 2024 12:51:49 +0300 Subject: [PATCH 08/12] Address review comments --- substrate/frame/support/src/lib.rs | 5 ++++- templates/parachain/pallets/template/Cargo.toml | 5 +---- templates/parachain/runtime/Cargo.toml | 2 -- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs index 443210cfab1a..d76073a97a35 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -915,7 +915,10 @@ pub mod pallet_prelude { pub use scale_info::TypeInfo; pub use sp_inherents::MakeFatalError; pub use sp_runtime::{ - traits::{CheckedAdd, MaybeSerializeDeserialize, Member, One, ValidateUnsigned}, + traits::{ + CheckedAdd, CheckedConversion, CheckedDiv, CheckedMul, CheckedShl, CheckedShr, + CheckedSub, MaybeSerializeDeserialize, Member, One, ValidateUnsigned, Zero, + }, transaction_validity::{ InvalidTransaction, TransactionLongevity, TransactionPriority, TransactionSource, TransactionTag, TransactionValidity, TransactionValidityError, UnknownTransaction, diff --git a/templates/parachain/pallets/template/Cargo.toml b/templates/parachain/pallets/template/Cargo.toml index dc1088cb33fe..f78612fbdb26 100644 --- a/templates/parachain/pallets/template/Cargo.toml +++ b/templates/parachain/pallets/template/Cargo.toml @@ -16,10 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"] codec = { features = ["derive"], workspace = true } scale-info = { features = ["derive"], workspace = true } -frame = { workspace = true, default-features = false, features = [ - "experimental", - "runtime", -] } +frame = { workspace = true, default-features = false, features = ["runtime"] } [features] default = ["std"] diff --git a/templates/parachain/runtime/Cargo.toml b/templates/parachain/runtime/Cargo.toml index a51e42d55ead..c9c08608f3b1 100644 --- a/templates/parachain/runtime/Cargo.toml +++ b/templates/parachain/runtime/Cargo.toml @@ -33,8 +33,6 @@ serde_json = { workspace = true, default-features = false, features = ["alloc"] pallet-parachain-template = { workspace = true } polkadot-sdk = { workspace = true, default-features = false, features = [ - "experimental", - "pallet-aura", "pallet-authorship", "pallet-balances", From a2817e4aec7da4e6eaeef0d610097cf34dd160fe Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Mon, 14 Oct 2024 14:03:28 +0300 Subject: [PATCH 09/12] fix --- templates/parachain/pallets/template/Cargo.toml | 7 ++++++- templates/parachain/runtime/Cargo.toml | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/templates/parachain/pallets/template/Cargo.toml b/templates/parachain/pallets/template/Cargo.toml index f78612fbdb26..49686b3cd4c9 100644 --- a/templates/parachain/pallets/template/Cargo.toml +++ b/templates/parachain/pallets/template/Cargo.toml @@ -16,7 +16,12 @@ targets = ["x86_64-unknown-linux-gnu"] codec = { features = ["derive"], workspace = true } scale-info = { features = ["derive"], workspace = true } -frame = { workspace = true, default-features = false, features = ["runtime"] } +frame = { workspace = true, default-features = false, features = [ + "runtime", +] } + +[dev-dependencies] +frame = { workspace = true, default-features = false, features = ["experimental"] } [features] default = ["std"] diff --git a/templates/parachain/runtime/Cargo.toml b/templates/parachain/runtime/Cargo.toml index c9c08608f3b1..90ffa31f021e 100644 --- a/templates/parachain/runtime/Cargo.toml +++ b/templates/parachain/runtime/Cargo.toml @@ -68,6 +68,9 @@ polkadot-sdk = { workspace = true, default-features = false, features = [ # Cumulus cumulus-pallet-parachain-system = { workspace = true } +[dev-dependencies] +polkadot-sdk = { workspace = true, default-features = false, features = ["experimental"] } + [features] default = ["std"] std = [ From 769a54de9ad98a23b8b0f2ebae82cdb33e5618a5 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Mon, 14 Oct 2024 14:20:05 +0300 Subject: [PATCH 10/12] fix --- templates/parachain/pallets/template/Cargo.toml | 4 +--- templates/parachain/runtime/Cargo.toml | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/templates/parachain/pallets/template/Cargo.toml b/templates/parachain/pallets/template/Cargo.toml index 49686b3cd4c9..dc1088cb33fe 100644 --- a/templates/parachain/pallets/template/Cargo.toml +++ b/templates/parachain/pallets/template/Cargo.toml @@ -17,12 +17,10 @@ codec = { features = ["derive"], workspace = true } scale-info = { features = ["derive"], workspace = true } frame = { workspace = true, default-features = false, features = [ + "experimental", "runtime", ] } -[dev-dependencies] -frame = { workspace = true, default-features = false, features = ["experimental"] } - [features] default = ["std"] runtime-benchmarks = ["frame/runtime-benchmarks"] diff --git a/templates/parachain/runtime/Cargo.toml b/templates/parachain/runtime/Cargo.toml index 90ffa31f021e..a51e42d55ead 100644 --- a/templates/parachain/runtime/Cargo.toml +++ b/templates/parachain/runtime/Cargo.toml @@ -33,6 +33,8 @@ serde_json = { workspace = true, default-features = false, features = ["alloc"] pallet-parachain-template = { workspace = true } polkadot-sdk = { workspace = true, default-features = false, features = [ + "experimental", + "pallet-aura", "pallet-authorship", "pallet-balances", @@ -68,9 +70,6 @@ polkadot-sdk = { workspace = true, default-features = false, features = [ # Cumulus cumulus-pallet-parachain-system = { workspace = true } -[dev-dependencies] -polkadot-sdk = { workspace = true, default-features = false, features = ["experimental"] } - [features] default = ["std"] std = [ From 54711299c843550601d33e9c7bcbc8292ff51a0c Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Mon, 14 Oct 2024 14:27:29 +0300 Subject: [PATCH 11/12] fix --- templates/parachain/runtime/Cargo.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/templates/parachain/runtime/Cargo.toml b/templates/parachain/runtime/Cargo.toml index a51e42d55ead..c9c08608f3b1 100644 --- a/templates/parachain/runtime/Cargo.toml +++ b/templates/parachain/runtime/Cargo.toml @@ -33,8 +33,6 @@ serde_json = { workspace = true, default-features = false, features = ["alloc"] pallet-parachain-template = { workspace = true } polkadot-sdk = { workspace = true, default-features = false, features = [ - "experimental", - "pallet-aura", "pallet-authorship", "pallet-balances", From 79e1e47bbba4bc3040a8dd154719d3b7382f1d82 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Mon, 14 Oct 2024 15:00:47 +0300 Subject: [PATCH 12/12] Remove unneeded feature --- templates/parachain/node/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/parachain/node/Cargo.toml b/templates/parachain/node/Cargo.toml index eada504f45f8..ba5f1212b79c 100644 --- a/templates/parachain/node/Cargo.toml +++ b/templates/parachain/node/Cargo.toml @@ -21,7 +21,7 @@ serde_json = { workspace = true, default-features = true } docify = { workspace = true } color-print = { workspace = true } -polkadot-sdk = { workspace = true, features = ["experimental", "node"] } +polkadot-sdk = { workspace = true, features = ["node"] } parachain-template-runtime = { workspace = true }