// Copyright 2020 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see .
//! The Rococo runtime for v1 parachains.
#![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"]
use pallet_transaction_payment::CurrencyAdapter;
use sp_std::prelude::*;
use codec::Encode;
use primitives::v1::{
AccountId, AccountIndex, Balance, BlockNumber, Hash, Nonce, Signature, Moment,
GroupRotationInfo, CoreState, Id, ValidationData, ValidationCode, CandidateEvent,
ValidatorId, ValidatorIndex, CommittedCandidateReceipt, OccupiedCoreAssumption,
PersistedValidationData,
};
use runtime_common::{
SlowAdjustingFeeUpdate,
impls::ToAuthor,
BlockHashCount, MaximumBlockWeight, AvailableBlockRatio, MaximumBlockLength,
BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, MaximumExtrinsicWeight,
};
use runtime_parachains::{
self,
runtime_api_impl::v1 as runtime_api_impl,
};
use frame_support::{
parameter_types, construct_runtime, debug,
traits::{KeyOwnerProofSystem, Filter},
weights::Weight,
};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
ApplyExtrinsicResult, KeyTypeId, Perbill, curve::PiecewiseLinear,
transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority},
traits::{
BlakeTwo256, Block as BlockT, OpaqueKeys, IdentityLookup,
Extrinsic as ExtrinsicT, SaturatedConversion, Verify,
},
};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
#[cfg(any(feature = "std", test))]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
use pallet_grandpa::{AuthorityId as GrandpaId, fg_primitives};
use sp_core::OpaqueMetadata;
use sp_staking::SessionIndex;
use pallet_session::historical as session_historical;
use frame_system::EnsureRoot;
use runtime_common::{paras_sudo_wrapper, paras_registrar};
use runtime_parachains::origin as parachains_origin;
use runtime_parachains::configuration as parachains_configuration;
use runtime_parachains::inclusion as parachains_inclusion;
use runtime_parachains::inclusion_inherent as parachains_inclusion_inherent;
use runtime_parachains::initializer as parachains_initializer;
use runtime_parachains::paras as parachains_paras;
use runtime_parachains::router as parachains_router;
use runtime_parachains::scheduler as parachains_scheduler;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_staking::StakerStatus;
/// Constant values used within the runtime.
pub mod constants;
use constants::{time::*, currency::*, fee::*};
// Make the WASM binary available.
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
/// The address format for describing accounts.
pub type Address = AccountId;
/// Block header type as expected by this runtime.
pub type Header = generic::Header;
/// Block type as expected by this runtime.
pub type Block = generic::Block;
/// A Block signed with a Justification
pub type SignedBlock = generic::SignedBlock;
/// BlockId type as expected by this runtime.
pub type BlockId = generic::BlockId;
/// The SignedExtension to the basic transaction logic.
pub type SignedExtra = (
frame_system::CheckSpecVersion,
frame_system::CheckTxVersion,
frame_system::CheckGenesis,
frame_system::CheckMortality,
frame_system::CheckNonce,
frame_system::CheckWeight,
pallet_transaction_payment::ChargeTransactionPayment,
);
#[cfg(not(feature = "disable-runtime-api"))]
sp_api::impl_runtime_apis! {
impl sp_api::Core for Runtime {
fn version() -> RuntimeVersion {
VERSION
}
fn execute_block(block: Block) {
Executive::execute_block(block)
}
fn initialize_block(header: &::Header) {
Executive::initialize_block(header)
}
}
impl sp_api::Metadata for Runtime {
fn metadata() -> OpaqueMetadata {
Runtime::metadata().into()
}
}
impl block_builder_api::BlockBuilder for Runtime {
fn apply_extrinsic(extrinsic: ::Extrinsic) -> ApplyExtrinsicResult {
Executive::apply_extrinsic(extrinsic)
}
fn finalize_block() -> ::Header {
Executive::finalize_block()
}
fn inherent_extrinsics(data: inherents::InherentData) -> Vec<::Extrinsic> {
data.create_extrinsics()
}
fn check_inherents(
block: Block,
data: inherents::InherentData,
) -> inherents::CheckInherentsResult {
data.check_extrinsics(&block)
}
fn random_seed() -> ::Hash {
Babe::randomness().into()
}
}
impl tx_pool_api::runtime_api::TaggedTransactionQueue for Runtime {
fn validate_transaction(
source: TransactionSource,
tx: ::Extrinsic,
) -> TransactionValidity {
Executive::validate_transaction(source, tx)
}
}
impl offchain_primitives::OffchainWorkerApi for Runtime {
fn offchain_worker(header: &::Header) {
Executive::offchain_worker(header)
}
}
impl primitives::v1::ParachainHost for Runtime {
fn validators() -> Vec {
runtime_api_impl::validators::()
}
fn validator_groups() -> (Vec>, GroupRotationInfo) {
runtime_api_impl::validator_groups::()
}
fn availability_cores() -> Vec> {
runtime_api_impl::availability_cores::()
}
fn full_validation_data(para_id: Id, assumption: OccupiedCoreAssumption)
-> Option> {
runtime_api_impl::full_validation_data::(para_id, assumption)
}
fn persisted_validation_data(para_id: Id, assumption: OccupiedCoreAssumption)
-> Option> {
runtime_api_impl::persisted_validation_data::(para_id, assumption)
}
fn check_validation_outputs(
para_id: Id,
outputs: primitives::v1::ValidationOutputs,
) -> bool {
runtime_api_impl::check_validation_outputs::(para_id, outputs)
}
fn session_index_for_child() -> SessionIndex {
runtime_api_impl::session_index_for_child::()
}
fn validation_code(para_id: Id, assumption: OccupiedCoreAssumption)
-> Option {
runtime_api_impl::validation_code::(para_id, assumption)
}
fn candidate_pending_availability(para_id: Id) -> Option> {
runtime_api_impl::candidate_pending_availability::(para_id)
}
fn candidate_events() -> Vec> {
runtime_api_impl::candidate_events::(|ev| {
match ev {
Event::parachains_inclusion(ev) => {
Some(ev)
}
_ => None,
}
})
}
fn validator_discovery(validators: Vec) -> Vec