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

Commit e13ce1c

Browse files
gupnikjuangiriniggwpezbkchr
authored andcommitted
Moves Block to frame_system instead of construct_runtime and removes Header and BlockNumber (#14437)
* Initial setup * Adds node block * Uses UncheckedExtrinsic and removes Where section * Updates frame_system to use Block * Adds deprecation warning * Fixes pallet-timestamp * Removes Header and BlockNumber * Addresses review comments * Addresses review comments * Adds comment about compiler bug * Removes where clause * Refactors code * Fixes errors in cargo check * Fixes errors in cargo check * Fixes warnings in cargo check * Formatting * Fixes construct_runtime tests * Uses import instead of full path for BlockNumber * Uses import instead of full path for Header * Formatting * Fixes construct_runtime tests * Fixes imports in benchmarks * Formatting * Fixes construct_runtime tests * Formatting * Minor updates * Fixes construct_runtime ui tests * Fixes construct_runtime ui tests with 1.70 * Fixes docs * Fixes docs * Adds u128 mock block type * Fixes split example * fixes for cumulus * ".git/.scripts/commands/fmt/fmt.sh" * Updates new tests * Fixes fully-qualified path in few places * Formatting * Update frame/examples/default-config/src/lib.rs Co-authored-by: Juan <[email protected]> * Update frame/support/procedural/src/construct_runtime/mod.rs Co-authored-by: Juan <[email protected]> * ".git/.scripts/commands/fmt/fmt.sh" * Addresses some review comments * Fixes build * ".git/.scripts/commands/fmt/fmt.sh" * Update frame/democracy/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <[email protected]> * Update frame/democracy/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <[email protected]> * Update frame/support/procedural/src/construct_runtime/mod.rs Co-authored-by: Oliver Tale-Yazdi <[email protected]> * Update frame/support/procedural/src/construct_runtime/mod.rs Co-authored-by: Oliver Tale-Yazdi <[email protected]> * Addresses review comments * Updates trait bounds * Minor fix * ".git/.scripts/commands/fmt/fmt.sh" * Removes unnecessary bound * ".git/.scripts/commands/fmt/fmt.sh" * Updates test * Fixes build * Adds a bound for header * ".git/.scripts/commands/fmt/fmt.sh" * Removes where block * Minor fix * Minor fix * Fixes tests * ".git/.scripts/commands/update-ui/update-ui.sh" 1.70 * Updates test * Update primitives/runtime/src/traits.rs Co-authored-by: Bastian Köcher <[email protected]> * Update primitives/runtime/src/traits.rs Co-authored-by: Bastian Köcher <[email protected]> * Updates doc * Updates doc --------- Co-authored-by: command-bot <> Co-authored-by: Juan <[email protected]> Co-authored-by: Oliver Tale-Yazdi <[email protected]> Co-authored-by: Bastian Köcher <[email protected]>
1 parent 022f15a commit e13ce1c

File tree

277 files changed

+2017
-2450
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

277 files changed

+2017
-2450
lines changed

bin/node-template/pallets/template/src/mock.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,15 @@ use crate as pallet_template;
22
use frame_support::traits::{ConstU16, ConstU64};
33
use sp_core::H256;
44
use sp_runtime::{
5-
testing::Header,
65
traits::{BlakeTwo256, IdentityLookup},
76
BuildStorage,
87
};
98

10-
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
119
type Block = frame_system::mocking::MockBlock<Test>;
1210

1311
// Configure a mock runtime to test the pallet.
1412
frame_support::construct_runtime!(
15-
pub enum Test where
16-
Block = Block,
17-
NodeBlock = Block,
18-
UncheckedExtrinsic = UncheckedExtrinsic,
13+
pub enum Test
1914
{
2015
System: frame_system,
2116
TemplateModule: pallet_template,
@@ -30,12 +25,11 @@ impl frame_system::Config for Test {
3025
type RuntimeOrigin = RuntimeOrigin;
3126
type RuntimeCall = RuntimeCall;
3227
type Index = u64;
33-
type BlockNumber = u64;
3428
type Hash = H256;
3529
type Hashing = BlakeTwo256;
3630
type AccountId = u64;
3731
type Lookup = IdentityLookup<Self::AccountId>;
38-
type Header = Header;
32+
type Block = Block;
3933
type RuntimeEvent = RuntimeEvent;
4034
type BlockHashCount = ConstU64<250>;
4135
type Version = ();

bin/node-template/runtime/src/lib.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ parameter_types! {
155155
impl frame_system::Config for Runtime {
156156
/// The basic call filter to use in dispatchable.
157157
type BaseCallFilter = frame_support::traits::Everything;
158+
/// The block type for the runtime.
159+
type Block = Block;
158160
/// Block & extrinsics weights: base values and limits.
159161
type BlockWeights = BlockWeights;
160162
/// The maximum length of a block (in bytes).
@@ -167,14 +169,10 @@ impl frame_system::Config for Runtime {
167169
type Lookup = AccountIdLookup<AccountId, ()>;
168170
/// The index type for storing how many extrinsics an account has signed.
169171
type Index = Index;
170-
/// The index type for blocks.
171-
type BlockNumber = BlockNumber;
172172
/// The type for hashing blocks and tries.
173173
type Hash = Hash;
174174
/// The hashing algorithm used.
175175
type Hashing = BlakeTwo256;
176-
/// The header type.
177-
type Header = generic::Header<BlockNumber, BlakeTwo256>;
178176
/// The ubiquitous event type.
179177
type RuntimeEvent = RuntimeEvent;
180178
/// The ubiquitous origin type.
@@ -278,12 +276,7 @@ impl pallet_template::Config for Runtime {
278276

279277
// Create the runtime by composing the FRAME pallets that were previously configured.
280278
construct_runtime!(
281-
pub struct Runtime
282-
where
283-
Block = Block,
284-
NodeBlock = opaque::Block,
285-
UncheckedExtrinsic = UncheckedExtrinsic,
286-
{
279+
pub struct Runtime {
287280
System: frame_system,
288281
Timestamp: pallet_timestamp,
289282
Aura: pallet_aura,

bin/node/runtime/src/lib.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,11 @@ impl frame_system::Config for Runtime {
227227
type RuntimeOrigin = RuntimeOrigin;
228228
type RuntimeCall = RuntimeCall;
229229
type Index = Index;
230-
type BlockNumber = BlockNumber;
231230
type Hash = Hash;
232231
type Hashing = BlakeTwo256;
233232
type AccountId = AccountId;
234233
type Lookup = Indices;
235-
type Header = generic::Header<BlockNumber, BlakeTwo256>;
234+
type Block = Block;
236235
type RuntimeEvent = RuntimeEvent;
237236
type BlockHashCount = BlockHashCount;
238237
type Version = Version;
@@ -1868,10 +1867,7 @@ impl pallet_statement::Config for Runtime {
18681867
}
18691868

18701869
construct_runtime!(
1871-
pub struct Runtime where
1872-
Block = Block,
1873-
NodeBlock = node_primitives::Block,
1874-
UncheckedExtrinsic = UncheckedExtrinsic
1870+
pub struct Runtime
18751871
{
18761872
System: frame_system,
18771873
Utility: pallet_utility,

frame/alliance/src/benchmarking.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use sp_std::{
2727

2828
use frame_benchmarking::v1::{account, benchmarks_instance_pallet, BenchmarkError};
2929
use frame_support::traits::{EnsureOrigin, Get, UnfilteredDispatchable};
30-
use frame_system::{Pallet as System, RawOrigin as SystemOrigin};
30+
use frame_system::{pallet_prelude::BlockNumberFor, Pallet as System, RawOrigin as SystemOrigin};
3131

3232
use super::{Call as AllianceCall, Pallet as Alliance, *};
3333

@@ -432,7 +432,7 @@ benchmarks_instance_pallet! {
432432
false,
433433
)?;
434434

435-
System::<T>::set_block_number(T::BlockNumber::max_value());
435+
System::<T>::set_block_number(BlockNumberFor::<T>::max_value());
436436

437437
}: close(SystemOrigin::Signed(voter), last_hash.clone(), index, Weight::MAX, bytes_in_storage)
438438
verify {
@@ -504,7 +504,7 @@ benchmarks_instance_pallet! {
504504
}
505505

506506
// caller is prime, prime already votes aye by creating the proposal
507-
System::<T>::set_block_number(T::BlockNumber::max_value());
507+
System::<T>::set_block_number(BlockNumberFor::<T>::max_value());
508508

509509
}: close(SystemOrigin::Signed(voter), last_hash.clone(), index, Weight::MAX, bytes_in_storage)
510510
verify {

frame/alliance/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ pub mod pallet {
309309

310310
/// The number of blocks a member must wait between giving a retirement notice and retiring.
311311
/// Supposed to be greater than time required to `kick_member`.
312-
type RetirementPeriod: Get<Self::BlockNumber>;
312+
type RetirementPeriod: Get<BlockNumberFor<Self>>;
313313
}
314314

315315
#[pallet::error]
@@ -477,7 +477,7 @@ pub mod pallet {
477477
#[pallet::storage]
478478
#[pallet::getter(fn retiring_members)]
479479
pub type RetiringMembers<T: Config<I>, I: 'static = ()> =
480-
StorageMap<_, Blake2_128Concat, T::AccountId, T::BlockNumber, OptionQuery>;
480+
StorageMap<_, Blake2_128Concat, T::AccountId, BlockNumberFor<T>, OptionQuery>;
481481

482482
/// The current list of accounts deemed unscrupulous. These accounts non grata cannot submit
483483
/// candidacy.

frame/alliance/src/mock.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
pub use sp_core::H256;
2121
use sp_runtime::traits::Hash;
2222
pub use sp_runtime::{
23-
testing::Header,
2423
traits::{BlakeTwo256, IdentityLookup},
2524
BuildStorage,
2625
};
@@ -53,12 +52,11 @@ impl frame_system::Config for Test {
5352
type RuntimeOrigin = RuntimeOrigin;
5453
type RuntimeCall = RuntimeCall;
5554
type Index = u64;
56-
type BlockNumber = BlockNumber;
5755
type Hash = H256;
5856
type Hashing = BlakeTwo256;
5957
type AccountId = AccountId;
6058
type Lookup = IdentityLookup<Self::AccountId>;
61-
type Header = Header;
59+
type Block = Block;
6260
type RuntimeEvent = RuntimeEvent;
6361
type BlockHashCount = BlockHashCount;
6462
type DbWeight = ();
@@ -238,14 +236,10 @@ impl Config for Test {
238236
type RetirementPeriod = RetirementPeriod;
239237
}
240238

241-
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
242239
type Block = frame_system::mocking::MockBlock<Test>;
243240

244241
frame_support::construct_runtime!(
245-
pub enum Test where
246-
Block = Block,
247-
NodeBlock = Block,
248-
UncheckedExtrinsic = UncheckedExtrinsic,
242+
pub enum Test
249243
{
250244
System: frame_system,
251245
Balances: pallet_balances,

frame/asset-conversion/src/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ use frame_support::{
7272
ensure,
7373
traits::tokens::{AssetId, Balance},
7474
};
75-
use frame_system::{ensure_signed, pallet_prelude::OriginFor};
75+
use frame_system::{
76+
ensure_signed,
77+
pallet_prelude::{BlockNumberFor, OriginFor},
78+
};
7679
pub use pallet::*;
7780
use sp_arithmetic::traits::Unsigned;
7881
use sp_runtime::{
@@ -357,7 +360,7 @@ pub mod pallet {
357360
}
358361

359362
#[pallet::hooks]
360-
impl<T: Config> Hooks<T::BlockNumber> for Pallet<T> {
363+
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
361364
fn integrity_test() {
362365
assert!(
363366
T::MaxSwapPathLength::get() > 1,

frame/asset-conversion/src/mock.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,13 @@ use frame_system::{EnsureSigned, EnsureSignedBy};
3131
use sp_arithmetic::Permill;
3232
use sp_core::H256;
3333
use sp_runtime::{
34-
testing::Header,
3534
traits::{AccountIdConversion, BlakeTwo256, IdentityLookup},
3635
BuildStorage,
3736
};
38-
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
3937
type Block = frame_system::mocking::MockBlock<Test>;
4038

4139
construct_runtime!(
42-
pub enum Test where
43-
Block = Block,
44-
NodeBlock = Block,
45-
UncheckedExtrinsic = UncheckedExtrinsic,
40+
pub enum Test
4641
{
4742
System: frame_system,
4843
Balances: pallet_balances,
@@ -59,12 +54,11 @@ impl frame_system::Config for Test {
5954
type RuntimeOrigin = RuntimeOrigin;
6055
type RuntimeCall = RuntimeCall;
6156
type Index = u64;
62-
type BlockNumber = u64;
6357
type Hash = H256;
6458
type Hashing = BlakeTwo256;
6559
type AccountId = u128;
6660
type Lookup = IdentityLookup<Self::AccountId>;
67-
type Header = Header;
61+
type Block = Block;
6862
type RuntimeEvent = RuntimeEvent;
6963
type BlockHashCount = ConstU64<250>;
7064
type DbWeight = ();

frame/asset-rate/src/mock.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,14 @@ use crate as pallet_asset_rate;
2121
use frame_support::traits::{ConstU16, ConstU64};
2222
use sp_core::H256;
2323
use sp_runtime::{
24-
testing::Header,
2524
traits::{BlakeTwo256, IdentityLookup},
2625
BuildStorage,
2726
};
2827

29-
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
3028
type Block = frame_system::mocking::MockBlock<Test>;
3129

3230
frame_support::construct_runtime!(
33-
pub enum Test where
34-
Block = Block,
35-
NodeBlock = Block,
36-
UncheckedExtrinsic = UncheckedExtrinsic,
31+
pub enum Test
3732
{
3833
System: frame_system,
3934
AssetRate: pallet_asset_rate,
@@ -49,12 +44,11 @@ impl frame_system::Config for Test {
4944
type RuntimeOrigin = RuntimeOrigin;
5045
type RuntimeCall = RuntimeCall;
5146
type Index = u64;
52-
type BlockNumber = u64;
5347
type Hash = H256;
5448
type Hashing = BlakeTwo256;
5549
type AccountId = u64;
5650
type Lookup = IdentityLookup<Self::AccountId>;
57-
type Header = Header;
51+
type Block = Block;
5852
type RuntimeEvent = RuntimeEvent;
5953
type BlockHashCount = ConstU64<250>;
6054
type Version = ();

frame/assets/src/mock.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,14 @@ use frame_support::{
2828
use sp_core::H256;
2929
use sp_io::storage;
3030
use sp_runtime::{
31-
testing::Header,
3231
traits::{BlakeTwo256, IdentityLookup},
3332
BuildStorage,
3433
};
3534

36-
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
3735
type Block = frame_system::mocking::MockBlock<Test>;
3836

3937
construct_runtime!(
40-
pub enum Test where
41-
Block = Block,
42-
NodeBlock = Block,
43-
UncheckedExtrinsic = UncheckedExtrinsic,
38+
pub enum Test
4439
{
4540
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
4641
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -58,12 +53,11 @@ impl frame_system::Config for Test {
5853
type RuntimeOrigin = RuntimeOrigin;
5954
type RuntimeCall = RuntimeCall;
6055
type Index = u64;
61-
type BlockNumber = u64;
6256
type Hash = H256;
6357
type Hashing = BlakeTwo256;
6458
type AccountId = AccountId;
6559
type Lookup = IdentityLookup<Self::AccountId>;
66-
type Header = Header;
60+
type Block = Block;
6761
type RuntimeEvent = RuntimeEvent;
6862
type BlockHashCount = ConstU64<250>;
6963
type DbWeight = ();

frame/atomic-swap/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ use frame_support::{
5050
weights::Weight,
5151
RuntimeDebugNoBound,
5252
};
53+
use frame_system::pallet_prelude::BlockNumberFor;
5354
use scale_info::TypeInfo;
5455
use sp_io::hashing::blake2_256;
5556
use sp_runtime::RuntimeDebug;
@@ -69,7 +70,7 @@ pub struct PendingSwap<T: Config> {
6970
/// Action of this swap.
7071
pub action: T::SwapAction,
7172
/// End block of the lock.
72-
pub end_block: T::BlockNumber,
73+
pub end_block: BlockNumberFor<T>,
7374
}
7475

7576
/// Hashed proof type.
@@ -249,7 +250,7 @@ pub mod pallet {
249250
target: T::AccountId,
250251
hashed_proof: HashedProof,
251252
action: T::SwapAction,
252-
duration: T::BlockNumber,
253+
duration: BlockNumberFor<T>,
253254
) -> DispatchResult {
254255
let source = ensure_signed(origin)?;
255256
ensure!(

frame/atomic-swap/src/tests.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,14 @@ use crate as pallet_atomic_swap;
66
use frame_support::traits::{ConstU32, ConstU64};
77
use sp_core::H256;
88
use sp_runtime::{
9-
testing::Header,
109
traits::{BlakeTwo256, IdentityLookup},
1110
BuildStorage,
1211
};
1312

14-
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
1513
type Block = frame_system::mocking::MockBlock<Test>;
1614

1715
frame_support::construct_runtime!(
18-
pub enum Test where
19-
Block = Block,
20-
NodeBlock = Block,
21-
UncheckedExtrinsic = UncheckedExtrinsic,
16+
pub enum Test
2217
{
2318
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
2419
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -33,13 +28,12 @@ impl frame_system::Config for Test {
3328
type DbWeight = ();
3429
type RuntimeOrigin = RuntimeOrigin;
3530
type Index = u64;
36-
type BlockNumber = u64;
3731
type Hash = H256;
3832
type RuntimeCall = RuntimeCall;
3933
type Hashing = BlakeTwo256;
4034
type AccountId = u64;
4135
type Lookup = IdentityLookup<Self::AccountId>;
42-
type Header = Header;
36+
type Block = Block;
4337
type RuntimeEvent = RuntimeEvent;
4438
type BlockHashCount = ConstU64<250>;
4539
type Version = ();

frame/aura/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub mod pallet {
102102

103103
#[pallet::hooks]
104104
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
105-
fn on_initialize(_: T::BlockNumber) -> Weight {
105+
fn on_initialize(_: BlockNumberFor<T>) -> Weight {
106106
if let Some(new_slot) = Self::current_slot_from_digests() {
107107
let current_slot = CurrentSlot::<T>::get();
108108

@@ -134,7 +134,7 @@ pub mod pallet {
134134
}
135135

136136
#[cfg(feature = "try-runtime")]
137-
fn try_state(_: T::BlockNumber) -> Result<(), sp_runtime::TryRuntimeError> {
137+
fn try_state(_: BlockNumberFor<T>) -> Result<(), sp_runtime::TryRuntimeError> {
138138
Self::do_try_state()
139139
}
140140
}

0 commit comments

Comments
 (0)