diff --git a/Cargo.lock b/Cargo.lock index 2c808f2a6be68..241a5c8e76b8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8763,8 +8763,6 @@ dependencies = [ "parity-scale-codec", "polkadot-sdk-frame", "scale-info", - "sp-genesis-builder", - "sp-runtime", "substrate-wasm-builder", ] @@ -14625,6 +14623,7 @@ dependencies = [ "sp-consensus-aura", "sp-consensus-grandpa", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-offchain", @@ -19745,13 +19744,7 @@ dependencies = [ name = "solochain-template-runtime" version = "0.0.0" dependencies = [ - "frame-benchmarking", - "frame-executive", - "frame-support", - "frame-system", - "frame-system-benchmarking", "frame-system-rpc-runtime-api", - "frame-try-runtime", "pallet-aura", "pallet-balances", "pallet-grandpa", @@ -19761,20 +19754,8 @@ dependencies = [ "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", "parity-scale-codec", + "polkadot-sdk-frame", "scale-info", - "sp-api", - "sp-block-builder", - "sp-consensus-aura", - "sp-consensus-grandpa", - "sp-core", - "sp-genesis-builder", - "sp-inherents", - "sp-offchain", - "sp-runtime", - "sp-session", - "sp-storage 19.0.0", - "sp-transaction-pool", - "sp-version", "substrate-wasm-builder", ] diff --git a/substrate/frame/Cargo.toml b/substrate/frame/Cargo.toml index 41ece6c9a27fe..d4e65cfe96d2f 100644 --- a/substrate/frame/Cargo.toml +++ b/substrate/frame/Cargo.toml @@ -38,6 +38,7 @@ frame-system = { workspace = true } # primitive types used for developing FRAME runtimes. sp-version = { optional = true, workspace = true } sp-api = { optional = true, workspace = true } +sp-genesis-builder = { optional = true, workspace = true } sp-block-builder = { optional = true, workspace = true } sp-transaction-pool = { optional = true, workspace = true } sp-offchain = { optional = true, workspace = true } @@ -71,6 +72,7 @@ runtime = [ "sp-block-builder", "sp-consensus-aura", "sp-consensus-grandpa", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-session", @@ -81,6 +83,14 @@ runtime = [ "frame-executive", "frame-system-rpc-runtime-api", ] +serde = [ + "sp-consensus-aura?/serde", + "sp-consensus-grandpa?/serde", + + "sp-core/serde", + "sp-runtime/serde", + "sp-version?/serde", +] std = [ "codec/std", "frame-benchmarking?/std", @@ -98,6 +108,7 @@ std = [ "sp-consensus-aura?/std", "sp-consensus-grandpa?/std", "sp-core/std", + "sp-genesis-builder?/std", "sp-inherents?/std", "sp-io/std", "sp-offchain?/std", diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 3836e71cb00f2..466c7f460a566 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -233,6 +233,7 @@ pub mod runtime { pub use sp_block_builder::*; pub use sp_consensus_aura::*; pub use sp_consensus_grandpa::*; + pub use sp_genesis_builder::{Result as GenesisBuilderResult, *}; pub use sp_offchain::*; pub use sp_session::runtime_api::*; pub use sp_transaction_pool::runtime_api::*; @@ -383,6 +384,8 @@ pub mod deps { #[cfg(feature = "runtime")] pub use sp_consensus_grandpa; #[cfg(feature = "runtime")] + pub use sp_genesis_builder; + #[cfg(feature = "runtime")] pub use sp_inherents; #[cfg(feature = "runtime")] pub use sp_offchain; diff --git a/templates/minimal/runtime/Cargo.toml b/templates/minimal/runtime/Cargo.toml index 5d3cf8492e522..13af2be6d23f4 100644 --- a/templates/minimal/runtime/Cargo.toml +++ b/templates/minimal/runtime/Cargo.toml @@ -26,10 +26,6 @@ pallet-timestamp = { workspace = true } pallet-transaction-payment = { workspace = true } pallet-transaction-payment-rpc-runtime-api = { workspace = true } -# genesis builder that allows us to interact with runtime genesis config -sp-genesis-builder = { workspace = true } -sp-runtime = { features = ["serde"], workspace = true } - # local pallet templates pallet-minimal-template = { workspace = true } @@ -52,7 +48,5 @@ std = [ "pallet-minimal-template/std", - "sp-genesis-builder/std", - "sp-runtime/std", "substrate-wasm-builder", ] diff --git a/templates/minimal/runtime/src/lib.rs b/templates/minimal/runtime/src/lib.rs index 08ad537ecdd14..eec6f095cda86 100644 --- a/templates/minimal/runtime/src/lib.rs +++ b/templates/minimal/runtime/src/lib.rs @@ -36,7 +36,7 @@ use frame::{ runtime::{ apis::{ self, impl_runtime_apis, ApplyExtrinsicResult, CheckInherentsResult, - ExtrinsicInclusionMode, OpaqueMetadata, + ExtrinsicInclusionMode, GenesisBuilderResult, OpaqueMetadata, PresetId, }, prelude::*, }, @@ -274,16 +274,16 @@ impl_runtime_apis! { } } - impl sp_genesis_builder::GenesisBuilder for Runtime { - fn build_state(config: Vec) -> sp_genesis_builder::Result { + impl apis::GenesisBuilder for Runtime { + fn build_state(config: Vec) -> GenesisBuilderResult { build_state::(config) } - fn get_preset(id: &Option) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id, |_| None) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } diff --git a/templates/solochain/node/src/benchmarking.rs b/templates/solochain/node/src/benchmarking.rs index d1d8c2ccabaf6..474f8e52b07d0 100644 --- a/templates/solochain/node/src/benchmarking.rs +++ b/templates/solochain/node/src/benchmarking.rs @@ -4,7 +4,10 @@ use crate::service::FullClient; -use runtime::{AccountId, Balance, BalancesCall, SystemCall}; +use runtime::interface::{ + AccountId, Balance, BalancesCall, BlockHashCount, Runtime, RuntimeCall, Signature, SignedExtra, + SignedPayload, SystemCall, UncheckedExtrinsic, VERSION, +}; use sc_cli::Result; use sc_client_api::BlockBackend; use solochain_template_runtime as runtime; @@ -98,38 +101,36 @@ impl frame_benchmarking_cli::ExtrinsicBuilder for TransferKeepAliveBuilder { pub fn create_benchmark_extrinsic( client: &FullClient, sender: sp_core::sr25519::Pair, - call: runtime::RuntimeCall, + call: RuntimeCall, nonce: u32, -) -> runtime::UncheckedExtrinsic { +) -> UncheckedExtrinsic { let genesis_hash = client.block_hash(0).ok().flatten().expect("Genesis block exists; qed"); let best_hash = client.chain_info().best_hash; let best_block = client.chain_info().best_number; - let period = runtime::BlockHashCount::get() - .checked_next_power_of_two() - .map(|c| c / 2) - .unwrap_or(2) as u64; - let extra: runtime::SignedExtra = ( - frame_system::CheckNonZeroSender::::new(), - frame_system::CheckSpecVersion::::new(), - frame_system::CheckTxVersion::::new(), - frame_system::CheckGenesis::::new(), - frame_system::CheckEra::::from(sp_runtime::generic::Era::mortal( + let period = + BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2) as u64; + let extra: SignedExtra = ( + frame_system::CheckNonZeroSender::::new(), + frame_system::CheckSpecVersion::::new(), + frame_system::CheckTxVersion::::new(), + frame_system::CheckGenesis::::new(), + frame_system::CheckEra::::from(sp_runtime::generic::Era::mortal( period, best_block.saturated_into(), )), - frame_system::CheckNonce::::from(nonce), - frame_system::CheckWeight::::new(), - pallet_transaction_payment::ChargeTransactionPayment::::from(0), + frame_system::CheckNonce::::from(nonce), + frame_system::CheckWeight::::new(), + pallet_transaction_payment::ChargeTransactionPayment::::from(0), ); - let raw_payload = runtime::SignedPayload::from_raw( + let raw_payload = SignedPayload::from_raw( call.clone(), extra.clone(), ( (), - runtime::VERSION.spec_version, - runtime::VERSION.transaction_version, + VERSION.spec_version, + VERSION.transaction_version, genesis_hash, best_hash, (), @@ -139,10 +140,10 @@ pub fn create_benchmark_extrinsic( ); let signature = raw_payload.using_encoded(|e| sender.sign(e)); - runtime::UncheckedExtrinsic::new_signed( + UncheckedExtrinsic::new_signed( call, sp_runtime::AccountId32::from(sender.public()).into(), - runtime::Signature::Sr25519(signature), + Signature::Sr25519(signature), extra, ) } diff --git a/templates/solochain/node/src/chain_spec.rs b/templates/solochain/node/src/chain_spec.rs index 651025e68ded9..12b6959c27334 100644 --- a/templates/solochain/node/src/chain_spec.rs +++ b/templates/solochain/node/src/chain_spec.rs @@ -1,5 +1,8 @@ use sc_service::ChainType; -use solochain_template_runtime::{AccountId, Signature, WASM_BINARY}; +use solochain_template_runtime::{ + interface::{AccountId, Signature}, + WASM_BINARY, +}; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_consensus_grandpa::AuthorityId as GrandpaId; use sp_core::{sr25519, Pair, Public}; diff --git a/templates/solochain/node/src/command.rs b/templates/solochain/node/src/command.rs index 624ace1bf350a..fa23baecbdf9c 100644 --- a/templates/solochain/node/src/command.rs +++ b/templates/solochain/node/src/command.rs @@ -7,7 +7,7 @@ use crate::{ use frame_benchmarking_cli::{BenchmarkCmd, ExtrinsicFactory, SUBSTRATE_REFERENCE_HARDWARE}; use sc_cli::SubstrateCli; use sc_service::PartialComponents; -use solochain_template_runtime::{Block, EXISTENTIAL_DEPOSIT}; +use solochain_template_runtime::interface::{Block, OpaqueBlock, EXISTENTIAL_DEPOSIT}; use sp_keyring::Sr25519Keyring; impl SubstrateCli for Cli { @@ -180,8 +180,8 @@ pub fn run() -> sc_cli::Result<()> { match config.network.network_backend { sc_network::config::NetworkBackendType::Libp2p => service::new_full::< sc_network::NetworkWorker< - solochain_template_runtime::opaque::Block, - ::Hash, + OpaqueBlock, + ::Hash, >, >(config) .map_err(sc_cli::Error::Service), diff --git a/templates/solochain/node/src/rpc.rs b/templates/solochain/node/src/rpc.rs index fe2b6ca72ede5..268a42df508e8 100644 --- a/templates/solochain/node/src/rpc.rs +++ b/templates/solochain/node/src/rpc.rs @@ -9,7 +9,7 @@ use std::sync::Arc; use jsonrpsee::RpcModule; use sc_transaction_pool_api::TransactionPool; -use solochain_template_runtime::{opaque::Block, AccountId, Balance, Nonce}; +use solochain_template_runtime::interface::{AccountId, Balance, Nonce, OpaqueBlock as Block}; use sp_api::ProvideRuntimeApi; use sp_block_builder::BlockBuilder; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; diff --git a/templates/solochain/node/src/service.rs b/templates/solochain/node/src/service.rs index 06d4b8ab7a59b..fff4fd8344794 100644 --- a/templates/solochain/node/src/service.rs +++ b/templates/solochain/node/src/service.rs @@ -7,7 +7,7 @@ use sc_consensus_grandpa::SharedVoterState; use sc_service::{error::Error as ServiceError, Configuration, TaskManager, WarpSyncParams}; use sc_telemetry::{Telemetry, TelemetryWorker}; use sc_transaction_pool_api::OffchainTransactionPoolFactory; -use solochain_template_runtime::{self, opaque::Block, RuntimeApi}; +use solochain_template_runtime::{self, interface::OpaqueBlock as Block, RuntimeApi}; use sp_consensus_aura::sr25519::AuthorityPair as AuraPair; use std::{sync::Arc, time::Duration}; diff --git a/templates/solochain/runtime/Cargo.toml b/templates/solochain/runtime/Cargo.toml index f06c80b9a0321..52bb0525f3cc6 100644 --- a/templates/solochain/runtime/Cargo.toml +++ b/templates/solochain/runtime/Cargo.toml @@ -21,11 +21,11 @@ scale-info = { features = [ "serde", ], workspace = true } -# frame -frame-support = { features = ["experimental"], workspace = true } -frame-system = { workspace = true } -frame-try-runtime = { optional = true, workspace = true } -frame-executive = { workspace = true } +# this is a frame-based runtime, thus importing `frame` with runtime feature enabled. +frame = { features = [ + "runtime", + "serde", +], workspace = true } # frame pallets pallet-aura = { workspace = true } @@ -35,39 +35,10 @@ pallet-sudo = { workspace = true } pallet-timestamp = { workspace = true } pallet-transaction-payment = { workspace = true } -# primitives -sp-api = { workspace = true } -sp-block-builder = { workspace = true } -sp-consensus-aura = { features = [ - "serde", -], workspace = true } -sp-consensus-grandpa = { features = [ - "serde", -], workspace = true } -sp-core = { features = [ - "serde", -], workspace = true } -sp-inherents = { workspace = true } -sp-offchain = { workspace = true } -sp-runtime = { features = [ - "serde", -], workspace = true } -sp-session = { workspace = true } -sp-storage = { workspace = true } -sp-transaction-pool = { workspace = true } -sp-version = { features = [ - "serde", -], workspace = true } -sp-genesis-builder = { workspace = true } - # RPC related frame-system-rpc-runtime-api = { workspace = true } pallet-transaction-payment-rpc-runtime-api = { workspace = true } -# Used for runtime benchmarking -frame-benchmarking = { optional = true, workspace = true } -frame-system-benchmarking = { optional = true, workspace = true } - # The pallet in this template. pallet-template = { workspace = true } @@ -80,14 +51,7 @@ std = [ "codec/std", "scale-info/std", - "frame-executive/std", - "frame-support/std", - "frame-system-benchmarking?/std", - "frame-system-rpc-runtime-api/std", - "frame-system/std", - - "frame-benchmarking?/std", - "frame-try-runtime?/std", + "frame/std", "pallet-aura/std", "pallet-balances/std", @@ -98,41 +62,21 @@ std = [ "pallet-transaction-payment-rpc-runtime-api/std", "pallet-transaction-payment/std", - "sp-api/std", - "sp-block-builder/std", - "sp-consensus-aura/std", - "sp-consensus-grandpa/std", - "sp-core/std", - "sp-genesis-builder/std", - "sp-inherents/std", - "sp-offchain/std", - "sp-runtime/std", - "sp-session/std", - "sp-storage/std", - "sp-transaction-pool/std", - "sp-version/std", - + "frame-system-rpc-runtime-api/std", "substrate-wasm-builder", ] runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system-benchmarking/runtime-benchmarks", - "frame-system/runtime-benchmarks", + "frame/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-grandpa/runtime-benchmarks", "pallet-sudo/runtime-benchmarks", "pallet-template/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", ] try-runtime = [ - "frame-executive/try-runtime", - "frame-support/try-runtime", - "frame-system/try-runtime", - "frame-try-runtime/try-runtime", + "frame/try-runtime", "pallet-aura/try-runtime", "pallet-balances/try-runtime", "pallet-grandpa/try-runtime", @@ -140,5 +84,4 @@ try-runtime = [ "pallet-template/try-runtime", "pallet-timestamp/try-runtime", "pallet-transaction-payment/try-runtime", - "sp-runtime/try-runtime", ] diff --git a/templates/solochain/runtime/src/lib.rs b/templates/solochain/runtime/src/lib.rs index 9de95ac956951..b38c05e884714 100644 --- a/templates/solochain/runtime/src/lib.rs +++ b/templates/solochain/runtime/src/lib.rs @@ -5,67 +5,54 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); extern crate alloc; use alloc::{vec, vec::Vec}; -use pallet_grandpa::AuthorityId as GrandpaId; -use sp_api::impl_runtime_apis; -use sp_consensus_aura::sr25519::AuthorityId as AuraId; -use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; -use sp_runtime::{ - create_runtime_str, generic, impl_opaque_keys, - traits::{BlakeTwo256, Block as BlockT, IdentifyAccount, NumberFor, One, Verify}, - transaction_validity::{TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, MultiSignature, -}; -#[cfg(feature = "std")] -use sp_version::NativeVersion; -use sp_version::RuntimeVersion; -pub use frame_support::{ - construct_runtime, derive_impl, parameter_types, - traits::{ - ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, KeyOwnerProofSystem, Randomness, - StorageInfo, +use frame::{ + deps::{ + frame_support::{ + genesis_builder_helper::{build_state, get_preset}, + runtime, + weights::{ + constants::{RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND}, + IdentityFee, Weight, + }, + }, + sp_core::{crypto::KeyTypeId, Void, H256}, + sp_runtime::{generic, impl_opaque_keys, MultiAddress, MultiSignature, Perbill}, }, - weights::{ - constants::{ - BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND, + prelude::*, + runtime::{ + apis::{ + self, impl_runtime_apis, sr25519::AuthorityId as AuraId, ApplyExtrinsicResult, + AuthorityList, CheckInherentsResult, EquivocationProof, ExtrinsicInclusionMode, + GenesisBuilderResult, InherentData, OpaqueKeyOwnershipProof, OpaqueMetadata, PresetId, + SetId, SlotDuration, }, - IdentityFee, Weight, + prelude::*, + }, + traits::{ + BlakeTwo256, Block as BlockT, IdentifyAccount, NumberFor, One, VariantCountOf, Verify, }, - StorageValue, -}; -use frame_support::{ - genesis_builder_helper::{build_state, get_preset}, - traits::VariantCountOf, }; -pub use frame_system::Call as SystemCall; -pub use pallet_balances::Call as BalancesCall; -pub use pallet_timestamp::Call as TimestampCall; -use pallet_transaction_payment::{ConstFeeMultiplier, FungibleAdapter, Multiplier}; -#[cfg(any(feature = "std", test))] -pub use sp_runtime::BuildStorage; -pub use sp_runtime::{Perbill, Permill}; - -/// Import the template pallet. -pub use pallet_template; +use pallet_transaction_payment::{ConstFeeMultiplier, Multiplier}; /// An index to a block. -pub type BlockNumber = u32; +type BlockNumber = u32; /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. -pub type Signature = MultiSignature; +type Signature = MultiSignature; /// Some way of identifying an account on the chain. We intentionally make it equivalent /// to the public key of our transaction signing scheme. -pub type AccountId = <::Signer as IdentifyAccount>::AccountId; +type AccountId = <::Signer as IdentifyAccount>::AccountId; /// Balance of an account. -pub type Balance = u128; +type Balance = u128; /// Index of a transaction in the chain. -pub type Nonce = u32; +type Nonce = u32; /// A hash of some data used by the chain. -pub type Hash = sp_core::H256; +type Hash = H256; /// Opaque types. These are used by the CLI to instantiate machinery that don't need to know /// the specifics of the runtime. They can then be made to be agnostic over specific formats @@ -74,7 +61,7 @@ pub type Hash = sp_core::H256; pub mod opaque { use super::*; - pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic; + pub use frame::deps::sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic; /// Opaque block header type. pub type Header = generic::Header; @@ -93,8 +80,8 @@ pub mod opaque { // To learn more about runtime versioning, see: // https://docs.substrate.io/main-docs/build/upgrade#runtime-versioning -#[sp_version::runtime_version] -pub const VERSION: RuntimeVersion = RuntimeVersion { +#[runtime_version] +const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("solochain-template-runtime"), impl_name: create_runtime_str!("solochain-template-runtime"), authoring_version: 1, @@ -116,16 +103,11 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { /// up by `pallet_aura` to implement `fn slot_duration()`. /// /// Change this to adjust the block time. -pub const MILLISECS_PER_BLOCK: u64 = 6000; +const MILLISECS_PER_BLOCK: u64 = 6000; // NOTE: Currently it is not possible to change the slot duration after the chain has started. // Attempting to do so will brick block production. -pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; - -// Time is measured by 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; +const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; /// The version information used to identify this runtime when compiled natively. #[cfg(feature = "std")] @@ -149,9 +131,7 @@ parameter_types! { pub const SS58Prefix: u8 = 42; } -/// The default types are being injected by [`derive_impl`](`frame_support::derive_impl`) from -/// [`SoloChainDefaultConfig`](`struct@frame_system::config_preludes::SolochainDefaultConfig`), -/// but overridden as needed. +/// Implements the types required for the system pallet. #[derive_impl(frame_system::config_preludes::SolochainDefaultConfig)] impl frame_system::Config for Runtime { /// The block type for the runtime. @@ -176,7 +156,7 @@ impl frame_system::Config for Runtime { type AccountData = pallet_balances::AccountData; /// This is used as an identifier of the chain. 42 is the generic substrate prefix. type SS58Prefix = SS58Prefix; - type MaxConsumers = frame_support::traits::ConstU32<16>; + type MaxConsumers = ConstU32<16>; } impl pallet_aura::Config for Runtime { @@ -195,10 +175,11 @@ impl pallet_grandpa::Config for Runtime { type MaxNominators = ConstU32<0>; type MaxSetIdSessionEntries = ConstU64<0>; - type KeyOwnerProof = sp_core::Void; + type KeyOwnerProof = Void; type EquivocationReportSystem = (); } +// Implements the types required for the timestamp pallet. impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; @@ -208,8 +189,9 @@ impl pallet_timestamp::Config for Runtime { } /// Existential deposit. -pub const EXISTENTIAL_DEPOSIT: u128 = 500; +const EXISTENTIAL_DEPOSIT: u128 = 500; +// Implements the types required for the balances pallet. impl pallet_balances::Config for Runtime { type MaxLocks = ConstU32<50>; type MaxReserves = (); @@ -232,15 +214,17 @@ parameter_types! { pub FeeMultiplier: Multiplier = Multiplier::one(); } +// Implements the types required for the transaction payment pallet. impl pallet_transaction_payment::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type OnChargeTransaction = FungibleAdapter; type OperationalFeeMultiplier = ConstU8<5>; + type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter; type WeightToFee = IdentityFee; type LengthToFee = IdentityFee; type FeeMultiplierUpdate = ConstFeeMultiplier; } +// Implements the types required for the sudo pallet. impl pallet_sudo::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; @@ -254,7 +238,7 @@ impl pallet_template::Config for Runtime { } // Create the runtime by composing the FRAME pallets that were previously configured. -#[frame_support::runtime] +#[runtime] mod runtime { #[runtime::runtime] #[runtime::derive( @@ -297,13 +281,13 @@ mod runtime { } /// The address format for describing accounts. -pub type Address = sp_runtime::MultiAddress; +type Address = MultiAddress; /// Block header type as expected by this runtime. -pub type Header = generic::Header; +type Header = generic::Header; /// Block type as expected by this runtime. -pub type Block = generic::Block; +type Block = generic::Block; /// The SignedExtension to the basic transaction logic. -pub type SignedExtra = ( +type SignedExtra = ( frame_system::CheckNonZeroSender, frame_system::CheckSpecVersion, frame_system::CheckTxVersion, @@ -321,12 +305,11 @@ pub type SignedExtra = ( type Migrations = (); /// Unchecked extrinsic type as expected by this runtime. -pub type UncheckedExtrinsic = - generic::UncheckedExtrinsic; +type UncheckedExtrinsic = generic::UncheckedExtrinsic; /// The payload being signed in transactions. -pub type SignedPayload = generic::SignedPayload; -/// Executive: handles dispatch to the various modules. -pub type Executive = frame_executive::Executive< +type SignedPayload = generic::SignedPayload; +/// RuntimeExecutive: handles dispatch to the various modules. +type RuntimeExecutive = Executive< Runtime, Block, frame_system::ChainContext, @@ -335,8 +318,20 @@ pub type Executive = frame_executive::Executive< Migrations, >; +#[cfg(feature = "try-runtime")] +use frame::deps::frame_try_runtime; +#[cfg(feature = "runtime-benchmarks")] +use frame::{ + deps::{ + frame_benchmarking, frame_system_benchmarking, sp_runtime::RuntimeString, + sp_storage::TrackedStorageKey, + }, + traits::{StorageInfo, WhitelistedStorageKeys}, +}; + #[cfg(feature = "runtime-benchmarks")] mod benches { + use super::*; frame_benchmarking::define_benchmarks!( [frame_benchmarking, BaselineBench::] [frame_system, SystemBench::] @@ -348,21 +343,21 @@ mod benches { } impl_runtime_apis! { - impl sp_api::Core for Runtime { + impl apis::Core for Runtime { fn version() -> RuntimeVersion { VERSION } fn execute_block(block: Block) { - Executive::execute_block(block); + RuntimeExecutive::execute_block(block); } - fn initialize_block(header: &::Header) -> sp_runtime::ExtrinsicInclusionMode { - Executive::initialize_block(header) + fn initialize_block(header: &::Header) -> ExtrinsicInclusionMode { + RuntimeExecutive::initialize_block(header) } } - impl sp_api::Metadata for Runtime { + impl apis::Metadata for Runtime { fn metadata() -> OpaqueMetadata { OpaqueMetadata::new(Runtime::metadata().into()) } @@ -376,46 +371,46 @@ impl_runtime_apis! { } } - impl sp_block_builder::BlockBuilder for Runtime { + impl apis::BlockBuilder for Runtime { fn apply_extrinsic(extrinsic: ::Extrinsic) -> ApplyExtrinsicResult { - Executive::apply_extrinsic(extrinsic) + RuntimeExecutive::apply_extrinsic(extrinsic) } fn finalize_block() -> ::Header { - Executive::finalize_block() + RuntimeExecutive::finalize_block() } - fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<::Extrinsic> { + fn inherent_extrinsics(data: InherentData) -> Vec<::Extrinsic> { data.create_extrinsics() } fn check_inherents( block: Block, - data: sp_inherents::InherentData, - ) -> sp_inherents::CheckInherentsResult { + data: InherentData, + ) -> CheckInherentsResult { data.check_extrinsics(&block) } } - impl sp_transaction_pool::runtime_api::TaggedTransactionQueue for Runtime { + impl apis::TaggedTransactionQueue for Runtime { fn validate_transaction( source: TransactionSource, tx: ::Extrinsic, block_hash: ::Hash, ) -> TransactionValidity { - Executive::validate_transaction(source, tx, block_hash) + RuntimeExecutive::validate_transaction(source, tx, block_hash) } } - impl sp_offchain::OffchainWorkerApi for Runtime { + impl apis::OffchainWorkerApi for Runtime { fn offchain_worker(header: &::Header) { - Executive::offchain_worker(header) + RuntimeExecutive::offchain_worker(header) } } - impl sp_consensus_aura::AuraApi for Runtime { - fn slot_duration() -> sp_consensus_aura::SlotDuration { - sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration()) + impl apis::AuraApi for Runtime { + fn slot_duration() -> SlotDuration { + SlotDuration::from_millis(Aura::slot_duration()) } fn authorities() -> Vec { @@ -423,7 +418,7 @@ impl_runtime_apis! { } } - impl sp_session::SessionKeys for Runtime { + impl apis::SessionKeys for Runtime { fn generate_session_keys(seed: Option>) -> Vec { opaque::SessionKeys::generate(seed) } @@ -435,29 +430,29 @@ impl_runtime_apis! { } } - impl sp_consensus_grandpa::GrandpaApi for Runtime { - fn grandpa_authorities() -> sp_consensus_grandpa::AuthorityList { + impl apis::GrandpaApi for Runtime { + fn grandpa_authorities() -> AuthorityList { Grandpa::grandpa_authorities() } - fn current_set_id() -> sp_consensus_grandpa::SetId { + fn current_set_id() -> SetId { Grandpa::current_set_id() } fn submit_report_equivocation_unsigned_extrinsic( - _equivocation_proof: sp_consensus_grandpa::EquivocationProof< + _equivocation_proof: EquivocationProof< ::Hash, NumberFor, >, - _key_owner_proof: sp_consensus_grandpa::OpaqueKeyOwnershipProof, + _key_owner_proof:OpaqueKeyOwnershipProof, ) -> Option<()> { None } fn generate_key_ownership_proof( - _set_id: sp_consensus_grandpa::SetId, - _authority_id: GrandpaId, - ) -> Option { + _set_id: SetId, + _authority_id: pallet_grandpa::AuthorityId, + ) -> Option { // NOTE: this is the only implementation possible since we've // defined our key owner proof type as a bottom type (i.e. a type // with no values). @@ -519,10 +514,9 @@ impl_runtime_apis! { impl frame_benchmarking::Benchmark for Runtime { fn benchmark_metadata(extra: bool) -> ( Vec, - Vec, + Vec, ) { use frame_benchmarking::{baseline, Benchmarking, BenchmarkList}; - use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; use baseline::Pallet as BaselineBench; @@ -536,16 +530,14 @@ impl_runtime_apis! { fn dispatch_benchmark( config: frame_benchmarking::BenchmarkConfig - ) -> Result, sp_runtime::RuntimeString> { + ) -> Result, RuntimeString> { use frame_benchmarking::{baseline, Benchmarking, BenchmarkBatch}; - use sp_storage::TrackedStorageKey; use frame_system_benchmarking::Pallet as SystemBench; use baseline::Pallet as BaselineBench; impl frame_system_benchmarking::Config for Runtime {} impl baseline::Config for Runtime {} - use frame_support::traits::WhitelistedStorageKeys; let whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); let mut batches = Vec::::new(); @@ -562,7 +554,7 @@ impl_runtime_apis! { // NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to // have a backtrace here. If any of the pre/post migration checks fail, we shall stop // right here and right now. - let weight = Executive::try_runtime_upgrade(checks).unwrap(); + let weight = RuntimeExecutive::try_runtime_upgrade(checks).unwrap(); (weight, BlockWeights::get().max_block) } @@ -574,21 +566,48 @@ impl_runtime_apis! { ) -> Weight { // NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to // have a backtrace here. - Executive::try_execute_block(block, state_root_check, signature_check, select).expect("execute-block failed") + RuntimeExecutive::try_execute_block(block, state_root_check, signature_check, select).expect("execute-block failed") } } - impl sp_genesis_builder::GenesisBuilder for Runtime { - fn build_state(config: Vec) -> sp_genesis_builder::Result { + impl apis::GenesisBuilder for Runtime { + fn build_state(config: Vec) -> GenesisBuilderResult { build_state::(config) } - fn get_preset(id: &Option) -> Option> { + fn get_preset(id: &Option) -> Option> { get_preset::(id, |_| None) } - fn preset_names() -> Vec { + fn preset_names() -> Vec { vec![] } } } + +pub mod interface { + pub type AccountId = super::AccountId; + pub type Balance = super::Balance; + pub type Nonce = super::Nonce; + + pub type Block = super::Block; + pub type OpaqueBlock = super::opaque::Block; + pub type BlockHashCount = super::BlockHashCount; + + pub type UncheckedExtrinsic = super::UncheckedExtrinsic; + + pub type Signature = super::Signature; + pub type SignedExtra = super::SignedExtra; + pub type SignedPayload = super::SignedPayload; + + pub use frame::deps::frame_system::Call as SystemCall; + pub use pallet_balances::Call as BalancesCall; + pub use pallet_timestamp::Call as TimestampCall; + + pub type Runtime = super::Runtime; + pub type RuntimeCall = super::RuntimeCall; + + pub const EXISTENTIAL_DEPOSIT: u128 = super::EXISTENTIAL_DEPOSIT; + + pub const VERSION: super::RuntimeVersion = super::VERSION; +} diff --git a/umbrella/Cargo.toml b/umbrella/Cargo.toml index 79e7c0c38edaa..8d2be6f2e104c 100644 --- a/umbrella/Cargo.toml +++ b/umbrella/Cargo.toml @@ -503,6 +503,7 @@ serde = [ "pallet-transaction-storage?/serde", "pallet-treasury?/serde", "pallet-xcm?/serde", + "polkadot-sdk-frame?/serde", "snowbridge-beacon-primitives?/serde", "snowbridge-core?/serde", "snowbridge-ethereum?/serde",