Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Migrate frame-system to pallet attribute macro #7898

Merged
57 commits merged into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
6291431
PRINT_PALLET_UPGRADE=1 cargo check -p frame-system
ascjones Jan 13, 2021
7c1a11f
Copy attributes, imports, mods and type defs
ascjones Jan 13, 2021
ea53dde
Copy Config trait
ascjones Jan 13, 2021
519a7f2
Annotate constants
ascjones Jan 13, 2021
7816dc7
Tabify
ascjones Jan 13, 2021
a624cc0
Migrate hooks
ascjones Jan 14, 2021
306f023
Upgrade template rename interface to hooks
ascjones Jan 14, 2021
1fb8b3b
Migrate pallet call
ascjones Jan 14, 2021
cb8aa19
Migrate Event
ascjones Jan 14, 2021
d973e4a
Migrate Error
ascjones Jan 14, 2021
6ee8dba
Migrate Origin
ascjones Jan 14, 2021
2c9d575
Remove optional validate_unsigned
ascjones Jan 14, 2021
21dd9d8
Remove remaining TODO_MAYBE_WHERE_CLAUSE
ascjones Jan 14, 2021
fea632a
Overwrite original lib.rs with migrated lib2.rs.
ascjones Jan 14, 2021
32c3aca
Add required Event IsType constraint
ascjones Jan 14, 2021
d4fcfc1
Add disable supertrait check
ascjones Jan 14, 2021
68b0316
Fix leftover Trait trait
ascjones Jan 14, 2021
2f8152a
Add missing pallet prefix for weight attributes
ascjones Jan 14, 2021
7eb1fd3
Add missing Error type parameter
ascjones Jan 14, 2021
1de98d7
Add missing Hooks type parameter
ascjones Jan 14, 2021
36295ac
Private call visibility, restore original helper types and helpers etc
ascjones Jan 14, 2021
4983150
Fix hooks type parameter
ascjones Jan 14, 2021
a82525e
Rename RawEvent to Event
ascjones Jan 14, 2021
5fead51
Add missing storage type annotations
ascjones Jan 14, 2021
1c436f3
Remove unused imports
ascjones Jan 14, 2021
d68661a
Add GenesisConfig helpers for compat
ascjones Jan 14, 2021
7432519
Fix unused import warnings
ascjones Jan 14, 2021
d2a2d5b
Update frame/support/procedural/src/storage/print_pallet_upgrade.rs
ascjones Jan 14, 2021
b88b122
Fix test errors and warnings
ascjones Jan 14, 2021
73a8225
Fix remaining errors and warnings
ascjones Jan 14, 2021
05d1a6b
Merge remote-tracking branch 'origin/aj-migrate-system' into aj-migra…
ascjones Jan 14, 2021
0b48bb1
Apply review suggestion: fix formatting
ascjones Jan 14, 2021
8fc23c8
Apply review suggestion: annotate BlockLength as constant
ascjones Jan 14, 2021
d71ef58
Apply review suggestion: add triling comma
ascjones Jan 14, 2021
3f2dc74
Apply review suggestion: add triling comma
ascjones Jan 14, 2021
ba04282
Apply review suggestion: add trailing comma
ascjones Jan 14, 2021
e46b920
Apply review suggestion: fix storage type indentation
ascjones Jan 14, 2021
71e689a
Apply review suggestion: remove redundant Origin type alias
ascjones Jan 14, 2021
6aa7b98
Add missing codec derives for BlockLength
ascjones Jan 15, 2021
aeced3f
Restore module docs
ascjones Jan 15, 2021
3949b5a
Module -> Pallet renamel
ascjones Jan 15, 2021
a3b727f
Revert "Update frame/support/procedural/src/storage/print_pallet_upgr…
ascjones Jan 15, 2021
0831f09
Apply review suggestion: merge crate imports
ascjones Jan 15, 2021
8a0197e
Revert "Upgrade template rename interface to hooks"
ascjones Jan 15, 2021
1709098
Single line import
ascjones Jan 15, 2021
004fa67
Refactor generated genesis build
ascjones Jan 15, 2021
455cb43
Import sp_io::storage
ascjones Jan 15, 2021
33476a1
Revert previous, fully qualify sp_io::storage
ascjones Jan 15, 2021
b994fc7
Fix ui tests
ascjones Jan 15, 2021
eae729c
Merge branch 'master' into aj-migrate-system
ascjones Jan 15, 2021
2790a29
Merge branch 'master' into aj-migrate-system
ascjones Jan 18, 2021
cb4439d
Fix errors after merge, missing changes
ascjones Jan 18, 2021
a3d2963
Merge branch 'master' into aj-migrate-system
ascjones Jan 19, 2021
3f95d26
Set UpgradedToDualRefCount to true in genesis build
ascjones Jan 19, 2021
aeb9ea1
Annotated Runtime version with constant, exposing it via metadata
ascjones Jan 19, 2021
3bccfa5
Merge branch 'master' into aj-migrate-system
ascjones Jan 20, 2021
23d42c7
Add metadata attribute
ascjones Jan 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions bin/node/executor/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ fn full_native_block_import_works() {
let events = vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
event: Event::frame_system(frame_system::Event::ExtrinsicSuccess(
DispatchInfo { weight: timestamp_weight, class: DispatchClass::Mandatory, ..Default::default() }
)),
topics: vec![],
Expand All @@ -350,7 +350,7 @@ fn full_native_block_import_works() {
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
event: Event::frame_system(frame_system::Event::ExtrinsicSuccess(
DispatchInfo { weight: transfer_weight, ..Default::default() }
)),
topics: vec![],
Expand Down Expand Up @@ -381,7 +381,7 @@ fn full_native_block_import_works() {
let events = vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
event: Event::frame_system(frame_system::Event::ExtrinsicSuccess(
DispatchInfo { weight: timestamp_weight, class: DispatchClass::Mandatory, ..Default::default() }
)),
topics: vec![],
Expand All @@ -404,7 +404,7 @@ fn full_native_block_import_works() {
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
event: Event::frame_system(frame_system::Event::ExtrinsicSuccess(
DispatchInfo { weight: transfer_weight, ..Default::default() }
)),
topics: vec![],
Expand All @@ -427,7 +427,7 @@ fn full_native_block_import_works() {
},
EventRecord {
phase: Phase::ApplyExtrinsic(2),
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
event: Event::frame_system(frame_system::Event::ExtrinsicSuccess(
DispatchInfo { weight: transfer_weight, ..Default::default() }
)),
topics: vec![],
Expand Down
2 changes: 1 addition & 1 deletion bin/node/executor/tests/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use codec::{Encode, Joiner};
use frame_support::{
StorageValue, StorageMap,
StorageValue,
traits::Currency,
weights::{GetDispatchInfo, constants::ExtrinsicBaseWeight, IdentityFee, WeightToFeePolynomial},
};
Expand Down
1 change: 0 additions & 1 deletion bin/node/executor/tests/submit_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ fn should_submit_signed_twice_from_all_accounts() {
#[test]
fn submitted_transaction_should_be_valid() {
use codec::Encode;
use frame_support::storage::StorageMap;
use sp_runtime::transaction_validity::{TransactionSource, TransactionTag};
use sp_runtime::traits::StaticLookup;

Expand Down
8 changes: 4 additions & 4 deletions frame/balances/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ macro_rules! decl_tests {
assert_eq!(
events(),
[
Event::system(system::RawEvent::NewAccount(1)),
Event::system(system::Event::NewAccount(1)),
Event::balances(RawEvent::Endowed(1, 100)),
Event::balances(RawEvent::BalanceSet(1, 100, 0)),
]
Expand All @@ -758,7 +758,7 @@ macro_rules! decl_tests {
events(),
[
Event::balances(RawEvent::DustLost(1, 99)),
Event::system(system::RawEvent::KilledAccount(1))
Event::system(system::Event::KilledAccount(1))
]
);
});
Expand All @@ -775,7 +775,7 @@ macro_rules! decl_tests {
assert_eq!(
events(),
[
Event::system(system::RawEvent::NewAccount(1)),
Event::system(system::Event::NewAccount(1)),
Event::balances(RawEvent::Endowed(1, 100)),
Event::balances(RawEvent::BalanceSet(1, 100, 0)),
]
Expand All @@ -791,7 +791,7 @@ macro_rules! decl_tests {
assert_eq!(
events(),
[
Event::system(system::RawEvent::KilledAccount(1))
Event::system(system::Event::KilledAccount(1))
]
);
});
Expand Down
4 changes: 2 additions & 2 deletions frame/balances/src/tests_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() {
assert_eq!(
events(),
[
Event::system(system::RawEvent::NewAccount(1)),
Event::system(system::Event::NewAccount(1)),
Event::balances(RawEvent::Endowed(1, 100)),
Event::balances(RawEvent::BalanceSet(1, 100, 0)),
]
Expand All @@ -187,7 +187,7 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() {
events(),
[
Event::balances(RawEvent::DustLost(1, 1)),
Event::system(system::RawEvent::KilledAccount(1))
Event::system(system::Event::KilledAccount(1))
]
);
});
Expand Down
14 changes: 7 additions & 7 deletions frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ fn instantiate_and_call_and_deposit_event() {
pretty_assertions::assert_eq!(System::events(), vec![
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::system(frame_system::RawEvent::NewAccount(ALICE.clone())),
event: MetaEvent::system(frame_system::Event::NewAccount(ALICE.clone())),
topics: vec![],
},
EventRecord {
Expand All @@ -490,7 +490,7 @@ fn instantiate_and_call_and_deposit_event() {
},
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::system(frame_system::RawEvent::NewAccount(addr.clone())),
event: MetaEvent::system(frame_system::Event::NewAccount(addr.clone())),
topics: vec![],
},
EventRecord {
Expand Down Expand Up @@ -651,7 +651,7 @@ fn test_set_rent_code_and_hash() {
assert_eq!(System::events(), vec![
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::system(frame_system::RawEvent::NewAccount(ALICE)),
event: MetaEvent::system(frame_system::Event::NewAccount(ALICE)),
topics: vec![],
},
EventRecord {
Expand Down Expand Up @@ -1233,7 +1233,7 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage:
assert_eq!(System::events(), vec![
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::system(frame_system::RawEvent::NewAccount(ALICE)),
event: MetaEvent::system(frame_system::Event::NewAccount(ALICE)),
topics: vec![],
},
EventRecord {
Expand Down Expand Up @@ -1388,7 +1388,7 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage:
},
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::system(frame_system::RawEvent::NewAccount(CHARLIE)),
event: MetaEvent::system(frame_system::Event::NewAccount(CHARLIE)),
topics: vec![],
},
EventRecord {
Expand All @@ -1398,7 +1398,7 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage:
},
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::system(frame_system::RawEvent::NewAccount(addr_django.clone())),
event: MetaEvent::system(frame_system::Event::NewAccount(addr_django.clone())),
topics: vec![],
},
EventRecord {
Expand Down Expand Up @@ -1438,7 +1438,7 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage:
assert_eq!(System::events(), vec![
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::system(system::RawEvent::KilledAccount(addr_django.clone())),
event: MetaEvent::system(system::Event::KilledAccount(addr_django.clone())),
topics: vec![],
},
EventRecord {
Expand Down
16 changes: 8 additions & 8 deletions frame/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@

use sp_std::{prelude::*, marker::PhantomData};
use frame_support::{
StorageValue, StorageMap, weights::{GetDispatchInfo, DispatchInfo, DispatchClass},
weights::{GetDispatchInfo, DispatchInfo, DispatchClass},
traits::{OnInitialize, OnFinalize, OnRuntimeUpgrade, OffchainWorker},
dispatch::PostDispatchInfo,
};
Expand Down Expand Up @@ -261,11 +261,11 @@ where

/// Returns if the runtime was upgraded since the last time this function was called.
fn runtime_upgraded() -> bool {
let last = frame_system::LastRuntimeUpgrade::get();
let last = frame_system::LastRuntimeUpgrade::<System>::get();
let current = <System::Version as frame_support::traits::Get<_>>::get();

if last.map(|v| v.was_upgraded(&current)).unwrap_or(true) {
frame_system::LastRuntimeUpgrade::put(
frame_system::LastRuntimeUpgrade::<System>::put(
frame_system::LastRuntimeUpgradeInfo::from(current),
);
true
Expand Down Expand Up @@ -998,7 +998,7 @@ mod tests {
new_test_ext(1).execute_with(|| {
RUNTIME_VERSION.with(|v| *v.borrow_mut() = Default::default());
// It should be added at genesis
assert!(frame_system::LastRuntimeUpgrade::exists());
assert!(frame_system::LastRuntimeUpgrade::<Runtime>::exists());
assert!(!Executive::runtime_upgraded());

RUNTIME_VERSION.with(|v| *v.borrow_mut() = sp_version::RuntimeVersion {
Expand All @@ -1008,7 +1008,7 @@ mod tests {
assert!(Executive::runtime_upgraded());
assert_eq!(
Some(LastRuntimeUpgradeInfo { spec_version: 1.into(), spec_name: "".into() }),
frame_system::LastRuntimeUpgrade::get(),
frame_system::LastRuntimeUpgrade::<Runtime>::get(),
);

RUNTIME_VERSION.with(|v| *v.borrow_mut() = sp_version::RuntimeVersion {
Expand All @@ -1019,7 +1019,7 @@ mod tests {
assert!(Executive::runtime_upgraded());
assert_eq!(
Some(LastRuntimeUpgradeInfo { spec_version: 1.into(), spec_name: "test".into() }),
frame_system::LastRuntimeUpgrade::get(),
frame_system::LastRuntimeUpgrade::<Runtime>::get(),
);

RUNTIME_VERSION.with(|v| *v.borrow_mut() = sp_version::RuntimeVersion {
Expand All @@ -1030,11 +1030,11 @@ mod tests {
});
assert!(!Executive::runtime_upgraded());

frame_system::LastRuntimeUpgrade::take();
frame_system::LastRuntimeUpgrade::<Runtime>::take();
assert!(Executive::runtime_upgraded());
assert_eq!(
Some(LastRuntimeUpgradeInfo { spec_version: 1.into(), spec_name: "test".into() }),
frame_system::LastRuntimeUpgrade::get(),
frame_system::LastRuntimeUpgrade::<Runtime>::get(),
);
})
}
Expand Down
2 changes: 1 addition & 1 deletion frame/session/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use sp_std::vec;
use frame_benchmarking::benchmarks;
use frame_support::{
codec::Decode,
storage::{StorageValue, StorageMap},
storage::StorageValue,
traits::{KeyOwnerProofSystem, OnInitialize},
};
use frame_system::RawOrigin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ pub mod pallet {{
#[pallet::generate_store({store_vis} trait Store)]
pub struct Pallet{decl_gen}(PhantomData{use_gen_tuple});

#[pallet::interface]
#[pallet::hooks]
ascjones marked this conversation as resolved.
Show resolved Hide resolved
impl{impl_gen} Hooks<BlockNumberFor<T>> for Pallet{use_gen}
// TODO_MAYBE_WHERE_CLAUSE
{{
Expand Down
2 changes: 1 addition & 1 deletion frame/system/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use sp_core::{ChangesTrieConfiguration, storage::well_known_keys};
use sp_runtime::traits::Hash;
use frame_benchmarking::{benchmarks, whitelisted_caller};
use frame_support::{
storage::{self, StorageMap},
storage,
traits::Get,
weights::DispatchClass,
};
Expand Down
1 change: 0 additions & 1 deletion frame/system/src/extensions/check_mortality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
1 change: 0 additions & 1 deletion frame/system/src/extensions/check_nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use codec::{Encode, Decode};
use crate::Config;
use frame_support::{
weights::DispatchInfo,
StorageMap,
};
use sp_runtime::{
traits::{SignedExtension, DispatchInfoOf, Dispatchable, One},
Expand Down
27 changes: 13 additions & 14 deletions frame/system/src/extensions/check_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use sp_runtime::{
use frame_support::{
traits::{Get},
weights::{PostDispatchInfo, DispatchInfo, DispatchClass, priority::FrameTransactionPriority},
StorageValue,
};

/// Block resource (weight) limit check.
Expand Down Expand Up @@ -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(())
}

Expand Down Expand Up @@ -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);
})
}
Expand Down Expand Up @@ -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.
Expand All @@ -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());
})
Expand Down Expand Up @@ -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()) }
};
Expand Down Expand Up @@ -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);
Expand All @@ -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,
);
})
Expand All @@ -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,
);

Expand All @@ -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,
);
})
Expand Down
Loading