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.7k
Root origin always bypass all filter, other origin cannot bypass BaseCallFilter even when constructed from Root origin #9948
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
066c07d
improve root filter bypass
thiolliere 455a90a
improve doc
thiolliere 9766a10
fmt
thiolliere 1411f7b
refactor test for more understandable flow
thiolliere f9ed7b8
Update frame/support/procedural/src/construct_runtime/expand/origin.rs
thiolliere 84a9ac0
match
thiolliere 45336a1
Merge remote-tracking branch 'origin/master' into gui-improve-root-fi…
thiolliere 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -82,8 +82,9 @@ pub fn expand_outer_origin( | |||||
Ok(quote! { | ||||||
#( #query_origin_part_macros )* | ||||||
|
||||||
// WARNING: All instance must hold the filter `frame_system::Config::BaseCallFilter`, except | ||||||
// when caller is system Root. One can use `OriginTrait::reset_filter` to do so. | ||||||
/// The runtime origin type represanting the origin of a call. | ||||||
/// | ||||||
/// Origin is always created with the base filter configured in `frame_system::Config::BaseCallFilter`. | ||||||
#[derive(Clone)] | ||||||
pub struct Origin { | ||||||
caller: OriginCaller, | ||||||
|
@@ -140,7 +141,9 @@ pub fn expand_outer_origin( | |||||
} | ||||||
|
||||||
fn filter_call(&self, call: &Self::Call) -> bool { | ||||||
(self.filter)(call) | ||||||
// Root bypass all filters | ||||||
thiolliere marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
matches!(self.caller, OriginCaller::system(#system_path::Origin::<#runtime>::Root)) | ||||||
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.
Suggested change
Or use an absolute path to 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. indeed, done in 84a9ac0 |
||||||
|| (self.filter)(call) | ||||||
} | ||||||
|
||||||
fn caller(&self) -> &Self::PalletsOrigin { | ||||||
|
@@ -157,15 +160,14 @@ pub fn expand_outer_origin( | |||||
} | ||||||
} | ||||||
|
||||||
/// Create with system none origin and `frame-system::Config::BaseCallFilter`. | ||||||
fn none() -> Self { | ||||||
#system_path::RawOrigin::None.into() | ||||||
} | ||||||
/// Create with system root origin and no filter. | ||||||
|
||||||
fn root() -> Self { | ||||||
#system_path::RawOrigin::Root.into() | ||||||
} | ||||||
/// Create with system signed origin and `frame-system::Config::BaseCallFilter`. | ||||||
|
||||||
fn signed(by: <#runtime as #system_path::Config>::AccountId) -> Self { | ||||||
#system_path::RawOrigin::Signed(by).into() | ||||||
} | ||||||
|
@@ -191,7 +193,7 @@ pub fn expand_outer_origin( | |||||
pub fn none() -> Self { | ||||||
<Origin as #scrate::traits::OriginTrait>::none() | ||||||
} | ||||||
/// Create with system root origin and no filter. | ||||||
/// Create with system root origin and `frame-system::Config::BaseCallFilter`. | ||||||
pub fn root() -> Self { | ||||||
<Origin as #scrate::traits::OriginTrait>::root() | ||||||
} | ||||||
|
@@ -221,9 +223,7 @@ pub fn expand_outer_origin( | |||||
} | ||||||
|
||||||
impl From<#system_path::Origin<#runtime>> for Origin { | ||||||
/// Convert to runtime origin: | ||||||
/// * root origin is built with no filter | ||||||
/// * others use `frame-system::Config::BaseCallFilter` | ||||||
/// Convert to runtime origin, using as filter: `frame-system::Config::BaseCallFilter`. | ||||||
fn from(x: #system_path::Origin<#runtime>) -> Self { | ||||||
let o: OriginCaller = x.into(); | ||||||
o.into() | ||||||
|
@@ -237,10 +237,7 @@ pub fn expand_outer_origin( | |||||
filter: #scrate::sp_std::rc::Rc::new(Box::new(|_| true)), | ||||||
}; | ||||||
|
||||||
// Root has no filter | ||||||
if !matches!(o.caller, OriginCaller::system(#system_path::Origin::<#runtime>::Root)) { | ||||||
#scrate::traits::OriginTrait::reset_filter(&mut o); | ||||||
} | ||||||
#scrate::traits::OriginTrait::reset_filter(&mut o); | ||||||
|
||||||
o | ||||||
} | ||||||
|
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
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.
Using proper intra doc links here would be nice.
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.
I'll do in a follow up when I get more time #9962