mirror of
https://github.com/pezkuwichain/pezkuwi-runtime-templates.git
synced 2026-07-26 23:25:41 +00:00
dc4f0129f1
* impl apis exported * runtime version test moved to constants * constants exported * constant related errors fixed * pallet configs exported * xmc_config moved to configs * types extracted
161 lines
5.4 KiB
Rust
161 lines
5.4 KiB
Rust
#![cfg_attr(not(feature = "std"), no_std)]
|
|
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
|
|
#![recursion_limit = "256"]
|
|
|
|
// Make the WASM binary available.
|
|
#[cfg(feature = "std")]
|
|
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
|
|
|
pub mod apis;
|
|
pub mod configs;
|
|
pub mod constants;
|
|
mod types;
|
|
mod weights;
|
|
|
|
use frame_support::{
|
|
construct_runtime,
|
|
weights::{WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial},
|
|
};
|
|
use smallvec::smallvec;
|
|
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
|
|
use sp_runtime::impl_opaque_keys;
|
|
#[cfg(any(feature = "std", test))]
|
|
pub use sp_runtime::BuildStorage;
|
|
pub use sp_runtime::{MultiAddress, Perbill, Permill};
|
|
use sp_std::prelude::*;
|
|
#[cfg(feature = "std")]
|
|
use sp_version::NativeVersion;
|
|
|
|
use crate::{
|
|
configs::pallet_custom_origins,
|
|
constants::{currency::MILLICENTS, POLY_DEGREE, P_FACTOR, Q_FACTOR},
|
|
weights::ExtrinsicBaseWeight,
|
|
};
|
|
pub use crate::{
|
|
configs::RuntimeBlockWeights,
|
|
types::{
|
|
AccountId, Balance, Block, BlockNumber, Executive, Nonce, Signature, UncheckedExtrinsic,
|
|
},
|
|
};
|
|
|
|
/// Handles converting a weight scalar to a fee value, based on the scale and
|
|
/// granularity of the node's balance type.
|
|
///
|
|
/// This should typically create a mapping between the following ranges:
|
|
/// - `[0, MAXIMUM_BLOCK_WEIGHT]`
|
|
/// - `[Balance::min, Balance::max]`
|
|
///
|
|
/// Yet, it can be used for any other sort of change to weight-fee. Some
|
|
/// examples being:
|
|
/// - Setting it to `0` will essentially disable the weight fee.
|
|
/// - Setting it to `1` will cause the literal `#[weight = x]` values to be
|
|
/// charged.
|
|
pub struct WeightToFee;
|
|
|
|
impl WeightToFeePolynomial for WeightToFee {
|
|
type Balance = Balance;
|
|
|
|
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
|
|
// in Rococo, extrinsic base weight (smallest non-zero weight) is mapped to 1
|
|
// MILLIUNIT: in our template, we map to 1/10 of that, or 1/10 MILLIUNIT
|
|
let p = MILLICENTS / P_FACTOR;
|
|
let q = Q_FACTOR * Balance::from(ExtrinsicBaseWeight::get().ref_time());
|
|
smallvec![WeightToFeeCoefficient {
|
|
degree: POLY_DEGREE,
|
|
negative: false,
|
|
coeff_frac: Perbill::from_rational(p % q, q),
|
|
coeff_integer: p / q,
|
|
}]
|
|
}
|
|
}
|
|
|
|
/// 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 of data like extrinsics, allowing for them to
|
|
/// continue syncing the network through upgrades to even the core data
|
|
/// structures.
|
|
pub mod opaque {
|
|
pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
|
|
use sp_runtime::{
|
|
generic,
|
|
traits::{BlakeTwo256, Hash as HashT},
|
|
};
|
|
|
|
use super::*;
|
|
/// Opaque block header type.
|
|
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
|
/// Opaque block type.
|
|
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
|
|
/// Opaque block identifier type.
|
|
pub type BlockId = generic::BlockId<Block>;
|
|
/// Opaque block hash type.
|
|
pub type Hash = <BlakeTwo256 as HashT>::Output;
|
|
}
|
|
|
|
impl_opaque_keys! {
|
|
pub struct SessionKeys {
|
|
pub aura: Aura,
|
|
}
|
|
}
|
|
|
|
/// The version information used to identify this runtime when compiled
|
|
/// natively.
|
|
#[cfg(feature = "std")]
|
|
pub fn native_version() -> NativeVersion {
|
|
use crate::constants::VERSION;
|
|
|
|
NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
|
|
}
|
|
|
|
// Create the runtime by composing the FRAME pallets that were previously
|
|
// configured.
|
|
construct_runtime!(
|
|
pub enum Runtime
|
|
{
|
|
// System Support
|
|
System: frame_system = 0,
|
|
ParachainSystem: cumulus_pallet_parachain_system = 1,
|
|
Timestamp: pallet_timestamp = 2,
|
|
ParachainInfo: parachain_info = 3,
|
|
Proxy: pallet_proxy = 4,
|
|
Utility: pallet_utility = 5,
|
|
Multisig: pallet_multisig = 6,
|
|
Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>} = 7,
|
|
Preimage: pallet_preimage::{Pallet, Call, Storage, Event<T>, HoldReason} = 8,
|
|
|
|
// Monetary
|
|
Balances: pallet_balances = 10,
|
|
TransactionPayment: pallet_transaction_payment = 11,
|
|
Assets: pallet_assets = 12,
|
|
Treasury: pallet_treasury::{Pallet, Call, Storage, Config<T>, Event<T>} = 13,
|
|
|
|
// Governance
|
|
Sudo: pallet_sudo = 15,
|
|
ConvictionVoting: pallet_conviction_voting::{Pallet, Call, Storage, Event<T>} = 16,
|
|
Referenda: pallet_referenda::{Pallet, Call, Storage, Event<T>} = 17,
|
|
Origins: pallet_custom_origins::{Origin} = 18,
|
|
Whitelist: pallet_whitelist::{Pallet, Call, Storage, Event<T>} = 19,
|
|
|
|
// Collator Support. The order of these 4 are important and shall not change.
|
|
Authorship: pallet_authorship = 20,
|
|
CollatorSelection: pallet_collator_selection = 21,
|
|
Session: pallet_session = 22,
|
|
Aura: pallet_aura = 23,
|
|
AuraExt: cumulus_pallet_aura_ext = 24,
|
|
|
|
// XCM Helpers
|
|
XcmpQueue: cumulus_pallet_xcmp_queue = 30,
|
|
PolkadotXcm: pallet_xcm = 31,
|
|
CumulusXcm: cumulus_pallet_xcm = 32,
|
|
MessageQueue: pallet_message_queue = 33,
|
|
}
|
|
);
|
|
|
|
cumulus_pallet_parachain_system::register_validate_block! {
|
|
Runtime = Runtime,
|
|
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
|
|
}
|
|
|
|
#[cfg(feature = "runtime-benchmarks")]
|
|
mod benchmark;
|