mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 12:48:00 +00:00
Root origin always bypass all filter, other origin cannot bypass BaseCallFilter even when constructed from Root origin (#9948)
* improve root filter bypass * improve doc * fmt * refactor test for more understandable flow * Update frame/support/procedural/src/construct_runtime/expand/origin.rs Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> * match Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
committed by
GitHub
parent
cec88b7144
commit
e81a425241
@@ -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,11 @@ pub fn expand_outer_origin(
|
||||
}
|
||||
|
||||
fn filter_call(&self, call: &Self::Call) -> bool {
|
||||
(self.filter)(call)
|
||||
match self.caller {
|
||||
// Root bypasses all filters
|
||||
OriginCaller::system(#system_path::Origin::<#runtime>::Root) => true,
|
||||
_ => (self.filter)(call),
|
||||
}
|
||||
}
|
||||
|
||||
fn caller(&self) -> &Self::PalletsOrigin {
|
||||
@@ -157,15 +162,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 +195,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 +225,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 +239,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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user