mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-24 02:01:06 +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
@@ -379,7 +379,7 @@ benchmarks! {
|
||||
let root = RawOrigin::Root;
|
||||
}: _(root, v, d)
|
||||
verify {
|
||||
assert_eq!(<Voting<T>>::iter().count() as u32, 0);
|
||||
assert_eq!(<Voting<T>>::iter().count() as u32, v - d);
|
||||
}
|
||||
|
||||
election_phragmen {
|
||||
|
||||
@@ -591,15 +591,18 @@ pub mod pallet {
|
||||
/// ## Complexity
|
||||
/// - Check is_defunct_voter() details.
|
||||
#[pallet::call_index(5)]
|
||||
#[pallet::weight(T::WeightInfo::clean_defunct_voters(*_num_voters, *_num_defunct))]
|
||||
#[pallet::weight(T::WeightInfo::clean_defunct_voters(*num_voters, *num_defunct))]
|
||||
pub fn clean_defunct_voters(
|
||||
origin: OriginFor<T>,
|
||||
_num_voters: u32,
|
||||
_num_defunct: u32,
|
||||
num_voters: u32,
|
||||
num_defunct: u32,
|
||||
) -> DispatchResult {
|
||||
let _ = ensure_root(origin)?;
|
||||
|
||||
<Voting<T>>::iter()
|
||||
.take(num_voters as usize)
|
||||
.filter(|(_, x)| Self::is_defunct_voter(&x.votes))
|
||||
.take(num_defunct as usize)
|
||||
.for_each(|(dv, _)| Self::do_remove_voter(&dv));
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user