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
--- a/pallets/scheduler/src/lib.rs
+++ b/pallets/scheduler/src/lib.rs
@@ -55,11 +55,11 @@
 mod benchmarking;
 pub mod weights;
 
-use sp_std::{prelude::*, marker::PhantomData, borrow::Borrow};
+use sp_std::{prelude::*, marker::PhantomData, borrow::Borrow, cmp};
 use codec::{Encode, Decode, Codec};
 use sp_runtime::{
 	RuntimeDebug,
-	traits::{One, BadOrigin, Saturating},
+	traits::{Zero, One, BadOrigin, Saturating},
 };
 use frame_support::{
 	decl_module, decl_storage, decl_event, decl_error,
@@ -74,19 +74,20 @@
 use frame_system::{self as system, ensure_signed};
 pub use weights::WeightInfo;
 use scale_info::TypeInfo;
-use sp_runtime::ApplyExtrinsicResult;
-use sp_runtime::traits::{IdentifyAccount, Verify};
-use sp_runtime::{MultiSignature};
 use sp_core::{H160};
+use sp_runtime::transaction_validity::TransactionValidityError;
+use frame_support::weights::PostDispatchInfo;
+use sp_runtime::DispatchErrorWithPostInfo;
 
 pub trait ApplyCall<T: frame_system::Config + Config, SelfContainedSignedInfo> {
-	fn apply_call(signer: T::AccountId, function: <T as Config>::Call); //<T as system::Config>
+	fn apply_call(
+		signer: T::AccountId,
+		function: <T as Config>::Call,
+	) -> Result<
+		Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,
+		TransactionValidityError,
+	>;
 }
-
-/// The address format for describing accounts.
-//pub type Signature = MultiSignature;
-// pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
-//pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
 
 /// Our pallet's configuration trait. All our types and constants go in here. If the
 /// pallet is dependent on specific other pallets, then their configuration traits
@@ -437,7 +438,7 @@
 
 
 						let sender = ensure_signed(origin).unwrap_or_default();
-						T::Executor::apply_call(sender.clone(), s.call.clone());
+						let apply_result = T::Executor::apply_call(sender.clone(), s.call.clone());
 
 						let maybe_id = s.maybe_id.clone();
 						if let Some((period, count)) = s.maybe_periodic {
@@ -509,18 +510,20 @@
 			<<T as Config>::Origin as From<T::PalletsOrigin>>::from(origin.clone()).into(),
 		)
 		.unwrap_or_default();
-		let who_will_pay = sender; // T::SponsorshipHandler::get_sponsor(&sender, &call).unwrap_or(sender);
-		let sponsor = T::PalletsOrigin::from(system::RawOrigin::Signed(who_will_pay));
-		let r = call.clone().dispatch(sponsor.into());
+		//let who_will_pay = sender; // T::SponsorshipHandler::get_sponsor(&sender, &call).unwrap_or(sender);
+		//let sponsor = T::PalletsOrigin::from(system::RawOrigin::Signed(who_will_pay));
+		//let r = call.clone().dispatch(sponsor.into());
+
+		//let sender = ensure_signed(origin).unwrap_or_default();
+		let apply_result = T::Executor::apply_call(sender.clone(), call.clone());
 
 		//T::PaymentHandler::validate(sponsor.into(), call.clone(), ); todo dispatch call
 
 		// sanitize maybe_periodic
-		let maybe_periodic = None;
-		// let maybe_periodic = maybe_periodic
-		// 	.filter(|p| p.1 > 1 && !p.0.is_zero())
-		// 	// Limit the repetitions to 100 calls and remove one from the number of repetitions since we will schedule one now.
-		// 	.map(|(p, c)| (p, std::cmp::min(c, PERIODIC_CALLS_LIMIT) - 1));
+		let maybe_periodic = maybe_periodic
+			.filter(|p| p.1 > 1 && !p.0.is_zero())
+			// Limit the repetitions to 100 calls and remove one from the number of repetitions since we will schedule one now.
+			.map(|(p, c)| (p, cmp::min(c, PERIODIC_CALLS_LIMIT) - 1));
 
 		let s = Some(Scheduled {
 			maybe_id,
@@ -578,6 +581,7 @@
 		if let Some(s) = scheduled {
 			if let Some(id) = s.maybe_id {
 				Lookup::<T>::remove(id);
+				// todo add back money / displace to another function for consistency
 			}
 			Self::deposit_event(RawEvent::Canceled(when, index));
 			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