git.delta.rocks / unique-network / refs/commits / 96d265cead38

difftreelog

fix scheduler doesn't change nonce

Daniel Shiposha2022-11-08parent: #a4f0bd9.patch.diff
in: master

2 files changed

modifiedruntime/common/scheduler.rsdiffbeforeafterboth
before · runtime/common/scheduler.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use frame_support::{18	dispatch::{GetDispatchInfo, PostDispatchInfo, DispatchInfo},19};20use sp_runtime::{21	traits::{Dispatchable, Applyable, Member},22	generic::Era,23	transaction_validity::TransactionValidityError,24	DispatchErrorWithPostInfo,25};26use codec::Encode;27use crate::{Runtime, RuntimeCall, RuntimeOrigin, maintenance};28use up_common::types::AccountId;29use fp_self_contained::SelfContainedCall;30use pallet_unique_scheduler_v2::DispatchCall;31use pallet_transaction_payment::ChargeTransactionPayment;3233/// The SignedExtension to the basic transaction logic.34pub type SignedExtraScheduler = (35	frame_system::CheckSpecVersion<Runtime>,36	frame_system::CheckGenesis<Runtime>,37	frame_system::CheckEra<Runtime>,38	frame_system::CheckNonce<Runtime>,39	frame_system::CheckWeight<Runtime>,40	maintenance::CheckMaintenance,41	ChargeTransactionPayment<Runtime>,42);4344fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtraScheduler {45	(46		frame_system::CheckSpecVersion::<Runtime>::new(),47		frame_system::CheckGenesis::<Runtime>::new(),48		frame_system::CheckEra::<Runtime>::from(Era::Immortal),49		frame_system::CheckNonce::<Runtime>::from(frame_system::Pallet::<Runtime>::account_nonce(50			from,51		)),52		frame_system::CheckWeight::<Runtime>::new(),53		maintenance::CheckMaintenance,54		ChargeTransactionPayment::<Runtime>::from(0),55	)56}5758pub struct SchedulerPaymentExecutor;5960impl<T: frame_system::Config + pallet_unique_scheduler_v2::Config, SelfContainedSignedInfo>61	DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor62where63	<T as frame_system::Config>::RuntimeCall: Member64		+ Dispatchable<RuntimeOrigin = RuntimeOrigin, Info = DispatchInfo>65		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>66		+ GetDispatchInfo67		+ From<frame_system::Call<Runtime>>,68	SelfContainedSignedInfo: Send + Sync + 'static,69	RuntimeCall: From<<T as frame_system::Config>::RuntimeCall>70		+ From<<T as pallet_unique_scheduler_v2::Config>::RuntimeCall>71		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,72	sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,73{74	fn dispatch_call(75		signer: Option<<T as frame_system::Config>::AccountId>,76		call: <T as pallet_unique_scheduler_v2::Config>::RuntimeCall,77	) -> Result<78		Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,79		TransactionValidityError,80	> {81		let dispatch_info = call.get_dispatch_info();82		let len = call.encoded_size();8384		let signed = match signer {85			Some(signer) => fp_self_contained::CheckedSignature::Signed(86				signer.clone().into(),87				get_signed_extras(signer.into()),88			),89			None => fp_self_contained::CheckedSignature::Unsigned,90		};9192		let extrinsic = fp_self_contained::CheckedExtrinsic::<93			AccountId,94			RuntimeCall,95			SignedExtraScheduler,96			SelfContainedSignedInfo,97		> {98			signed,99			function: call.into(),100		};101102		extrinsic.apply::<Runtime>(&dispatch_info, len)103	}104}
after · runtime/common/scheduler.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use frame_support::{18	dispatch::{GetDispatchInfo, PostDispatchInfo, DispatchInfo},19};20use sp_runtime::{21	traits::{Dispatchable, Applyable, Member},22	generic::Era,23	transaction_validity::TransactionValidityError,24	DispatchErrorWithPostInfo,25};26use codec::Encode;27use crate::{Runtime, RuntimeCall, RuntimeOrigin, maintenance};28use up_common::types::AccountId;29use fp_self_contained::SelfContainedCall;30use pallet_unique_scheduler_v2::DispatchCall;31use pallet_transaction_payment::ChargeTransactionPayment;3233/// The SignedExtension to the basic transaction logic.34pub type SignedExtraScheduler = (35	frame_system::CheckWeight<Runtime>,36	maintenance::CheckMaintenance,37	ChargeTransactionPayment<Runtime>,38);3940fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtraScheduler {41	(42		frame_system::CheckWeight::<Runtime>::new(),43		maintenance::CheckMaintenance,44		ChargeTransactionPayment::<Runtime>::from(0),45	)46}4748pub struct SchedulerPaymentExecutor;4950impl<T: frame_system::Config + pallet_unique_scheduler_v2::Config, SelfContainedSignedInfo>51	DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor52where53	<T as frame_system::Config>::RuntimeCall: Member54		+ Dispatchable<RuntimeOrigin = RuntimeOrigin, Info = DispatchInfo>55		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>56		+ GetDispatchInfo57		+ From<frame_system::Call<Runtime>>,58	SelfContainedSignedInfo: Send + Sync + 'static,59	RuntimeCall: From<<T as frame_system::Config>::RuntimeCall>60		+ From<<T as pallet_unique_scheduler_v2::Config>::RuntimeCall>61		+ SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,62	sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,63{64	fn dispatch_call(65		signer: Option<<T as frame_system::Config>::AccountId>,66		call: <T as pallet_unique_scheduler_v2::Config>::RuntimeCall,67	) -> Result<68		Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,69		TransactionValidityError,70	> {71		let dispatch_info = call.get_dispatch_info();72		let len = call.encoded_size();7374		let signed = match signer {75			Some(signer) => fp_self_contained::CheckedSignature::Signed(76				signer.clone().into(),77				get_signed_extras(signer.into()),78			),79			None => fp_self_contained::CheckedSignature::Unsigned,80		};8182		let extrinsic = fp_self_contained::CheckedExtrinsic::<83			AccountId,84			RuntimeCall,85			SignedExtraScheduler,86			SelfContainedSignedInfo,87		> {88			signed,89			function: call.into(),90		};9192		extrinsic.apply::<Runtime>(&dispatch_info, len)93	}94}
modifiedtests/src/scheduler.seqtest.tsdiffbeforeafterboth
--- a/tests/src/scheduler.seqtest.ts
+++ b/tests/src/scheduler.seqtest.ts
@@ -467,6 +467,23 @@
     // After the `numFilledBlocks` the periodic operation will eventually be executed
     expect(await helper.testUtils.testValue()).to.be.equal(secondExecTestVal);
   });
+
+  itSub('scheduled operations does not change nonce', async ({helper}) => {
+    const scheduledId = await helper.arrange.makeScheduledId();
+    const blocksBeforeExecution = 4;
+
+    await helper.scheduler
+      .scheduleAfter<DevUniqueHelper>(scheduledId, blocksBeforeExecution)
+      .balance.transferToSubstrate(alice, bob.address, 1n);
+
+    const initNonce = await helper.chain.getNonce(alice.address);
+
+    await helper.wait.newBlocks(blocksBeforeExecution + 1);
+
+    const finalNonce = await helper.chain.getNonce(alice.address);
+
+    expect(initNonce).to.be.equal(finalNonce);
+  });
 });
 
 describe('Negative Test: Scheduling', () => {