From d864254b7aeb559dc5537b70b7cd00da9d86b846 Mon Sep 17 00:00:00 2001 From: Gavin Wood Date: Thu, 12 Sep 2019 16:47:03 +0200 Subject: [PATCH] Sudo can dispatch from an account (#3604) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Sudo can dispatch from an account. * Fix * Bump runtime. * Update srml/sudo/src/lib.rs Co-Authored-By: Bastian Köcher --- substrate/node/runtime/src/lib.rs | 4 ++-- substrate/srml/sudo/src/lib.rs | 38 +++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/substrate/node/runtime/src/lib.rs b/substrate/node/runtime/src/lib.rs index 0a30e09f5e..562dea598f 100644 --- a/substrate/node/runtime/src/lib.rs +++ b/substrate/node/runtime/src/lib.rs @@ -82,8 +82,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to equal spec_version. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 156, - impl_version: 158, + spec_version: 157, + impl_version: 157, apis: RUNTIME_API_VERSIONS, }; diff --git a/substrate/srml/sudo/src/lib.rs b/substrate/srml/sudo/src/lib.rs index 845f1e4104..7d80851719 100644 --- a/substrate/srml/sudo/src/lib.rs +++ b/substrate/srml/sudo/src/lib.rs @@ -113,9 +113,10 @@ decl_module! { /// # /// - O(1). /// - Limited storage reads. - /// - No DB writes. + /// - One DB write (event). + /// - Unknown weight of derivative `proposal` execution. /// # - #[weight = SimpleDispatchInfo::FixedOperational(1_000_000)] + #[weight = SimpleDispatchInfo::FreeOperational] fn sudo(origin, proposal: Box) { // This is a public call, so we ensure that the origin is some signed account. let sender = ensure_signed(origin)?; @@ -151,6 +152,37 @@ decl_module! { Self::deposit_event(RawEvent::KeyChanged(Self::key())); >::put(new); } + + /// Authenticates the sudo key and dispatches a function call with `Signed` origin from + /// a given account. + /// + /// The dispatch origin for this call must be _Signed_. + /// + /// # + /// - O(1). + /// - Limited storage reads. + /// - One DB write (event). + /// - Unknown weight of derivative `proposal` execution. + /// # + #[weight = SimpleDispatchInfo::FixedOperational(0)] + fn sudo_as(origin, who: ::Source, proposal: Box) { + // This is a public call, so we ensure that the origin is some signed account. + let sender = ensure_signed(origin)?; + ensure!(sender == Self::key(), "only the current sudo key can sudo"); + + let who = T::Lookup::lookup(who)?; + + let res = match proposal.dispatch(system::RawOrigin::Signed(who).into()) { + Ok(_) => true, + Err(e) => { + let e: DispatchError = e.into(); + runtime_io::print(e); + false + } + }; + + Self::deposit_event(RawEvent::SudoAsDone(res)); + } } } @@ -160,6 +192,8 @@ decl_event!( Sudid(bool), /// The sudoer just switched identity; the old key is supplied. KeyChanged(AccountId), + /// A sudo just took place. + SudoAsDone(bool), } );