git.delta.rocks / unique-network / refs/commits / 8d5b101bd644

difftreelog

Scheduler without sponsorship features

str-mv2022-04-12parent: #dce25d2.patch.diff
in: master

5 files changed

modifiedpallets/scheduler/src/lib.rsdiffbeforeafterboth
--- a/pallets/scheduler/src/lib.rs
+++ b/pallets/scheduler/src/lib.rs
@@ -361,7 +361,6 @@
 				} else {
 					false
 				};
-
 				let call = match s.call.as_value().cloned() {
 					Some(c) => c,
 					None => {
@@ -419,18 +418,18 @@
 				)
 				.unwrap();
 
-				// if call have id and periodic, it was be reserved
-				if s.maybe_id.is_some() && s.maybe_periodic.is_some() {
-					let _ = T::CallExecutor::pay_for_call(
-						s.maybe_id.unwrap(),
-						sender.clone(),
-						call.clone(),
-					);
-				}
+				// // if call have id it was be reserved
+				// if s.maybe_id.is_some() {
+				// 	let _ = T::CallExecutor::pay_for_call(
+				// 		s.maybe_id.unwrap(),
+				// 		sender.clone(),
+				// 		call.clone(),
+				// 	);
+				// }
 
 				let r = T::CallExecutor::dispatch_call(sender, call.clone());
 
-				let mut actual_call_weight: Weight = item_weight; //PostDispatchInfo;
+				let mut actual_call_weight: Weight = item_weight;
 				let result: Result<_, DispatchError> = match r {
 					Ok(o) => match o {
 						Ok(di) => {
@@ -472,7 +471,8 @@
 					Agenda::<T>::append(wake, Some(s));
 				}
 			}
-			total_weight
+			0
+			//total_weight
 		}
 	}
 
@@ -719,18 +719,18 @@
 		};
 
 		// reserve balance for periodic execution
-		let sender =
-			ensure_signed(<<T as Config>::Origin as From<T::PalletsOrigin>>::from(origin).into())?;
-		let repeats = match maybe_periodic {
-			Some(p) => p.1,
-			None => 0,
-		};
-		let _ = T::CallExecutor::reserve_balance(
-			id.clone(),
-			sender,
-			call.as_value().unwrap().clone(),
-			repeats,
-		);
+		// let sender =
+		// 	ensure_signed(<<T as Config>::Origin as From<T::PalletsOrigin>>::from(origin).into())?;
+		// let repeats = match maybe_periodic {
+		// 	Some(p) => p.1,
+		// 	None => 1,
+		// };
+		// let _ = T::CallExecutor::reserve_balance(
+		// 	id.clone(),
+		// 	sender,
+		// 	call.as_value().unwrap().clone(),
+		// 	repeats,
+		// );
 
 		Agenda::<T>::append(when, Some(s));
 		let index = Agenda::<T>::decode_len(when).unwrap_or(1) as u32 - 1;
@@ -755,13 +755,13 @@
 								return Err(BadOrigin.into());
 							}
 							// release balance reserve
-							let sender = ensure_signed(
-								<<T as Config>::Origin as From<T::PalletsOrigin>>::from(
-									origin.unwrap(),
-								)
-								.into(),
-							)?;
-							let _ = T::CallExecutor::cancel_reserve(id, sender);
+							// let sender = ensure_signed(
+							// 	<<T as Config>::Origin as From<T::PalletsOrigin>>::from(
+							// 		origin.unwrap(),
+							// 	)
+							// 	.into(),
+							// )?;
+							// let _ = T::CallExecutor::cancel_reserve(id, sender);
 
 							s.call.ensure_unrequested::<T::PreimageProvider>();
 						}
modifiedruntime/opal/src/lib.rsdiffbeforeafterboth
--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -29,7 +29,7 @@
 use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256, U256, H160};
 use sp_runtime::DispatchError;
 use fp_self_contained::*;
-use sp_runtime::traits::{SignedExtension, Member};
+use sp_runtime::traits::{Member};
 // #[cfg(any(feature = "std", test))]
 // pub use sp_runtime::BuildStorage;
 
@@ -78,7 +78,7 @@
 	traits::{BaseArithmetic, Unsigned},
 };
 use smallvec::smallvec;
-use scale_info::TypeInfo;
+// use scale_info::TypeInfo;
 use codec::{Encode, Decode};
 use pallet_evm::{Account as EVMAccount, FeeCalculator, GasWeightMapping, OnMethodCall};
 use fp_rpc::TransactionStatus;
@@ -898,7 +898,7 @@
 type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment<Runtime>;
 use frame_support::traits::NamedReservableCurrency;
 
-fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtra {
+fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtraScheduler {
 	(
 		frame_system::CheckSpecVersion::<Runtime>::new(),
 		frame_system::CheckGenesis::<Runtime>::new(),
@@ -907,7 +907,8 @@
 			from,
 		)),
 		frame_system::CheckWeight::<Runtime>::new(),
-		pallet_charge_transaction::ChargeTransactionPayment::<Runtime>::new(0),
+		// sponsoring transaction logic
+		// pallet_charge_transaction::ChargeTransactionPayment::<Runtime>::new(0),
 	)
 }
 
@@ -937,13 +938,14 @@
 		let extrinsic = fp_self_contained::CheckedExtrinsic::<
 			AccountId,
 			Call,
-			SignedExtra,
+			SignedExtraScheduler,
 			SelfContainedSignedInfo,
 		> {
-			signed: CheckedSignature::<AccountId, SignedExtra, SelfContainedSignedInfo>::Signed(
-				signer.clone().into(),
-				get_signed_extras(signer.into()),
-			),
+			signed:
+				CheckedSignature::<AccountId, SignedExtraScheduler, SelfContainedSignedInfo>::Signed(
+					signer.clone().into(),
+					get_signed_extras(signer.into()),
+				),
 			function: call.into(),
 		};
 
@@ -957,23 +959,13 @@
 		count: u32,
 	) -> Result<(), DispatchError> {
 		let dispatch_info = call.get_dispatch_info();
-		let fee_charger = ChargeTransactionPayment::new(0);
-		let pre = match fee_charger.pre_dispatch(
-			&sponsor.clone().into(),
-			&call.into(),
-			&dispatch_info,
-			0,
-		) {
-			Ok(p) => p,
-			Err(_) => fail!("failed to get pre dispatch info"),
-		};
+		let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0)
+			.saturating_mul(count.into());
 
-		let count: u128 = count.into();
-		let total_fee: u128 = pre.2.map(|imbalance| imbalance.peek()).unwrap() * count;
 		<Balances as NamedReservableCurrency<AccountId>>::reserve_named(
 			&id,
 			&(sponsor.into()),
-			total_fee,
+			weight.into(),
 		)
 	}
 
@@ -983,24 +975,12 @@
 		call: <T as pallet_unq_scheduler::Config>::Call,
 	) -> Result<u128, DispatchError> {
 		let dispatch_info = call.get_dispatch_info();
-		let fee_charger = ChargeTransactionPayment::new(0);
-		let pre = match fee_charger.pre_dispatch(
-			&sponsor.clone().into(),
-			&call.into(),
-			&dispatch_info,
-			0,
-		) {
-			Ok(p) => p,
-			Err(_) => fail!("failed to get pre dispatch info"),
-		};
-
-		let single_fee: u128 = pre.2.map(|imbalance| imbalance.peek()).unwrap();
-
+		let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0);
 		Ok(
 			<Balances as NamedReservableCurrency<AccountId>>::unreserve_named(
 				&id,
 				&(sponsor.into()),
-				single_fee,
+				weight.into(),
 			),
 		)
 	}
@@ -1184,6 +1164,13 @@
 	ChargeTransactionPayment,
 	//pallet_contract_helpers::ContractHelpersExtension<Runtime>,
 );
+pub type SignedExtraScheduler = (
+	frame_system::CheckSpecVersion<Runtime>,
+	frame_system::CheckGenesis<Runtime>,
+	frame_system::CheckEra<Runtime>,
+	frame_system::CheckNonce<Runtime>,
+	frame_system::CheckWeight<Runtime>,
+);
 /// Unchecked extrinsic type as expected by this runtime.
 pub type UncheckedExtrinsic =
 	fp_self_contained::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
modifiedruntime/quartz/src/lib.rsdiffbeforeafterboth
--- a/runtime/quartz/src/lib.rs
+++ b/runtime/quartz/src/lib.rs
@@ -33,10 +33,7 @@
 
 use sp_runtime::{
 	Permill, Perbill, Percent, create_runtime_str, generic, impl_opaque_keys,
-	traits::{
-		AccountIdLookup, BlakeTwo256, Block as BlockT, AccountIdConversion, Zero, SignedExtension,
-		Member,
-	},
+	traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, AccountIdConversion, Zero, Member},
 	transaction_validity::{TransactionSource, TransactionValidity},
 	ApplyExtrinsicResult, RuntimeAppPublic,
 };
@@ -952,7 +949,7 @@
 type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment<Runtime>;
 use frame_support::traits::NamedReservableCurrency;
 
-fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtra {
+fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtraScheduler {
 	(
 		frame_system::CheckSpecVersion::<Runtime>::new(),
 		frame_system::CheckGenesis::<Runtime>::new(),
@@ -961,7 +958,8 @@
 			from,
 		)),
 		frame_system::CheckWeight::<Runtime>::new(),
-		pallet_charge_transaction::ChargeTransactionPayment::<Runtime>::new(0),
+		// sponsoring transaction logic
+		// pallet_charge_transaction::ChargeTransactionPayment::<Runtime>::new(0),
 	)
 }
 
@@ -991,13 +989,14 @@
 		let extrinsic = fp_self_contained::CheckedExtrinsic::<
 			AccountId,
 			Call,
-			SignedExtra,
+			SignedExtraScheduler,
 			SelfContainedSignedInfo,
 		> {
-			signed: CheckedSignature::<AccountId, SignedExtra, SelfContainedSignedInfo>::Signed(
-				signer.clone().into(),
-				get_signed_extras(signer.into()),
-			),
+			signed:
+				CheckedSignature::<AccountId, SignedExtraScheduler, SelfContainedSignedInfo>::Signed(
+					signer.clone().into(),
+					get_signed_extras(signer.into()),
+				),
 			function: call.into(),
 		};
 
@@ -1011,23 +1010,13 @@
 		count: u32,
 	) -> Result<(), DispatchError> {
 		let dispatch_info = call.get_dispatch_info();
-		let fee_charger = ChargeTransactionPayment::new(0);
-		let pre = match fee_charger.pre_dispatch(
-			&sponsor.clone().into(),
-			&call.into(),
-			&dispatch_info,
-			0,
-		) {
-			Ok(p) => p,
-			Err(_) => fail!("failed to get pre dispatch info"),
-		};
+		let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0)
+			.saturating_mul(count.into());
 
-		let count: u128 = count.into();
-		let total_fee: u128 = pre.2.map(|imbalance| imbalance.peek()).unwrap() * count;
 		<Balances as NamedReservableCurrency<AccountId>>::reserve_named(
 			&id,
 			&(sponsor.into()),
-			total_fee,
+			weight.into(),
 		)
 	}
 
@@ -1037,24 +1026,12 @@
 		call: <T as pallet_unq_scheduler::Config>::Call,
 	) -> Result<u128, DispatchError> {
 		let dispatch_info = call.get_dispatch_info();
-		let fee_charger = ChargeTransactionPayment::new(0);
-		let pre = match fee_charger.pre_dispatch(
-			&sponsor.clone().into(),
-			&call.into(),
-			&dispatch_info,
-			0,
-		) {
-			Ok(p) => p,
-			Err(_) => fail!("failed to get pre dispatch info"),
-		};
-
-		let single_fee: u128 = pre.2.map(|imbalance| imbalance.peek()).unwrap();
-
+		let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0);
 		Ok(
 			<Balances as NamedReservableCurrency<AccountId>>::unreserve_named(
 				&id,
 				&(sponsor.into()),
-				single_fee,
+				weight.into(),
 			),
 		)
 	}
@@ -1182,6 +1159,15 @@
 	pallet_charge_transaction::ChargeTransactionPayment<Runtime>,
 	//pallet_contract_helpers::ContractHelpersExtension<Runtime>,
 );
+
+pub type SignedExtraScheduler = (
+	frame_system::CheckSpecVersion<Runtime>,
+	frame_system::CheckGenesis<Runtime>,
+	frame_system::CheckEra<Runtime>,
+	frame_system::CheckNonce<Runtime>,
+	frame_system::CheckWeight<Runtime>,
+	// pallet_charge_transaction::ChargeTransactionPayment<Runtime>,
+);
 /// Unchecked extrinsic type as expected by this runtime.
 pub type UncheckedExtrinsic =
 	fp_self_contained::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
modifiedruntime/unique/src/lib.rsdiffbeforeafterboth
--- a/runtime/unique/src/lib.rs
+++ b/runtime/unique/src/lib.rs
@@ -37,7 +37,7 @@
 	traits::{
 		Applyable, BlockNumberProvider, Dispatchable, PostDispatchInfoOf, Saturating,
 		CheckedConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, AccountIdConversion,
-		Zero, Member, SignedExtension,
+		Zero, Member,
 	},
 	transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError},
 	ApplyExtrinsicResult, RuntimeAppPublic, SaturatedConversion, DispatchErrorWithPostInfo,
@@ -918,7 +918,7 @@
 type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment<Runtime>;
 use frame_support::traits::NamedReservableCurrency;
 
-fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtra {
+fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtraScheduler {
 	(
 		frame_system::CheckSpecVersion::<Runtime>::new(),
 		frame_system::CheckGenesis::<Runtime>::new(),
@@ -927,7 +927,8 @@
 			from,
 		)),
 		frame_system::CheckWeight::<Runtime>::new(),
-		pallet_charge_transaction::ChargeTransactionPayment::<Runtime>::new(0),
+		// sponsoring transaction logic
+		// pallet_charge_transaction::ChargeTransactionPayment::<Runtime>::new(0),
 	)
 }
 
@@ -957,13 +958,14 @@
 		let extrinsic = fp_self_contained::CheckedExtrinsic::<
 			AccountId,
 			Call,
-			SignedExtra,
+			SignedExtraScheduler,
 			SelfContainedSignedInfo,
 		> {
-			signed: CheckedSignature::<AccountId, SignedExtra, SelfContainedSignedInfo>::Signed(
-				signer.clone().into(),
-				get_signed_extras(signer.into()),
-			),
+			signed:
+				CheckedSignature::<AccountId, SignedExtraScheduler, SelfContainedSignedInfo>::Signed(
+					signer.clone().into(),
+					get_signed_extras(signer.into()),
+				),
 			function: call.into(),
 		};
 
@@ -977,23 +979,13 @@
 		count: u32,
 	) -> Result<(), DispatchError> {
 		let dispatch_info = call.get_dispatch_info();
-		let fee_charger = ChargeTransactionPayment::new(0);
-		let pre = match fee_charger.pre_dispatch(
-			&sponsor.clone().into(),
-			&call.into(),
-			&dispatch_info,
-			0,
-		) {
-			Ok(p) => p,
-			Err(_) => fail!("failed to get pre dispatch info"),
-		};
+		let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0)
+			.saturating_mul(count.into());
 
-		let count: u128 = count.into();
-		let total_fee: u128 = pre.2.map(|imbalance| imbalance.peek()).unwrap() * count;
 		<Balances as NamedReservableCurrency<AccountId>>::reserve_named(
 			&id,
 			&(sponsor.into()),
-			total_fee,
+			weight.into(),
 		)
 	}
 
@@ -1003,24 +995,12 @@
 		call: <T as pallet_unq_scheduler::Config>::Call,
 	) -> Result<u128, DispatchError> {
 		let dispatch_info = call.get_dispatch_info();
-		let fee_charger = ChargeTransactionPayment::new(0);
-		let pre = match fee_charger.pre_dispatch(
-			&sponsor.clone().into(),
-			&call.into(),
-			&dispatch_info,
-			0,
-		) {
-			Ok(p) => p,
-			Err(_) => fail!("failed to get pre dispatch info"),
-		};
-
-		let single_fee: u128 = pre.2.map(|imbalance| imbalance.peek()).unwrap();
-
+		let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0);
 		Ok(
 			<Balances as NamedReservableCurrency<AccountId>>::unreserve_named(
 				&id,
 				&(sponsor.into()),
-				single_fee,
+				weight.into(),
 			),
 		)
 	}
@@ -1173,6 +1153,14 @@
 	pallet_charge_transaction::ChargeTransactionPayment<Runtime>,
 	//pallet_contract_helpers::ContractHelpersExtension<Runtime>,
 );
+pub type SignedExtraScheduler = (
+	frame_system::CheckSpecVersion<Runtime>,
+	frame_system::CheckGenesis<Runtime>,
+	frame_system::CheckEra<Runtime>,
+	frame_system::CheckNonce<Runtime>,
+	frame_system::CheckWeight<Runtime>,
+	// pallet_charge_transaction::ChargeTransactionPayment<Runtime>,
+);
 /// Unchecked extrinsic type as expected by this runtime.
 pub type UncheckedExtrinsic =
 	fp_self_contained::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
modifiedtests/src/scheduler.test.tsdiffbeforeafterboth
4545
46chai.use(chaiAsPromised);46chai.use(chaiAsPromised);
4747
48describe('Scheduling token and balance transfers', () => {48describe.skip('Scheduling token and balance transfers', () => {
49 let alice: IKeyringPair;49 let alice: IKeyringPair;
50 let bob: IKeyringPair;50 let bob: IKeyringPair;
51 let scheduledIdBase: string;51 let scheduledIdBase: string;