This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Abstract away the executive #14742
Draft
gupnik
wants to merge
12
commits into
master
Choose a base branch
from
gupnik/executive
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Abstract away the executive #14742
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
84c4e25
Abstracts away the executive
gupnik 3fc33ad
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik b1e5d3e
Abstracts away the executive in node and test-utils
gupnik 74ea0d8
Fixes tests
gupnik 6c76f2c
Handles custom runtime upgrade
gupnik 10eac86
Fixes try-runtime section
gupnik 2275555
Minor fix
gupnik d802240
Minor fix
gupnik 99adead
Minor fix
gupnik b3b0afe
Adds a UI Test
gupnik 2fbed47
Updates syntax
gupnik 747084d
Minor fix
gupnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
frame/support/procedural/src/construct_runtime/expand/executive.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// This file is part of Substrate. | ||
|
||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License | ||
|
||
use crate::construct_runtime::parse::ExecutiveSection; | ||
use frame_support_procedural_tools::generate_crate_access_2018; | ||
use proc_macro2::{Ident, TokenStream}; | ||
use quote::quote; | ||
use syn::Result; | ||
|
||
pub fn expand_executive( | ||
runtime: &Ident, | ||
system: &Ident, | ||
scrate: &TokenStream, | ||
block: &TokenStream, | ||
executive_section: ExecutiveSection, | ||
) -> Result<TokenStream> { | ||
let executive = generate_crate_access_2018("frame-executive")?; | ||
|
||
let on_runtime_upgrade = match executive_section.custom_on_runtime_upgrade { | ||
Some(custom) => quote!(#custom), | ||
None => quote!(()), | ||
}; | ||
|
||
let try_runtime_section = if let Ok(try_runtime) = | ||
generate_crate_access_2018("frame-try-runtime") | ||
{ | ||
quote! { | ||
#[cfg(feature = "try-runtime")] | ||
impl #runtime { | ||
fn api_impl_try_runtime_upgrade(checks: #try_runtime::UpgradeCheckSelect) -> Result<Weight, #scrate::sp_runtime::TryRuntimeError> { | ||
Executive::try_runtime_upgrade(checks) | ||
} | ||
|
||
fn api_impl_try_execute_block( | ||
block: #block, | ||
state_root_check: bool, | ||
signature_check: bool, | ||
select: #try_runtime::TryStateSelect | ||
) -> Result<Weight, &'static str> { | ||
Executive::try_execute_block(block, state_root_check, signature_check, select) | ||
} | ||
} | ||
} | ||
} else { | ||
quote!() | ||
}; | ||
|
||
let res = quote! { | ||
/// Executive: handles dispatch to the various modules. | ||
pub type Executive = #executive::Executive< | ||
#runtime, | ||
#block, | ||
#system::ChainContext<#runtime>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is kinda cheating, if you want to be pedantic. There's now no good way to configure this. But I am not sure if this is all that useful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I will add the support to provide a custom Executive as well, using the syntax you suggested above. |
||
#runtime, | ||
AllPalletsWithSystem, | ||
#on_runtime_upgrade | ||
>; | ||
|
||
impl #runtime { | ||
pub fn api_impl_core_execute_block(block: #block) { | ||
Executive::execute_block(block); | ||
} | ||
|
||
pub fn api_impl_core_initialize_block(header: &<#block as #scrate::sp_runtime::traits::Block>::Header) { | ||
Executive::initialize_block(header); | ||
} | ||
|
||
pub fn api_impl_builder_apply_extrinsic(extrinsic: <#block as #scrate::sp_runtime::traits::Block>::Extrinsic) -> #scrate::sp_runtime::ApplyExtrinsicResult { | ||
Executive::apply_extrinsic(extrinsic) | ||
} | ||
|
||
pub fn api_impl_builder_finalize_block() -> <#block as #scrate::sp_runtime::traits::Block>::Header { | ||
Executive::finalize_block() | ||
} | ||
|
||
pub fn api_impl_validate_transaction( | ||
source: #scrate::sp_runtime::transaction_validity::TransactionSource, | ||
tx: <Block as #scrate::sp_runtime::traits::Block>::Extrinsic, | ||
block_hash: <Block as #scrate::sp_runtime::traits::Block>::Hash, | ||
) -> #scrate::sp_runtime::transaction_validity::TransactionValidity { | ||
Executive::validate_transaction(source, tx, block_hash) | ||
} | ||
|
||
pub fn api_impl_offchain_worker(header: &<Block as #scrate::sp_runtime::traits::Block>::Header) { | ||
Executive::offchain_worker(header) | ||
} | ||
} | ||
|
||
#try_runtime_section | ||
}; | ||
|
||
Ok(res) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will play nicely with the new
frame
crate, it should re-export theframe-executive
.