difftreelog
fix scheduler config/dispatch_call
in: master
2 files changed
runtime/common/config/pallets/scheduler.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/scheduler.rs
+++ b/runtime/common/config/pallets/scheduler.rs
@@ -14,13 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use frame_support::{traits::EqualPrivilegeOnly, weights::Weight, parameter_types};
-use frame_system::EnsureSigned;
+use frame_support::{traits::{PrivilegeCmp, EnsureOrigin}, weights::Weight, parameter_types};
+use frame_system::{EnsureRoot, RawOrigin};
use sp_runtime::Perbill;
+use core::cmp::Ordering;
+use codec::Decode;
use crate::{
runtime_common::{scheduler::SchedulerPaymentExecutor, config::substrate::RuntimeBlockWeights},
Runtime, Call, Event, Origin, OriginCaller, Balances,
};
+use pallet_unique_scheduler::ScheduledEnsureOriginSuccess;
use up_common::types::AccountId;
parameter_types! {
@@ -32,6 +35,36 @@
pub const Preimage: Option<u32> = Some(10);
}
+pub struct EnsureSignedOrRoot<AccountId>(sp_std::marker::PhantomData<AccountId>);
+impl<O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>, AccountId: Decode>
+ EnsureOrigin<O> for EnsureSignedOrRoot<AccountId> {
+ type Success = ScheduledEnsureOriginSuccess<AccountId>;
+ fn try_origin(o: O) -> Result<Self::Success, O> {
+ o.into().and_then(|o| match o {
+ RawOrigin::Root => Ok(ScheduledEnsureOriginSuccess::Root),
+ RawOrigin::Signed(who) => Ok(ScheduledEnsureOriginSuccess::Signed(who)),
+ r => Err(O::from(r)),
+ })
+ }
+}
+
+pub struct EqualOrRootOnly;
+impl PrivilegeCmp<OriginCaller> for EqualOrRootOnly {
+ fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option<Ordering> {
+ use RawOrigin::*;
+
+ let left = left.clone().try_into().ok()?;
+ let right = right.clone().try_into().ok()?;
+
+ match (left, right) {
+ (Root, Root) => Some(Ordering::Equal),
+ (Root, _) => Some(Ordering::Greater),
+ (_, Root) => Some(Ordering::Less),
+ lr @ _ => (lr.0 == lr.1).then(|| Ordering::Equal)
+ }
+ }
+}
+
impl pallet_unique_scheduler::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
@@ -39,11 +72,12 @@
type PalletsOrigin = OriginCaller;
type RuntimeCall = RuntimeCall;
type MaximumWeight = MaximumSchedulerWeight;
- type ScheduleOrigin = EnsureSigned<AccountId>;
+ type ScheduleOrigin = EnsureSignedOrRoot<AccountId>;
+ type PrioritySetOrigin = EnsureRoot<AccountId>;
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type WeightInfo = ();
type CallExecutor = SchedulerPaymentExecutor;
- type OriginPrivilegeCmp = EqualPrivilegeOnly;
+ type OriginPrivilegeCmp = EqualOrRootOnly;
type PreimageProvider = ();
type NoPreimagePostponement = NoPreimagePostponement;
}
runtime/common/scheduler.rsdiffbeforeafterboth74 sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,74 sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,75{75{76 fn dispatch_call(76 fn dispatch_call(77 signer: <T as frame_system::Config>::AccountId,77 signer: Option<<T as frame_system::Config>::AccountId>,78 call: <T as pallet_unique_scheduler::Config>::Call,78 call: <T as pallet_unique_scheduler::Config>::Call,79 ) -> Result<79 ) -> Result<80 Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,80 Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,81 TransactionValidityError,81 TransactionValidityError,82 > {82 > {83 let dispatch_info = call.get_dispatch_info();83 let dispatch_info = call.get_dispatch_info();84 let len = call.encoded_size();84 let len = call.encoded_size();8585 let extrinsic = fp_self_contained::CheckedExtrinsic::<86 let signed = match signer {86 AccountId,87 Call,88 SignedExtraScheduler,89 SelfContainedSignedInfo,90 > {91 signed: fp_self_contained::CheckedSignature::<87 Some(signer) => fp_self_contained::CheckedSignature::Signed(signer.clone().into(), get_signed_extras(signer.into())),92 AccountId,88 None => fp_self_contained::CheckedSignature::Unsigned,93 SignedExtraScheduler,94 SelfContainedSignedInfo,95 >::Signed(signer.clone().into(), get_signed_extras(signer.into())),96 function: call.into(),97 };89 };90 91 let extrinsic = fp_self_contained::CheckedExtrinsic::<92 AccountId,93 Call,94 SignedExtraScheduler,95 SelfContainedSignedInfo,96 > {97 signed,98 function: call.into(),99 };9810099 extrinsic.apply::<Runtime>(&dispatch_info, len)101 extrinsic.apply::<Runtime>(&dispatch_info, len)100 }102 }