From e8d17cbec9b7ea739f32e2d5f7d183558ce8efc1 Mon Sep 17 00:00:00 2001
From: Serban Iorga <serban@parity.io>
Date: Thu, 20 Feb 2025 11:04:39 +0200
Subject: [PATCH] derive `DecodeWithMemTracking` for `RuntimeCall` (#7634)

Related to https://github.com/paritytech/polkadot-sdk/issues/7360
---
 .../src/bridge_common_config.rs               | 19 +++++++++--
 prdoc/pr_7634.prdoc                           | 16 ++++++++++
 .../src/construct_runtime/expand/call.rs      |  1 +
 .../construct_runtime/expand/freeze_reason.rs |  5 ++-
 .../construct_runtime/expand/hold_reason.rs   |  5 ++-
 .../src/construct_runtime/expand/lock_id.rs   |  5 ++-
 .../src/construct_runtime/expand/origin.rs    |  9 ++++--
 .../construct_runtime/expand/outer_enums.rs   |  1 +
 .../construct_runtime/expand/slash_reason.rs  |  5 ++-
 .../src/construct_runtime/expand/task.rs      |  1 +
 .../construct_runtime/expand/view_function.rs |  1 +
 .../support/procedural/src/dynamic_params.rs  |  7 ++++
 .../procedural/src/pallet/expand/call.rs      |  1 +
 .../procedural/src/pallet/expand/error.rs     |  1 +
 .../procedural/src/pallet/expand/event.rs     |  1 +
 .../procedural/src/pallet/expand/tasks.rs     |  1 +
 .../src/pallet/expand/view_functions.rs       |  1 +
 .../procedural/src/pallet/parse/composite.rs  |  5 ++-
 .../pallet_error_too_large.rs                 | 32 ++++++++++++++++---
 .../pallet_error_too_large.stderr             | 24 +++++++-------
 .../call_argument_invalid_bound_3.rs          |  4 +--
 .../error_does_not_derive_pallet_error.rs     |  2 +-
 .../pallet_ui/pass/error_nested_types.rs      | 10 +++---
 23 files changed, 123 insertions(+), 34 deletions(-)
 create mode 100644 prdoc/pr_7634.prdoc

diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_common_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_common_config.rs
index ef86e7e4983..4ff417a4751 100644
--- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_common_config.rs
+++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_common_config.rs
@@ -24,7 +24,7 @@
 use super::{weights, AccountId, Balance, Balances, BlockNumber, Runtime, RuntimeEvent};
 use bp_messages::LegacyLaneId;
 use bp_relayers::RewardsAccountParams;
-use codec::{Decode, Encode, MaxEncodedLen};
+use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
 use frame_support::parameter_types;
 use scale_info::TypeInfo;
 use xcm::VersionedLocation;
@@ -36,7 +36,18 @@ parameter_types! {
 }
 
 /// Showcasing that we can handle multiple different rewards with the same pallet.
-#[derive(Clone, Copy, Debug, Decode, Encode, Eq, MaxEncodedLen, PartialEq, TypeInfo)]
+#[derive(
+	Clone,
+	Copy,
+	Debug,
+	Decode,
+	DecodeWithMemTracking,
+	Encode,
+	Eq,
+	MaxEncodedLen,
+	PartialEq,
+	TypeInfo,
+)]
 pub enum BridgeReward {
 	/// Rewards for the R/W bridge—distinguished by the `RewardsAccountParams` key.
 	RococoWestend(RewardsAccountParams<LegacyLaneId>),
@@ -51,7 +62,9 @@ impl From<RewardsAccountParams<LegacyLaneId>> for BridgeReward {
 }
 
 /// An enum representing the different types of supported beneficiaries.
-#[derive(Clone, Debug, Decode, Encode, Eq, MaxEncodedLen, PartialEq, TypeInfo)]
+#[derive(
+	Clone, Debug, Decode, DecodeWithMemTracking, Encode, Eq, MaxEncodedLen, PartialEq, TypeInfo,
+)]
 pub enum BridgeRewardBeneficiaries {
 	/// A local chain account.
 	LocalAccount(AccountId),
diff --git a/prdoc/pr_7634.prdoc b/prdoc/pr_7634.prdoc
new file mode 100644
index 00000000000..f1bdd383b2f
--- /dev/null
+++ b/prdoc/pr_7634.prdoc
@@ -0,0 +1,16 @@
+# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
+# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
+
+title: derive `DecodeWithMemTracking` for `RuntimeCall`
+
+doc:
+  - audience: Runtime Dev
+    description: |
+      This PR derives `DecodeWithMemTracking` for `RuntimeCall`.
+      All the types used in the `RuntimeCall` should implement `DecodeWithMemTracking` as well.
+
+crates:
+  - name: frame-support-procedural
+    bump: major
+  - name: bridge-hub-westend-runtime
+    bump: none
diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/call.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/call.rs
index 411d74ecbb3..43648118cab 100644
--- a/substrate/frame/support/procedural/src/construct_runtime/expand/call.rs
+++ b/substrate/frame/support/procedural/src/construct_runtime/expand/call.rs
@@ -62,6 +62,7 @@ pub fn expand_outer_dispatch(
 			Clone, PartialEq, Eq,
 			#scrate::__private::codec::Encode,
 			#scrate::__private::codec::Decode,
+			#scrate::__private::codec::DecodeWithMemTracking,
 			#scrate::__private::scale_info::TypeInfo,
 			#scrate::__private::RuntimeDebug,
 		)]
diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/freeze_reason.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/freeze_reason.rs
index f12f9952664..b36d54fb79e 100644
--- a/substrate/frame/support/procedural/src/construct_runtime/expand/freeze_reason.rs
+++ b/substrate/frame/support/procedural/src/construct_runtime/expand/freeze_reason.rs
@@ -58,7 +58,10 @@ pub fn expand_outer_freeze_reason(pallet_decls: &[Pallet], scrate: &TokenStream)
 		/// A reason for placing a freeze on funds.
 		#[derive(
 			Copy, Clone, Eq, PartialEq,
-			#scrate::__private::codec::Encode, #scrate::__private::codec::Decode, #scrate::__private::codec::MaxEncodedLen,
+			#scrate::__private::codec::Encode,
+			#scrate::__private::codec::Decode,
+			#scrate::__private::codec::DecodeWithMemTracking,
+			#scrate::__private::codec::MaxEncodedLen,
 			#scrate::__private::scale_info::TypeInfo,
 			#scrate::__private::RuntimeDebug,
 		)]
diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/hold_reason.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/hold_reason.rs
index cdab92712fd..b729c3d0a19 100644
--- a/substrate/frame/support/procedural/src/construct_runtime/expand/hold_reason.rs
+++ b/substrate/frame/support/procedural/src/construct_runtime/expand/hold_reason.rs
@@ -58,7 +58,10 @@ pub fn expand_outer_hold_reason(pallet_decls: &[Pallet], scrate: &TokenStream) -
 		/// A reason for placing a hold on funds.
 		#[derive(
 			Copy, Clone, Eq, PartialEq,
-			#scrate::__private::codec::Encode, #scrate::__private::codec::Decode, #scrate::__private::codec::MaxEncodedLen,
+			#scrate::__private::codec::Encode,
+			#scrate::__private::codec::Decode,
+			#scrate::__private::codec::DecodeWithMemTracking,
+			#scrate::__private::codec::MaxEncodedLen,
 			#scrate::__private::scale_info::TypeInfo,
 			#scrate::__private::RuntimeDebug,
 		)]
diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/lock_id.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/lock_id.rs
index e67c0da00ea..902acc58d5a 100644
--- a/substrate/frame/support/procedural/src/construct_runtime/expand/lock_id.rs
+++ b/substrate/frame/support/procedural/src/construct_runtime/expand/lock_id.rs
@@ -51,7 +51,10 @@ pub fn expand_outer_lock_id(pallet_decls: &[Pallet], scrate: &TokenStream) -> To
 		/// An identifier for each lock placed on funds.
 		#[derive(
 			Copy, Clone, Eq, PartialEq,
-			#scrate::__private::codec::Encode, #scrate::__private::codec::Decode, #scrate::__private::codec::MaxEncodedLen,
+			#scrate::__private::codec::Encode,
+			#scrate::__private::codec::Decode,
+			#scrate::__private::codec::DecodeWithMemTracking,
+			#scrate::__private::codec::MaxEncodedLen,
 			#scrate::__private::scale_info::TypeInfo,
 			#scrate::__private::RuntimeDebug,
 		)]
diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/origin.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/origin.rs
index aada9f7af75..7883541b901 100644
--- a/substrate/frame/support/procedural/src/construct_runtime/expand/origin.rs
+++ b/substrate/frame/support/procedural/src/construct_runtime/expand/origin.rs
@@ -200,8 +200,13 @@ pub fn expand_outer_origin(
 		}
 
 		#[derive(
-			Clone, PartialEq, Eq, #scrate::__private::RuntimeDebug, #scrate::__private::codec::Encode,
-			#scrate::__private::codec::Decode, #scrate::__private::scale_info::TypeInfo, #scrate::__private::codec::MaxEncodedLen,
+			Clone, PartialEq, Eq,
+			#scrate::__private::RuntimeDebug,
+			#scrate::__private::codec::Encode,
+			#scrate::__private::codec::Decode,
+			#scrate::__private::codec::DecodeWithMemTracking,
+			#scrate::__private::scale_info::TypeInfo,
+			#scrate::__private::codec::MaxEncodedLen,
 		)]
 		#[allow(non_camel_case_types)]
 		pub enum OriginCaller {
diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/outer_enums.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/outer_enums.rs
index 1f19687c36f..1495bd21012 100644
--- a/substrate/frame/support/procedural/src/construct_runtime/expand/outer_enums.rs
+++ b/substrate/frame/support/procedural/src/construct_runtime/expand/outer_enums.rs
@@ -159,6 +159,7 @@ pub fn expand_outer_enum(
 			#event_custom_derives
 			#scrate::__private::codec::Encode,
 			#scrate::__private::codec::Decode,
+			#scrate::__private::codec::DecodeWithMemTracking,
 			#scrate::__private::scale_info::TypeInfo,
 			#scrate::__private::Debug,
 		)]
diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/slash_reason.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/slash_reason.rs
index 892b842b174..a0e441dec26 100644
--- a/substrate/frame/support/procedural/src/construct_runtime/expand/slash_reason.rs
+++ b/substrate/frame/support/procedural/src/construct_runtime/expand/slash_reason.rs
@@ -51,7 +51,10 @@ pub fn expand_outer_slash_reason(pallet_decls: &[Pallet], scrate: &TokenStream)
 		/// A reason for slashing funds.
 		#[derive(
 			Copy, Clone, Eq, PartialEq,
-			#scrate::__private::codec::Encode, #scrate::__private::codec::Decode, #scrate::__private::codec::MaxEncodedLen,
+			#scrate::__private::codec::Encode,
+			#scrate::__private::codec::Decode,
+			#scrate::__private::codec::DecodeWithMemTracking,
+			#scrate::__private::codec::MaxEncodedLen,
 			#scrate::__private::scale_info::TypeInfo,
 			#scrate::__private::RuntimeDebug,
 		)]
diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs
index b9b8efb8c00..b1cf4f858de 100644
--- a/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs
+++ b/substrate/frame/support/procedural/src/construct_runtime/expand/task.rs
@@ -88,6 +88,7 @@ pub fn expand_outer_task(
 			Clone, Eq, PartialEq,
 			#scrate::__private::codec::Encode,
 			#scrate::__private::codec::Decode,
+			#scrate::__private::codec::DecodeWithMemTracking,
 			#scrate::__private::scale_info::TypeInfo,
 			#scrate::__private::RuntimeDebug,
 		)]
diff --git a/substrate/frame/support/procedural/src/construct_runtime/expand/view_function.rs b/substrate/frame/support/procedural/src/construct_runtime/expand/view_function.rs
index df6b4c42a9b..082a2e6ea30 100644
--- a/substrate/frame/support/procedural/src/construct_runtime/expand/view_function.rs
+++ b/substrate/frame/support/procedural/src/construct_runtime/expand/view_function.rs
@@ -43,6 +43,7 @@ pub fn expand_outer_query(
 			Clone, PartialEq, Eq,
 			#scrate::__private::codec::Encode,
 			#scrate::__private::codec::Decode,
+			#scrate::__private::codec::DecodeWithMemTracking,
 			#scrate::__private::scale_info::TypeInfo,
 			#scrate::__private::RuntimeDebug,
 		)]
diff --git a/substrate/frame/support/procedural/src/dynamic_params.rs b/substrate/frame/support/procedural/src/dynamic_params.rs
index ad62f59e6b0..9cc04e8a164 100644
--- a/substrate/frame/support/procedural/src/dynamic_params.rs
+++ b/substrate/frame/support/procedural/src/dynamic_params.rs
@@ -266,6 +266,7 @@ impl ToTokens for DynamicPalletParamAttr {
 					Eq,
 					#scrate::__private::codec::Encode,
 					#scrate::__private::codec::Decode,
+					#scrate::__private::codec::DecodeWithMemTracking,
 					#scrate::__private::codec::MaxEncodedLen,
 					#scrate::__private::RuntimeDebug,
 					#scrate::__private::scale_info::TypeInfo
@@ -284,6 +285,7 @@ impl ToTokens for DynamicPalletParamAttr {
 					Eq,
 					#scrate::__private::codec::Encode,
 					#scrate::__private::codec::Decode,
+					#scrate::__private::codec::DecodeWithMemTracking,
 					#scrate::__private::codec::MaxEncodedLen,
 					#scrate::__private::RuntimeDebug,
 					#scrate::__private::scale_info::TypeInfo
@@ -302,6 +304,7 @@ impl ToTokens for DynamicPalletParamAttr {
 					Eq,
 					#scrate::__private::codec::Encode,
 					#scrate::__private::codec::Decode,
+					#scrate::__private::codec::DecodeWithMemTracking,
 					#scrate::__private::codec::MaxEncodedLen,
 					#scrate::__private::RuntimeDebug,
 					#scrate::__private::scale_info::TypeInfo
@@ -336,6 +339,7 @@ impl ToTokens for DynamicPalletParamAttr {
 						Eq,
 						#scrate::__private::codec::Encode,
 						#scrate::__private::codec::Decode,
+						#scrate::__private::codec::DecodeWithMemTracking,
 						#scrate::__private::codec::MaxEncodedLen,
 						#scrate::__private::RuntimeDebug,
 						#scrate::__private::scale_info::TypeInfo
@@ -473,6 +477,7 @@ impl ToTokens for DynamicParamAggregatedEnum {
 				Eq,
 				#scrate::__private::codec::Encode,
 				#scrate::__private::codec::Decode,
+				#scrate::__private::codec::DecodeWithMemTracking,
 				#scrate::__private::codec::MaxEncodedLen,
 				#scrate::sp_runtime::RuntimeDebug,
 				#scrate::__private::scale_info::TypeInfo
@@ -492,6 +497,7 @@ impl ToTokens for DynamicParamAggregatedEnum {
 				Eq,
 				#scrate::__private::codec::Encode,
 				#scrate::__private::codec::Decode,
+				#scrate::__private::codec::DecodeWithMemTracking,
 				#scrate::__private::codec::MaxEncodedLen,
 				#scrate::sp_runtime::RuntimeDebug,
 				#scrate::__private::scale_info::TypeInfo
@@ -510,6 +516,7 @@ impl ToTokens for DynamicParamAggregatedEnum {
 				Eq,
 				#scrate::__private::codec::Encode,
 				#scrate::__private::codec::Decode,
+				#scrate::__private::codec::DecodeWithMemTracking,
 				#scrate::__private::codec::MaxEncodedLen,
 				#scrate::sp_runtime::RuntimeDebug,
 				#scrate::__private::scale_info::TypeInfo
diff --git a/substrate/frame/support/procedural/src/pallet/expand/call.rs b/substrate/frame/support/procedural/src/pallet/expand/call.rs
index 87fb4b8967e..a968b5f9df8 100644
--- a/substrate/frame/support/procedural/src/pallet/expand/call.rs
+++ b/substrate/frame/support/procedural/src/pallet/expand/call.rs
@@ -306,6 +306,7 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
 			#frame_support::PartialEqNoBound,
 			#frame_support::__private::codec::Encode,
 			#frame_support::__private::codec::Decode,
+			#frame_support::__private::codec::DecodeWithMemTracking,
 			#frame_support::__private::scale_info::TypeInfo,
 		)]
 		#[codec(encode_bound())]
diff --git a/substrate/frame/support/procedural/src/pallet/expand/error.rs b/substrate/frame/support/procedural/src/pallet/expand/error.rs
index 646655cfe14..5df82d453e0 100644
--- a/substrate/frame/support/procedural/src/pallet/expand/error.rs
+++ b/substrate/frame/support/procedural/src/pallet/expand/error.rs
@@ -122,6 +122,7 @@ pub fn expand_error(def: &mut Def) -> proc_macro2::TokenStream {
 		#[derive(
 			#frame_support::__private::codec::Encode,
 			#frame_support::__private::codec::Decode,
+			#frame_support::__private::codec::DecodeWithMemTracking,
 			#frame_support::__private::scale_info::TypeInfo,
 			#frame_support::PalletError,
 		)]
diff --git a/substrate/frame/support/procedural/src/pallet/expand/event.rs b/substrate/frame/support/procedural/src/pallet/expand/event.rs
index 45ca4b7df94..8ebf077d092 100644
--- a/substrate/frame/support/procedural/src/pallet/expand/event.rs
+++ b/substrate/frame/support/procedural/src/pallet/expand/event.rs
@@ -123,6 +123,7 @@ pub fn expand_event(def: &mut Def) -> proc_macro2::TokenStream {
 			#frame_support::DebugNoBound,
 			#frame_support::__private::codec::Encode,
 			#frame_support::__private::codec::Decode,
+			#frame_support::__private::codec::DecodeWithMemTracking,
 			#frame_support::__private::scale_info::TypeInfo,
 		)]
 	));
diff --git a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs
index b6346ca8ff3..6cd2436c464 100644
--- a/substrate/frame/support/procedural/src/pallet/expand/tasks.rs
+++ b/substrate/frame/support/procedural/src/pallet/expand/tasks.rs
@@ -99,6 +99,7 @@ impl TaskEnumDef {
 					#frame_support::PartialEqNoBound,
 					#frame_support::pallet_prelude::Encode,
 					#frame_support::pallet_prelude::Decode,
+					#frame_support::pallet_prelude::DecodeWithMemTracking,
 					#frame_support::pallet_prelude::TypeInfo,
 				)]
 				#[codec(encode_bound())]
diff --git a/substrate/frame/support/procedural/src/pallet/expand/view_functions.rs b/substrate/frame/support/procedural/src/pallet/expand/view_functions.rs
index 5838db9d89d..0222301852c 100644
--- a/substrate/frame/support/procedural/src/pallet/expand/view_functions.rs
+++ b/substrate/frame/support/procedural/src/pallet/expand/view_functions.rs
@@ -108,6 +108,7 @@ fn expand_view_function(
 			#frame_support::PartialEqNoBound,
 			#frame_support::__private::codec::Encode,
 			#frame_support::__private::codec::Decode,
+			#frame_support::__private::codec::DecodeWithMemTracking,
 			#frame_support::__private::scale_info::TypeInfo,
 		)]
 		#[codec(encode_bound())]
diff --git a/substrate/frame/support/procedural/src/pallet/parse/composite.rs b/substrate/frame/support/procedural/src/pallet/parse/composite.rs
index 20fc30cd26b..b3131d29f33 100644
--- a/substrate/frame/support/procedural/src/pallet/parse/composite.rs
+++ b/substrate/frame/support/procedural/src/pallet/parse/composite.rs
@@ -151,7 +151,10 @@ impl CompositeDef {
 			let derive_attr: syn::Attribute = syn::parse_quote! {
 				#[derive(
 					Copy, Clone, Eq, PartialEq,
-					#scrate::__private::codec::Encode, #scrate::__private::codec::Decode, #scrate::__private::codec::MaxEncodedLen,
+					#scrate::__private::codec::Encode,
+					#scrate::__private::codec::Decode,
+					#scrate::__private::codec::DecodeWithMemTracking,
+					#scrate::__private::codec::MaxEncodedLen,
 					#scrate::__private::scale_info::TypeInfo,
 					#scrate::__private::RuntimeDebug,
 				)]
diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.rs b/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.rs
index 3ec1d566961..fe1478a6369 100644
--- a/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.rs
+++ b/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.rs
@@ -33,22 +33,46 @@ mod pallet {
 	}
 }
 
-#[derive(scale_info::TypeInfo, frame_support::PalletError, codec::Encode, codec::Decode)]
+#[derive(
+	scale_info::TypeInfo,
+	frame_support::PalletError,
+	codec::Encode,
+	codec::Decode,
+	codec::DecodeWithMemTracking,
+)]
 pub enum Nested1 {
 	Nested2(Nested2),
 }
 
-#[derive(scale_info::TypeInfo, frame_support::PalletError, codec::Encode, codec::Decode)]
+#[derive(
+	scale_info::TypeInfo,
+	frame_support::PalletError,
+	codec::Encode,
+	codec::Decode,
+	codec::DecodeWithMemTracking,
+)]
 pub enum Nested2 {
 	Nested3(Nested3),
 }
 
-#[derive(scale_info::TypeInfo, frame_support::PalletError, codec::Encode, codec::Decode)]
+#[derive(
+	scale_info::TypeInfo,
+	frame_support::PalletError,
+	codec::Encode,
+	codec::Decode,
+	codec::DecodeWithMemTracking,
+)]
 pub enum Nested3 {
 	Nested4(Nested4),
 }
 
-#[derive(scale_info::TypeInfo, frame_support::PalletError, codec::Encode, codec::Decode)]
+#[derive(
+	scale_info::TypeInfo,
+	frame_support::PalletError,
+	codec::Encode,
+	codec::Decode,
+	codec::DecodeWithMemTracking,
+)]
 pub enum Nested4 {
 	Num(u8),
 }
diff --git a/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.stderr b/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.stderr
index 75116f71919..349fbab002c 100644
--- a/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.stderr
+++ b/substrate/frame/support/test/tests/construct_runtime_ui/pallet_error_too_large.stderr
@@ -1,13 +1,13 @@
 error[E0080]: evaluation of constant value failed
-  --> tests/construct_runtime_ui/pallet_error_too_large.rs:91:1
-   |
-91 | / construct_runtime! {
-92 | |     pub struct Runtime
-93 | |     {
-94 | |         System: frame_system::{Pallet, Call, Storage, Config<T>, Event<T>},
-95 | |         Pallet: pallet::{Pallet},
-96 | |     }
-97 | | }
-   | |_^ the evaluated program panicked at 'The maximum encoded size of the error type in the `Pallet` pallet exceeds `MAX_MODULE_ERROR_ENCODED_SIZE`', $DIR/tests/construct_runtime_ui/pallet_error_too_large.rs:91:1
-   |
-   = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `frame_support::construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info)
+   --> tests/construct_runtime_ui/pallet_error_too_large.rs:115:1
+    |
+115 | / construct_runtime! {
+116 | |     pub struct Runtime
+117 | |     {
+118 | |         System: frame_system::{Pallet, Call, Storage, Config<T>, Event<T>},
+119 | |         Pallet: pallet::{Pallet},
+120 | |     }
+121 | | }
+    | |_^ the evaluated program panicked at 'The maximum encoded size of the error type in the `Pallet` pallet exceeds `MAX_MODULE_ERROR_ENCODED_SIZE`', $DIR/tests/construct_runtime_ui/pallet_error_too_large.rs:115:1
+    |
+    = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `frame_support::construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_3.rs b/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_3.rs
index 22507b196e4..f4f13c8ef64 100644
--- a/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_3.rs
+++ b/substrate/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_3.rs
@@ -17,7 +17,7 @@
 
 #[frame_support::pallet]
 mod pallet {
-	use codec::{Decode, Encode};
+	use codec::{Decode, DecodeWithMemTracking, Encode};
 	use frame_support::pallet_prelude::{DispatchResultWithPostInfo, Hooks};
 	use frame_system::pallet_prelude::{BlockNumberFor, OriginFor};
 
@@ -30,7 +30,7 @@ mod pallet {
 	#[pallet::hooks]
 	impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
 
-	#[derive(Encode, Decode, scale_info::TypeInfo, PartialEq, Clone)]
+	#[derive(Encode, Decode, DecodeWithMemTracking, scale_info::TypeInfo, PartialEq, Clone)]
 	struct Bar;
 
 	#[pallet::call]
diff --git a/substrate/frame/support/test/tests/pallet_ui/error_does_not_derive_pallet_error.rs b/substrate/frame/support/test/tests/pallet_ui/error_does_not_derive_pallet_error.rs
index 3c6730471cb..ae7d4a3d48e 100644
--- a/substrate/frame/support/test/tests/pallet_ui/error_does_not_derive_pallet_error.rs
+++ b/substrate/frame/support/test/tests/pallet_ui/error_does_not_derive_pallet_error.rs
@@ -30,7 +30,7 @@ mod pallet {
 	}
 }
 
-#[derive(scale_info::TypeInfo, codec::Encode, codec::Decode)]
+#[derive(scale_info::TypeInfo, codec::Encode, codec::Decode, codec::DecodeWithMemTracking)]
 enum MyError {}
 
 fn main() {}
diff --git a/substrate/frame/support/test/tests/pallet_ui/pass/error_nested_types.rs b/substrate/frame/support/test/tests/pallet_ui/pass/error_nested_types.rs
index 0e0dc589051..008ff341957 100644
--- a/substrate/frame/support/test/tests/pallet_ui/pass/error_nested_types.rs
+++ b/substrate/frame/support/test/tests/pallet_ui/pass/error_nested_types.rs
@@ -15,7 +15,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-use codec::{Decode, Encode};
+use codec::{Decode, DecodeWithMemTracking, Encode};
 use frame_support::PalletError;
 
 #[frame_support::pallet]
@@ -33,7 +33,7 @@ mod pallet {
 	}
 }
 
-#[derive(Encode, Decode, PalletError, scale_info::TypeInfo)]
+#[derive(Encode, Decode, DecodeWithMemTracking, PalletError, scale_info::TypeInfo)]
 pub enum MyError {
 	Foo,
 	Bar,
@@ -42,17 +42,17 @@ pub enum MyError {
 	Wrapper(Wrapper),
 }
 
-#[derive(Encode, Decode, PalletError, scale_info::TypeInfo)]
+#[derive(Encode, Decode, DecodeWithMemTracking, PalletError, scale_info::TypeInfo)]
 pub enum NestedError {
 	Quux,
 }
 
-#[derive(Encode, Decode, PalletError, scale_info::TypeInfo)]
+#[derive(Encode, Decode, DecodeWithMemTracking, PalletError, scale_info::TypeInfo)]
 pub struct MyStruct {
 	field: u8,
 }
 
-#[derive(Encode, Decode, PalletError, scale_info::TypeInfo)]
+#[derive(Encode, Decode, DecodeWithMemTracking, PalletError, scale_info::TypeInfo)]
 pub struct Wrapper(bool);
 
 fn main() {}
-- 
GitLab