mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 06:21:02 +00:00
[FRAME] Warn on unchecked weight witness (#1818)
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>
This commit is contained in:
committed by
GitHub
parent
e3c97e4860
commit
64877492c5
@@ -554,14 +554,26 @@ pub mod pallet {
|
||||
///
|
||||
/// Origin must be the `ChannelManager`.
|
||||
#[pallet::call_index(3)]
|
||||
#[pallet::weight(<T as Config>::WeightInfo::force_clean_hrmp(*_inbound, *_outbound))]
|
||||
#[pallet::weight(<T as Config>::WeightInfo::force_clean_hrmp(*num_inbound, *num_outbound))]
|
||||
pub fn force_clean_hrmp(
|
||||
origin: OriginFor<T>,
|
||||
para: ParaId,
|
||||
_inbound: u32,
|
||||
_outbound: u32,
|
||||
num_inbound: u32,
|
||||
num_outbound: u32,
|
||||
) -> DispatchResult {
|
||||
T::ChannelManager::ensure_origin(origin)?;
|
||||
|
||||
ensure!(
|
||||
HrmpIngressChannelsIndex::<T>::decode_len(para).unwrap_or_default() <=
|
||||
num_inbound as usize,
|
||||
Error::<T>::WrongWitness
|
||||
);
|
||||
ensure!(
|
||||
HrmpEgressChannelsIndex::<T>::decode_len(para).unwrap_or_default() <=
|
||||
num_outbound as usize,
|
||||
Error::<T>::WrongWitness
|
||||
);
|
||||
|
||||
Self::clean_hrmp_after_outgoing(¶);
|
||||
Ok(())
|
||||
}
|
||||
@@ -575,9 +587,16 @@ pub mod pallet {
|
||||
///
|
||||
/// Origin must be the `ChannelManager`.
|
||||
#[pallet::call_index(4)]
|
||||
#[pallet::weight(<T as Config>::WeightInfo::force_process_hrmp_open(*_channels))]
|
||||
pub fn force_process_hrmp_open(origin: OriginFor<T>, _channels: u32) -> DispatchResult {
|
||||
#[pallet::weight(<T as Config>::WeightInfo::force_process_hrmp_open(*channels))]
|
||||
pub fn force_process_hrmp_open(origin: OriginFor<T>, channels: u32) -> DispatchResult {
|
||||
T::ChannelManager::ensure_origin(origin)?;
|
||||
|
||||
ensure!(
|
||||
HrmpOpenChannelRequestsList::<T>::decode_len().unwrap_or_default() as u32 <=
|
||||
channels,
|
||||
Error::<T>::WrongWitness
|
||||
);
|
||||
|
||||
let host_config = configuration::Pallet::<T>::config();
|
||||
Self::process_hrmp_open_channel_requests(&host_config);
|
||||
Ok(())
|
||||
@@ -592,9 +611,16 @@ pub mod pallet {
|
||||
///
|
||||
/// Origin must be the `ChannelManager`.
|
||||
#[pallet::call_index(5)]
|
||||
#[pallet::weight(<T as Config>::WeightInfo::force_process_hrmp_close(*_channels))]
|
||||
pub fn force_process_hrmp_close(origin: OriginFor<T>, _channels: u32) -> DispatchResult {
|
||||
#[pallet::weight(<T as Config>::WeightInfo::force_process_hrmp_close(*channels))]
|
||||
pub fn force_process_hrmp_close(origin: OriginFor<T>, channels: u32) -> DispatchResult {
|
||||
T::ChannelManager::ensure_origin(origin)?;
|
||||
|
||||
ensure!(
|
||||
HrmpCloseChannelRequestsList::<T>::decode_len().unwrap_or_default() as u32 <=
|
||||
channels,
|
||||
Error::<T>::WrongWitness
|
||||
);
|
||||
|
||||
Self::process_hrmp_close_channel_requests();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user