difftreelog
fix make schedulerv2 take fees
in: master
3 files changed
pallets/scheduler-v2/src/lib.rsdiffbeforeafterboth81 traits::{81 traits::{82 schedule::{self, DispatchTime},82 schedule::{self, DispatchTime},83 EnsureOrigin, Get, IsType, OriginTrait, PrivilegeCmp, StorageVersion, PreimageRecipient,83 EnsureOrigin, Get, IsType, OriginTrait, PrivilegeCmp, StorageVersion, PreimageRecipient,84 ConstU32,84 ConstU32, UnfilteredDispatchable,85 },85 },86 weights::Weight,86 weights::{Weight, PostDispatchInfo}, unsigned::TransactionValidityError,87};87};888889use frame_system::{self as system};89use frame_system::{self as system};90use scale_info::TypeInfo;90use scale_info::TypeInfo;91use sp_runtime::{91use sp_runtime::{92 traits::{BadOrigin, One, Saturating, Zero, Hash},92 traits::{BadOrigin, One, Saturating, Zero, Hash},93 BoundedVec, RuntimeDebug,93 BoundedVec, RuntimeDebug, DispatchErrorWithPostInfo,94};94};95use sp_core::H160;95use sp_std::{borrow::Borrow, cmp::Ordering, marker::PhantomData, prelude::*};96use sp_std::{borrow::Borrow, cmp::Ordering, marker::PhantomData, prelude::*};96pub use weights::WeightInfo;97pub use weights::WeightInfo;9798206 }207 }207}208}209210pub enum ScheduledEnsureOriginSuccess<AccountId> {211 Root,212 Signed(AccountId),213 Unsigned,214}208215209pub type TaskName = [u8; 32];216pub type TaskName = [u8; 32];210217312 /// The aggregated call type.319 /// The aggregated call type.313 type Call: Parameter320 type Call: Parameter314 + Dispatchable<Origin = <Self as Config>::Origin, PostInfo = PostDispatchInfo>321 + Dispatchable<Origin = <Self as Config>::Origin, PostInfo = PostDispatchInfo>322 + UnfilteredDispatchable<Origin = <Self as system::Config>::Origin>315 + GetDispatchInfo323 + GetDispatchInfo316 + From<system::Call<Self>>;324 + From<system::Call<Self>>;317325321329322 /// Required origin to schedule or cancel calls.330 /// Required origin to schedule or cancel calls.323 type ScheduleOrigin: EnsureOrigin<<Self as system::Config>::Origin>;331 type ScheduleOrigin: EnsureOrigin<332 <Self as system::Config>::Origin,333 Success = ScheduledEnsureOriginSuccess<Self::AccountId>,334 >;324335325 /// Compare the privileges of origins.336 /// Compare the privileges of origins.341 /// The preimage provider with which we look up call hashes to get the call.352 /// The preimage provider with which we look up call hashes to get the call.342 type Preimages: SchedulerPreimages<Self>;353 type Preimages: SchedulerPreimages<Self>;354355 /// The helper type used for custom transaction fee logic.356 type CallExecutor: DispatchCall<Self, H160>;343 }357 }344358345 #[pallet::storage]359 #[pallet::storage]726}740}727use ServiceTaskError::*;741use ServiceTaskError::*;742743/// A Scheduler-Runtime interface for finer payment handling.744pub trait DispatchCall<T: frame_system::Config + Config, SelfContainedSignedInfo> {745 /// Resolve the call dispatch, including any post-dispatch operations.746 fn dispatch_call(747 signer: Option<T::AccountId>,748 function: <T as Config>::Call,749 ) -> Result<750 Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,751 TransactionValidityError,752 >;753}728754729impl<T: Config> Pallet<T> {755impl<T: Config> Pallet<T> {730 /// Service up to `max` agendas queue starting from earliest incompletely executed agenda.756 /// Service up to `max` agendas queue starting from earliest incompletely executed agenda.927 return Err(Overweight);953 return Err(Overweight);928 }954 }955956 // let scheduled_origin =957 // <<T as Config>::Origin as From<T::PalletsOrigin>>::from(origin.clone());958 let ensured_origin = T::ScheduleOrigin::ensure_origin(dispatch_origin.into());959960 let r = match ensured_origin {961 Ok(ScheduledEnsureOriginSuccess::Root) => {962 Ok(call.dispatch_bypass_filter(frame_system::RawOrigin::Root.into()))963 },964 Ok(ScheduledEnsureOriginSuccess::Signed(sender)) => {965 // Execute transaction via chain default pipeline966 // That means dispatch will be processed like any user's extrinsic e.g. transaction fees will be taken967 T::CallExecutor::dispatch_call(Some(sender), call.clone())968 },969 Ok(ScheduledEnsureOriginSuccess::Unsigned) => {970 // Unsigned version of the above971 T::CallExecutor::dispatch_call(None, call.clone())972 }973 Err(e) => Ok(Err(e.into())),974 };929975930 let (maybe_actual_call_weight, result) = match call.dispatch(dispatch_origin) {976 let (maybe_actual_call_weight, result) = match r {977 Ok(result) => match result {931 Ok(post_info) => (post_info.actual_weight, Ok(())),978 Ok(post_info) => (post_info.actual_weight, Ok(())),932 Err(error_and_info) => (979 Err(error_and_info) => (933 error_and_info.post_info.actual_weight,980 error_and_info.post_info.actual_weight,934 Err(error_and_info.error),981 Err(error_and_info.error),935 ),982 ),936 };983 },984 Err(_) => {985 log::error!(986 target: "runtime::scheduler",987 "Warning: Scheduler has failed to execute a post-dispatch transaction. \988 This block might have become invalid.");989 (None, Err(DispatchError::CannotLookup))990 }991 };937 let call_weight = maybe_actual_call_weight.unwrap_or(call_weight);992 let call_weight = maybe_actual_call_weight.unwrap_or(call_weight);938 weight.check_accrue(base_weight);993 weight.check_accrue(base_weight);939 weight.check_accrue(call_weight);994 weight.check_accrue(call_weight);runtime/common/config/pallets/scheduler.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/scheduler.rs
+++ b/runtime/common/config/pallets/scheduler.rs
@@ -27,7 +27,7 @@
runtime_common::{scheduler::SchedulerPaymentExecutor, config::substrate::RuntimeBlockWeights},
Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, OriginCaller, Balances,
};
-use pallet_unique_scheduler::ScheduledEnsureOriginSuccess;
+use pallet_unique_scheduler_v2::ScheduledEnsureOriginSuccess;
use up_common::types::AccountId;
parameter_types! {
@@ -98,4 +98,5 @@
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type WeightInfo = ();
type Preimages = ();
+ type CallExecutor = SchedulerPaymentExecutor;
}
runtime/common/scheduler.rsdiffbeforeafterboth--- a/runtime/common/scheduler.rs
+++ b/runtime/common/scheduler.rs
@@ -28,11 +28,11 @@
use crate::{Runtime, RuntimeCall, RuntimeOrigin, Balances, maintenance};
use up_common::types::{AccountId, Balance};
use fp_self_contained::SelfContainedCall;
-use pallet_unique_scheduler::DispatchCall;
+use pallet_unique_scheduler_v2::DispatchCall;
use pallet_transaction_payment::ChargeTransactionPayment;
-type SponsorshipChargeTransactionPayment =
- pallet_charge_transaction::ChargeTransactionPayment<Runtime>;
+// type SponsorshipChargeTransactionPayment =
+// pallet_charge_transaction::ChargeTransactionPayment<Runtime>;
/// The SignedExtension to the basic transaction logic.
pub type SignedExtraScheduler = (
@@ -61,7 +61,7 @@
pub struct SchedulerPaymentExecutor;
-impl<T: frame_system::Config + pallet_unique_scheduler::Config, SelfContainedSignedInfo>
+impl<T: frame_system::Config + pallet_unique_scheduler_v2::Config, SelfContainedSignedInfo>
DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor
where
<T as frame_system::Config>::RuntimeCall: Member
@@ -71,13 +71,13 @@
+ From<frame_system::Call<Runtime>>,
SelfContainedSignedInfo: Send + Sync + 'static,
RuntimeCall: From<<T as frame_system::Config>::RuntimeCall>
- + From<<T as pallet_unique_scheduler::Config>::RuntimeCall>
+ + From<<T as pallet_unique_scheduler_v2::Config>::RuntimeCall>
+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,
sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,
{
fn dispatch_call(
signer: Option<<T as frame_system::Config>::AccountId>,
- call: <T as pallet_unique_scheduler::Config>::RuntimeCall,
+ call: <T as pallet_unique_scheduler_v2::Config>::RuntimeCall,
) -> Result<
Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,
TransactionValidityError,
@@ -105,52 +105,99 @@
extrinsic.apply::<Runtime>(&dispatch_info, len)
}
+}
- fn reserve_balance(
- id: [u8; 16],
- sponsor: <T as frame_system::Config>::AccountId,
- call: <T as pallet_unique_scheduler::Config>::RuntimeCall,
- count: u32,
- ) -> Result<(), DispatchError> {
- let dispatch_info = call.get_dispatch_info();
- let weight: Balance =
- SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0)
- .saturating_mul(count.into());
- <Balances as NamedReservableCurrency<AccountId>>::reserve_named(
- &id,
- &(sponsor.into()),
- weight,
- )
- }
+// impl<T: frame_system::Config + pallet_unique_scheduler::Config, SelfContainedSignedInfo>
+// DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor
+// where
+// <T as frame_system::Config>::Call: Member
+// + Dispatchable<Origin = Origin, Info = DispatchInfo>
+// + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>
+// + GetDispatchInfo
+// + From<frame_system::Call<Runtime>>,
+// SelfContainedSignedInfo: Send + Sync + 'static,
+// Call: From<<T as frame_system::Config>::Call>
+// + From<<T as pallet_unique_scheduler::Config>::Call>
+// + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,
+// sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,
+// {
+// fn dispatch_call(
+// signer: Option<<T as frame_system::Config>::AccountId>,
+// call: <T as pallet_unique_scheduler::Config>::Call,
+// ) -> Result<
+// Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,
+// TransactionValidityError,
+// > {
+// let dispatch_info = call.get_dispatch_info();
+// let len = call.encoded_size();
- fn pay_for_call(
- id: [u8; 16],
- sponsor: <T as frame_system::Config>::AccountId,
- call: <T as pallet_unique_scheduler::Config>::RuntimeCall,
- ) -> Result<u128, DispatchError> {
- let dispatch_info = call.get_dispatch_info();
- let weight: Balance =
- SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0);
- Ok(
- <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(
- &id,
- &(sponsor.into()),
- weight,
- ),
- )
- }
+// let signed = match signer {
+// Some(signer) => fp_self_contained::CheckedSignature::Signed(
+// signer.clone().into(),
+// get_signed_extras(signer.into()),
+// ),
+// None => fp_self_contained::CheckedSignature::Unsigned,
+// };
- fn cancel_reserve(
- id: [u8; 16],
- sponsor: <T as frame_system::Config>::AccountId,
- ) -> Result<u128, DispatchError> {
- Ok(
- <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(
- &id,
- &(sponsor.into()),
- u128::MAX,
- ),
- )
- }
-}
+// let extrinsic = fp_self_contained::CheckedExtrinsic::<
+// AccountId,
+// Call,
+// SignedExtraScheduler,
+// SelfContainedSignedInfo,
+// > {
+// signed,
+// function: call.into(),
+// };
+
+// extrinsic.apply::<Runtime>(&dispatch_info, len)
+// }
+
+// fn reserve_balance(
+// id: [u8; 16],
+// sponsor: <T as frame_system::Config>::AccountId,
+// call: <T as pallet_unique_scheduler::Config>::Call,
+// count: u32,
+// ) -> Result<(), DispatchError> {
+// let dispatch_info = call.get_dispatch_info();
+// let weight: Balance =
+// SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0)
+// .saturating_mul(count.into());
+
+// <Balances as NamedReservableCurrency<AccountId>>::reserve_named(
+// &id,
+// &(sponsor.into()),
+// weight,
+// )
+// }
+
+// fn pay_for_call(
+// id: [u8; 16],
+// sponsor: <T as frame_system::Config>::AccountId,
+// call: <T as pallet_unique_scheduler::Config>::Call,
+// ) -> Result<u128, DispatchError> {
+// let dispatch_info = call.get_dispatch_info();
+// let weight: Balance =
+// SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0);
+// Ok(
+// <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(
+// &id,
+// &(sponsor.into()),
+// weight,
+// ),
+// )
+// }
+
+// fn cancel_reserve(
+// id: [u8; 16],
+// sponsor: <T as frame_system::Config>::AccountId,
+// ) -> Result<u128, DispatchError> {
+// Ok(
+// <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(
+// &id,
+// &(sponsor.into()),
+// u128::MAX,
+// ),
+// )
+// }
+// }