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

Moves Block, NodeBlock and UncheckedExtrinsic to frame_system, instead of construct_runtime #14193

Closed
wants to merge 74 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
74 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
989d2fc
Hopefully this fixes
gupnik Jun 10, 2023
ad7a25c
Fixes pallet-timestamp
gupnik Jun 11, 2023
c71aa74
Fixes node-template runtime
gupnik Jun 11, 2023
268e71f
Fixes node runtime
gupnik Jun 11, 2023
1616670
Fixes node-template
gupnik Jun 11, 2023
7bd6da7
Fixes cargo check
gupnik Jun 12, 2023
559e0e4
More fixes
gupnik Jun 12, 2023
c96d9bc
More fixes
gupnik Jun 13, 2023
0a19f0d
More fixes
gupnik Jun 13, 2023
6cb0ab9
".git/.scripts/commands/fmt/fmt.sh"
Jun 13, 2023
4ce055c
More fixes
gupnik Jun 13, 2023
9ab1b37
Removes unused import
gupnik Jun 13, 2023
54aebda
Fixes warnings
gupnik Jun 13, 2023
375bc0f
Fixes warnings
gupnik Jun 13, 2023
ee2eb17
Fixes warnings
gupnik Jun 13, 2023
9a9d41d
Fixes warnings
gupnik Jun 13, 2023
23bfc19
Fixes warnings
gupnik Jun 13, 2023
e63d231
Fixes warnings
gupnik Jun 13, 2023
3b50fe4
Fixes warnings
gupnik Jun 13, 2023
709d6a6
Fixes warnings
gupnik Jun 13, 2023
63decd8
Fixes tests
gupnik Jun 14, 2023
f66589a
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 14, 2023
b60fb81
".git/.scripts/commands/fmt/fmt.sh"
Jun 14, 2023
e5dafb9
Fixes tests
gupnik Jun 14, 2023
21abefc
Fixes doc link
gupnik Jun 14, 2023
8e2607a
Fixes warnings
gupnik Jun 14, 2023
2e4a3d2
Fixes warnings
gupnik Jun 14, 2023
b197dd0
Fixes warnings
gupnik Jun 14, 2023
dbf809e
Fixes warnings
gupnik Jun 14, 2023
922deb8
Fixes doc link and warnings
gupnik Jun 14, 2023
3377b38
Fixes tests
gupnik Jun 14, 2023
688922e
Minor update
gupnik Jun 14, 2023
dc3bf2c
Fixes tests
gupnik Jun 14, 2023
ccc76a2
Fixes impl_runtime_api
gupnik Jun 14, 2023
e0b1b14
Minor update
gupnik Jun 14, 2023
7eff183
Removes unused import
gupnik Jun 14, 2023
d39a6f2
Removes unused import
gupnik Jun 14, 2023
13db70d
Fixes tests
gupnik Jun 14, 2023
b8ded7f
Addresses review comments
gupnik Jun 18, 2023
f7a5450
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 18, 2023
7f82fe4
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 19, 2023
dbf3db3
Updates pallet-society
gupnik Jun 19, 2023
67a56fb
Updates pallet-society
gupnik Jun 19, 2023
6f40dda
Removes use_attr
gupnik Jun 19, 2023
701acd8
Fixes try-runtime-cli
gupnik Jun 19, 2023
f859b13
".git/.scripts/commands/fmt/fmt.sh"
Jun 19, 2023
204a1bc
Fixes unused import in ui tests
gupnik Jun 19, 2023
05b8873
Fixes sp-api tests
gupnik Jun 19, 2023
bf4b6aa
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 19, 2023
c9576f3
Fixes build
gupnik Jun 19, 2023
6f706bd
Uses u32 in mock block
gupnik Jun 20, 2023
60bd4c6
Uses u32 in mock block
gupnik Jun 20, 2023
dc946ad
Fixes type
gupnik Jun 20, 2023
f5f00d9
Revert "Fixes type"
gupnik Jun 20, 2023
cadd1e4
Revert "Uses u32 in mock block"
gupnik Jun 20, 2023
0040c20
Revert "Uses u32 in mock block"
gupnik Jun 20, 2023
88a92b6
Adds u32 block type
gupnik Jun 20, 2023
24e9580
Fixes doc tests
gupnik Jun 20, 2023
a2ecd52
".git/.scripts/commands/fmt/fmt.sh"
Jun 20, 2023
37d6cf4
Revert "Fixes doc tests"
gupnik Jun 20, 2023
6d18500
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 20, 2023
8461e97
Removes doc for decl_* to make CI happy
gupnik Jun 20, 2023
1c45275
Fixes sp-api doc
gupnik Jun 20, 2023
9296a79
Fixes rpc-support doc
gupnik Jun 20, 2023
86b6824
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 20, 2023
c537e8f
".git/.scripts/commands/fmt/fmt.sh"
Jun 21, 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 @@ -154,6 +154,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 @@ -277,10 +279,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
9 changes: 4 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 @@ -216,7 +215,6 @@ fn construct_runtime_final_expansion(
) -> Result<TokenStream2> {
let ExplicitRuntimeDeclaration {
name,
where_section: WhereSection { block, node_block, unchecked_extrinsic },
pallets,
pallets_token,
} = definition;
Expand Down Expand Up @@ -256,6 +254,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 Down Expand Up @@ -289,9 +291,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
98 changes: 1 addition & 97 deletions frame/support/procedural/src/construct_runtime/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// limitations under the License.

use frame_support_procedural_tools::syn_ext as ext;
use proc_macro2::{Span, TokenStream};
use proc_macro2::TokenStream;
use quote::ToTokens;
use std::collections::{HashMap, HashSet};
use syn::{
Expand Down Expand Up @@ -62,15 +62,13 @@ pub enum RuntimeDeclaration {
#[derive(Debug)]
pub struct ImplicitRuntimeDeclaration {
pub name: Ident,
pub where_section: 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 pallets: Vec<Pallet>,
pub pallets_token: token::Brace,
}
Expand All @@ -87,7 +85,6 @@ impl Parse for RuntimeDeclaration {
}

let name = input.parse::<syn::Ident>()?;
let where_section = input.parse()?;
let pallets =
input.parse::<ext::Braces<ext::Punctuated<PalletDeclaration, Token![,]>>>()?;
let pallets_token = pallets.token;
Expand All @@ -96,95 +93,18 @@ impl Parse for RuntimeDeclaration {
PalletsConversion::Implicit(pallets) =>
Ok(RuntimeDeclaration::Implicit(ImplicitRuntimeDeclaration {
name,
where_section,
pallets,
})),
PalletsConversion::Explicit(pallets) =>
Ok(RuntimeDeclaration::Explicit(ExplicitRuntimeDeclaration {
name,
where_section,
pallets,
pallets_token,
})),
}
}
}

#[derive(Debug)]
pub struct WhereSection {
pub block: syn::TypePath,
pub node_block: syn::TypePath,
pub unchecked_extrinsic: syn::TypePath,
}

impl Parse for WhereSection {
gupnik marked this conversation as resolved.
Show resolved Hide resolved
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()?;
definitions.push(definition);
if !input.peek(Token![,]) {
if !input.peek(token::Brace) {
return Err(input.error("Expected `,` or `{`"))
}
break
}
input.parse::<Token![,]>()?;
}
let block = remove_kind(input, WhereKind::Block, &mut definitions)?.value;
let node_block = remove_kind(input, WhereKind::NodeBlock, &mut definitions)?.value;
let unchecked_extrinsic =
remove_kind(input, WhereKind::UncheckedExtrinsic, &mut definitions)?.value;
if let Some(WhereDefinition { ref kind_span, ref kind, .. }) = definitions.first() {
let msg = format!(
"`{:?}` was declared above. Please use exactly one declaration for `{:?}`.",
kind, kind
);
return Err(Error::new(*kind_span, msg))
}
Ok(Self { block, node_block, unchecked_extrinsic })
}
}

#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
pub enum WhereKind {
Block,
NodeBlock,
UncheckedExtrinsic,
}

#[derive(Debug)]
pub struct WhereDefinition {
pub kind_span: Span,
pub kind: WhereKind,
pub value: syn::TypePath,
}

impl Parse for WhereDefinition {
fn parse(input: ParseStream) -> Result<Self> {
let lookahead = input.lookahead1();
let (kind_span, kind) = if lookahead.peek(keyword::Block) {
(input.parse::<keyword::Block>()?.span(), WhereKind::Block)
} else if lookahead.peek(keyword::NodeBlock) {
(input.parse::<keyword::NodeBlock>()?.span(), WhereKind::NodeBlock)
} else if lookahead.peek(keyword::UncheckedExtrinsic) {
(input.parse::<keyword::UncheckedExtrinsic>()?.span(), WhereKind::UncheckedExtrinsic)
} else {
return Err(lookahead.error())
};

Ok(Self {
kind_span,
kind,
value: {
let _: Token![=] = input.parse()?;
input.parse()?
},
})
}
}

/// The declaration of a pallet.
#[derive(Debug, Clone)]
pub struct PalletDeclaration {
Expand Down Expand Up @@ -502,22 +422,6 @@ impl PalletPart {
}
}

fn remove_kind(
input: ParseStream,
kind: WhereKind,
definitions: &mut Vec<WhereDefinition>,
) -> Result<WhereDefinition> {
if let Some(pos) = definitions.iter().position(|d| d.kind == kind) {
Ok(definitions.remove(pos))
} else {
let msg = format!(
"Missing associated type for `{:?}`. Add `{:?}` = ... to where section.",
kind, kind
);
Err(input.error(msg))
}
}

/// The declaration of a part without its generics
#[derive(Debug, Clone)]
pub struct PalletPartNoGeneric {
Expand Down
5 changes: 5 additions & 0 deletions frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ pub mod pallet {
type Index = u32;
type BlockNumber = u32;
type Header = sp_runtime::generic::Header<Self::BlockNumber, Self::Hashing>;
type Block = sp_runtime::generic::Block<Self::Header, sp_runtime::OpaqueExtrinsic>;
type Hash = sp_core::hash::H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = u64;
Expand Down Expand Up @@ -340,6 +341,10 @@ pub mod pallet {
/// The block header.
type Header: Parameter + traits::Header<Number = Self::BlockNumber, Hash = Self::Hash>;
gupnik marked this conversation as resolved.
Show resolved Hide resolved

/// The Block type used by the runtime. This is used by `construct_runtime` to retrieve the
/// extrinsics or other block specific data as needed.
type Block: Parameter + traits::Block<Header = Self::Header, Hash = Self::Hash>;

/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
#[pallet::constant]
type BlockHashCount: Get<Self::BlockNumber>;
Expand Down