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 11 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
6 changes: 2 additions & 4 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 Down Expand Up @@ -279,10 +281,6 @@ 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,
{
System: frame_system,
Timestamp: pallet_timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ use crate::construct_runtime::Pallet;
use proc_macro2::TokenStream;
use quote::quote;
use std::str::FromStr;
use syn::{Ident, TypePath};
use syn::Ident;

pub fn expand_outer_inherent(
runtime: &Ident,
block: &TypePath,
unchecked_extrinsic: &TypePath,
block: &TokenStream,
unchecked_extrinsic: &TokenStream,
pallet_decls: &[Pallet],
scrate: &TokenStream,
) -> TokenStream {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ use crate::construct_runtime::Pallet;
use proc_macro2::TokenStream;
use quote::quote;
use std::str::FromStr;
use syn::{Ident, TypePath};
use syn::Ident;

pub fn expand_runtime_metadata(
runtime: &Ident,
pallet_declarations: &[Pallet],
scrate: &TokenStream,
extrinsic: &TypePath,
extrinsic: &TokenStream,
) -> TokenStream {
let pallets = pallet_declarations
.iter()
Expand Down
25 changes: 20 additions & 5 deletions frame/support/procedural/src/construct_runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ use frame_support_procedural_tools::{
use itertools::Itertools;
use parse::{
ExplicitRuntimeDeclaration, ImplicitRuntimeDeclaration, Pallet, RuntimeDeclaration,
WhereSection,
};
use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
Expand Down Expand Up @@ -224,9 +223,9 @@ fn construct_runtime_final_expansion(
) -> Result<TokenStream2> {
let ExplicitRuntimeDeclaration {
name,
where_section: WhereSection { block, node_block, unchecked_extrinsic },
pallets,
pallets_token,
where_section,
} = definition;

let system_pallet =
Expand Down Expand Up @@ -264,6 +263,10 @@ fn construct_runtime_final_expansion(
let scrate = generate_crate_access(hidden_crate_name, "frame-support");
let scrate_decl = generate_hidden_includes(hidden_crate_name, "frame-support");

let frame_system = generate_crate_access_2018("frame-system")?;
let block = quote!(<#name as #frame_system::Config>::Block);
let unchecked_extrinsic = quote!(<#block as #scrate::sp_runtime::traits::Block>::Extrinsic);

let outer_event = expand::expand_outer_event(&name, &pallets, &scrate)?;

let outer_origin = expand::expand_outer_origin(&name, system_pallet, &pallets, &scrate)?;
Expand All @@ -283,7 +286,22 @@ fn construct_runtime_final_expansion(
let integrity_test = decl_integrity_test(&scrate);
let static_assertions = decl_static_assertions(&name, &pallets, &scrate);

let warning = if let Some(where_section) = where_section {
Some(proc_macro_warning::Warning::new_deprecated("WhereSection")
.old("use where section")
.new("use `frame_system::Config` to set the `Block` type and remove this section")
.help_links(&[
"https://github.com/paritytech/substrate/pull/14193"
])
.span(where_section.span)
.build())
} else {
None
};

let res = quote!(
#warning

#scrate_decl

// Prevent UncheckedExtrinsic to print unused warning.
Expand All @@ -297,9 +315,6 @@ fn construct_runtime_final_expansion(
#scrate::scale_info::TypeInfo
)]
pub struct #name;
impl #scrate::sp_runtime::traits::GetNodeBlockType for #name {
type NodeBlock = #node_block;
}
impl #scrate::sp_runtime::traits::GetRuntimeBlockType for #name {
type RuntimeBlock = #block;
}
Expand Down
14 changes: 10 additions & 4 deletions frame/support/procedural/src/construct_runtime/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ pub enum RuntimeDeclaration {
#[derive(Debug)]
pub struct ImplicitRuntimeDeclaration {
pub name: Ident,
pub where_section: WhereSection,
pub where_section: Option<WhereSection>,
pub pallets: Vec<PalletDeclaration>,
}

/// Declaration of a runtime with all pallet having explicit declaration of parts.
#[derive(Debug)]
pub struct ExplicitRuntimeDeclaration {
pub name: Ident,
pub where_section: WhereSection,
pub where_section: Option<WhereSection>,
pub pallets: Vec<Pallet>,
pub pallets_token: token::Brace,
}
Expand All @@ -87,7 +87,11 @@ impl Parse for RuntimeDeclaration {
}

let name = input.parse::<syn::Ident>()?;
let where_section = input.parse()?;
let where_section = if input.peek(token::Where) {
Some(input.parse()?)
} else {
None
};
let pallets =
input.parse::<ext::Braces<ext::Punctuated<PalletDeclaration, Token![,]>>>()?;
let pallets_token = pallets.token;
Expand All @@ -112,6 +116,7 @@ impl Parse for RuntimeDeclaration {

#[derive(Debug)]
pub struct WhereSection {
pub span: Span,
pub block: syn::TypePath,
pub node_block: syn::TypePath,
pub unchecked_extrinsic: syn::TypePath,
Expand All @@ -120,6 +125,7 @@ pub struct WhereSection {
impl Parse for WhereSection {
fn parse(input: ParseStream) -> Result<Self> {
input.parse::<token::Where>()?;

let mut definitions = Vec::new();
while !input.peek(token::Brace) {
let definition: WhereDefinition = input.parse()?;
Expand All @@ -143,7 +149,7 @@ impl Parse for WhereSection {
);
return Err(Error::new(*kind_span, msg))
}
Ok(Self { block, node_block, unchecked_extrinsic })
Ok(Self { span: input.span(), block, node_block, unchecked_extrinsic })
}
}

Expand Down
40 changes: 20 additions & 20 deletions frame/support/procedural/src/pallet/expand/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream {
let frame_system = &def.frame_system;
quote::quote! {
impl<#type_impl_gen>
#frame_support::traits::Hooks<<T as #frame_system::Config>::BlockNumber>
#frame_support::traits::Hooks<#frame_system::pallet_prelude::BlockNumberFor::<T>>
for #pallet_ident<#type_use_gen> #where_clause {}
}
} else {
Expand Down Expand Up @@ -137,50 +137,50 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream {
#hooks_impl

impl<#type_impl_gen>
#frame_support::traits::OnFinalize<<T as #frame_system::Config>::BlockNumber>
#frame_support::traits::OnFinalize<#frame_system::pallet_prelude::BlockNumberFor::<T>>
for #pallet_ident<#type_use_gen> #where_clause
{
fn on_finalize(n: <T as #frame_system::Config>::BlockNumber) {
fn on_finalize(n: #frame_system::pallet_prelude::BlockNumberFor::<T>) {
#frame_support::sp_tracing::enter_span!(
#frame_support::sp_tracing::trace_span!("on_finalize")
);
<
Self as #frame_support::traits::Hooks<
<T as #frame_system::Config>::BlockNumber
#frame_system::pallet_prelude::BlockNumberFor::<T>
>
>::on_finalize(n)
}
}

impl<#type_impl_gen>
#frame_support::traits::OnIdle<<T as #frame_system::Config>::BlockNumber>
#frame_support::traits::OnIdle<#frame_system::pallet_prelude::BlockNumberFor::<T>>
for #pallet_ident<#type_use_gen> #where_clause
{
fn on_idle(
n: <T as #frame_system::Config>::BlockNumber,
n: #frame_system::pallet_prelude::BlockNumberFor::<T>,
remaining_weight: #frame_support::weights::Weight
) -> #frame_support::weights::Weight {
<
Self as #frame_support::traits::Hooks<
<T as #frame_system::Config>::BlockNumber
#frame_system::pallet_prelude::BlockNumberFor::<T>
>
>::on_idle(n, remaining_weight)
}
}

impl<#type_impl_gen>
#frame_support::traits::OnInitialize<<T as #frame_system::Config>::BlockNumber>
#frame_support::traits::OnInitialize<#frame_system::pallet_prelude::BlockNumberFor::<T>>
for #pallet_ident<#type_use_gen> #where_clause
{
fn on_initialize(
n: <T as #frame_system::Config>::BlockNumber
n: #frame_system::pallet_prelude::BlockNumberFor::<T>
) -> #frame_support::weights::Weight {
#frame_support::sp_tracing::enter_span!(
#frame_support::sp_tracing::trace_span!("on_initialize")
);
<
Self as #frame_support::traits::Hooks<
<T as #frame_system::Config>::BlockNumber
#frame_system::pallet_prelude::BlockNumberFor::<T>
>
>::on_initialize(n)
}
Expand All @@ -205,7 +205,7 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream {

<
Self as #frame_support::traits::Hooks<
<T as #frame_system::Config>::BlockNumber
#frame_system::pallet_prelude::BlockNumberFor::<T>
>
>::on_runtime_upgrade()
}
Expand All @@ -215,7 +215,7 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream {
<
Self
as
#frame_support::traits::Hooks<<T as #frame_system::Config>::BlockNumber>
#frame_support::traits::Hooks<#frame_system::pallet_prelude::BlockNumberFor::<T>>
>::pre_upgrade()
}

Expand All @@ -226,19 +226,19 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream {
<
Self
as
#frame_support::traits::Hooks<<T as #frame_system::Config>::BlockNumber>
#frame_support::traits::Hooks<#frame_system::pallet_prelude::BlockNumberFor::<T>>
>::post_upgrade(state)
}
}

impl<#type_impl_gen>
#frame_support::traits::OffchainWorker<<T as #frame_system::Config>::BlockNumber>
#frame_support::traits::OffchainWorker<#frame_system::pallet_prelude::BlockNumberFor::<T>>
for #pallet_ident<#type_use_gen> #where_clause
{
fn offchain_worker(n: <T as #frame_system::Config>::BlockNumber) {
fn offchain_worker(n: #frame_system::pallet_prelude::BlockNumberFor::<T>) {
<
Self as #frame_support::traits::Hooks<
<T as #frame_system::Config>::BlockNumber
#frame_system::pallet_prelude::BlockNumberFor::<T>
>
>::offchain_worker(n)
}
Expand All @@ -253,7 +253,7 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream {
fn integrity_test() {
<
Self as #frame_support::traits::Hooks<
<T as #frame_system::Config>::BlockNumber
#frame_system::pallet_prelude::BlockNumberFor::<T>
>
>::integrity_test()
}
Expand All @@ -262,17 +262,17 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream {

#[cfg(feature = "try-runtime")]
impl<#type_impl_gen>
#frame_support::traits::TryState<<T as #frame_system::Config>::BlockNumber>
#frame_support::traits::TryState<#frame_system::pallet_prelude::BlockNumberFor::<T>>
for #pallet_ident<#type_use_gen> #where_clause
{
fn try_state(
n: <T as #frame_system::Config>::BlockNumber,
n: #frame_system::pallet_prelude::BlockNumberFor::<T>,
_s: #frame_support::traits::TryStateSelect
) -> Result<(), #frame_support::sp_runtime::TryRuntimeError> {
#log_try_state
<
Self as #frame_support::traits::Hooks<
<T as #frame_system::Config>::BlockNumber
#frame_system::pallet_prelude::BlockNumberFor::<T>
>
>::try_state(n)
}
Expand Down
4 changes: 2 additions & 2 deletions frame/system/src/extensions/check_genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::{Config, Pallet};
use crate::{Config, Pallet, pallet_prelude::BlockNumberFor};
use codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_runtime::{
Expand Down Expand Up @@ -60,7 +60,7 @@ impl<T: Config + Send + Sync> SignedExtension for CheckGenesis<T> {
const IDENTIFIER: &'static str = "CheckGenesis";

fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
Ok(<Pallet<T>>::block_hash(T::BlockNumber::zero()))
Ok(<Pallet<T>>::block_hash(BlockNumberFor::<T>::zero()))
}

fn pre_dispatch(
Expand Down
4 changes: 2 additions & 2 deletions frame/system/src/extensions/check_mortality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::{BlockHash, Config, Pallet};
use crate::{BlockHash, Config, Pallet, pallet_prelude::BlockNumberFor};
use codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_runtime::{
Expand Down Expand Up @@ -78,7 +78,7 @@ impl<T: Config + Send + Sync> SignedExtension for CheckMortality<T> {

fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
let current_u64 = <Pallet<T>>::block_number().saturated_into::<u64>();
let n = self.0.birth(current_u64).saturated_into::<T::BlockNumber>();
let n = self.0.birth(current_u64).saturated_into::<BlockNumberFor<T>>();
if !<BlockHash<T>>::contains_key(n) {
Err(InvalidTransaction::AncientBirthBlock.into())
} else {
Expand Down
Loading