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

Moves Block to frame_system instead of construct_runtime and removes Header and BlockNumber #14437

Merged
merged 79 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
e0f4cc7
Initial setup
gupnik May 15, 2023
5d688f8
Adds node block
gupnik May 15, 2023
1681e65
Uses UncheckedExtrinsic and removes Where section
gupnik May 15, 2023
3e461f1
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik May 23, 2023
a69a911
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 3, 2023
a5e7cb6
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 5, 2023
2590f43
Updates frame_system to use Block
gupnik Jun 5, 2023
f4e772a
Adds deprecation warning
gupnik Jun 5, 2023
2eb58e8
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 22, 2023
b6ca21e
Fixes pallet-timestamp
gupnik Jun 22, 2023
1333eb3
Removes Header and BlockNumber
gupnik Jun 22, 2023
373af30
Addresses review comments
gupnik Jun 24, 2023
55a698c
Addresses review comments
gupnik Jun 24, 2023
c1db41a
Adds comment about compiler bug
gupnik Jun 24, 2023
a36245c
Removes where clause
gupnik Jun 25, 2023
d4e113f
Refactors code
gupnik Jun 25, 2023
6e3ae77
Fixes errors in cargo check
gupnik Jun 25, 2023
d9e6ce8
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 25, 2023
4de134c
Fixes errors in cargo check
gupnik Jun 25, 2023
884ceaf
Fixes warnings in cargo check
gupnik Jun 25, 2023
211138e
Formatting
gupnik Jun 25, 2023
eaa8b29
Fixes construct_runtime tests
gupnik Jun 27, 2023
f8c6153
Uses import instead of full path for BlockNumber
gupnik Jun 27, 2023
3df4b15
Uses import instead of full path for Header
gupnik Jun 27, 2023
cb55082
Formatting
gupnik Jun 27, 2023
6d9286f
Fixes construct_runtime tests
gupnik Jun 27, 2023
09f50ef
Fixes imports in benchmarks
gupnik Jun 27, 2023
67223f4
Formatting
gupnik Jun 27, 2023
3f05c25
Fixes construct_runtime tests
gupnik Jun 27, 2023
03cffab
Formatting
gupnik Jun 27, 2023
fe4e9cc
Minor updates
gupnik Jun 27, 2023
85d992e
Fixes construct_runtime ui tests
gupnik Jun 27, 2023
bae2306
Fixes construct_runtime ui tests with 1.70
gupnik Jun 27, 2023
27b47ba
Fixes docs
gupnik Jun 27, 2023
09fe084
Fixes docs
gupnik Jun 27, 2023
827f7e0
Adds u128 mock block type
gupnik Jun 28, 2023
f70e152
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 28, 2023
ded2d97
Fixes split example
gupnik Jun 28, 2023
2715d40
fixes for cumulus
gupnik Jun 28, 2023
3226bcb
".git/.scripts/commands/fmt/fmt.sh"
Jun 28, 2023
fef6829
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 28, 2023
2454cfa
Updates new tests
gupnik Jun 28, 2023
87742a3
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 28, 2023
61842c6
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 29, 2023
e7ddf9f
Fixes fully-qualified path in few places
gupnik Jul 4, 2023
c93f9d5
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jul 4, 2023
89e66de
Formatting
gupnik Jul 4, 2023
64bb577
Update frame/examples/default-config/src/lib.rs
gupnik Jul 5, 2023
e8c14b0
Update frame/support/procedural/src/construct_runtime/mod.rs
gupnik Jul 5, 2023
2f1a514
".git/.scripts/commands/fmt/fmt.sh"
Jul 8, 2023
16f10af
Addresses some review comments
gupnik Jul 10, 2023
5754b72
Fixes build
gupnik Jul 10, 2023
4775cc1
".git/.scripts/commands/fmt/fmt.sh"
Jul 10, 2023
1571503
Update frame/democracy/src/lib.rs
gupnik Jul 11, 2023
ab86af2
Update frame/democracy/src/lib.rs
gupnik Jul 11, 2023
b443c40
Update frame/support/procedural/src/construct_runtime/mod.rs
gupnik Jul 11, 2023
0f3cee1
Update frame/support/procedural/src/construct_runtime/mod.rs
gupnik Jul 11, 2023
8bb8fb9
Addresses review comments
gupnik Jul 11, 2023
83f7841
Updates trait bounds
gupnik Jul 11, 2023
644b5be
Minor fix
gupnik Jul 11, 2023
2d219d5
".git/.scripts/commands/fmt/fmt.sh"
Jul 11, 2023
a09d3c9
Removes unnecessary bound
gupnik Jul 11, 2023
f624f25
".git/.scripts/commands/fmt/fmt.sh"
Jul 11, 2023
c87594c
Updates test
gupnik Jul 11, 2023
3dcc6b6
Merge branch 'gupnik/cr-try2' of github.com:paritytech/substrate into…
gupnik Jul 11, 2023
90c0a21
Fixes build
gupnik Jul 11, 2023
e595d28
Adds a bound for header
gupnik Jul 12, 2023
a25532f
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jul 12, 2023
5e96a39
".git/.scripts/commands/fmt/fmt.sh"
Jul 12, 2023
b14d234
Removes where block
gupnik Jul 12, 2023
ef9ca39
Minor fix
gupnik Jul 12, 2023
a65653c
Minor fix
gupnik Jul 12, 2023
c559e51
Fixes tests
gupnik Jul 13, 2023
d1a6169
".git/.scripts/commands/update-ui/update-ui.sh" 1.70
Jul 13, 2023
e89e93e
Updates test
gupnik Jul 13, 2023
277300f
Update primitives/runtime/src/traits.rs
gupnik Jul 13, 2023
c3be2e0
Update primitives/runtime/src/traits.rs
gupnik Jul 13, 2023
5c823a5
Updates doc
gupnik Jul 13, 2023
3e41fa2
Updates doc
gupnik Jul 13, 2023
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: 2 additions & 8 deletions bin/node-template/pallets/template/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@ use crate as pallet_template;
use frame_support::traits::{ConstU16, ConstU64};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system,
TemplateModule: pallet_template,
Expand All @@ -30,12 +25,11 @@ impl frame_system::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
Expand Down
13 changes: 3 additions & 10 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ parameter_types! {
impl frame_system::Config for Runtime {
/// The basic call filter to use in dispatchable.
type BaseCallFilter = frame_support::traits::Everything;
/// The block type for the runtime.
type Block = Block;
/// Block & extrinsics weights: base values and limits.
type BlockWeights = BlockWeights;
/// The maximum length of a block (in bytes).
Expand All @@ -167,14 +169,10 @@ impl frame_system::Config for Runtime {
type Lookup = AccountIdLookup<AccountId, ()>;
/// The index type for storing how many extrinsics an account has signed.
type Index = Index;
/// The index type for blocks.
type BlockNumber = BlockNumber;
/// The type for hashing blocks and tries.
type Hash = Hash;
/// The hashing algorithm used.
type Hashing = BlakeTwo256;
/// The header type.
type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// The ubiquitous event type.
type RuntimeEvent = RuntimeEvent;
/// The ubiquitous origin type.
Expand Down Expand Up @@ -278,12 +276,7 @@ impl pallet_template::Config for Runtime {

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub struct Runtime
where
Block = Block,
NodeBlock = opaque::Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
pub struct Runtime {
System: frame_system,
Timestamp: pallet_timestamp,
Aura: pallet_aura,
Expand Down
8 changes: 2 additions & 6 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,11 @@ impl frame_system::Config for Runtime {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = Index;
type BlockNumber = BlockNumber;
type Hash = Hash;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = Indices;
type Header = generic::Header<BlockNumber, BlakeTwo256>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = Version;
Expand Down Expand Up @@ -1868,10 +1867,7 @@ impl pallet_statement::Config for Runtime {
}

construct_runtime!(
pub struct Runtime where
Block = Block,
NodeBlock = node_primitives::Block,
UncheckedExtrinsic = UncheckedExtrinsic
pub struct Runtime
{
System: frame_system,
Utility: pallet_utility,
Expand Down
6 changes: 3 additions & 3 deletions frame/alliance/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use sp_std::{

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

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

Expand Down Expand Up @@ -432,7 +432,7 @@ benchmarks_instance_pallet! {
false,
)?;

System::<T>::set_block_number(T::BlockNumber::max_value());
System::<T>::set_block_number(BlockNumberFor::<T>::max_value());

}: close(SystemOrigin::Signed(voter), last_hash.clone(), index, Weight::MAX, bytes_in_storage)
verify {
Expand Down Expand Up @@ -504,7 +504,7 @@ benchmarks_instance_pallet! {
}

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

}: close(SystemOrigin::Signed(voter), last_hash.clone(), index, Weight::MAX, bytes_in_storage)
verify {
Expand Down
4 changes: 2 additions & 2 deletions frame/alliance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ pub mod pallet {

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

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

/// The current list of accounts deemed unscrupulous. These accounts non grata cannot submit
/// candidacy.
Expand Down
10 changes: 2 additions & 8 deletions frame/alliance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
pub use sp_core::H256;
use sp_runtime::traits::Hash;
pub use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
Expand Down Expand Up @@ -53,12 +52,11 @@ impl frame_system::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = BlockNumber;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type DbWeight = ();
Expand Down Expand Up @@ -238,14 +236,10 @@ impl Config for Test {
type RetirementPeriod = RetirementPeriod;
}

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system,
Balances: pallet_balances,
Expand Down
7 changes: 5 additions & 2 deletions frame/asset-conversion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ use frame_support::{
ensure,
traits::tokens::{AssetId, Balance},
};
use frame_system::{ensure_signed, pallet_prelude::OriginFor};
use frame_system::{
ensure_signed,
pallet_prelude::{BlockNumberFor, OriginFor},
};
pub use pallet::*;
use sp_arithmetic::traits::Unsigned;
use sp_runtime::{
Expand Down Expand Up @@ -357,7 +360,7 @@ pub mod pallet {
}

#[pallet::hooks]
impl<T: Config> Hooks<T::BlockNumber> for Pallet<T> {
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn integrity_test() {
assert!(
T::MaxSwapPathLength::get() > 1,
Expand Down
10 changes: 2 additions & 8 deletions frame/asset-conversion/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,13 @@ use frame_system::{EnsureSigned, EnsureSignedBy};
use sp_arithmetic::Permill;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{AccountIdConversion, BlakeTwo256, IdentityLookup},
BuildStorage,
};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system,
Balances: pallet_balances,
Expand All @@ -59,12 +54,11 @@ impl frame_system::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u128;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type DbWeight = ();
Expand Down
10 changes: 2 additions & 8 deletions frame/asset-rate/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,14 @@ use crate as pallet_asset_rate;
use frame_support::traits::{ConstU16, ConstU64};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system,
AssetRate: pallet_asset_rate,
Expand All @@ -49,12 +44,11 @@ impl frame_system::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
Expand Down
10 changes: 2 additions & 8 deletions frame/assets/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,14 @@ use frame_support::{
use sp_core::H256;
use sp_io::storage;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Expand All @@ -58,12 +53,11 @@ impl frame_system::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type DbWeight = ();
Expand Down
5 changes: 3 additions & 2 deletions frame/atomic-swap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ use frame_support::{
weights::Weight,
RuntimeDebugNoBound,
};
use frame_system::pallet_prelude::BlockNumberFor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this be the standard:

All pallets must contain these lines:

use frame_system::pallet_prelude::*;
use frame_support::pallet_prelude::*;

// needed to make things work in construct_runtime
pub use pallet::*;

#[frame_support::pallet]
pub mod pallet {
	use super::*;
}

This can probably simplify a lot of imports.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(story for another day, of course)

use scale_info::TypeInfo;
use sp_io::hashing::blake2_256;
use sp_runtime::RuntimeDebug;
Expand All @@ -69,7 +70,7 @@ pub struct PendingSwap<T: Config> {
/// Action of this swap.
pub action: T::SwapAction,
/// End block of the lock.
pub end_block: T::BlockNumber,
pub end_block: BlockNumberFor<T>,
}

/// Hashed proof type.
Expand Down Expand Up @@ -249,7 +250,7 @@ pub mod pallet {
target: T::AccountId,
hashed_proof: HashedProof,
action: T::SwapAction,
duration: T::BlockNumber,
duration: BlockNumberFor<T>,
) -> DispatchResult {
let source = ensure_signed(origin)?;
ensure!(
Expand Down
10 changes: 2 additions & 8 deletions frame/atomic-swap/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ use crate as pallet_atomic_swap;
use frame_support::traits::{ConstU32, ConstU64};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Expand All @@ -33,13 +28,12 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
Expand Down
4 changes: 2 additions & 2 deletions frame/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub mod pallet {

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_: T::BlockNumber) -> Weight {
fn on_initialize(_: BlockNumberFor<T>) -> Weight {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good example for what I suggested above, because we already have frame_system::pallet_prelude in scope :)

if let Some(new_slot) = Self::current_slot_from_digests() {
let current_slot = CurrentSlot::<T>::get();

Expand Down Expand Up @@ -134,7 +134,7 @@ pub mod pallet {
}

#[cfg(feature = "try-runtime")]
fn try_state(_: T::BlockNumber) -> Result<(), sp_runtime::TryRuntimeError> {
fn try_state(_: BlockNumberFor<T>) -> Result<(), sp_runtime::TryRuntimeError> {
Self::do_try_state()
}
}
Expand Down
Loading