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 <juangirini@gmail.com>

* Update frame/support/procedural/src/construct_runtime/mod.rs

Co-authored-by: Juan <juangirini@gmail.com>

* ".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 <oliver.tale-yazdi@parity.io>

* Update frame/democracy/src/lib.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/support/procedural/src/construct_runtime/mod.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/support/procedural/src/construct_runtime/mod.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* 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 <git@kchr.de>

* Update primitives/runtime/src/traits.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Updates doc

* Updates doc

---------

Co-authored-by: command-bot <>
Co-authored-by: Juan <juangirini@gmail.com>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
gupnik
2023-07-13 17:31:34 +05:30
committed by GitHub
parent e42a669c50
commit 5e7b27e98c
277 changed files with 2017 additions and 2450 deletions
@@ -22,9 +22,13 @@
#![recursion_limit = "128"]
use codec::MaxEncodedLen;
use frame_support::{parameter_types, traits::PalletInfo as _};
use frame_support::{
derive_impl, parameter_types, traits::PalletInfo as _, weights::RuntimeDbWeight,
};
use frame_system::limits::{BlockLength, BlockWeights};
use scale_info::TypeInfo;
use sp_core::sr25519;
use sp_api::RuntimeVersion;
use sp_core::{sr25519, ConstU64};
use sp_runtime::{
generic,
traits::{BlakeTwo256, Verify},
@@ -37,9 +41,8 @@ parameter_types! {
#[frame_support::pallet(dev_mode)]
mod module1 {
use self::frame_system::pallet_prelude::*;
use frame_support::pallet_prelude::*;
use frame_support_test as frame_system;
use frame_system::pallet_prelude::*;
#[pallet::pallet]
pub struct Pallet<T, I = ()>(_);
@@ -75,10 +78,9 @@ mod module1 {
#[frame_support::pallet(dev_mode)]
mod module2 {
use self::frame_system::pallet_prelude::*;
use super::*;
use frame_support::pallet_prelude::*;
use frame_support_test as frame_system;
use frame_system::pallet_prelude::*;
#[pallet::pallet]
pub struct Pallet<T>(_);
@@ -122,10 +124,9 @@ mod nested {
#[frame_support::pallet(dev_mode)]
pub mod module3 {
use self::frame_system::pallet_prelude::*;
use super::*;
use frame_support::pallet_prelude::*;
use frame_support_test as frame_system;
use frame_system::pallet_prelude::*;
#[pallet::pallet]
pub struct Pallet<T>(_);
@@ -180,10 +181,9 @@ mod nested {
#[frame_support::pallet(dev_mode)]
pub mod module3 {
use self::frame_system::pallet_prelude::*;
use super::*;
use frame_support::pallet_prelude::*;
use frame_support_test as frame_system;
use frame_system::pallet_prelude::*;
#[pallet::pallet]
pub struct Pallet<T>(_);
@@ -256,15 +256,10 @@ pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, RuntimeCall, Signature, ()>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
use frame_support_test as system;
frame_support::construct_runtime!(
pub struct Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
pub struct Runtime
{
System: system::{Pallet, Call, Event<T>, Origin<T>} = 30,
System: frame_system::{Pallet, Call, Event<T>, Origin<T>} = 30,
Module1_1: module1::<Instance1>::{Pallet, Call, Storage, Event<T>, Origin<T>},
Module2: module2::{Pallet, Call, Storage, Event<T>, Origin},
Module1_2: module1::<Instance2>::{Pallet, Call, Storage, Event<T>, Origin<T>},
@@ -280,15 +275,18 @@ frame_support::construct_runtime!(
}
);
impl frame_support_test::Config for Runtime {
type BlockNumber = BlockNumber;
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Runtime {
type AccountId = AccountId;
type Lookup = sp_runtime::traits::IdentityLookup<AccountId>;
type BaseCallFilter = frame_support::traits::Everything;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type PalletInfo = PalletInfo;
type DbWeight = ();
type OnSetCode = ();
type Block = Block;
type BlockHashCount = ConstU64<10>;
}
impl module1::Config<module1::Instance1> for Runtime {
@@ -336,7 +334,7 @@ fn test_pub() -> AccountId {
fn check_modules_error_type() {
sp_io::TestExternalities::default().execute_with(|| {
assert_eq!(
Module1_1::fail(system::Origin::<Runtime>::Root.into()),
Module1_1::fail(frame_system::Origin::<Runtime>::Root.into()),
Err(DispatchError::Module(ModuleError {
index: 31,
error: [0; 4],
@@ -344,7 +342,7 @@ fn check_modules_error_type() {
})),
);
assert_eq!(
Module2::fail(system::Origin::<Runtime>::Root.into()),
Module2::fail(frame_system::Origin::<Runtime>::Root.into()),
Err(DispatchError::Module(ModuleError {
index: 32,
error: [0; 4],
@@ -352,7 +350,7 @@ fn check_modules_error_type() {
})),
);
assert_eq!(
Module1_2::fail(system::Origin::<Runtime>::Root.into()),
Module1_2::fail(frame_system::Origin::<Runtime>::Root.into()),
Err(DispatchError::Module(ModuleError {
index: 33,
error: [0; 4],
@@ -360,7 +358,7 @@ fn check_modules_error_type() {
})),
);
assert_eq!(
NestedModule3::fail(system::Origin::<Runtime>::Root.into()),
NestedModule3::fail(frame_system::Origin::<Runtime>::Root.into()),
Err(DispatchError::Module(ModuleError {
index: 34,
error: [0; 4],
@@ -368,7 +366,7 @@ fn check_modules_error_type() {
})),
);
assert_eq!(
Module1_3::fail(system::Origin::<Runtime>::Root.into()),
Module1_3::fail(frame_system::Origin::<Runtime>::Root.into()),
Err(DispatchError::Module(ModuleError {
index: 6,
error: [0; 4],
@@ -376,7 +374,7 @@ fn check_modules_error_type() {
})),
);
assert_eq!(
Module1_4::fail(system::Origin::<Runtime>::Root.into()),
Module1_4::fail(frame_system::Origin::<Runtime>::Root.into()),
Err(DispatchError::Module(ModuleError {
index: 3,
error: [0; 4],
@@ -384,7 +382,7 @@ fn check_modules_error_type() {
})),
);
assert_eq!(
Module1_5::fail(system::Origin::<Runtime>::Root.into()),
Module1_5::fail(frame_system::Origin::<Runtime>::Root.into()),
Err(DispatchError::Module(ModuleError {
index: 4,
error: [0; 4],
@@ -392,7 +390,7 @@ fn check_modules_error_type() {
})),
);
assert_eq!(
Module1_6::fail(system::Origin::<Runtime>::Root.into()),
Module1_6::fail(frame_system::Origin::<Runtime>::Root.into()),
Err(DispatchError::Module(ModuleError {
index: 1,
error: [0; 4],
@@ -400,7 +398,7 @@ fn check_modules_error_type() {
})),
);
assert_eq!(
Module1_7::fail(system::Origin::<Runtime>::Root.into()),
Module1_7::fail(frame_system::Origin::<Runtime>::Root.into()),
Err(DispatchError::Module(ModuleError {
index: 2,
error: [0; 4],
@@ -408,7 +406,7 @@ fn check_modules_error_type() {
})),
);
assert_eq!(
Module1_8::fail(system::Origin::<Runtime>::Root.into()),
Module1_8::fail(frame_system::Origin::<Runtime>::Root.into()),
Err(DispatchError::Module(ModuleError {
index: 12,
error: [0; 4],
@@ -416,7 +414,7 @@ fn check_modules_error_type() {
})),
);
assert_eq!(
Module1_9::fail(system::Origin::<Runtime>::Root.into()),
Module1_9::fail(frame_system::Origin::<Runtime>::Root.into()),
Err(DispatchError::Module(ModuleError {
index: 13,
error: [0; 4],
@@ -436,7 +434,7 @@ fn integrity_test_works() {
fn origin_codec() {
use codec::Encode;
let origin = OriginCaller::system(system::RawOrigin::None);
let origin = OriginCaller::system(frame_system::RawOrigin::None);
assert_eq!(origin.encode()[0], 30);
let origin = OriginCaller::Module1_1(module1::Origin(Default::default()));
@@ -471,7 +469,8 @@ fn origin_codec() {
fn event_codec() {
use codec::Encode;
let event = system::Event::<Runtime>::ExtrinsicSuccess;
let event =
frame_system::Event::<Runtime>::ExtrinsicSuccess { dispatch_info: Default::default() };
assert_eq!(RuntimeEvent::from(event).encode()[0], 30);
let event = module1::Event::<Runtime, module1::Instance1>::A(test_pub());
@@ -508,7 +507,7 @@ fn event_codec() {
#[test]
fn call_codec() {
use codec::Encode;
assert_eq!(RuntimeCall::System(system::Call::noop {}).encode()[0], 30);
assert_eq!(RuntimeCall::System(frame_system::Call::remark { remark: vec![1] }).encode()[0], 30);
assert_eq!(RuntimeCall::Module1_1(module1::Call::fail {}).encode()[0], 31);
assert_eq!(RuntimeCall::Module2(module2::Call::fail {}).encode()[0], 32);
assert_eq!(RuntimeCall::Module1_2(module1::Call::fail {}).encode()[0], 33);
@@ -639,15 +638,67 @@ fn call_subtype_conversion() {
fn test_metadata() {
use frame_support::metadata::{v14::*, *};
use scale_info::meta_type;
use sp_core::Encode;
fn maybe_docs(doc: Vec<&'static str>) -> Vec<&'static str> {
if cfg!(feature = "no-metadata-docs") {
vec![]
} else {
doc
}
}
let pallets = vec![
PalletMetadata {
name: "System",
storage: None,
calls: Some(meta_type::<system::Call<Runtime>>().into()),
event: Some(meta_type::<system::Event<Runtime>>().into()),
constants: vec![],
error: Some(meta_type::<system::Error<Runtime>>().into()),
calls: Some(meta_type::<frame_system::Call<Runtime>>().into()),
event: Some(meta_type::<frame_system::Event<Runtime>>().into()),
constants: vec![
PalletConstantMetadata {
name: "BlockWeights",
ty: meta_type::<BlockWeights>(),
value: BlockWeights::default().encode(),
docs: maybe_docs(vec![" Block & extrinsics weights: base values and limits."]),
},
PalletConstantMetadata {
name: "BlockLength",
ty: meta_type::<BlockLength>(),
value: BlockLength::default().encode(),
docs: maybe_docs(vec![" The maximum length of a block (in bytes)."]),
},
PalletConstantMetadata {
name: "BlockHashCount",
ty: meta_type::<u64>(),
value: 10u64.encode(),
docs: maybe_docs(vec![" Maximum number of block number to block hash mappings to keep (oldest pruned first)."]),
},
PalletConstantMetadata {
name: "DbWeight",
ty: meta_type::<RuntimeDbWeight>(),
value: RuntimeDbWeight::default().encode(),
docs: maybe_docs(vec![" The weight of runtime database operations the runtime can invoke.",]),
},
PalletConstantMetadata {
name: "Version",
ty: meta_type::<RuntimeVersion>(),
value: RuntimeVersion::default().encode(),
docs: maybe_docs(vec![ " Get the chain's current version."]),
},
PalletConstantMetadata {
name: "SS58Prefix",
ty: meta_type::<u16>(),
value: 0u16.encode(),
docs: maybe_docs(vec![
" The designated SS58 prefix of this chain.",
"",
" This replaces the \"ss58Format\" property declared in the chain spec. Reason is",
" that the runtime should know about the prefix in order to make use of it as",
" an identifier of the chain.",
]),
},
],
error: Some(meta_type::<frame_system::Error<Runtime>>().into()),
index: 30,
},
PalletMetadata {
@@ -781,7 +832,7 @@ fn test_metadata() {
fn pallet_in_runtime_is_correct() {
assert_eq!(PalletInfo::index::<System>().unwrap(), 30);
assert_eq!(PalletInfo::name::<System>().unwrap(), "System");
assert_eq!(PalletInfo::module_name::<System>().unwrap(), "system");
assert_eq!(PalletInfo::module_name::<System>().unwrap(), "frame_system");
assert!(PalletInfo::crate_version::<System>().is_some());
assert_eq!(PalletInfo::index::<Module1_1>().unwrap(), 31);