diff --git a/cumulus/pallets/parachain-system/src/block_weight/mock.rs b/cumulus/pallets/parachain-system/src/block_weight/mock.rs index 7dba292f55de3..8b2a738f26dc2 100644 --- a/cumulus/pallets/parachain-system/src/block_weight/mock.rs +++ b/cumulus/pallets/parachain-system/src/block_weight/mock.rs @@ -194,6 +194,7 @@ pub mod test_pallet { } } + #[allow(deprecated)] #[pallet::validate_unsigned] impl sp_runtime::traits::ValidateUnsigned for Pallet { type Call = Call; diff --git a/polkadot/runtime/common/src/claims/benchmarking.rs b/polkadot/runtime/common/src/claims/benchmarking.rs index f9150f7980e50..93fc24c72e085 100644 --- a/polkadot/runtime/common/src/claims/benchmarking.rs +++ b/polkadot/runtime/common/src/claims/benchmarking.rs @@ -26,10 +26,7 @@ use frame_support::{ }; use frame_system::RawOrigin; use secp_utils::*; -use sp_runtime::{ - traits::{DispatchTransaction, ValidateUnsigned}, - DispatchResult, -}; +use sp_runtime::{traits::DispatchTransaction, DispatchResult}; const SEED: u32 = 0; @@ -74,6 +71,9 @@ fn create_claim_attest(input: u32) -> DispatchResult { mod benchmarks { use super::*; + #[allow(deprecated)] + use sp_runtime::traits::ValidateUnsigned; + // Benchmark `claim` including `validate_unsigned` logic. #[benchmark] fn claim() -> Result<(), BenchmarkError> { @@ -104,6 +104,7 @@ mod benchmarks { { let call = as Decode>::decode(&mut &*call_enc) .expect("call is encoded above, encoding must be correct"); + #[allow(deprecated)] super::Pallet::::validate_unsigned(source, &call) .map_err(|e| -> &'static str { e.into() })?; call.dispatch_bypass_filter(RawOrigin::None.into())?; @@ -168,6 +169,7 @@ mod benchmarks { { let call = as Decode>::decode(&mut &*call_enc) .expect("call is encoded above, encoding must be correct"); + #[allow(deprecated)] super::Pallet::::validate_unsigned(source, &call) .map_err(|e| -> &'static str { e.into() })?; call.dispatch_bypass_filter(RawOrigin::None.into())?; diff --git a/polkadot/runtime/common/src/claims/mod.rs b/polkadot/runtime/common/src/claims/mod.rs index 234939da42110..eb7a29184b8aa 100644 --- a/polkadot/runtime/common/src/claims/mod.rs +++ b/polkadot/runtime/common/src/claims/mod.rs @@ -496,6 +496,7 @@ pub mod pallet { } } + #[allow(deprecated)] #[pallet::validate_unsigned] impl ValidateUnsigned for Pallet { type Call = Call; diff --git a/polkadot/runtime/common/src/claims/tests.rs b/polkadot/runtime/common/src/claims/tests.rs index dff2623cb9342..b420081d0568c 100644 --- a/polkadot/runtime/common/src/claims/tests.rs +++ b/polkadot/runtime/common/src/claims/tests.rs @@ -564,6 +564,7 @@ fn real_eth_sig_works() { } #[test] +#[allow(deprecated)] fn validate_unsigned_works() { use sp_runtime::traits::ValidateUnsigned; let source = sp_runtime::transaction_validity::TransactionSource::External; diff --git a/polkadot/runtime/parachains/src/disputes/slashing.rs b/polkadot/runtime/parachains/src/disputes/slashing.rs index a750ac7750e3a..a24b754635446 100644 --- a/polkadot/runtime/parachains/src/disputes/slashing.rs +++ b/polkadot/runtime/parachains/src/disputes/slashing.rs @@ -531,6 +531,7 @@ pub mod pallet { } } + #[allow(deprecated)] #[pallet::validate_unsigned] impl ValidateUnsigned for Pallet { type Call = Call; diff --git a/polkadot/runtime/parachains/src/paras/mod.rs b/polkadot/runtime/parachains/src/paras/mod.rs index 4ffdb98dcdb87..b8a2d4097af4b 100644 --- a/polkadot/runtime/parachains/src/paras/mod.rs +++ b/polkadot/runtime/parachains/src/paras/mod.rs @@ -1365,6 +1365,7 @@ pub mod pallet { } } + #[allow(deprecated)] #[pallet::validate_unsigned] impl ValidateUnsigned for Pallet { type Call = Call; diff --git a/polkadot/runtime/parachains/src/paras/tests.rs b/polkadot/runtime/parachains/src/paras/tests.rs index 04b7c1a1f6734..1facdd498e405 100644 --- a/polkadot/runtime/parachains/src/paras/tests.rs +++ b/polkadot/runtime/parachains/src/paras/tests.rs @@ -1457,6 +1457,7 @@ fn pvf_check_submit_vote() { let call = Call::include_pvf_check_statement { stmt: stmt.clone(), signature: signature.clone() }; + #[allow(deprecated)] let validate_unsigned = ::validate_unsigned(TransactionSource::InBlock, &call) .map(|_| ()); @@ -2263,6 +2264,7 @@ fn apply_authorized_force_set_current_code_works() { code: ValidationCode| -> (Result<_, _>, DispatchResultWithPostInfo) { let call = Call::apply_authorized_force_set_current_code { para, new_code: code.clone() }; + #[allow(deprecated)] let validate_unsigned = ::validate_unsigned(TransactionSource::InBlock, &call) .map(|_| ()); diff --git a/prdoc/pr_10150.prdoc b/prdoc/pr_10150.prdoc new file mode 100644 index 0000000000000..5084fdd43f168 --- /dev/null +++ b/prdoc/pr_10150.prdoc @@ -0,0 +1,40 @@ +title: Deprecate `ValidateUnsigned` trait and `#[pallet::validate_unsigned]` attribute. + +doc: + - audience: [Runtime Dev, Runtime User] + description: | + Deprecate the `ValidateUnsigned` trait and `#[pallet::validate_unsigned]` attribute as part of phase 2 of Extrinsic Horizon. + +crates: + - name: sp-runtime + bump: minor + - name: frame-system + bump: patch + - name: frame-support + bump: patch + - name: frame-support-procedural + bump: patch + - name: polkadot-runtime-common + bump: patch + - name: polkadot-runtime-parachains + bump: patch + - name: pallet-babe + bump: patch + - name: pallet-beefy + bump: patch + - name: pallet-election-provider-multi-phase + bump: patch + - name: pallet-election-provider-multi-block + bump: patch + - name: frame-executive + bump: patch + - name: pallet-grandpa + bump: patch + - name: pallet-im-online + bump: patch + - name: pallet-mixnet + bump: patch + - name: cumulus-pallet-parachain-system + bump: patch + - name: substrate-test-runtime + bump: patch \ No newline at end of file diff --git a/substrate/frame/babe/src/lib.rs b/substrate/frame/babe/src/lib.rs index 3dde0393bc026..aaff956b54fbf 100644 --- a/substrate/frame/babe/src/lib.rs +++ b/substrate/frame/babe/src/lib.rs @@ -476,6 +476,7 @@ pub mod pallet { } } + #[allow(deprecated)] #[pallet::validate_unsigned] impl ValidateUnsigned for Pallet { type Call = Call; diff --git a/substrate/frame/babe/src/tests.rs b/substrate/frame/babe/src/tests.rs index 9371a1d0e3ded..1b2fd1490a00b 100644 --- a/substrate/frame/babe/src/tests.rs +++ b/substrate/frame/babe/src/tests.rs @@ -717,6 +717,7 @@ fn report_equivocation_invalid_equivocation_proof() { } #[test] +#[allow(deprecated)] fn report_equivocation_validate_unsigned_prevents_duplicates() { use sp_runtime::transaction_validity::{ InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity, diff --git a/substrate/frame/beefy/src/lib.rs b/substrate/frame/beefy/src/lib.rs index 992226e5b2164..69b3731a02c11 100644 --- a/substrate/frame/beefy/src/lib.rs +++ b/substrate/frame/beefy/src/lib.rs @@ -422,6 +422,7 @@ pub mod pallet { } } + #[allow(deprecated)] #[pallet::validate_unsigned] impl ValidateUnsigned for Pallet { type Call = Call; diff --git a/substrate/frame/beefy/src/tests.rs b/substrate/frame/beefy/src/tests.rs index 0a43831508862..2aa1c5c41bc16 100644 --- a/substrate/frame/beefy/src/tests.rs +++ b/substrate/frame/beefy/src/tests.rs @@ -728,6 +728,7 @@ fn report_double_voting_invalid_equivocation_proof() { } #[test] +#[allow(deprecated)] fn report_double_voting_validate_unsigned_prevents_duplicates() { use sp_runtime::transaction_validity::{ InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity, diff --git a/substrate/frame/election-provider-multi-block/src/lib.rs b/substrate/frame/election-provider-multi-block/src/lib.rs index 7869c806fcca3..2c15488328fce 100644 --- a/substrate/frame/election-provider-multi-block/src/lib.rs +++ b/substrate/frame/election-provider-multi-block/src/lib.rs @@ -2753,9 +2753,7 @@ mod election_provider { Phase, }; use frame_election_provider_support::{BoundedSupport, BoundedSupports, ElectionProvider}; - use frame_support::{ - assert_storage_noop, testing_prelude::bounded_vec, unsigned::ValidateUnsigned, - }; + use frame_support::{assert_storage_noop, testing_prelude::bounded_vec}; // This is probably the most important test of all, a basic, correct scenario. This test should // be studied in detail, and all of the branches of how it can go wrong or diverge from the @@ -3059,7 +3057,9 @@ mod election_provider { } #[test] + #[allow(deprecated)] fn call_to_elect_should_prevent_any_submission() { + use frame_support::unsigned::ValidateUnsigned; ExtBuilder::full().build_and_execute(|| { roll_to_signed_open(); assert!(MultiBlock::current_phase().is_signed()); diff --git a/substrate/frame/election-provider-multi-block/src/unsigned/benchmarking.rs b/substrate/frame/election-provider-multi-block/src/unsigned/benchmarking.rs index 72b3e30ac3ec6..aa249394cfc4f 100644 --- a/substrate/frame/election-provider-multi-block/src/unsigned/benchmarking.rs +++ b/substrate/frame/election-provider-multi-block/src/unsigned/benchmarking.rs @@ -45,7 +45,9 @@ mod benchmarks { #[block] { - assert_ok!(Pallet::::validate_unsigned(TransactionSource::Local, &call)); + #[allow(deprecated)] + let result = Pallet::::validate_unsigned(TransactionSource::Local, &call); + assert_ok!(result); } Ok(()) diff --git a/substrate/frame/election-provider-multi-block/src/unsigned/mod.rs b/substrate/frame/election-provider-multi-block/src/unsigned/mod.rs index 8afafd2af5713..e9ea21d8cc1bf 100644 --- a/substrate/frame/election-provider-multi-block/src/unsigned/mod.rs +++ b/substrate/frame/election-provider-multi-block/src/unsigned/mod.rs @@ -180,6 +180,7 @@ mod pallet { } } + #[allow(deprecated)] #[pallet::validate_unsigned] impl ValidateUnsigned for Pallet { type Call = Call; @@ -370,6 +371,7 @@ mod pallet { } #[cfg(test)] +#[allow(deprecated)] mod validate_unsigned { use frame_election_provider_support::Support; use frame_support::{ diff --git a/substrate/frame/election-provider-multi-phase/src/lib.rs b/substrate/frame/election-provider-multi-phase/src/lib.rs index 7bdc592476e08..ed970ced1bc3b 100644 --- a/substrate/frame/election-provider-multi-phase/src/lib.rs +++ b/substrate/frame/election-provider-multi-phase/src/lib.rs @@ -1214,6 +1214,7 @@ pub mod pallet { PreDispatchDifferentRound, } + #[allow(deprecated)] #[pallet::validate_unsigned] impl ValidateUnsigned for Pallet { type Call = Call; diff --git a/substrate/frame/election-provider-multi-phase/src/unsigned.rs b/substrate/frame/election-provider-multi-phase/src/unsigned.rs index 703e4910b83b8..510e042ac9e6f 100644 --- a/substrate/frame/election-provider-multi-phase/src/unsigned.rs +++ b/substrate/frame/election-provider-multi-phase/src/unsigned.rs @@ -1111,13 +1111,17 @@ mod tests { use sp_runtime::{ bounded_vec, offchain::storage_lock::{BlockAndTime, StorageLock}, - traits::{Dispatchable, ValidateUnsigned, Zero}, + traits::{Dispatchable, Zero}, ModuleError, PerU16, }; + #[allow(deprecated)] + use sp_runtime::traits::ValidateUnsigned; + type Assignment = crate::unsigned::Assignment; #[test] + #[allow(deprecated)] fn validate_unsigned_retracts_wrong_phase() { ExtBuilder::default().desired_targets(0).build_and_execute(|| { let solution = RawSolution:: { @@ -1190,6 +1194,7 @@ mod tests { } #[test] + #[allow(deprecated)] fn validate_unsigned_retracts_low_score() { ExtBuilder::default().desired_targets(0).build_and_execute(|| { roll_to_unsigned(); @@ -1236,6 +1241,7 @@ mod tests { } #[test] + #[allow(deprecated)] fn validate_unsigned_retracts_incorrect_winner_count() { ExtBuilder::default().desired_targets(1).build_and_execute(|| { roll_to_unsigned(); @@ -1262,6 +1268,7 @@ mod tests { } #[test] + #[allow(deprecated)] fn priority_is_set() { ExtBuilder::default() .miner_tx_priority(20) @@ -1907,6 +1914,7 @@ mod tests { } #[test] + #[allow(deprecated)] fn ocw_solution_must_have_correct_round() { let (mut ext, pool) = ExtBuilder::default().build_offchainify(0); ext.execute_with(|| { diff --git a/substrate/frame/executive/src/lib.rs b/substrate/frame/executive/src/lib.rs index ad1ee38e4ec64..0c7894f98a810 100644 --- a/substrate/frame/executive/src/lib.rs +++ b/substrate/frame/executive/src/lib.rs @@ -68,14 +68,6 @@ //! # use sp_runtime::transaction_validity::{ //! # TransactionValidity, UnknownTransaction, TransactionSource, //! # }; -//! # use sp_runtime::traits::ValidateUnsigned; -//! # impl ValidateUnsigned for Runtime { -//! # type Call = (); -//! # -//! # fn validate_unsigned(_source: TransactionSource, _call: &Self::Call) -> TransactionValidity { -//! # UnknownTransaction::NoUnsignedValidator.into() -//! # } -//! # } //! /// Executive: handles dispatch to the various modules. //! pub type Executive = executive::Executive; //! ``` @@ -135,12 +127,15 @@ use sp_runtime::{ generic::Digest, traits::{ self, Applyable, CheckEqual, Checkable, Dispatchable, Header, LazyBlock, NumberFor, One, - ValidateUnsigned, Zero, + Zero, }, transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError}, ApplyExtrinsicResult, ExtrinsicInclusionMode, }; +#[allow(deprecated)] +use sp_runtime::traits::ValidateUnsigned; + #[cfg(feature = "try-runtime")] use ::{ frame_support::{ diff --git a/substrate/frame/executive/src/tests.rs b/substrate/frame/executive/src/tests.rs index b12f3aa474824..fa307a2869f31 100644 --- a/substrate/frame/executive/src/tests.rs +++ b/substrate/frame/executive/src/tests.rs @@ -145,6 +145,7 @@ mod custom { } } + #[allow(deprecated)] #[pallet::validate_unsigned] impl ValidateUnsigned for Pallet { type Call = Call; @@ -267,6 +268,7 @@ mod custom2 { } } + #[allow(deprecated)] #[pallet::validate_unsigned] impl ValidateUnsigned for Pallet { type Call = Call; diff --git a/substrate/frame/grandpa/src/lib.rs b/substrate/frame/grandpa/src/lib.rs index 0451792e977c6..62c191c6f7ab2 100644 --- a/substrate/frame/grandpa/src/lib.rs +++ b/substrate/frame/grandpa/src/lib.rs @@ -359,6 +359,7 @@ pub mod pallet { } } + #[allow(deprecated)] #[pallet::validate_unsigned] impl ValidateUnsigned for Pallet { type Call = Call; diff --git a/substrate/frame/grandpa/src/tests.rs b/substrate/frame/grandpa/src/tests.rs index 0960efeb10b2a..2402955c95efe 100644 --- a/substrate/frame/grandpa/src/tests.rs +++ b/substrate/frame/grandpa/src/tests.rs @@ -661,6 +661,7 @@ fn report_equivocation_invalid_equivocation_proof() { } #[test] +#[allow(deprecated)] fn report_equivocation_validate_unsigned_prevents_duplicates() { use sp_runtime::transaction_validity::{ InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity, diff --git a/substrate/frame/im-online/src/benchmarking.rs b/substrate/frame/im-online/src/benchmarking.rs index 06b7231b1f485..c561e32bcfda6 100644 --- a/substrate/frame/im-online/src/benchmarking.rs +++ b/substrate/frame/im-online/src/benchmarking.rs @@ -22,10 +22,7 @@ use frame_benchmarking::v2::*; use frame_support::{traits::UnfilteredDispatchable, WeakBoundedVec}; use frame_system::RawOrigin; -use sp_runtime::{ - traits::{ValidateUnsigned, Zero}, - transaction_validity::TransactionSource, -}; +use sp_runtime::{traits::Zero, transaction_validity::TransactionSource}; use crate::*; @@ -83,6 +80,7 @@ mod benchmarks { #[block] { + #[allow(deprecated)] Pallet::::validate_unsigned(TransactionSource::InBlock, &call) .map_err(<&str>::from)?; } @@ -100,6 +98,7 @@ mod benchmarks { #[block] { + #[allow(deprecated)] Pallet::::validate_unsigned(TransactionSource::InBlock, &call) .map_err(<&str>::from)?; as Decode>::decode(&mut &*call_enc) diff --git a/substrate/frame/im-online/src/lib.rs b/substrate/frame/im-online/src/lib.rs index dc18f394a767c..0051cdc6c04f7 100644 --- a/substrate/frame/im-online/src/lib.rs +++ b/substrate/frame/im-online/src/lib.rs @@ -447,6 +447,7 @@ pub mod pallet { /// incorrect. pub(crate) const INVALID_VALIDATORS_LEN: u8 = 10; + #[allow(deprecated)] #[pallet::validate_unsigned] impl ValidateUnsigned for Pallet { type Call = Call; diff --git a/substrate/frame/im-online/src/tests.rs b/substrate/frame/im-online/src/tests.rs index 5a5c69b43b122..c8307be138961 100644 --- a/substrate/frame/im-online/src/tests.rs +++ b/substrate/frame/im-online/src/tests.rs @@ -120,6 +120,7 @@ fn heartbeat( }; let signature = id.sign(&heartbeat.encode()).unwrap(); + #[allow(deprecated)] ImOnline::pre_dispatch(&crate::Call::heartbeat { heartbeat: heartbeat.clone(), signature: signature.clone(), diff --git a/substrate/frame/mixnet/src/lib.rs b/substrate/frame/mixnet/src/lib.rs index 8fdadc0dfe6f2..edb43bf6f1c99 100644 --- a/substrate/frame/mixnet/src/lib.rs +++ b/substrate/frame/mixnet/src/lib.rs @@ -303,6 +303,7 @@ pub mod pallet { } } + #[allow(deprecated)] #[pallet::validate_unsigned] impl ValidateUnsigned for Pallet { type Call = Call; diff --git a/substrate/frame/sassafras/src/lib.rs b/substrate/frame/sassafras/src/lib.rs index f54387b2a8b6e..1bf8cefa9358a 100644 --- a/substrate/frame/sassafras/src/lib.rs +++ b/substrate/frame/sassafras/src/lib.rs @@ -463,6 +463,7 @@ pub mod pallet { } } + #[allow(deprecated)] #[pallet::validate_unsigned] impl ValidateUnsigned for Pallet { type Call = Call; diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/unsigned.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/unsigned.rs index 737a39ea681e0..ab30d194d2326 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/expand/unsigned.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/expand/unsigned.rs @@ -46,6 +46,7 @@ pub fn expand_outer_validate_unsigned( quote! { #( #query_validate_unsigned_part_macros )* + #[allow(deprecated)] impl #scrate::unsigned::ValidateUnsigned for #runtime { type Call = RuntimeCall; diff --git a/substrate/frame/support/procedural/src/pallet/expand/validate_unsigned.rs b/substrate/frame/support/procedural/src/pallet/expand/validate_unsigned.rs index 8769955851712..cd99c7f09c909 100644 --- a/substrate/frame/support/procedural/src/pallet/expand/validate_unsigned.rs +++ b/substrate/frame/support/procedural/src/pallet/expand/validate_unsigned.rs @@ -25,6 +25,12 @@ pub fn expand_validate_unsigned(def: &mut Def) -> TokenStream { let macro_ident = Ident::new(&format!("__is_validate_unsigned_part_defined_{}", count), def.item.span()); + let maybe_compile_warning = def + .validate_unsigned + .as_ref() + .and_then(|v| v.warning.as_ref()) + .map_or_else(|| TokenStream::new(), |w| quote! { #w }); + let maybe_compile_error = if def.validate_unsigned.is_none() { quote! { compile_error!(concat!( @@ -48,7 +54,7 @@ pub fn expand_validate_unsigned(def: &mut Def) -> TokenStream { #maybe_compile_error } } - + #maybe_compile_warning #[doc(hidden)] pub use #macro_ident as is_validate_unsigned_part_defined; } diff --git a/substrate/frame/support/procedural/src/pallet/parse/validate_unsigned.rs b/substrate/frame/support/procedural/src/pallet/parse/validate_unsigned.rs index 9f59d26aac82d..e21735e2e4e7e 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/validate_unsigned.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/validate_unsigned.rs @@ -16,10 +16,15 @@ // limitations under the License. use super::helper; +use crate::COUNTER; +use proc_macro_warning::FormattedWarning; use syn::spanned::Spanned; /// The definition of the pallet validate unsigned implementation. -pub struct ValidateUnsignedDef {} +pub struct ValidateUnsignedDef { + /// Compile time warning. + pub warning: Option, +} impl ValidateUnsignedDef { pub fn try_from(item: &mut syn::Item) -> syn::Result { @@ -50,6 +55,24 @@ impl ValidateUnsignedDef { helper::check_pallet_struct_usage(&item.self_ty)?; helper::check_impl_gen(&item.generics, item.impl_token.span())?; - Ok(ValidateUnsignedDef {}) + // Check if the `#[allow(deprecated)]` attribute is present + let allow_dep: syn::Attribute = syn::parse_quote!(#[allow(deprecated)]); + let warning = if item.attrs.iter().any(|attr| attr == &allow_dep) { + None + } else { + const DEPRECATION_MSG: &str = "#[pallet::validate_unsigned] will be removed after \ + April 2027. Use `#[pallet::authorize]` with `frame_system::AuthorizeCall` instead."; + const REFERENCE_LINK: &str = "https://github.com/paritytech/polkadot-sdk/issues/2415"; + let count = COUNTER.with(|counter| counter.borrow_mut().inc()); + let warning = proc_macro_warning::FormattedWarning::new_deprecated( + format!("validate_unsigned_deprecation_{count}"), + format!("\n{DEPRECATION_MSG}\n\n\t\tFor more info see:\n\t\t\t{REFERENCE_LINK}"), + item.span(), + ); + + Some(warning) + }; + + Ok(ValidateUnsignedDef { warning }) } } diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs index d017a9402a89c..5b4ee6164e5ec 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -96,6 +96,7 @@ pub mod view_functions; pub mod weights; #[doc(hidden)] pub mod unsigned { + #[allow(deprecated)] #[doc(hidden)] pub use crate::sp_runtime::traits::ValidateUnsigned; #[doc(hidden)] @@ -447,8 +448,7 @@ pub mod pallet_prelude { pub use sp_runtime::{ traits::{ CheckedAdd, CheckedConversion, CheckedDiv, CheckedMul, CheckedShl, CheckedShr, - CheckedSub, MaybeSerializeDeserialize, Member, One, ValidateResult, ValidateUnsigned, - Zero, + CheckedSub, MaybeSerializeDeserialize, Member, One, ValidateResult, Zero, }, transaction_validity::{ InvalidTransaction, TransactionLongevity, TransactionPriority, TransactionSource, @@ -458,6 +458,9 @@ pub mod pallet_prelude { Debug, DispatchError, MAX_MODULE_ERROR_ENCODED_SIZE, }; pub use sp_weights::Weight; + + #[allow(deprecated)] + pub use sp_runtime::traits::ValidateUnsigned; } /// The pallet macro has 2 purposes: @@ -1213,6 +1216,13 @@ pub mod pallet_macros { /// } pub use frame_support_procedural::composite_enum; + /// Deprecation Notice + /// + /// The `#[pallet::validate_unsigned]` attribute has been deprecated and will be removed in + /// a future release. Use [`sp_runtime::traits::TransactionExtension`] instead. + /// + /// For more information, see: + /// --- /// Allows the pallet to validate unsigned transactions. /// /// Item must be defined as: diff --git a/substrate/frame/support/test/tests/pallet.rs b/substrate/frame/support/test/tests/pallet.rs index 7d50c0008a843..c9e56ae9c9708 100644 --- a/substrate/frame/support/test/tests/pallet.rs +++ b/substrate/frame/support/test/tests/pallet.rs @@ -504,6 +504,7 @@ pub mod pallet { )] pub struct Origin(PhantomData); + #[allow(deprecated)] #[pallet::validate_unsigned] impl ValidateUnsigned for Pallet where @@ -1074,11 +1075,13 @@ fn inherent_expand() { } #[test] +#[allow(deprecated)] fn validate_unsigned_expand() { use frame_support::pallet_prelude::{ InvalidTransaction, TransactionSource, TransactionValidityError, ValidTransaction, ValidateUnsigned, }; + let call = pallet::Call::::foo_no_post_info {}; let validity = pallet::Pallet::validate_unsigned(TransactionSource::Local, &call).unwrap_err(); diff --git a/substrate/frame/support/test/tests/pallet_instance.rs b/substrate/frame/support/test/tests/pallet_instance.rs index 0ab763eaa89cd..974f132110f9a 100644 --- a/substrate/frame/support/test/tests/pallet_instance.rs +++ b/substrate/frame/support/test/tests/pallet_instance.rs @@ -221,6 +221,7 @@ pub mod pallet { #[scale_info(skip_type_params(T, I))] pub struct Origin(PhantomData<(T, I)>); + #[allow(deprecated)] #[pallet::validate_unsigned] impl, I: 'static> ValidateUnsigned for Pallet { type Call = Call; diff --git a/substrate/frame/support/test/tests/runtime.rs b/substrate/frame/support/test/tests/runtime.rs index 416fae5feb5fc..b74c9a5bcad41 100644 --- a/substrate/frame/support/test/tests/runtime.rs +++ b/substrate/frame/support/test/tests/runtime.rs @@ -33,7 +33,7 @@ use scale_info::TypeInfo; use sp_core::sr25519; use sp_runtime::{ generic, - traits::{BlakeTwo256, ValidateUnsigned, Verify}, + traits::{BlakeTwo256, Verify}, DispatchError, ModuleError, }; use sp_version::RuntimeVersion; @@ -197,6 +197,7 @@ mod nested { fn build(&self) {} } + #[allow(deprecated)] #[pallet::validate_unsigned] impl ValidateUnsigned for Pallet { type Call = Call; @@ -285,6 +286,7 @@ pub mod module3 { #[pallet::storage] pub type Storage = StorageValue<_, u32>; + #[allow(deprecated)] #[pallet::validate_unsigned] impl ValidateUnsigned for Pallet { type Call = Call; @@ -1011,10 +1013,12 @@ fn test_validate_unsigned() { use frame_support::pallet_prelude::*; let call = RuntimeCall::NestedModule3(nested::module3::Call::fail {}); + #[allow(deprecated)] let validity = Runtime::validate_unsigned(TransactionSource::Local, &call).unwrap_err(); assert_eq!(validity, TransactionValidityError::Invalid(InvalidTransaction::Call)); let call = RuntimeCall::Module3(module3::Call::fail {}); + #[allow(deprecated)] let validity = Runtime::validate_unsigned(TransactionSource::Local, &call).unwrap_err(); assert_eq!( validity, diff --git a/substrate/frame/support/test/tests/runtime_legacy_ordering.rs b/substrate/frame/support/test/tests/runtime_legacy_ordering.rs index e25c803a56a34..4873c7cb5d1a1 100644 --- a/substrate/frame/support/test/tests/runtime_legacy_ordering.rs +++ b/substrate/frame/support/test/tests/runtime_legacy_ordering.rs @@ -33,7 +33,7 @@ use scale_info::TypeInfo; use sp_core::sr25519; use sp_runtime::{ generic, - traits::{BlakeTwo256, ValidateUnsigned, Verify}, + traits::{BlakeTwo256, Verify}, DispatchError, ModuleError, }; use sp_version::RuntimeVersion; @@ -197,6 +197,7 @@ mod nested { fn build(&self) {} } + #[allow(deprecated)] #[pallet::validate_unsigned] impl ValidateUnsigned for Pallet { type Call = Call; @@ -285,6 +286,7 @@ pub mod module3 { #[pallet::storage] pub type Storage = StorageValue<_, u32>; + #[allow(deprecated)] #[pallet::validate_unsigned] impl ValidateUnsigned for Pallet { type Call = Call; @@ -1011,10 +1013,12 @@ fn test_validate_unsigned() { use frame_support::pallet_prelude::*; let call = RuntimeCall::NestedModule3(nested::module3::Call::fail {}); + #[allow(deprecated)] let validity = Runtime::validate_unsigned(TransactionSource::Local, &call).unwrap_err(); assert_eq!(validity, TransactionValidityError::Invalid(InvalidTransaction::Call)); let call = RuntimeCall::Module3(module3::Call::fail {}); + #[allow(deprecated)] let validity = Runtime::validate_unsigned(TransactionSource::Local, &call).unwrap_err(); assert_eq!( validity, diff --git a/substrate/frame/support/test/tests/tasks.rs b/substrate/frame/support/test/tests/tasks.rs index 9a61da0ec8f0a..5ec21d609475f 100644 --- a/substrate/frame/support/test/tests/tasks.rs +++ b/substrate/frame/support/test/tests/tasks.rs @@ -135,6 +135,7 @@ fn tasks_work() { } #[test] +#[allow(deprecated)] fn do_task_unsigned_validation_rejects_external_source() { new_test_ext().execute_with(|| { use frame_support::pallet_prelude::{ diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index 673ab8d5f6e9d..fb7576141d56c 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -1132,8 +1132,9 @@ pub mod pallet { } } + #[allow(deprecated)] #[pallet::validate_unsigned] - impl sp_runtime::traits::ValidateUnsigned for Pallet { + impl ValidateUnsigned for Pallet { type Call = Call; fn validate_unsigned(source: TransactionSource, call: &Self::Call) -> TransactionValidity { if let Call::apply_authorized_upgrade { ref code } = call { diff --git a/substrate/primitives/runtime/src/generic/checked_extrinsic.rs b/substrate/primitives/runtime/src/generic/checked_extrinsic.rs index 62b738559ed5d..560b7b543c66e 100644 --- a/substrate/primitives/runtime/src/generic/checked_extrinsic.rs +++ b/substrate/primitives/runtime/src/generic/checked_extrinsic.rs @@ -23,7 +23,7 @@ use crate::{ traits::{ self, AsTransactionAuthorizedOrigin, DispatchInfoOf, DispatchTransaction, Dispatchable, ExtensionVariant, InvalidVersion, MaybeDisplay, Member, Pipeline, PostDispatchInfoOf, - TransactionExtension, ValidateUnsigned, + TransactionExtension, }, transaction_validity::{TransactionSource, TransactionValidity}, }; @@ -90,7 +90,8 @@ where { type Call = Call; - fn validate>( + #[allow(deprecated)] + fn validate>( &self, source: TransactionSource, info: &DispatchInfoOf, @@ -114,7 +115,8 @@ where } } - fn apply>( + #[allow(deprecated)] + fn apply>( self, info: &DispatchInfoOf, len: usize, diff --git a/substrate/primitives/runtime/src/traits/mod.rs b/substrate/primitives/runtime/src/traits/mod.rs index 3dd4173bf19de..28aae6fe2c52c 100644 --- a/substrate/primitives/runtime/src/traits/mod.rs +++ b/substrate/primitives/runtime/src/traits/mod.rs @@ -1861,6 +1861,7 @@ pub trait Applyable: Sized + Send + Sync { /// /// IMPORTANT: Ensure that *some* origin has been authorized after validating the transaction. /// If no origin was authorized, the transaction must be rejected. + #[allow(deprecated)] fn validate>( &self, source: TransactionSource, @@ -1873,6 +1874,7 @@ pub trait Applyable: Sized + Send + Sync { /// /// IMPORTANT: Ensure that *some* origin has been authorized after validating the /// transaction. If no origin was authorized, the transaction must be rejected. + #[allow(deprecated)] fn apply>( self, info: &DispatchInfoOf, @@ -1899,6 +1901,16 @@ pub trait GetNodeBlockType { /// function is called right before dispatching the call wrapped by an unsigned extrinsic. The /// [`validate_unsigned`](Self::validate_unsigned) function is mainly being used in the context of /// the transaction pool to check the validity of the call wrapped by an unsigned extrinsic. +/// +/// # Deprecation Notice +/// +/// This trait is deprecated and will be removed after April 2027. Use +/// `#[pallet::authorize]` with `frame_system::AuthorizeCall` transaction extension instead. +/// +/// For more information, see: +#[deprecated( + note = "`ValidateUnsigned` will be removed after April 2027. Use `#[pallet::authorize]` with `frame_system::AuthorizeCall` instead. See https://github.com/paritytech/polkadot-sdk/issues/2415" +)] pub trait ValidateUnsigned { /// The call to validate type Call; diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index ff59929d4e59c..637aabddcf93e 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -1266,6 +1266,7 @@ mod tests { } #[test] + #[allow(deprecated)] fn validate_unsigned_works() { sp_tracing::try_init_simple(); new_test_ext().execute_with(|| { diff --git a/substrate/test-utils/runtime/src/substrate_test_pallet.rs b/substrate/test-utils/runtime/src/substrate_test_pallet.rs index b128935aff509..7cf931f0e744d 100644 --- a/substrate/test-utils/runtime/src/substrate_test_pallet.rs +++ b/substrate/test-utils/runtime/src/substrate_test_pallet.rs @@ -217,6 +217,7 @@ pub mod pallet { } } + #[allow(deprecated)] #[pallet::validate_unsigned] impl ValidateUnsigned for Pallet { type Call = Call;