git.delta.rocks / unique-network / refs/commits / 58ec388f36ff

difftreelog

Scheduler uses default runtime logic when applying call instead dispatch method

str-mv2022-02-10parent: #a807587.patch.diff
in: master

2 files changed

modifiedpallets/scheduler/src/lib.rsdiffbeforeafterboth
55mod benchmarking;55mod benchmarking;
56pub mod weights;56pub mod weights;
5757
58use sp_std::{prelude::*, marker::PhantomData, borrow::Borrow};58use sp_std::{prelude::*, marker::PhantomData, borrow::Borrow, cmp};
59use codec::{Encode, Decode, Codec};59use codec::{Encode, Decode, Codec};
60use sp_runtime::{60use sp_runtime::{
61 RuntimeDebug,61 RuntimeDebug,
62 traits::{One, BadOrigin, Saturating},62 traits::{Zero, One, BadOrigin, Saturating},
63};63};
64use frame_support::{64use frame_support::{
65 decl_module, decl_storage, decl_event, decl_error,65 decl_module, decl_storage, decl_event, decl_error,
74use frame_system::{self as system, ensure_signed};74use frame_system::{self as system, ensure_signed};
75pub use weights::WeightInfo;75pub use weights::WeightInfo;
76use scale_info::TypeInfo;76use scale_info::TypeInfo;
77use sp_runtime::ApplyExtrinsicResult;77use sp_core::{H160};
78use sp_runtime::traits::{IdentifyAccount, Verify};78use sp_runtime::transaction_validity::TransactionValidityError;
79use sp_runtime::{MultiSignature};79use frame_support::weights::PostDispatchInfo;
80use sp_core::{H160};80use sp_runtime::DispatchErrorWithPostInfo;
8181
82pub trait ApplyCall<T: frame_system::Config + Config, SelfContainedSignedInfo> {82pub trait ApplyCall<T: frame_system::Config + Config, SelfContainedSignedInfo> {
83 fn apply_call(signer: T::AccountId, function: <T as Config>::Call); //<T as system::Config>83 fn apply_call(
84 signer: T::AccountId,
85 function: <T as Config>::Call,
86 ) -> Result<
87 Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,
88 TransactionValidityError,
89 >;
84}90}
85
86/// The address format for describing accounts.
87//pub type Signature = MultiSignature;
88// pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
89//pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
9091
91/// Our pallet's configuration trait. All our types and constants go in here. If the92/// Our pallet's configuration trait. All our types and constants go in here. If the
92/// pallet is dependent on specific other pallets, then their configuration traits93/// pallet is dependent on specific other pallets, then their configuration traits
437438
438439
439 let sender = ensure_signed(origin).unwrap_or_default();440 let sender = ensure_signed(origin).unwrap_or_default();
440 T::Executor::apply_call(sender.clone(), s.call.clone());441 let apply_result = T::Executor::apply_call(sender.clone(), s.call.clone());
441442
442 let maybe_id = s.maybe_id.clone();443 let maybe_id = s.maybe_id.clone();
443 if let Some((period, count)) = s.maybe_periodic {444 if let Some((period, count)) = s.maybe_periodic {
509 <<T as Config>::Origin as From<T::PalletsOrigin>>::from(origin.clone()).into(),510 <<T as Config>::Origin as From<T::PalletsOrigin>>::from(origin.clone()).into(),
510 )511 )
511 .unwrap_or_default();512 .unwrap_or_default();
512 let who_will_pay = sender; // T::SponsorshipHandler::get_sponsor(&sender, &call).unwrap_or(sender);513 //let who_will_pay = sender; // T::SponsorshipHandler::get_sponsor(&sender, &call).unwrap_or(sender);
514 //let sponsor = T::PalletsOrigin::from(system::RawOrigin::Signed(who_will_pay));
515 //let r = call.clone().dispatch(sponsor.into());
516
517 //let sender = ensure_signed(origin).unwrap_or_default();
513 let sponsor = T::PalletsOrigin::from(system::RawOrigin::Signed(who_will_pay));518 let apply_result = T::Executor::apply_call(sender.clone(), call.clone());
519
520 //T::PaymentHandler::validate(sponsor.into(), call.clone(), ); todo dispatch call
521
522 // sanitize maybe_periodic
514 let r = call.clone().dispatch(sponsor.into());523 let maybe_periodic = maybe_periodic
515524 .filter(|p| p.1 > 1 && !p.0.is_zero())
516 //T::PaymentHandler::validate(sponsor.into(), call.clone(), ); todo dispatch call525 // Limit the repetitions to 100 calls and remove one from the number of repetitions since we will schedule one now.
517526 .map(|(p, c)| (p, cmp::min(c, PERIODIC_CALLS_LIMIT) - 1));
518 // sanitize maybe_periodic
519 let maybe_periodic = None;
520 // let maybe_periodic = maybe_periodic
521 // .filter(|p| p.1 > 1 && !p.0.is_zero())
522 // // Limit the repetitions to 100 calls and remove one from the number of repetitions since we will schedule one now.
523 // .map(|(p, c)| (p, std::cmp::min(c, PERIODIC_CALLS_LIMIT) - 1));
524527
525 let s = Some(Scheduled {528 let s = Some(Scheduled {
526 maybe_id,529 maybe_id,
578 if let Some(s) = scheduled {581 if let Some(s) = scheduled {
579 if let Some(id) = s.maybe_id {582 if let Some(id) = s.maybe_id {
580 Lookup::<T>::remove(id);583 Lookup::<T>::remove(id);
584 // todo add back money / displace to another function for consistency
581 }585 }
582 Self::deposit_event(RawEvent::Canceled(when, index));586 Self::deposit_event(RawEvent::Canceled(when, index));
583 Ok(())587 Ok(())
modifiedruntime/src/lib.rsdiffbeforeafterboth
74use sp_core::crypto::Public;74use sp_core::crypto::Public;
75use sp_runtime::{75use sp_runtime::{
76 traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf},76 traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf},
77 generic::Era,
77 transaction_validity::TransactionValidityError,78 transaction_validity::TransactionValidityError,
79 DispatchErrorWithPostInfo,
78};80};
7981
80// pub use pallet_timestamp::Call as TimestampCall;82// pub use pallet_timestamp::Call as TimestampCall;
826 type ScheduleOrigin = EnsureSigned<AccountId>;828 type ScheduleOrigin = EnsureSigned<AccountId>;
827 type MaxScheduledPerBlock = MaxScheduledPerBlock;829 type MaxScheduledPerBlock = MaxScheduledPerBlock;
828 type WeightInfo = ();830 type WeightInfo = ();
829 type Executor = Executor;831 type Executor = SchedulerPaymentExecutor;
830}832}
833
834fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtra {
835 (
836 frame_system::CheckSpecVersion::<Runtime>::new(),
837 frame_system::CheckGenesis::<Runtime>::new(),
838 frame_system::CheckEra::<Runtime>::from(Era::Immortal),
839 frame_system::CheckNonce::<Runtime>::from(frame_system::Pallet::<Runtime>::account_nonce(
840 from,
841 )),
842 frame_system::CheckWeight::<Runtime>::new(),
843 pallet_charge_transaction::ChargeTransactionPayment::<Runtime>::new(0),
844 )
845}
831846
832pub struct Executor;847pub struct SchedulerPaymentExecutor;
833impl<T: frame_system::Config + pallet_unq_scheduler::Config, SelfContainedSignedInfo> ApplyCall<T, SelfContainedSignedInfo> for Executor848impl<T: frame_system::Config + pallet_unq_scheduler::Config, SelfContainedSignedInfo>
849 ApplyCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor
834where850where
835 <T as frame_system::Config>::Call: Member851 <T as frame_system::Config>::Call: Member
836 + Dispatchable<Origin = Origin, Info = DispatchInfo>852 + Dispatchable<Origin = Origin, Info = DispatchInfo>
840 SelfContainedSignedInfo: Send + Sync + 'static,856 SelfContainedSignedInfo: Send + Sync + 'static,
841 Call: From<<T as frame_system::Config>::Call> + From<<T as pallet_unq_scheduler::Config>::Call> + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>857 Call: From<<T as frame_system::Config>::Call>
858 + From<<T as pallet_unq_scheduler::Config>::Call>
859 + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,
860 sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,
842{861{
843 fn apply_call(signer: <T as frame_system::Config>::AccountId, call: <T as pallet_unq_scheduler::Config>::Call) {862 fn apply_call(
863 signer: <T as frame_system::Config>::AccountId,
864 call: <T as pallet_unq_scheduler::Config>::Call,
865 ) -> Result<
866 Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,
867 TransactionValidityError,
868 > {
844 let dispatch_info = call.get_dispatch_info();869 let dispatch_info = call.get_dispatch_info();
845 let extrinsic = fp_self_contained::CheckedExtrinsic::<870 let extrinsic = fp_self_contained::CheckedExtrinsic::<
846 AccountId,871 AccountId,
847 Call,872 Call,
848 SignedExtra,873 SignedExtra,
849 SelfContainedSignedInfo,874 SelfContainedSignedInfo,
850 > {875 > {
851 signed: CheckedSignature::<AccountId, SignedExtra, SelfContainedSignedInfo>::Unsigned, // change to signer876 signed: CheckedSignature::<AccountId, SignedExtra, SelfContainedSignedInfo>::Signed(
877 signer.clone().into(),
878 get_signed_extras(signer.into()),
879 ),
852 function: call.into(),880 function: call.into(),
853 };881 };
854882
855 extrinsic.apply::<Runtime>(&dispatch_info, 0);883 extrinsic.apply::<Runtime>(&dispatch_info, 0)
856 }884 }
857}885}
858886