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

Allow Sudo to do anything #6375

Merged
merged 2 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
12 changes: 6 additions & 6 deletions frame/sudo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@
#![cfg_attr(not(feature = "std"), no_std)]

use sp_std::prelude::*;
use sp_runtime::{DispatchResult, traits::{StaticLookup, Dispatchable}};
use sp_runtime::{DispatchResult, traits::StaticLookup};

use frame_support::{
Parameter, decl_module, decl_event, decl_storage, decl_error, ensure,
};
use frame_support::weights::{Weight, GetDispatchInfo};
use frame_support::{weights::{Weight, GetDispatchInfo}, traits::UnfilteredDispatchable};
use frame_system::{self as system, ensure_signed};

#[cfg(test)]
Expand All @@ -106,7 +106,7 @@ pub trait Trait: frame_system::Trait {
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;

/// A sudo-able call.
type Call: Parameter + Dispatchable<Origin=Self::Origin> + GetDispatchInfo;
type Call: Parameter + UnfilteredDispatchable<Origin=Self::Origin> + GetDispatchInfo;
}

decl_module! {
Expand All @@ -132,7 +132,7 @@ decl_module! {
let sender = ensure_signed(origin)?;
ensure!(sender == Self::key(), Error::<T>::RequireSudo);

let res = call.dispatch(frame_system::RawOrigin::Root.into());
let res = call.dispatch_bypass_filter(frame_system::RawOrigin::Root.into());
Self::deposit_event(RawEvent::Sudid(res.map(|_| ()).map_err(|e| e.error)));
}

Expand All @@ -152,7 +152,7 @@ decl_module! {
let sender = ensure_signed(origin)?;
ensure!(sender == Self::key(), Error::<T>::RequireSudo);

let res = call.dispatch(frame_system::RawOrigin::Root.into());
let res = call.dispatch_bypass_filter(frame_system::RawOrigin::Root.into());
Self::deposit_event(RawEvent::Sudid(res.map(|_| ()).map_err(|e| e.error)));
}

Expand Down Expand Up @@ -195,7 +195,7 @@ decl_module! {

let who = T::Lookup::lookup(who)?;

let res = match call.dispatch(frame_system::RawOrigin::Signed(who).into()) {
let res = match call.dispatch_bypass_filter(frame_system::RawOrigin::Signed(who).into()) {
Ok(_) => true,
Err(e) => {
sp_runtime::print(e);
Expand Down
18 changes: 13 additions & 5 deletions frame/sudo/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ use frame_support::{
};
use sp_core::H256;
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys.
// or public keys.
use sp_runtime::{Perbill, traits::{BlakeTwo256, IdentityLookup}, testing::Header};
use sp_io;
use crate as sudo;
use frame_support::traits::Filter;

// Logger module to track execution.
pub mod logger {
Expand Down Expand Up @@ -58,15 +59,15 @@ pub mod logger {

#[weight = *weight]
fn privileged_i32_log(origin, i: i32, weight: Weight){
// Ensure that the `origin` is `Root`.
// Ensure that the `origin` is `Root`.
ensure_root(origin)?;
<I32Log>::append(i);
Self::deposit_event(RawEvent::AppendI32(i, weight));
}

#[weight = *weight]
fn non_privileged_log(origin, i: i32, weight: Weight){
// Ensure that the `origin` is some signed account.
// Ensure that the `origin` is some signed account.
let sender = ensure_signed(origin)?;
<I32Log>::append(i);
<AccountLog<T>>::append(sender.clone());
Expand Down Expand Up @@ -112,16 +113,23 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}

pub struct BlockEverything;
impl Filter<Call> for BlockEverything {
fn filter(_: &Call) -> bool {
false
}
}

impl frame_system::Trait for Test {
type BaseCallFilter = ();
type BaseCallFilter = BlockEverything;
type Origin = Origin;
type Call = Call;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = TestEvent;
type BlockHashCount = BlockHashCount;
Expand Down