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
Emit error when construct_runtime imports a non-existent pallet part #8949
Merged
Merged
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
052ccf2
Emit error when construct_runtime imports a non-existent Call part
KiChjang 8aec97b
Reword and display pallet name when emitting part not found error
KiChjang daaed4a
Merge remote-tracking branch 'origin/master' into kckyeung/pallet-par…
KiChjang d40b71e
Migrate decl_outer_dispatch to a proc macro
KiChjang f4d5fcf
Rename calls.rs to call.rs
KiChjang f4c6afe
Create new construct_runtime_v2 macro
KiChjang 77fa5e8
Add UI test for importing non-existent call part in construct_runtime
KiChjang 7d29261
Emit error when construct_runtime imports a non-existent Config part
KiChjang 665f4b4
Emit error when construct_runtime imports a non-existent Event part
KiChjang 7097ec0
Migrate decl_outer_inherent to a proc macro
KiChjang c22fa21
Emit error when construct_runtime imports a non-existent Inherent part
KiChjang a2790ef
Migrate decl_outer_validate_unsigned to a proc macro
KiChjang 090dd14
Emit error when construct_runtime imports a non-existent ValidateUnsi…
KiChjang c1690d8
impl for old macro
gui1117 a5eeecc
fix line width
gui1117 57b4a5d
add doc
gui1117 d452eec
hide macroes and use unique counter everywhere
gui1117 4403724
Merge remote-tracking branch 'origin/master' into kckyeung/pallet-par…
KiChjang db15388
Remove construct_runtime_v2
KiChjang 852bdf5
Encapsulate pallet part check macros in a module
KiChjang 1012966
Fix macro definitions in dummy part checker
KiChjang d865fef
Tag ProvideInherent impl with #[pallet::inherent] properly for author…
KiChjang e291da7
Remove Call part from pallets that do not define it
KiChjang 3273e33
Add Call part unit tests
KiChjang a0ea5d5
Remove undefined Call part import from offences pallet
KiChjang a8aea68
Add tests for expand_outer_inherent
KiChjang c03c299
Remove Call part from pallets that do not define them
KiChjang 12343f9
Remove Call part imports from pallets that do not have it defined
KiChjang 3c41aef
Remove Call part import of the offences pallet from grandpa pallet mocks
KiChjang 143eccd
Update frame/support/test/tests/pallet.rs
KiChjang 4559a6c
Remove Call part imports for pallets that do not define them
KiChjang 517072c
Move inherent tests to inherent_expand
KiChjang 2602374
Add unit tests for expand_outer_validate_unsigned
KiChjang 1dfc27f
Merge remote-tracking branch 'origin/master' into kckyeung/pallet-par…
KiChjang b977dc7
Add newline at the end of file
KiChjang 8432e45
fix ui test
gui1117 26fefef
Small prayer to RNGsus for fixing CI
KiChjang 739f270
Merge remote-tracking branch 'origin/master' into kckyeung/pallet-par…
KiChjang 938fddb
Remove Call part from construct_runtime for randomness collective fli…
KiChjang 07507ad
Remove Call part import for randomness collective flip pallet
KiChjang e6ca013
Summon Laplace's demon instead of praying to RNGsus
KiChjang b05787b
Update test expectations
KiChjang 362b688
fix ui test and make sure it's flaky
TriplEight 5a3d244
Revert "fix ui test and make sure it's flaky"
TriplEight 3a06de2
Comment out test instead of putting it in conditional compilation
KiChjang 7789ac7
Update UI test expectations
KiChjang d4ad1c7
Update UI test expectations
KiChjang 7f1ee06
Emit error when construct_runtime imports a non-existent Origin part
KiChjang 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
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
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
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
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
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
145 changes: 145 additions & 0 deletions
145
frame/support/procedural/src/construct_runtime/expand/call.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,145 @@ | ||
// This file is part of Substrate. | ||
|
||
// Copyright (C) 2021 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::Pallet; | ||
use proc_macro2::TokenStream; | ||
use quote::quote; | ||
use syn::Ident; | ||
|
||
pub fn expand_outer_dispatch( | ||
runtime: &Ident, | ||
pallet_decls: &[Pallet], | ||
scrate: &TokenStream, | ||
) -> TokenStream { | ||
let mut variant_defs = TokenStream::new(); | ||
let mut variant_patterns = Vec::new(); | ||
let mut query_call_part_macros = Vec::new(); | ||
let mut pallet_names = Vec::new(); | ||
|
||
let pallets_with_call = pallet_decls | ||
.iter() | ||
.filter(|decl| decl.exists_part("Call")); | ||
|
||
for pallet_declaration in pallets_with_call { | ||
let name = &pallet_declaration.name; | ||
let path = &pallet_declaration.path; | ||
let index = pallet_declaration.index; | ||
|
||
variant_defs.extend(quote!(#[codec(index = #index)] #name( #scrate::dispatch::CallableCallFor<#name, #runtime> ),)); | ||
variant_patterns.push(quote!(Call::#name(call))); | ||
pallet_names.push(name); | ||
query_call_part_macros.push(quote! { | ||
#path::__substrate_call_check::is_call_part_defined!(#name); | ||
}); | ||
} | ||
|
||
quote! { | ||
#( #query_call_part_macros )* | ||
|
||
#[derive( | ||
Clone, PartialEq, Eq, | ||
#scrate::codec::Encode, | ||
#scrate::codec::Decode, | ||
#scrate::RuntimeDebug, | ||
)] | ||
pub enum Call { | ||
#variant_defs | ||
} | ||
impl #scrate::dispatch::GetDispatchInfo for Call { | ||
fn get_dispatch_info(&self) -> #scrate::dispatch::DispatchInfo { | ||
match self { | ||
#( #variant_patterns => call.get_dispatch_info(), )* | ||
} | ||
} | ||
} | ||
impl #scrate::dispatch::GetCallMetadata for Call { | ||
fn get_call_metadata(&self) -> #scrate::dispatch::CallMetadata { | ||
use #scrate::dispatch::GetCallName; | ||
match self { | ||
#( | ||
#variant_patterns => { | ||
let function_name = call.get_call_name(); | ||
let pallet_name = stringify!(#pallet_names); | ||
#scrate::dispatch::CallMetadata { function_name, pallet_name } | ||
} | ||
)* | ||
} | ||
} | ||
|
||
fn get_module_names() -> &'static [&'static str] { | ||
&[#( | ||
stringify!(#pallet_names), | ||
)*] | ||
} | ||
|
||
fn get_call_names(module: &str) -> &'static [&'static str] { | ||
use #scrate::dispatch::{Callable, GetCallName}; | ||
match module { | ||
#( | ||
stringify!(#pallet_names) => | ||
<<#pallet_names as Callable<#runtime>>::Call | ||
as GetCallName>::get_call_names(), | ||
)* | ||
_ => unreachable!(), | ||
} | ||
} | ||
} | ||
impl #scrate::dispatch::Dispatchable for Call { | ||
type Origin = Origin; | ||
type Config = Call; | ||
type Info = #scrate::weights::DispatchInfo; | ||
type PostInfo = #scrate::weights::PostDispatchInfo; | ||
fn dispatch(self, origin: Origin) -> #scrate::dispatch::DispatchResultWithPostInfo { | ||
if !<Self::Origin as #scrate::traits::OriginTrait>::filter_call(&origin, &self) { | ||
return #scrate::sp_std::result::Result::Err(#scrate::dispatch::DispatchError::BadOrigin.into()); | ||
} | ||
|
||
#scrate::traits::UnfilteredDispatchable::dispatch_bypass_filter(self, origin) | ||
} | ||
} | ||
impl #scrate::traits::UnfilteredDispatchable for Call { | ||
type Origin = Origin; | ||
fn dispatch_bypass_filter(self, origin: Origin) -> #scrate::dispatch::DispatchResultWithPostInfo { | ||
match self { | ||
#( | ||
#variant_patterns => | ||
#scrate::traits::UnfilteredDispatchable::dispatch_bypass_filter(call, origin), | ||
)* | ||
} | ||
} | ||
} | ||
|
||
#( | ||
impl #scrate::traits::IsSubType<#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> for Call { | ||
#[allow(unreachable_patterns)] | ||
fn is_sub_type(&self) -> Option<&#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> { | ||
match self { | ||
#variant_patterns => Some(call), | ||
// May be unreachable | ||
_ => None, | ||
shawntabrizi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
|
||
impl From<#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> for Call { | ||
fn from(call: #scrate::dispatch::CallableCallFor<#pallet_names, #runtime>) -> Self { | ||
#variant_patterns | ||
} | ||
} | ||
)* | ||
KiChjang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
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.
👍