diff --git a/Cargo.lock b/Cargo.lock index f56e5bd..243c7e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4166,6 +4166,8 @@ name = "minimal-template-runtime" version = "0.0.0" dependencies = [ "frame", + "frame-support", + "frame-system", "pallet-balances", "pallet-minimal-template", "pallet-sudo", @@ -4174,7 +4176,9 @@ dependencies = [ "pallet-transaction-payment-rpc-runtime-api", "parity-scale-codec", "scale-info", + "sp-core", "sp-genesis-builder", + "sp-runtime", "substrate-wasm-builder", ] diff --git a/node/src/service.rs b/node/src/service.rs index 08db8b5..38bf84b 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -16,7 +16,7 @@ // limitations under the License. use futures::FutureExt; -use runtime::{self, interface::OpaqueBlock as Block, RuntimeApi}; +use runtime::{interface::OpaqueBlock as Block, RuntimeApi}; use sc_client_api::backend::Backend; use sc_executor::WasmExecutor; use sc_service::{error::Error as ServiceError, Configuration, TaskManager}; diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 5ddabb0..647c74f 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -21,6 +21,12 @@ frame = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release- "experimental", "runtime", ] } +frame-support = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false } +frame-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false } + +## premitivies +sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0" , default-features = false } +sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0" , default-features = false } # pallets that we want to use pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0" , default-features = false } @@ -39,12 +45,19 @@ pallet-minimal-template = { path = "../pallets/template", default-features = fa substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false, optional = true} [features] -default = ["std"] +default = ["std", "with-rocksdb-weights"] +with-rocksdb-weights = [] +with-paritydb-weights = [] std = [ "parity-scale-codec/std", "scale-info/std", "frame/std", + "frame-support/std", + "frame-system/std", + + "sp-core/std", + "sp-runtime/std", "pallet-balances/std", "pallet-sudo/std", diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 00fcaf1..8698a23 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -25,6 +25,7 @@ use frame::{ deps::frame_support::{ genesis_builder_helper::{build_config, create_default_config}, weights::{FixedFee, NoFee}, + traits::Everything, }, prelude::*, runtime::{ @@ -36,6 +37,36 @@ use frame::{ }, }; +use frame_support::{ + weights::{constants::WEIGHT_REF_TIME_PER_MILLIS, IdentityFee, Weight}, +}; + +// Substrate FRAME +#[cfg(feature = "with-paritydb-weights")] +use frame_support::weights::constants::ParityDbWeight as RuntimeDbWeight; +#[cfg(feature = "with-rocksdb-weights")] +use frame_support::weights::constants::RocksDbWeight as RuntimeDbWeight; + +use sp_runtime::generic; +use sp_runtime::Perbill; +use sp_runtime::traits::BlakeTwo256; + +/// Type of block number. +pub type BlockNumber = u32; + +pub mod opaque { + use super::*; + + pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic; + + /// Opaque block header type. + pub type Header = generic::Header; + /// Opaque block type. + pub type Block = generic::Block; + /// Opaque block identifier type. + pub type BlockId = generic::BlockId; +} + #[runtime_version] pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("minimal-template-runtime"), @@ -79,16 +110,101 @@ construct_runtime!( } ); +const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); +/// We allow for 2000ms of compute with a 6 second average block time. +pub const WEIGHT_MILLISECS_PER_BLOCK: u64 = 2000; +pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts( + WEIGHT_MILLISECS_PER_BLOCK * WEIGHT_REF_TIME_PER_MILLIS, + u64::MAX, +); +pub const MAXIMUM_BLOCK_LENGTH: u32 = 5 * 1024 * 1024; + parameter_types! { pub const Version: RuntimeVersion = VERSION; + pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights + ::with_sensible_defaults(MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO); + pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength + ::max_with_normal_ratio(MAXIMUM_BLOCK_LENGTH, NORMAL_DISPATCH_RATIO); + pub const SS58Prefix: u8 = 42; } -#[derive_impl(frame_system::config_preludes::SolochainDefaultConfig)] impl frame_system::Config for Runtime { + /// The default type for storing how many extrinsics an account has signed. + type Nonce = u32; + type Block = Block; - type Version = Version; - type BlockHashCount = ConstU32<1024>; + + /// The default type for hashing blocks and tries. + type Hash = sp_core::hash::H256; + + /// The default hashing algorithm used. + type Hashing = sp_runtime::traits::BlakeTwo256; + + /// The default identifier used to distinguish between accounts. + type AccountId = sp_runtime::AccountId32; + + /// The lookup mechanism to get account ID from whatever is passed in dispatchers. + type Lookup = sp_runtime::traits::AccountIdLookup; + + /// The maximum number of consumers allowed on a single account. Using 128 as default. + type MaxConsumers = ConstU32<128>; + + /// The default data to be stored in an account. type AccountData = pallet_balances::AccountData<::Balance>; + + /// What to do if a new account is created. + type OnNewAccount = (); + + /// What to do if an account is fully reaped from the system. + type OnKilledAccount = (); + + /// Weight information for the extrinsics of this pallet. + type SystemWeightInfo = (); + + /// This is used as an identifier of the chain. + type SS58Prefix = SS58Prefix; + + /// Version of the runtime. + type Version = Version; + + /// Block & extrinsics weights: base values and limits. + type BlockWeights = BlockWeights; + + /// The maximum length of a block (in bytes). + type BlockLength = BlockLength; + + /// The weight of database operations that the runtime can invoke. + type DbWeight = RuntimeDbWeight; + + type RuntimeEvent = RuntimeEvent; + + /// The ubiquitous origin type injected by `construct_runtime!`. + type RuntimeOrigin = RuntimeOrigin; + + /// The aggregated dispatch type available for extrinsics, injected by + /// `construct_runtime!`. + type RuntimeCall = RuntimeCall; + + /// The aggregated Task type, injected by `construct_runtime!`. + type RuntimeTask = RuntimeTask; + + /// Converts a module to the index of the module, injected by `construct_runtime!`. + type PalletInfo = PalletInfo; + + /// The basic call filter to use in dispatchable. Supports everything as the default. + type BaseCallFilter = Everything; + + /// Maximum number of block number to block hash mappings to keep (oldest pruned first). + /// Using 256 as default. + type BlockHashCount = ConstU32<256>; + + /// The set code logic, just the default since we're not a parachain. + type OnSetCode = (); + type SingleBlockMigrations = (); + type MultiBlockMigrator = (); + type PreInherents = (); + type PostInherents = (); + type PostTransactions = (); } #[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)] @@ -112,6 +228,7 @@ impl pallet_transaction_payment::Config for Runtime { impl pallet_minimal_template::Config for Runtime {} type Block = frame::runtime::types_common::BlockOf; + type Header = HeaderFor; type RuntimeExecutive =