Migrate frame-system to pallet attribute macro (#7898)

* PRINT_PALLET_UPGRADE=1 cargo check -p frame-system

* Copy attributes, imports, mods and type defs

* Copy Config trait

* Annotate constants

* Tabify

* Migrate hooks

* Upgrade template rename interface to hooks

* Migrate pallet call

* Migrate Event

* Migrate Error

* Migrate Origin

* Remove optional validate_unsigned

* Remove remaining TODO_MAYBE_WHERE_CLAUSE

* Overwrite original lib.rs with migrated lib2.rs.

* Add required Event IsType constraint

* Add disable supertrait check

* Fix leftover Trait trait

* Add missing pallet prefix for weight attributes

* Add missing Error type parameter

* Add missing Hooks type parameter

* Private call visibility, restore original helper types and helpers etc

* Fix hooks type parameter

* Rename RawEvent to Event

* Add missing storage type annotations

* Remove unused imports

* Add GenesisConfig helpers for compat

* Fix unused import warnings

* Update frame/support/procedural/src/storage/print_pallet_upgrade.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Fix test errors and warnings

* Fix remaining errors and warnings

* Apply review suggestion: fix formatting

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Apply review suggestion: annotate BlockLength as constant

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Apply review suggestion: add triling comma

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Apply review suggestion: add triling comma

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Apply review suggestion: add trailing comma

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Apply review suggestion: fix storage type indentation

* Apply review suggestion: remove redundant Origin type alias

* Add missing codec derives for BlockLength

* Restore module docs

* Module -> Pallet renamel

* Revert "Update frame/support/procedural/src/storage/print_pallet_upgrade.rs"

This reverts commit d2a2d5b6

* Apply review suggestion: merge crate imports

Co-authored-by: Alexander Theißen <alex.theissen@me.com>

* Revert "Upgrade template rename interface to hooks"

This reverts commit 306f0239

* Single line import

* Refactor generated genesis build

* Import sp_io::storage

* Revert previous, fully qualify sp_io::storage

* Fix ui tests

* Fix errors after merge, missing changes

* Set UpgradedToDualRefCount to true in genesis build

* Annotated Runtime version with constant, exposing it via metadata

* Add metadata attribute

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
This commit is contained in:
Andrew Jones
2021-01-20 10:48:19 +00:00
committed by GitHub
parent 9d6b9684d9
commit 71ef82afbc
16 changed files with 595 additions and 542 deletions
@@ -17,7 +17,6 @@
use codec::{Encode, Decode};
use crate::{Config, Module, BlockHash};
use frame_support::StorageMap;
use sp_runtime::{
generic::Era,
traits::{SignedExtension, DispatchInfoOf, SaturatedConversion},
@@ -17,10 +17,7 @@
use codec::{Encode, Decode};
use crate::Config;
use frame_support::{
weights::DispatchInfo,
StorageMap,
};
use frame_support::weights::DispatchInfo;
use sp_runtime::{
traits::{SignedExtension, DispatchInfoOf, Dispatchable, One},
transaction_validity::{
@@ -28,7 +28,6 @@ use sp_runtime::{
use frame_support::{
traits::{Get},
weights::{PostDispatchInfo, DispatchInfo, DispatchClass, priority::FrameTransactionPriority},
StorageValue,
};
/// Block resource (weight) limit check.
@@ -115,8 +114,8 @@ impl<T: Config + Send + Sync> CheckWeight<T> where
let next_weight = Self::check_block_weight(info)?;
Self::check_extrinsic_weight(info)?;
crate::AllExtrinsicsLen::put(next_len);
crate::BlockWeight::put(next_weight);
crate::AllExtrinsicsLen::<T>::put(next_len);
crate::BlockWeight::<T>::put(next_weight);
Ok(())
}
@@ -257,7 +256,7 @@ impl<T: Config + Send + Sync> SignedExtension for CheckWeight<T> where
let unspent = post_info.calc_unspent(info);
if unspent > 0 {
crate::BlockWeight::mutate(|current_weight| {
crate::BlockWeight::<T>::mutate(|current_weight| {
current_weight.sub(unspent, info.class);
})
}
@@ -465,7 +464,7 @@ mod tests {
let normal_limit = normal_weight_limit();
// given almost full block
BlockWeight::mutate(|current_weight| {
BlockWeight::<Test>::mutate(|current_weight| {
current_weight.set(normal_limit, DispatchClass::Normal)
});
// will not fit.
@@ -475,7 +474,7 @@ mod tests {
// likewise for length limit.
let len = 100_usize;
AllExtrinsicsLen::put(normal_length_limit());
AllExtrinsicsLen::<Test>::put(normal_length_limit());
assert!(CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &normal, len).is_err());
assert!(CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &op, len).is_ok());
})
@@ -508,7 +507,7 @@ mod tests {
let normal = DispatchInfo::default();
let normal_limit = normal_weight_limit() as usize;
let reset_check_weight = |tx, s, f| {
AllExtrinsicsLen::put(0);
AllExtrinsicsLen::<Test>::put(0);
let r = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, tx, s);
if f { assert!(r.is_err()) } else { assert!(r.is_ok()) }
};
@@ -544,7 +543,7 @@ mod tests {
let len = 0_usize;
let reset_check_weight = |i, f, s| {
BlockWeight::mutate(|current_weight| {
BlockWeight::<Test>::mutate(|current_weight| {
current_weight.set(s, DispatchClass::Normal)
});
let r = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, i, len);
@@ -570,20 +569,20 @@ mod tests {
let base_extrinsic = block_weights().get(DispatchClass::Normal).base_extrinsic;
// We allow 75% for normal transaction, so we put 25% - extrinsic base weight
BlockWeight::mutate(|current_weight| {
BlockWeight::<Test>::mutate(|current_weight| {
current_weight.set(0, DispatchClass::Mandatory);
current_weight.set(256 - base_extrinsic, DispatchClass::Normal);
});
let pre = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &info, len).unwrap();
assert_eq!(BlockWeight::get().total(), info.weight + 256);
assert_eq!(BlockWeight::<Test>::get().total(), info.weight + 256);
assert!(
CheckWeight::<Test>::post_dispatch(pre, &info, &post_info, len, &Ok(()))
.is_ok()
);
assert_eq!(
BlockWeight::get().total(),
BlockWeight::<Test>::get().total(),
post_info.actual_weight.unwrap() + 256,
);
})
@@ -599,14 +598,14 @@ mod tests {
};
let len = 0_usize;
BlockWeight::mutate(|current_weight| {
BlockWeight::<Test>::mutate(|current_weight| {
current_weight.set(0, DispatchClass::Mandatory);
current_weight.set(128, DispatchClass::Normal);
});
let pre = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &info, len).unwrap();
assert_eq!(
BlockWeight::get().total(),
BlockWeight::<Test>::get().total(),
info.weight + 128 + block_weights().get(DispatchClass::Normal).base_extrinsic,
);
@@ -615,7 +614,7 @@ mod tests {
.is_ok()
);
assert_eq!(
BlockWeight::get().total(),
BlockWeight::<Test>::get().total(),
info.weight + 128 + block_weights().get(DispatchClass::Normal).base_extrinsic,
);
})