From 05cc9977b8b6b85aca2281ce2b829c8add8cfd5a Mon Sep 17 00:00:00 2001 From: Vadim Obradovich Date: Fri, 23 Aug 2024 15:16:08 +0200 Subject: [PATCH] chore(pallet_gear_voucher): Remove pallet_gear_voucher::call_deprecated and clean all references (#4168) --- gsdk/src/metadata/generated.rs | 9 - pallets/gear-voucher/src/internal.rs | 26 --- pallets/gear-voucher/src/lib.rs | 32 +-- pallets/gear-voucher/src/tests.rs | 49 ----- pallets/payment/src/tests.rs | 293 --------------------------- 5 files changed, 1 insertion(+), 408 deletions(-) diff --git a/gsdk/src/metadata/generated.rs b/gsdk/src/metadata/generated.rs index a2e7ab27986..dd99f0514ed 100644 --- a/gsdk/src/metadata/generated.rs +++ b/gsdk/src/metadata/generated.rs @@ -3144,13 +3144,6 @@ pub mod runtime_types { prolong_duration: ::core::option::Option<::core::primitive::u32>, }, #[codec(index = 4)] - #[doc = "See [`Pallet::call_deprecated`]."] - call_deprecated { - call: runtime_types::pallet_gear_voucher::internal::PrepaidCall< - ::core::primitive::u128, - >, - }, - #[codec(index = 5)] #[doc = "See [`Pallet::decline`]."] decline { voucher_id: runtime_types::pallet_gear_voucher::internal::VoucherId, @@ -8476,7 +8469,6 @@ pub mod calls { Call, Revoke, Update, - CallDeprecated, Decline, } impl CallInfo for GearVoucherCall { @@ -8487,7 +8479,6 @@ pub mod calls { Self::Call => "call", Self::Revoke => "revoke", Self::Update => "update", - Self::CallDeprecated => "call_deprecated", Self::Decline => "decline", } } diff --git a/pallets/gear-voucher/src/internal.rs b/pallets/gear-voucher/src/internal.rs index acfbf3ecc0e..1623fa4a63c 100644 --- a/pallets/gear-voucher/src/internal.rs +++ b/pallets/gear-voucher/src/internal.rs @@ -42,11 +42,6 @@ where /// determined destination; /// * For codes uploading: The voucher allows code uploading. /// - /// * Call is [`Self::call_deprecated`]: - /// * For messaging calls: The destination program of the given prepaid - /// call can be determined. - /// * For codes uploading: NEVER. - /// /// Returns [`None`] for other cases. pub fn get_sponsor(&self, caller: AccountIdOf) -> Option> { match self { @@ -57,11 +52,6 @@ where .map(|_| (*voucher_id).cast()) .ok(), - #[allow(deprecated)] - Self::call_deprecated { call: prepaid_call } => { - Pallet::::call_deprecated_sponsor(&caller, prepaid_call) - } - _ => None, } } @@ -84,22 +74,6 @@ impl Pallet { Ok(voucher) } - /// Return the account id of a synthetical account used to sponsor gas - /// and transaction fee for legacy vouchers implementation. - #[deprecated = "Legacy voucher issuing logic is deprecated, and this and \ - `call_deprecated` extrinsic exist only for backward support"] - pub fn call_deprecated_sponsor( - who: &T::AccountId, - call: &PrepaidCall>, - ) -> Option { - #[allow(deprecated)] - Self::prepaid_call_destination(who, call).map(|program_id| { - let entropy = (b"modlpy/voucher__", who, program_id).using_encoded(blake2_256); - Decode::decode(&mut TrailingZeroInput::new(entropy.as_ref())) - .expect("infinite length input; no invalid inputs for type; qed") - }) - } - /// Validate prepaid call with related params of voucher: origin, expiration. pub fn validate_prepaid( origin: AccountIdOf, diff --git a/pallets/gear-voucher/src/lib.rs b/pallets/gear-voucher/src/lib.rs index 8bc08ea0cef..324c0a8268f 100644 --- a/pallets/gear-voucher/src/lib.rs +++ b/pallets/gear-voucher/src/lib.rs @@ -57,8 +57,6 @@ use frame_support::{ }; use gear_core::ids::{MessageId, ProgramId}; pub use primitive_types::H256; -use sp_io::hashing::blake2_256; -use sp_runtime::traits::TrailingZeroInput; use sp_std::{convert::TryInto, vec::Vec}; pub use weights::WeightInfo; @@ -557,34 +555,6 @@ pub mod pallet { Ok(().into()) } - /// Legacy call for using irrevocable vouchers. - #[pallet::call_index(4)] - #[pallet::weight(T::CallsDispatcher::weight(call).saturating_add(T::DbWeight::get().reads(1)))] - pub fn call_deprecated( - origin: OriginFor, - call: PrepaidCall>, - ) -> DispatchResultWithPostInfo { - // Ensuring origin. - let origin = ensure_signed(origin)?; - - // Validating the call for legacy implementation. - match call { - PrepaidCall::UploadCode { .. } => { - return Err(Error::::CodeUploadingDisabled.into()) - } - PrepaidCall::DeclineVoucher => return Err(Error::::InexistentVoucher.into()), - PrepaidCall::SendMessage { .. } | PrepaidCall::SendReply { .. } => (), - }; - - // Looking for sponsor synthetic account. - #[allow(deprecated)] - let sponsor = Self::call_deprecated_sponsor(&origin, &call) - .ok_or(Error::::UnknownDestination)?; - - // Dispatching call. - T::CallsDispatcher::dispatch(origin, sponsor.clone(), sponsor.cast(), call) - } - /// Decline existing and not expired voucher. /// /// This extrinsic expires voucher of the caller, if it's still active, @@ -592,7 +562,7 @@ pub mod pallet { /// /// Arguments: /// * voucher_id: voucher id to be declined. - #[pallet::call_index(5)] + #[pallet::call_index(4)] #[pallet::weight(T::WeightInfo::decline())] pub fn decline(origin: OriginFor, voucher_id: VoucherId) -> DispatchResultWithPostInfo { // Ensuring origin. diff --git a/pallets/gear-voucher/src/tests.rs b/pallets/gear-voucher/src/tests.rs index b15aee3c469..b7453b20921 100644 --- a/pallets/gear-voucher/src/tests.rs +++ b/pallets/gear-voucher/src/tests.rs @@ -141,31 +141,6 @@ fn voucher_call_works() { }, )); - // Always ok, because legacy call doesn't access vouchers storage - // and just proxies payment to specific synthetic account. - assert_ok!(Voucher::call_deprecated( - RuntimeOrigin::signed(ALICE), - PrepaidCall::SendMessage { - destination: H256::random().cast(), - payload: vec![], - gas_limit: 0, - value: 0, - keep_alive: false - } - )); - - // Ok, if message exists in mailbox. - assert_ok!(Voucher::call_deprecated( - RuntimeOrigin::signed(ALICE), - PrepaidCall::SendReply { - reply_to_id: MAILBOXED_MESSAGE, - payload: vec![], - gas_limit: 0, - value: 0, - keep_alive: false - }, - )); - // Checking case of any program. assert_ok!(Voucher::issue( RuntimeOrigin::signed(ALICE), @@ -336,30 +311,6 @@ fn voucher_call_err_cases() { ), Error::::VoucherExpired ); - - // Message doesn't exist in mailbox. - assert_noop!( - Voucher::call_deprecated( - RuntimeOrigin::signed(BOB), - PrepaidCall::SendReply { - reply_to_id: H256::random().cast(), - payload: vec![], - gas_limit: 0, - value: 0, - keep_alive: false - }, - ), - Error::::UnknownDestination - ); - - // Code uploading is always forbidden for `call_deprecated`. - assert_noop!( - Voucher::call_deprecated( - RuntimeOrigin::signed(BOB), - PrepaidCall::UploadCode { code: vec![] }, - ), - Error::::CodeUploadingDisabled - ); }) } diff --git a/pallets/payment/src/tests.rs b/pallets/payment/src/tests.rs index 3d00febb256..d3e87c0a061 100644 --- a/pallets/payment/src/tests.rs +++ b/pallets/payment/src/tests.rs @@ -919,86 +919,6 @@ fn voucher_call_send_payer_expiry_err() { }); } -#[test] -fn voucher_call_deprecated_send_payer_ok() { - new_test_ext().execute_with(|| { - // Snapshot of the initial data. - let bob_initial_balance = Balances::free_balance(BOB); - let validator_initial_balance = Balances::free_balance(BLOCK_AUTHOR); - let voucher_initial_balance = 1_000_000_000; - let program_id = H256::random().cast(); - - // Mocking of legacy voucher issue. - #[allow(deprecated)] - let voucher_account_id = - GearVoucher::call_deprecated_sponsor(&BOB, &prepaid_send(program_id)) - .expect("Shouldn't return None"); - - assert_ok!(Balances::transfer_allow_death( - RuntimeOrigin::signed(ALICE), - voucher_account_id, - voucher_initial_balance, - )); - - assert_eq!( - Balances::free_balance(voucher_account_id), - voucher_initial_balance - ); - - // Creating a RuntimeCall (deprecated) that should be free for caller. - let call = voucher_call_deprecated_send(program_id); - - // Creating simulation of weight params for call to calculate fee. - let len = 100usize; - let fee_length = LengthToFeeFor::::weight_to_fee(&Weight::from_parts(len as u64, 0)); - - let weight = Weight::from_parts(1_000, 0); - let fee_weight = WeightToFeeFor::::weight_to_fee(&weight); - - let call_fee = fee_length + fee_weight; - - // Pre-dispatch of the call. - let pre = CustomChargeTransactionPayment::::from(0) - .pre_dispatch(&BOB, &call, &info_from_weight(weight), len) - .unwrap(); - - // Bob hasn't paid fees. - assert_eq!(Balances::free_balance(BOB), bob_initial_balance); - - // But the voucher has. - assert_eq!( - Balances::free_balance(voucher_account_id), - voucher_initial_balance - call_fee, - ); - - // Validator hasn't received fee yet. - assert_eq!( - Balances::free_balance(BLOCK_AUTHOR), - validator_initial_balance - ); - - // Post-dispatch of the call. - assert_ok!(CustomChargeTransactionPayment::::post_dispatch( - Some(pre), - &info_from_weight(weight), - &default_post_info(), - len, - &Ok(()) - )); - - // Validating balances and validator reward. - assert_eq!(Balances::free_balance(BOB), bob_initial_balance); - assert_eq!( - Balances::free_balance(voucher_account_id), - voucher_initial_balance - call_fee, - ); - assert_eq!( - Balances::free_balance(BLOCK_AUTHOR), - validator_initial_balance + call_fee, - ); - }); -} - #[test] fn voucher_call_reply_payer_ok() { new_test_ext().execute_with(|| { @@ -1092,133 +1012,6 @@ fn voucher_call_reply_payer_ok() { }); } -#[test] -fn voucher_call_deprecated_reply_payer_ok() { - new_test_ext().execute_with(|| { - // Snapshot of the initial data. - let bob_initial_balance = Balances::free_balance(BOB); - let validator_initial_balance = Balances::free_balance(BLOCK_AUTHOR); - let voucher_initial_balance = 1_000_000_000; - let program_id = H256::random().cast(); - let reply_to_id = H256::random().cast(); - - // Inserting message into Bob-s mailbox. - assert_ok!(MailboxOf::::insert( - UserStoredMessage::new( - reply_to_id, - program_id, - BOB.cast(), - Default::default(), - Default::default(), - ), - 1_000, - )); - - // Mocking of legacy voucher issue. - #[allow(deprecated)] - let voucher_account_id = - GearVoucher::call_deprecated_sponsor(&BOB, &prepaid_reply(reply_to_id)) - .expect("Shouldn't return None"); - - assert_ok!(Balances::transfer_allow_death( - RuntimeOrigin::signed(ALICE), - voucher_account_id, - voucher_initial_balance, - )); - - assert_eq!( - Balances::free_balance(voucher_account_id), - voucher_initial_balance - ); - - // Creating a RuntimeCall (deprecated) that should be free for caller. - let call = voucher_call_deprecated_reply(reply_to_id); - - // Creating simulation of weight params for call to calculate fee. - let len = 100usize; - let fee_length = LengthToFeeFor::::weight_to_fee(&Weight::from_parts(len as u64, 0)); - - let weight = Weight::from_parts(1_000, 0); - let fee_weight = WeightToFeeFor::::weight_to_fee(&weight); - - let call_fee = fee_length + fee_weight; - - // Pre-dispatch of the call. - let pre = CustomChargeTransactionPayment::::from(0) - .pre_dispatch(&BOB, &call, &info_from_weight(weight), len) - .unwrap(); - - // Bob hasn't paid fees. - assert_eq!(Balances::free_balance(BOB), bob_initial_balance); - - // But the voucher has. - assert_eq!( - Balances::free_balance(voucher_account_id), - voucher_initial_balance - call_fee, - ); - - // Validator hasn't received fee yet. - assert_eq!( - Balances::free_balance(BLOCK_AUTHOR), - validator_initial_balance - ); - - // Post-dispatch of the call. - assert_ok!(CustomChargeTransactionPayment::::post_dispatch( - Some(pre), - &info_from_weight(weight), - &default_post_info(), - len, - &Ok(()) - )); - - // Validating balances and validator reward. - assert_eq!(Balances::free_balance(BOB), bob_initial_balance); - assert_eq!( - Balances::free_balance(voucher_account_id), - voucher_initial_balance - call_fee, - ); - assert_eq!( - Balances::free_balance(BLOCK_AUTHOR), - validator_initial_balance + call_fee, - ); - }); -} - -#[test] -fn voucher_call_deprecated_reply_payer_err() { - new_test_ext().execute_with(|| { - // Snapshot of the initial data. - let bob_initial_balance = Balances::free_balance(BOB); - let reply_to_id = H256::random().cast(); - - // Creating a RuntimeCall (deprecated) that should not be free for caller. - let call = voucher_call_deprecated_reply(reply_to_id); - - // Creating simulation of weight params for call to calculate fee. - let len = 1usize; - let fee_length = LengthToFeeFor::::weight_to_fee(&Weight::from_parts(len as u64, 0)); - - let weight = Weight::from_parts(1, 0); - let fee_weight = WeightToFeeFor::::weight_to_fee(&weight); - - let call_fee = fee_length + fee_weight; - - // Pre-dispatch of the call. - assert_ok!( - CustomChargeTransactionPayment::::from(0).pre_dispatch( - &BOB, - &call, - &info_from_weight(weight), - len - ) - ); - - // Bob has paid fees due to lack of destination for the call. - assert_eq!(Balances::free_balance(BOB), bob_initial_balance - call_fee); - }); -} - #[test] fn voucher_call_upload_payer_ok() { new_test_ext().execute_with(|| { @@ -1355,39 +1148,6 @@ fn voucher_call_upload_payer_forbidden_err() { }); } -#[test] -fn voucher_call_deprecated_upload_payer_err() { - new_test_ext().execute_with(|| { - // Snapshot of the initial data. - let bob_initial_balance = Balances::free_balance(BOB); - - // Creating a RuntimeCall (deprecated) that should not be free for caller. - let call = voucher_call_deprecated_upload(vec![]); - - // Creating simulation of weight params for call to calculate fee. - let len = 1usize; - let fee_length = LengthToFeeFor::::weight_to_fee(&Weight::from_parts(len as u64, 0)); - - let weight = Weight::from_parts(1, 0); - let fee_weight = WeightToFeeFor::::weight_to_fee(&weight); - - let call_fee = fee_length + fee_weight; - - // Pre-dispatch of the call. - assert_ok!( - CustomChargeTransactionPayment::::from(0).pre_dispatch( - &BOB, - &call, - &info_from_weight(weight), - len - ) - ); - - // Bob has paid fees due forbid for the code uploading in call_deprecated. - assert_eq!(Balances::free_balance(BOB), bob_initial_balance - call_fee); - }); -} - #[test] fn voucher_call_decline_payer_ok() { new_test_ext().execute_with(|| { @@ -1532,41 +1292,6 @@ fn voucher_call_decline_payer_expired_err() { }); } -#[test] -fn voucher_call_deprecated_decline_payer_err() { - new_test_ext().execute_with(|| { - // Snapshot of the initial data. - let bob_initial_balance = Balances::free_balance(BOB); - - // Creating a RuntimeCall (deprecated) that should not be free for caller. - let call = RuntimeCall::GearVoucher(VoucherCall::call_deprecated { - call: PrepaidCall::DeclineVoucher, - }); - - // Creating simulation of weight params for call to calculate fee. - let len = 1usize; - let fee_length = LengthToFeeFor::::weight_to_fee(&Weight::from_parts(len as u64, 0)); - - let weight = Weight::from_parts(1, 0); - let fee_weight = WeightToFeeFor::::weight_to_fee(&weight); - - let call_fee = fee_length + fee_weight; - - // Pre-dispatch of the call. - assert_ok!( - CustomChargeTransactionPayment::::from(0).pre_dispatch( - &BOB, - &call, - &info_from_weight(weight), - len - ) - ); - - // Bob has paid fees due forbid for the code uploading in call_deprecated. - assert_eq!(Balances::free_balance(BOB), bob_initial_balance - call_fee); - }); -} - mod utils { use super::*; use crate::BalanceOf; @@ -1585,12 +1310,6 @@ mod utils { }) } - pub fn voucher_call_deprecated_send(destination: ProgramId) -> RuntimeCall { - RuntimeCall::GearVoucher(VoucherCall::call_deprecated { - call: prepaid_send(destination), - }) - } - pub fn voucher_call_reply(voucher_id: VoucherId, reply_to_id: MessageId) -> RuntimeCall { RuntimeCall::GearVoucher(VoucherCall::call { voucher_id, @@ -1598,12 +1317,6 @@ mod utils { }) } - pub fn voucher_call_deprecated_reply(reply_to_id: MessageId) -> RuntimeCall { - RuntimeCall::GearVoucher(VoucherCall::call_deprecated { - call: prepaid_reply(reply_to_id), - }) - } - pub fn voucher_call_upload(voucher_id: VoucherId, code: Vec) -> RuntimeCall { RuntimeCall::GearVoucher(VoucherCall::call { voucher_id, @@ -1611,12 +1324,6 @@ mod utils { }) } - pub fn voucher_call_deprecated_upload(code: Vec) -> RuntimeCall { - RuntimeCall::GearVoucher(VoucherCall::call_deprecated { - call: PrepaidCall::UploadCode { code }, - }) - } - pub fn prepaid_send(destination: ProgramId) -> PrepaidCall> { PrepaidCall::SendMessage { destination,