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

Commit 4868630

Browse files
ascjonesgui1117athei
authored
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 306f023 * 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>
1 parent a9ed67e commit 4868630

File tree

16 files changed

+575
-522
lines changed

16 files changed

+575
-522
lines changed

bin/node/executor/tests/basic.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ fn full_native_block_import_works() {
329329
let events = vec![
330330
EventRecord {
331331
phase: Phase::ApplyExtrinsic(0),
332-
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
332+
event: Event::frame_system(frame_system::Event::ExtrinsicSuccess(
333333
DispatchInfo { weight: timestamp_weight, class: DispatchClass::Mandatory, ..Default::default() }
334334
)),
335335
topics: vec![],
@@ -350,7 +350,7 @@ fn full_native_block_import_works() {
350350
},
351351
EventRecord {
352352
phase: Phase::ApplyExtrinsic(1),
353-
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
353+
event: Event::frame_system(frame_system::Event::ExtrinsicSuccess(
354354
DispatchInfo { weight: transfer_weight, ..Default::default() }
355355
)),
356356
topics: vec![],
@@ -381,7 +381,7 @@ fn full_native_block_import_works() {
381381
let events = vec![
382382
EventRecord {
383383
phase: Phase::ApplyExtrinsic(0),
384-
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
384+
event: Event::frame_system(frame_system::Event::ExtrinsicSuccess(
385385
DispatchInfo { weight: timestamp_weight, class: DispatchClass::Mandatory, ..Default::default() }
386386
)),
387387
topics: vec![],
@@ -404,7 +404,7 @@ fn full_native_block_import_works() {
404404
},
405405
EventRecord {
406406
phase: Phase::ApplyExtrinsic(1),
407-
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
407+
event: Event::frame_system(frame_system::Event::ExtrinsicSuccess(
408408
DispatchInfo { weight: transfer_weight, ..Default::default() }
409409
)),
410410
topics: vec![],
@@ -427,7 +427,7 @@ fn full_native_block_import_works() {
427427
},
428428
EventRecord {
429429
phase: Phase::ApplyExtrinsic(2),
430-
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
430+
event: Event::frame_system(frame_system::Event::ExtrinsicSuccess(
431431
DispatchInfo { weight: transfer_weight, ..Default::default() }
432432
)),
433433
topics: vec![],

bin/node/executor/tests/fees.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
use codec::{Encode, Joiner};
1919
use frame_support::{
20-
StorageValue, StorageMap,
20+
StorageValue,
2121
traits::Currency,
2222
weights::{GetDispatchInfo, constants::ExtrinsicBaseWeight, IdentityFee, WeightToFeePolynomial},
2323
};

bin/node/executor/tests/submit_transaction.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ fn should_submit_signed_twice_from_all_accounts() {
217217
#[test]
218218
fn submitted_transaction_should_be_valid() {
219219
use codec::Encode;
220-
use frame_support::storage::StorageMap;
221220
use sp_runtime::transaction_validity::{TransactionSource, TransactionTag};
222221
use sp_runtime::traits::StaticLookup;
223222

frame/balances/src/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ macro_rules! decl_tests {
737737
assert_eq!(
738738
events(),
739739
[
740-
Event::system(system::RawEvent::NewAccount(1)),
740+
Event::system(system::Event::NewAccount(1)),
741741
Event::balances(RawEvent::Endowed(1, 100)),
742742
Event::balances(RawEvent::BalanceSet(1, 100, 0)),
743743
]
@@ -749,7 +749,7 @@ macro_rules! decl_tests {
749749
events(),
750750
[
751751
Event::balances(RawEvent::DustLost(1, 99)),
752-
Event::system(system::RawEvent::KilledAccount(1))
752+
Event::system(system::Event::KilledAccount(1))
753753
]
754754
);
755755
});
@@ -766,7 +766,7 @@ macro_rules! decl_tests {
766766
assert_eq!(
767767
events(),
768768
[
769-
Event::system(system::RawEvent::NewAccount(1)),
769+
Event::system(system::Event::NewAccount(1)),
770770
Event::balances(RawEvent::Endowed(1, 100)),
771771
Event::balances(RawEvent::BalanceSet(1, 100, 0)),
772772
]
@@ -777,7 +777,7 @@ macro_rules! decl_tests {
777777
assert_eq!(
778778
events(),
779779
[
780-
Event::system(system::RawEvent::KilledAccount(1))
780+
Event::system(system::Event::KilledAccount(1))
781781
]
782782
);
783783
});

frame/balances/src/tests_local.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() {
170170
assert_eq!(
171171
events(),
172172
[
173-
Event::system(system::RawEvent::NewAccount(1)),
173+
Event::system(system::Event::NewAccount(1)),
174174
Event::balances(RawEvent::Endowed(1, 100)),
175175
Event::balances(RawEvent::BalanceSet(1, 100, 0)),
176176
]
@@ -187,7 +187,7 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() {
187187
events(),
188188
[
189189
Event::balances(RawEvent::DustLost(1, 1)),
190-
Event::system(system::RawEvent::KilledAccount(1))
190+
Event::system(system::Event::KilledAccount(1))
191191
]
192192
);
193193
});

frame/contracts/src/tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ fn instantiate_and_call_and_deposit_event() {
475475
pretty_assertions::assert_eq!(System::events(), vec![
476476
EventRecord {
477477
phase: Phase::Initialization,
478-
event: MetaEvent::system(frame_system::RawEvent::NewAccount(ALICE.clone())),
478+
event: MetaEvent::system(frame_system::Event::NewAccount(ALICE.clone())),
479479
topics: vec![],
480480
},
481481
EventRecord {
@@ -492,7 +492,7 @@ fn instantiate_and_call_and_deposit_event() {
492492
},
493493
EventRecord {
494494
phase: Phase::Initialization,
495-
event: MetaEvent::system(frame_system::RawEvent::NewAccount(addr.clone())),
495+
event: MetaEvent::system(frame_system::Event::NewAccount(addr.clone())),
496496
topics: vec![],
497497
},
498498
EventRecord {
@@ -653,7 +653,7 @@ fn test_set_rent_code_and_hash() {
653653
assert_eq!(System::events(), vec![
654654
EventRecord {
655655
phase: Phase::Initialization,
656-
event: MetaEvent::system(frame_system::RawEvent::NewAccount(ALICE)),
656+
event: MetaEvent::system(frame_system::Event::NewAccount(ALICE)),
657657
topics: vec![],
658658
},
659659
EventRecord {
@@ -1235,7 +1235,7 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage:
12351235
assert_eq!(System::events(), vec![
12361236
EventRecord {
12371237
phase: Phase::Initialization,
1238-
event: MetaEvent::system(frame_system::RawEvent::NewAccount(ALICE)),
1238+
event: MetaEvent::system(frame_system::Event::NewAccount(ALICE)),
12391239
topics: vec![],
12401240
},
12411241
EventRecord {
@@ -1390,7 +1390,7 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage:
13901390
},
13911391
EventRecord {
13921392
phase: Phase::Initialization,
1393-
event: MetaEvent::system(frame_system::RawEvent::NewAccount(CHARLIE)),
1393+
event: MetaEvent::system(frame_system::Event::NewAccount(CHARLIE)),
13941394
topics: vec![],
13951395
},
13961396
EventRecord {
@@ -1400,7 +1400,7 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage:
14001400
},
14011401
EventRecord {
14021402
phase: Phase::Initialization,
1403-
event: MetaEvent::system(frame_system::RawEvent::NewAccount(addr_django.clone())),
1403+
event: MetaEvent::system(frame_system::Event::NewAccount(addr_django.clone())),
14041404
topics: vec![],
14051405
},
14061406
EventRecord {
@@ -1440,7 +1440,7 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage:
14401440
assert_eq!(System::events(), vec![
14411441
EventRecord {
14421442
phase: Phase::Initialization,
1443-
event: MetaEvent::system(system::RawEvent::KilledAccount(addr_django.clone())),
1443+
event: MetaEvent::system(system::Event::KilledAccount(addr_django.clone())),
14441444
topics: vec![],
14451445
},
14461446
EventRecord {

frame/executive/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117

118118
use sp_std::{prelude::*, marker::PhantomData};
119119
use frame_support::{
120-
StorageValue, StorageMap, weights::{GetDispatchInfo, DispatchInfo, DispatchClass},
120+
weights::{GetDispatchInfo, DispatchInfo, DispatchClass},
121121
traits::{OnInitialize, OnFinalize, OnRuntimeUpgrade, OffchainWorker},
122122
dispatch::PostDispatchInfo,
123123
};
@@ -261,11 +261,11 @@ where
261261

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

267267
if last.map(|v| v.was_upgraded(&current)).unwrap_or(true) {
268-
frame_system::LastRuntimeUpgrade::put(
268+
frame_system::LastRuntimeUpgrade::<System>::put(
269269
frame_system::LastRuntimeUpgradeInfo::from(current),
270270
);
271271
true
@@ -998,7 +998,7 @@ mod tests {
998998
new_test_ext(1).execute_with(|| {
999999
RUNTIME_VERSION.with(|v| *v.borrow_mut() = Default::default());
10001000
// It should be added at genesis
1001-
assert!(frame_system::LastRuntimeUpgrade::exists());
1001+
assert!(frame_system::LastRuntimeUpgrade::<Runtime>::exists());
10021002
assert!(!Executive::runtime_upgraded());
10031003

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

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

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

1033-
frame_system::LastRuntimeUpgrade::take();
1033+
frame_system::LastRuntimeUpgrade::<Runtime>::take();
10341034
assert!(Executive::runtime_upgraded());
10351035
assert_eq!(
10361036
Some(LastRuntimeUpgradeInfo { spec_version: 1.into(), spec_name: "test".into() }),
1037-
frame_system::LastRuntimeUpgrade::get(),
1037+
frame_system::LastRuntimeUpgrade::<Runtime>::get(),
10381038
);
10391039
})
10401040
}

frame/session/benchmarking/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use sp_std::vec;
2828
use frame_benchmarking::benchmarks;
2929
use frame_support::{
3030
codec::Decode,
31-
storage::{StorageValue, StorageMap},
31+
storage::StorageValue,
3232
traits::{KeyOwnerProofSystem, OnInitialize},
3333
};
3434
use frame_system::RawOrigin;

frame/system/src/extensions/check_mortality.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
use codec::{Encode, Decode};
1919
use crate::{Config, Module, BlockHash};
20-
use frame_support::StorageMap;
2120
use sp_runtime::{
2221
generic::Era,
2322
traits::{SignedExtension, DispatchInfoOf, SaturatedConversion},

frame/system/src/extensions/check_nonce.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717

1818
use codec::{Encode, Decode};
1919
use crate::Config;
20-
use frame_support::{
21-
weights::DispatchInfo,
22-
StorageMap,
23-
};
20+
use frame_support::weights::DispatchInfo;
2421
use sp_runtime::{
2522
traits::{SignedExtension, DispatchInfoOf, Dispatchable, One},
2623
transaction_validity::{

0 commit comments

Comments
 (0)