#![cfg_attr(not(feature = "std"), no_std)]
#![recursion_limit = "256"]
#[cfg(all(feature = "std", not(feature = "metadata-hash")))]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
#[cfg(all(feature = "std", feature = "metadata-hash"))]
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary_dev.rs"));
#[cfg(feature = "std")]
pub fn wasm_binary_unwrap() -> &'static [u8] {
WASM_BINARY.expect(
"Development wasm binary is not available. This means the client is \
built with `SKIP_WASM_BUILD` flag and it is only usable for \
production chains. Please rebuild with the flag disabled.",
)
}
use constants::RuntimeBlockWeights;
use frame_support::{
construct_runtime,
genesis_builder_helper::{build_state, get_preset},
weights::Weight,
};
use pallet_aura::Authorities;
use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
use primitives::{AccountId, Balance, BlockNumber, Hash, Nonce, Signature};
pub use primitives::{AuraId, ParaId};
use sp_core::OpaqueMetadata;
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
use sp_runtime::{
generic,
traits::{BlakeTwo256, Block as BlockT},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult,
};
use sp_std::prelude::*;
use sp_version::RuntimeVersion;
#[cfg(feature = "runtime-benchmarks")]
use {
cumulus_pallet_session_benchmarking::Pallet as SessionBench,
frame_benchmarking::{BenchmarkBatch, BenchmarkList, Benchmarking},
frame_support::traits::StorageInfoTrait,
frame_system_benchmarking::Pallet as SystemBench,
pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark,
};
pub mod constants;
mod genesis_config_presets;
mod implementations;
mod pallets_consensus;
mod pallets_governance;
mod pallets_nodle;
mod pallets_parachain;
mod pallets_system;
mod pallets_util;
mod version;
mod weights;
mod xcm_config;
pub use genesis_config_presets::development_config_genesis;
pub use pallets_consensus::SessionKeys;
#[cfg(feature = "std")]
pub use version::native_version;
pub use version::VERSION;
construct_runtime! {
pub enum Runtime {
System: frame_system = 0,
Timestamp: pallet_timestamp = 1,
Balances: pallet_balances = 2,
TransactionPayment: pallet_transaction_payment = 3,
RandomnessCollectiveFlip: pallet_insecure_randomness_collective_flip = 4,
Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>} = 10,
CompanyReserve: pallet_reserve::<Instance1> = 11,
InternationalReserve: pallet_reserve::<Instance2> = 12,
UsaReserve: pallet_reserve::<Instance3> = 13,
Vesting: pallet_grants = 14,
Mandate: pallet_mandate::{Pallet, Call, Storage, Event<T>} = 15,
TechnicalCommittee: pallet_collective::<Instance1> = 16,
TechnicalMembership: pallet_membership::<Instance3> = 17,
CollatorSelection: pallet_collator_selection::{Pallet, Call, Storage, Event<T>, Config<T>} = 19,
Authorship: pallet_authorship = 20,
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 23,
Aura: pallet_aura::{Pallet, Config<T>, Storage} = 24,
AuraExt: cumulus_pallet_aura_ext::{Pallet, Config<T>, Storage} = 25,
ParachainSystem: cumulus_pallet_parachain_system = 30,
ParachainInfo: parachain_info = 31,
CumulusXcm: cumulus_pallet_xcm = 32,
MessageQueue: pallet_message_queue = 33,
XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 34,
PolkadotXcm: pallet_xcm::{Pallet, Call, Storage, Event<T>, Origin, Config<T>} = 35,
Utility: pallet_utility = 40,
Multisig: pallet_multisig = 41,
Uniques: pallet_uniques::{Pallet, Storage, Event<T>} = 42,
Preimage: pallet_preimage::{Pallet, Call, Storage, Event<T>, HoldReason} = 43,
NodleUniques: pallet_nodle_uniques = 44,
Sponsorship: pallet_sponsorship = 45,
Identity: pallet_identity::{Pallet, Call, Storage, Event<T>} = 46,
Allocations: pallet_allocations = 51,
AllocationsOracles: pallet_membership::<Instance2> = 52,
DaoReserve: pallet_reserve::<Instance4> = 60,
Contracts: pallet_contracts = 62,
}
}
#[cfg(feature = "runtime-benchmarks")]
mod benches {
frame_benchmarking::define_benchmarks!(
[frame_system, SystemBench::<Runtime>]
[pallet_timestamp, Timestamp]
[pallet_balances, Balances]
[pallet_scheduler, Scheduler]
[pallet_reserve, CompanyReserve]
[pallet_reserve, InternationalReserve]
[pallet_reserve, UsaReserve]
[pallet_grants, Vesting]
[pallet_collective, TechnicalCommittee ]
[pallet_membership, TechnicalMembership]
[pallet_collator_selection, CollatorSelection]
[pallet_session, SessionBench::<Runtime>]
[cumulus_pallet_parachain_system, ParachainSystem]
[pallet_message_queue, MessageQueue]
[cumulus_pallet_xcmp_queue, XcmpQueue]
[pallet_xcm, PalletXcmExtrinsicsBenchmark::<Runtime>]
[pallet_xcm_benchmarks::generic, XcmGenericBenchmarks]
[pallet_xcm_benchmarks::fungible, XcmFungibleBenchmarks]
[pallet_utility, Utility]
[pallet_multisig, Multisig]
[pallet_uniques, Uniques]
[pallet_preimage, Preimage]
[pallet_nodle_uniques, NodleUniques]
[pallet_sponsorship, Sponsorship]
[pallet_identity, Identity]
[pallet_allocations, Allocations]
[pallet_membership, AllocationsOracles]
[pallet_reserve, DaoReserve]
[pallet_contracts, Contracts]
);
}
pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
pub type SignedBlock = generic::SignedBlock<Block>;
pub type BlockId = generic::BlockId<Block>;
pub type SignedExtra = (
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
frame_system::CheckGenesis<Runtime>,
frame_system::CheckEra<Runtime>,
frame_system::CheckNonce<Runtime>,
frame_system::CheckWeight<Runtime>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
pallet_sponsorship::ChargeSponsor<Runtime>,
cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim<Runtime>,
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
);
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
pub type SignedPayload = generic::SignedPayload<RuntimeCall, SignedExtra>;
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, RuntimeCall, SignedExtra>;
pub type Executive =
frame_executive::Executive<Runtime, Block, frame_system::ChainContext<Runtime>, Runtime, AllPalletsWithSystem>;
#[cfg(feature = "runtime-benchmarks")]
pub type XcmGenericBenchmarks = pallet_xcm_benchmarks::generic::Pallet<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
pub type XcmFungibleBenchmarks = pallet_xcm_benchmarks::fungible::Pallet<Runtime>;
type EventRecord =
frame_system::EventRecord<<Runtime as frame_system::Config>::RuntimeEvent, <Runtime as frame_system::Config>::Hash>;
sp_api::impl_runtime_apis! {
impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
build_state::<RuntimeGenesisConfig>(config)
}
fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
get_preset::<RuntimeGenesisConfig>(id, &genesis_config_presets::get_preset)
}
fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
vec![
sp_genesis_builder::PresetId::from("development"),
]
}
}
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> sp_consensus_aura::SlotDuration {
sp_consensus_aura::SlotDuration::from_millis(constants::SLOT_DURATION)
}
fn authorities() -> Vec<AuraId> {
Authorities::<Runtime>::get().into_inner()
}
}
impl cumulus_primitives_aura::AuraUnincludedSegmentApi<Block> for Runtime {
fn can_build_upon(
included_hash: <Block as BlockT>::Hash,
slot: cumulus_primitives_aura::Slot,
) -> bool {
pallets_parachain::ConsensusHook::can_build_upon(included_hash, slot)
}
}
impl sp_session::SessionKeys<Block> for Runtime {
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
pallets_consensus::SessionKeys::generate(seed)
}
fn decode_session_keys(
encoded: Vec<u8>,
) -> Option<Vec<(Vec<u8>, sp_core::crypto::KeyTypeId)>> {
pallets_consensus::SessionKeys::decode_into_raw_public_keys(&encoded)
}
}
impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
version::VERSION
}
fn execute_block(block: Block) {
Executive::execute_block(block)
}
fn initialize_block(header: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
Executive::initialize_block(header)
}
}
impl sp_api::Metadata<Block> for Runtime {
fn metadata() -> OpaqueMetadata {
OpaqueMetadata::new(Runtime::metadata().into())
}
fn metadata_at_version(version: u32) -> Option<OpaqueMetadata> {
Runtime::metadata_at_version(version)
}
fn metadata_versions() -> sp_std::vec::Vec<u32> {
Runtime::metadata_versions()
}
}
impl sp_block_builder::BlockBuilder<Block> for Runtime {
fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
Executive::apply_extrinsic(extrinsic)
}
fn finalize_block() -> <Block as BlockT>::Header {
Executive::finalize_block()
}
fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
data.create_extrinsics()
}
fn check_inherents(
block: Block,
data: sp_inherents::InherentData,
) -> sp_inherents::CheckInherentsResult {
data.check_extrinsics(&block)
}
}
impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
fn validate_transaction(
source: TransactionSource,
tx: <Block as BlockT>::Extrinsic,
block_hash: <Block as BlockT>::Hash,
) -> TransactionValidity {
Executive::validate_transaction(source, tx, block_hash)
}
}
impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
fn offchain_worker(header: &<Block as BlockT>::Header) {
Executive::offchain_worker(header)
}
}
impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
fn account_nonce(account: AccountId) -> Nonce {
System::account_nonce(account)
}
}
impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<
Block,
Balance,
> for Runtime {
fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {
TransactionPayment::query_info(uxt, len)
}
fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> {
TransactionPayment::query_fee_details(uxt, len)
}
fn query_weight_to_fee(weight: Weight) -> Balance {
TransactionPayment::weight_to_fee(weight)
}
fn query_length_to_fee(length: u32) -> Balance {
TransactionPayment::length_to_fee(length)
}
}
impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
ParachainSystem::collect_collation_info(header)
}
}
impl pallet_contracts::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash, EventRecord>
for Runtime
{
fn call(
origin: AccountId,
dest: AccountId,
value: Balance,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
input_data: Vec<u8>,
) -> pallet_contracts::ContractExecResult<Balance,EventRecord> {
let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block);
Contracts::bare_call(
origin,
dest,
value,
gas_limit,
storage_deposit_limit,
input_data,
constants::CONTRACTS_DEBUG_OUTPUT,
pallet_contracts::CollectEvents::UnsafeCollect,
pallet_contracts::Determinism::Enforced,
)
}
fn instantiate(
origin: AccountId,
value: Balance,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
code: pallet_contracts::Code<Hash>,
data: Vec<u8>,
salt: Vec<u8>,
) -> pallet_contracts::ContractInstantiateResult<AccountId, Balance, EventRecord> {
let gas_limit = gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block);
Contracts::bare_instantiate(
origin,
value,
gas_limit,
storage_deposit_limit,
code,
data,
salt,
constants::CONTRACTS_DEBUG_OUTPUT,
pallet_contracts::CollectEvents::UnsafeCollect,
)
}
fn upload_code(
origin: AccountId,
code: Vec<u8>,
storage_deposit_limit: Option<Balance>,
determinism: pallet_contracts::Determinism,
) -> pallet_contracts::CodeUploadResult<Hash, Balance> {
Contracts::bare_upload_code(origin, code, storage_deposit_limit, determinism)
}
fn get_storage(
address: AccountId,
key: Vec<u8>,
) -> pallet_contracts::GetStorageResult {
Contracts::get_storage(address, key)
}
}
#[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime {
fn benchmark_metadata(extra: bool) -> (
Vec<frame_benchmarking::BenchmarkList>,
Vec<frame_support::traits::StorageInfo>,
) {
let mut list = Vec::<BenchmarkList>::new();
list_benchmarks!(list, extra);
let storage_info = AllPalletsWithSystem::storage_info();
(list, storage_info)
}
fn dispatch_benchmark(
config: frame_benchmarking::BenchmarkConfig,
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
let whitelist: Vec<sp_storage::TrackedStorageKey> = vec![
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),
];
let mut batches = Vec::<BenchmarkBatch>::new();
let params = (&config, &whitelist);
add_benchmarks!(params, batches);
if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)
}
}
#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_support::traits::UpgradeCheckSelect) -> (Weight, Weight) {
log::debug!("on_runtime_upgrade");
let weight = Executive::try_runtime_upgrade(checks);
(weight.unwrap(), constants::RuntimeBlockWeights::get().max_block)
}
fn execute_block(block: Block, state_root_check: bool, signature_check: bool, select: frame_support::traits::TryStateSelect) -> Weight {
log::debug!("Executive::try_execute_block {block:?}-{state_root_check:?}-{select:?}");
Executive::try_execute_block(block, state_root_check, signature_check,select).expect("execute-block failed")
}
}
}
cumulus_pallet_parachain_system::register_validate_block! {
Runtime = Runtime,
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
}
#[cfg(test)]
mod tests {
use super::*;
use frame_system::offchain::CreateSignedTransaction;
#[test]
fn validate_transaction_submitter_bounds() {
fn is_submit_signed_transaction<T>()
where
T: CreateSignedTransaction<RuntimeCall>,
{
}
is_submit_signed_transaction::<Runtime>();
}
#[test]
#[ignore = "failing due to preimage depency"]
fn check_pallet_storage_sizes() {
use frame_support::traits::StorageInfoTrait;
let mut storage_info = AllPalletsWithSystem::storage_info();
println!(
"| {:^30} | {:^30} | {:^10} | {:^15} |",
"Pallet", "Storage", "Max Values", "Max Size"
);
println!("| {:-<30} | {:-<30} | {:-<10} | {:-<15} |", "", "", "", "");
storage_info.sort_by_key(|k| k.max_size);
storage_info.reverse();
let mut failed = 0;
for info in storage_info {
let pallet_name = String::from_utf8(info.pallet_name).unwrap();
let storage_name = String::from_utf8(info.storage_name).unwrap();
println!(
"| {:<30} | {:<30} | {:<10} | {:<15} |",
pallet_name,
storage_name,
format!("{:?}", info.max_values),
format!("{:?}", info.max_size)
);
if let Some(size) = info.max_size {
if size > 4 * 1024 * 1024 {
failed += 1;
}
}
}
assert!(failed == 0, "{failed} pallets have too big storage");
}
}