Adds a warning to FRAME pallets when a function argument that starts
with `_` is used in the weight formula.
This is in most cases an error since the weight witness needs to be
checked.
Example:
```rust
#[pallet::call_index(0)]
#[pallet::weight(T::SystemWeightInfo::remark(_remark.len() as u32))]
pub fn remark(_origin: OriginFor<T>, _remark: Vec<u8>) -> DispatchResultWithPostInfo {
Ok(().into())
}
```
Produces this warning:
```pre
warning: use of deprecated constant `pallet::warnings::UncheckedWeightWitness_0::_w`:
It is deprecated to not check weight witness data.
Please instead ensure that all witness data for weight calculation is checked before usage.
For more info see:
<https://github.com/paritytech/polkadot-sdk/pull/1818>
--> substrate/frame/system/src/lib.rs:424:40
|
424 | pub fn remark(_origin: OriginFor<T>, _remark: Vec<u8>) -> DispatchResultWithPostInfo {
| ^^^^^^^
|
= note: `#[warn(deprecated)]` on by default
```
Can be suppressed like this, since in this case it is legit:
```rust
#[pallet::call_index(0)]
#[pallet::weight(T::SystemWeightInfo::remark(remark.len() as u32))]
pub fn remark(_origin: OriginFor<T>, remark: Vec<u8>) -> DispatchResultWithPostInfo {
let _ = remark; // We dont need to check the weight witness.
Ok(().into())
}
```
Changes:
- Add warning on uncheded weight witness
- Respect `subkeys` limit in `System::kill_prefix`
- Fix HRMP pallet and other warnings
- Update`proc_macro_warning` dependency
- Delete random folder `substrate/src/src` 🙈
- Adding Prdoc
---------
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
System Module
The System module 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.
Overview
The System module 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.
Interface
Dispatchable Functions
The System module does not implement any dispatchable functions.
Public Functions
See the Pallet struct for details of
publicly available functions.
Signed Extensions
The System module 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 typeT::Nonce. - [
CheckEra]: Checks the era of the transaction. Contains a single payload of typeEra. - [
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.
Usage
Prerequisites
Import the System module and derive your module's configuration trait from the system trait.
Example - Get extrinsic count and parent hash for the current block
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(0)]
pub fn system_module_example(origin: OriginFor<T>) -> DispatchResult {
let _sender = ensure_signed(origin)?;
let _extrinsic_count = <system::Pallet<T>>::extrinsic_count();
let _parent_hash = <system::Pallet<T>>::parent_hash();
Ok(())
}
}
}
License: Apache-2.0