Newer
Older
// This file is part of Substrate.
// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! # System Pallet
//! The System pallet provides low-level access to core types and cross-cutting utilities.
//! It acts as the base layer for other pallets to interact with the Substrate framework components.
//! The System pallet defines the core data types used in a Substrate runtime.
//! It also provides several utility functions (see [`Pallet`]) for other FRAME pallets.
//! In addition, it manages the storage items for extrinsics data, indexes, event records, and digest items,
//! among other things that support the execution of the current block.
//! It also handles low-level tasks like depositing logs, basic set up and take down of
//! temporary storage entries, and access to previous block hashes.
//! The System pallet does not implement any dispatchable functions.
//! See the [`Pallet`] struct for details of publicly available functions.
//! ### Signed Extensions
//!
//! The System pallet defines the following extensions:
//!
//! - [`CheckWeight`]: Checks the weight and length of the block and ensure that it does not
//! exceed the limits.
//! - [`CheckNonce`]: Checks the nonce of the transaction. Contains a single payload of type
//! `T::Index`.
//! - [`CheckEra`]: Checks the era of the transaction. Contains a single payload of type `Era`.
//! - [`CheckGenesis`]: Checks the provided genesis hash of the transaction. Must be a part of the
//! signed payload of the transaction.
//! - [`CheckSpecVersion`]: Checks that the runtime version is the same as the one used to sign the
//! transaction.
//! - [`CheckTxVersion`]: Checks that the transaction version is the same as the one used to sign the
//! transaction.
//!
//! Lookup the runtime aggregator file (e.g. `node/runtime`) to see the full list of signed
//! extensions included in a chain.
#[cfg(feature = "std")]
use sp_std::prelude::*;
#[cfg(any(feature = "std", test))]
use sp_std::map;
use sp_std::marker::PhantomData;
use sp_std::fmt::Debug;
use sp_version::RuntimeVersion;
use sp_runtime::{
RuntimeDebug, Perbill, DispatchError, Either, generic,
self, CheckEqual, AtLeast32Bit, Zero, Lookup, LookupError,
SimpleBitOps, Hash, Member, MaybeDisplay, BadOrigin,
MaybeSerializeDeserialize, MaybeMallocSizeOf, StaticLookup, One, Bounded,
Dispatchable, AtLeast32BitUnsigned, Saturating, StoredMapError,
offchain::storage_lock::BlockNumberProvider,
use sp_core::{ChangesTrieConfiguration, storage::well_known_keys};
Parameter, debug, storage,
Contains, Get, PalletInfo, OnNewAccount, OnKilledAccount, HandleLifetime,
StoredMap, EnsureOrigin, OriginTrait, Filter,
Weight, RuntimeDbWeight, DispatchInfo, DispatchClass,
extract_actual_weight, PerDispatchClass,
},
dispatch::DispatchResultWithPostInfo,
use codec::{Encode, Decode, FullCodec, EncodeLike};
#[cfg(feature = "std")]
use frame_support::traits::GenesisBuild;
use sp_io::TestExternalities;
Svyatoslav Nikolsky
committed
#[cfg(test)]
pub(crate) mod mock;
mod extensions;
#[cfg(test)]
mod tests;
#[cfg(feature = "std")]
pub mod mocking;
pub use extensions::{
check_mortality::CheckMortality, check_genesis::CheckGenesis, check_nonce::CheckNonce,
check_spec_version::CheckSpecVersion, check_tx_version::CheckTxVersion,
check_weight::CheckWeight,
};
// Backward compatible re-export.
pub use extensions::check_mortality::CheckMortality as CheckEra;
/// Compute the trie root of a list of extrinsics.
pub fn extrinsics_root<H: Hash, E: codec::Encode>(extrinsics: &[E]) -> H::Output {
extrinsics_data_root::<H>(extrinsics.iter().map(codec::Encode::encode).collect())
/// Compute the trie root of a list of extrinsics.
pub fn extrinsics_data_root<H: Hash>(xts: Vec<Vec<u8>>) -> H::Output {
/// An object to track the currently used extrinsic weight in a block.
pub type ConsumedWeight = PerDispatchClass<Weight>;
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
pub use pallet::*;
#[frame_support::pallet]
pub mod pallet {
use crate::{*, pallet_prelude::*, self as frame_system};
use frame_support::pallet_prelude::*;
/// System configuration trait. Implemented by runtime.
#[pallet::config]
#[pallet::disable_frame_system_supertrait_check]
pub trait Config: 'static + Eq + Clone {
/// The basic call filter to use in Origin. All origins are built with this filter as base,
/// except Root.
type BaseCallFilter: Filter<Self::Call>;
/// Block & extrinsics weights: base values and limits.
#[pallet::constant]
type BlockWeights: Get<limits::BlockWeights>;
/// The maximum length of a block (in bytes).
#[pallet::constant]
type BlockLength: Get<limits::BlockLength>;
/// The `Origin` type used by dispatchable calls.
type Origin:
Into<Result<RawOrigin<Self::AccountId>, Self::Origin>>
+ From<RawOrigin<Self::AccountId>>
+ Clone
+ OriginTrait<Call=Self::Call>;
/// The aggregated `Call` type.
type Call: Dispatchable + Debug;
/// Account index (aka nonce) type. This stores the number of previous transactions associated
/// with a sender account.
type Index:
Parameter + Member + MaybeSerializeDeserialize + Debug + Default + MaybeDisplay + AtLeast32Bit
+ Copy;
/// The block number type used by the runtime.
type BlockNumber:
Parameter + Member + MaybeSerializeDeserialize + Debug + MaybeDisplay +
AtLeast32BitUnsigned + Default + Bounded + Copy + sp_std::hash::Hash +
sp_std::str::FromStr + MaybeMallocSizeOf;
/// The output of the `Hashing` function.
type Hash:
Parameter + Member + MaybeSerializeDeserialize + Debug + MaybeDisplay + SimpleBitOps + Ord
+ Default + Copy + CheckEqual + sp_std::hash::Hash + AsRef<[u8]> + AsMut<[u8]> + MaybeMallocSizeOf;
/// The hashing system (algorithm) being used in the runtime (e.g. Blake2).
type Hashing: Hash<Output=Self::Hash>;
/// The user account identifier type for the runtime.
type AccountId: Parameter + Member + MaybeSerializeDeserialize + Debug + MaybeDisplay + Ord
+ Default;
/// Converting trait to take a source type and convert to `AccountId`.
///
/// Used to define the type and conversion mechanism for referencing accounts in transactions.
Loading full blame...