mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 11:07:56 +00:00
Moves Block to frame_system instead of construct_runtime and removes Header and BlockNumber (#14437)
* Initial setup * Adds node block * Uses UncheckedExtrinsic and removes Where section * Updates frame_system to use Block * Adds deprecation warning * Fixes pallet-timestamp * Removes Header and BlockNumber * Addresses review comments * Addresses review comments * Adds comment about compiler bug * Removes where clause * Refactors code * Fixes errors in cargo check * Fixes errors in cargo check * Fixes warnings in cargo check * Formatting * Fixes construct_runtime tests * Uses import instead of full path for BlockNumber * Uses import instead of full path for Header * Formatting * Fixes construct_runtime tests * Fixes imports in benchmarks * Formatting * Fixes construct_runtime tests * Formatting * Minor updates * Fixes construct_runtime ui tests * Fixes construct_runtime ui tests with 1.70 * Fixes docs * Fixes docs * Adds u128 mock block type * Fixes split example * fixes for cumulus * ".git/.scripts/commands/fmt/fmt.sh" * Updates new tests * Fixes fully-qualified path in few places * Formatting * Update frame/examples/default-config/src/lib.rs Co-authored-by: Juan <juangirini@gmail.com> * Update frame/support/procedural/src/construct_runtime/mod.rs Co-authored-by: Juan <juangirini@gmail.com> * ".git/.scripts/commands/fmt/fmt.sh" * Addresses some review comments * Fixes build * ".git/.scripts/commands/fmt/fmt.sh" * Update frame/democracy/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/democracy/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/support/procedural/src/construct_runtime/mod.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/support/procedural/src/construct_runtime/mod.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Addresses review comments * Updates trait bounds * Minor fix * ".git/.scripts/commands/fmt/fmt.sh" * Removes unnecessary bound * ".git/.scripts/commands/fmt/fmt.sh" * Updates test * Fixes build * Adds a bound for header * ".git/.scripts/commands/fmt/fmt.sh" * Removes where block * Minor fix * Minor fix * Fixes tests * ".git/.scripts/commands/update-ui/update-ui.sh" 1.70 * Updates test * Update primitives/runtime/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/runtime/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Updates doc * Updates doc --------- Co-authored-by: command-bot <> Co-authored-by: Juan <juangirini@gmail.com> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
@@ -645,259 +645,6 @@ impl<T> PaysFee<T> for (u64, Pays) {
|
||||
// END TODO
|
||||
|
||||
/// Declares a `Module` struct and a `Call` enum, which implements the dispatch logic.
|
||||
///
|
||||
/// ## Declaration
|
||||
///
|
||||
/// ```
|
||||
/// # #[macro_use]
|
||||
/// # extern crate frame_support;
|
||||
/// # use frame_support::dispatch;
|
||||
/// # use frame_system::{Config, ensure_signed};
|
||||
/// decl_module! {
|
||||
/// pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin {
|
||||
///
|
||||
/// // Private functions are dispatchable, but not available to other
|
||||
/// // FRAME pallets.
|
||||
/// #[weight = 0]
|
||||
/// fn my_function(origin, var: u64) -> dispatch::DispatchResult {
|
||||
/// // Your implementation
|
||||
/// Ok(())
|
||||
/// }
|
||||
///
|
||||
/// // Public functions are both dispatchable and available to other
|
||||
/// // FRAME pallets.
|
||||
/// #[weight = 0]
|
||||
/// pub fn my_public_function(origin) -> dispatch::DispatchResult {
|
||||
/// // Your implementation
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
/// # fn main() {}
|
||||
/// ```
|
||||
///
|
||||
/// The declaration is set with the header where:
|
||||
///
|
||||
/// * `Module`: The struct generated by the macro, with type `Config`.
|
||||
/// * `Call`: The enum generated for every pallet, which implements
|
||||
/// [`Callable`](./dispatch/trait.Callable.html).
|
||||
/// * `origin`: Alias of `T::RuntimeOrigin`.
|
||||
/// * `Result`: The expected return type from pallet functions.
|
||||
///
|
||||
/// The first parameter of dispatchable functions must always be `origin`.
|
||||
///
|
||||
/// ### Shorthand Example
|
||||
///
|
||||
/// The macro automatically expands a shorthand function declaration to return the
|
||||
/// [`DispatchResult`] type. These functions are the same:
|
||||
///
|
||||
/// ```
|
||||
/// # #[macro_use]
|
||||
/// # extern crate frame_support;
|
||||
/// # use frame_support::dispatch;
|
||||
/// # use frame_system::{Config, ensure_signed};
|
||||
/// decl_module! {
|
||||
/// pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin {
|
||||
/// #[weight = 0]
|
||||
/// fn my_long_function(origin) -> dispatch::DispatchResult {
|
||||
/// // Your implementation
|
||||
/// Ok(())
|
||||
/// }
|
||||
///
|
||||
/// #[weight = 0]
|
||||
/// fn my_short_function(origin) {
|
||||
/// // Your implementation
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
/// # fn main() {}
|
||||
/// ```
|
||||
///
|
||||
/// ### Consuming only portions of the annotated static weight
|
||||
///
|
||||
/// Per default a callable function consumes all of its static weight as declared via
|
||||
/// the #\[weight\] attribute. However, there are use cases where only a portion of this
|
||||
/// weight should be consumed. In that case the static weight is charged pre dispatch and
|
||||
/// the difference is refunded post dispatch.
|
||||
///
|
||||
/// In order to make use of this feature the function must return `DispatchResultWithPostInfo`
|
||||
/// in place of the default `DispatchResult`. Then the actually consumed weight can be returned.
|
||||
/// To consume a non default weight while returning an error
|
||||
/// [`WithPostDispatchInfo::with_weight`](./weight/trait.WithPostDispatchInfo.html) can be used
|
||||
/// to augment any error with custom weight information.
|
||||
///
|
||||
/// ```
|
||||
/// # #[macro_use]
|
||||
/// # extern crate frame_support;
|
||||
/// # use frame_support::{weights::Weight, dispatch::{DispatchResultWithPostInfo, WithPostDispatchInfo, PostDispatchInfo}};
|
||||
/// # use frame_system::{Config, ensure_signed};
|
||||
/// decl_module! {
|
||||
/// pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin {
|
||||
/// #[weight = 1_000_000]
|
||||
/// fn my_long_function(origin, do_expensive_calc: bool) -> DispatchResultWithPostInfo {
|
||||
/// ensure_signed(origin).map_err(|e| e.with_weight(Weight::from_parts(100_000, 0)))?;
|
||||
/// if do_expensive_calc {
|
||||
/// // do the expensive calculation
|
||||
/// // ...
|
||||
/// // return None to indicate that we are using all weight (the default)
|
||||
/// return Ok(None::<Weight>.into());
|
||||
/// }
|
||||
/// // expensive calculation not executed: use only a portion of the weight
|
||||
/// Ok(PostDispatchInfo { actual_weight: Some(Weight::from_parts(100_000, 0)), ..Default::default() })
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
/// # fn main() {}
|
||||
/// ```
|
||||
///
|
||||
/// ### Transactional Function Example
|
||||
///
|
||||
/// Transactional function discards all changes to storage if it returns `Err`, or commits if
|
||||
/// `Ok`, via the #\[transactional\] attribute. Note the attribute must be after #\[weight\].
|
||||
/// The #\[transactional\] attribute is deprecated since it is the default behaviour.
|
||||
///
|
||||
/// ```
|
||||
/// # #[macro_use]
|
||||
/// # extern crate frame_support;
|
||||
/// # use frame_support::transactional;
|
||||
/// # use frame_system::Config;
|
||||
/// decl_module! {
|
||||
/// pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin {
|
||||
/// #[weight = 0]
|
||||
/// #[transactional]
|
||||
/// fn my_short_function(origin) {
|
||||
/// // Your implementation
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
/// # fn main() {}
|
||||
/// ```
|
||||
///
|
||||
/// ### Privileged Function Example
|
||||
///
|
||||
/// A privileged function checks that the origin of the call is `ROOT`.
|
||||
///
|
||||
/// ```
|
||||
/// # #[macro_use]
|
||||
/// # extern crate frame_support;
|
||||
/// # use frame_support::dispatch;
|
||||
/// # use frame_system::{Config, ensure_signed, ensure_root};
|
||||
/// decl_module! {
|
||||
/// pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin {
|
||||
/// #[weight = 0]
|
||||
/// fn my_privileged_function(origin) -> dispatch::DispatchResult {
|
||||
/// ensure_root(origin)?;
|
||||
/// // Your implementation
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
/// # fn main() {}
|
||||
/// ```
|
||||
///
|
||||
/// ### Attributes on Functions
|
||||
///
|
||||
/// Attributes on functions are supported, but must be in the order of:
|
||||
/// 1. Optional #\[doc\] attribute.
|
||||
/// 2. #\[weight\] attribute.
|
||||
/// 3. Optional function attributes, for instance #\[transactional\]. Those function attributes will
|
||||
/// be written only on the dispatchable functions implemented on `Module`, not on the `Call` enum
|
||||
/// variant.
|
||||
///
|
||||
/// ## Multiple Module Instances Example
|
||||
///
|
||||
/// A Substrate module can be built such that multiple instances of the same module can be used
|
||||
/// within a single runtime. For example, the [Balances module](../pallet_balances/index.html) can
|
||||
/// be added multiple times to your runtime in order to support multiple, independent currencies for
|
||||
/// your blockchain. Here is an example of how you would declare such a module using the
|
||||
/// `decl_module!` macro:
|
||||
///
|
||||
/// ```
|
||||
/// # #[macro_use]
|
||||
/// # extern crate frame_support;
|
||||
/// # use frame_support::dispatch;
|
||||
/// # use frame_system::ensure_signed;
|
||||
/// # pub struct DefaultInstance;
|
||||
/// # pub trait Instance: 'static {}
|
||||
/// # impl Instance for DefaultInstance {}
|
||||
/// pub trait Config<I: Instance=DefaultInstance>: frame_system::Config {}
|
||||
///
|
||||
/// decl_module! {
|
||||
/// pub struct Module<T: Config<I>, I: Instance = DefaultInstance> for enum Call where origin: T::RuntimeOrigin {
|
||||
/// // Your implementation
|
||||
/// }
|
||||
/// }
|
||||
/// # fn main() {}
|
||||
/// ```
|
||||
///
|
||||
/// Note: `decl_storage` must be called to generate `Instance` trait and optionally
|
||||
/// `DefaultInstance` type.
|
||||
///
|
||||
/// ## Where clause
|
||||
///
|
||||
/// Besides the default `origin: T::RuntimeOrigin`, you can also pass other bounds to the module
|
||||
/// declaration. This where bound will be replicated to all types generated by this macro. The
|
||||
/// chaining of multiple trait bounds with `+` is not supported. If multiple bounds for one type are
|
||||
/// required, it needs to be split up into multiple bounds.
|
||||
///
|
||||
/// ```
|
||||
/// # #[macro_use]
|
||||
/// # extern crate frame_support;
|
||||
/// # use frame_support::dispatch;
|
||||
/// # use frame_system::{self as system, ensure_signed};
|
||||
/// pub trait Config: system::Config where Self::AccountId: From<u32> {}
|
||||
///
|
||||
/// decl_module! {
|
||||
/// pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin, T::AccountId: From<u32> {
|
||||
/// // Your implementation
|
||||
/// }
|
||||
/// }
|
||||
/// # fn main() {}
|
||||
/// ```
|
||||
///
|
||||
/// ## Reserved Functions
|
||||
///
|
||||
/// The following are reserved function signatures:
|
||||
///
|
||||
/// * `deposit_event`: Helper function for depositing an [event](https://docs.substrate.io/main-docs/build/events-errors/).
|
||||
/// The default behavior is to call `deposit_event` from the [System
|
||||
/// module](../frame_system/index.html). However, you can write your own implementation for events
|
||||
/// in your runtime. To use the default behavior, add `fn deposit_event() = default;` to your
|
||||
/// `Module`.
|
||||
///
|
||||
/// The following reserved functions also take the block number (with type `T::BlockNumber`) as an
|
||||
/// optional input:
|
||||
///
|
||||
/// * `on_runtime_upgrade`: Executes at the beginning of a block prior to on_initialize when there
|
||||
/// is a runtime upgrade. This allows each module to upgrade its storage before the storage items
|
||||
/// are used. As such, **calling other modules must be avoided**!! Using this function will
|
||||
/// implement the [`OnRuntimeUpgrade`](../sp_runtime/traits/trait.OnRuntimeUpgrade.html) trait.
|
||||
/// Function signature must be `fn on_runtime_upgrade() -> frame_support::weights::Weight`.
|
||||
///
|
||||
/// * `on_initialize`: Executes at the beginning of a block. Using this function will
|
||||
/// implement the [`OnInitialize`](./trait.OnInitialize.html) trait.
|
||||
/// Function signature can be either:
|
||||
/// * `fn on_initialize(n: BlockNumber) -> frame_support::weights::Weight` or
|
||||
/// * `fn on_initialize() -> frame_support::weights::Weight`
|
||||
///
|
||||
/// * `on_idle`: Executes at the end of a block. Passes a remaining weight to provide a threshold
|
||||
/// for when to execute non vital functions. Using this function will implement the
|
||||
/// [`OnIdle`](./traits/trait.OnIdle.html) trait.
|
||||
/// Function signature is:
|
||||
/// * `fn on_idle(n: BlockNumber, remaining_weight: Weight) -> frame_support::weights::Weight`
|
||||
///
|
||||
/// * `on_finalize`: Executes at the end of a block. Using this function will
|
||||
/// implement the [`OnFinalize`](./traits/trait.OnFinalize.html) trait.
|
||||
/// Function signature can be either:
|
||||
/// * `fn on_finalize(n: BlockNumber) -> frame_support::weights::Weight` or
|
||||
/// * `fn on_finalize() -> frame_support::weights::Weight`
|
||||
///
|
||||
/// * `offchain_worker`: Executes at the beginning of a block and produces extrinsics for a future
|
||||
/// block upon completion. Using this function will implement the
|
||||
/// [`OffchainWorker`](./traits/trait.OffchainWorker.html) trait.
|
||||
/// * `integrity_test`: Executes in a test generated by `construct_runtime`, note it doesn't execute
|
||||
/// in an externalities-provided environment. Implement
|
||||
/// [`IntegrityTest`](./trait.IntegrityTest.html) trait.
|
||||
#[macro_export]
|
||||
#[deprecated(note = "Will be removed after July 2023; use the attribute `#[pallet]` macro instead.
|
||||
For more info, see: <https://github.com/paritytech/substrate/pull/13705>")]
|
||||
@@ -3587,7 +3334,7 @@ mod weight_tests {
|
||||
#[pallet::config]
|
||||
#[pallet::disable_frame_system_supertrait_check]
|
||||
pub trait Config: 'static {
|
||||
type BlockNumber: Parameter + Default + MaxEncodedLen;
|
||||
type Block: Parameter + sp_runtime::traits::Block;
|
||||
type AccountId;
|
||||
type Balance;
|
||||
type BaseCallFilter: crate::traits::Contains<Self::RuntimeCall>;
|
||||
@@ -3653,6 +3400,11 @@ mod weight_tests {
|
||||
|
||||
pub mod pallet_prelude {
|
||||
pub type OriginFor<T> = <T as super::Config>::RuntimeOrigin;
|
||||
|
||||
pub type HeaderFor<T> =
|
||||
<<T as super::Config>::Block as sp_runtime::traits::HeaderProvider>::HeaderT;
|
||||
|
||||
pub type BlockNumberFor<T> = <HeaderFor<T> as sp_runtime::traits::Header>::Number;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3665,10 +3417,6 @@ mod weight_tests {
|
||||
|
||||
crate::construct_runtime!(
|
||||
pub enum Runtime
|
||||
where
|
||||
Block = Block,
|
||||
NodeBlock = Block,
|
||||
UncheckedExtrinsic = UncheckedExtrinsic,
|
||||
{
|
||||
System: self::frame_system,
|
||||
}
|
||||
@@ -3682,7 +3430,7 @@ mod weight_tests {
|
||||
}
|
||||
|
||||
impl Config for Runtime {
|
||||
type BlockNumber = BlockNumber;
|
||||
type Block = Block;
|
||||
type AccountId = AccountId;
|
||||
type Balance = Balance;
|
||||
type BaseCallFilter = crate::traits::Everything;
|
||||
|
||||
Reference in New Issue
Block a user