From fd3981b1c85abf4cbe3feb5b439789b002cecff7 Mon Sep 17 00:00:00 2001
From: Serban Iorga <serban@parity.io>
Date: Tue, 4 Feb 2025 14:15:33 +0200
Subject: [PATCH] Fix duplicate codec indexes (#7446)

Related to https://github.com/paritytech/polkadot-sdk/issues/7400 and
https://github.com/paritytech/polkadot-sdk/pull/7417

We need this in order to be able to update `parity-scale-codec` to the
latest version after it's released. That's because `parity-scale-codec`
added support for checking for duplicate indexes at compile time.

(cherry picked from commit 37446fcbb05150cd304fde157f87e9004f203403)
---
 substrate/frame/parameters/src/tests/mock.rs  |  2 +-
 .../src/construct_runtime/expand/origin.rs    |  1 +
 .../support/test/tests/enum_deprecation.rs    | 22 +++++++------------
 3 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/substrate/frame/parameters/src/tests/mock.rs b/substrate/frame/parameters/src/tests/mock.rs
index 53a3b3e394c..8d6f7d25cea 100644
--- a/substrate/frame/parameters/src/tests/mock.rs
+++ b/substrate/frame/parameters/src/tests/mock.rs
@@ -75,7 +75,7 @@ pub mod dynamic_params {
 	}
 
 	#[dynamic_pallet_params]
-	#[codec(index = 3)]
+	#[codec(index = 4)]
 	pub mod somE_weird_SPElLInG_s {
 		#[codec(index = 0)]
 		pub static V: u64 = 0;
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 1c4ab436ad9..9ce7b0ac8a8 100644
--- a/substrate/frame/support/procedural/src/construct_runtime/expand/origin.rs
+++ b/substrate/frame/support/procedural/src/construct_runtime/expand/origin.rs
@@ -210,6 +210,7 @@ pub fn expand_outer_origin(
 			system(#system_path::Origin<#runtime>),
 			#caller_variants
 			#[allow(dead_code)]
+			#[codec(skip)]
 			Void(#scrate::__private::Void)
 		}
 
diff --git a/substrate/frame/support/test/tests/enum_deprecation.rs b/substrate/frame/support/test/tests/enum_deprecation.rs
index c1167dfe339..72b14dad962 100644
--- a/substrate/frame/support/test/tests/enum_deprecation.rs
+++ b/substrate/frame/support/test/tests/enum_deprecation.rs
@@ -85,6 +85,7 @@ pub mod pallet {
 		T::AccountId: SomeAssociation1 + From<SomeType1>,
 	{
 		#[deprecated = "second"]
+		#[codec(index = 1)]
 		A,
 		#[deprecated = "first"]
 		#[codec(index = 0)]
@@ -157,20 +158,13 @@ fn pallet_metadata() {
 		// Example pallet events are partially and fully deprecated
 		let meta = example.event.unwrap();
 		assert_eq!(
-			// Result should be this, but instead we get the result below
-			// see: https://github.com/paritytech/parity-scale-codec/issues/507
-			//
-			// DeprecationInfoIR::VariantsDeprecated(BTreeMap::from([
-			// 	(codec::Compact(0), DeprecationStatusIR::Deprecated { note: "first", since: None
-			// }), 	(
-			// 		codec::Compact(1),
-			// 		DeprecationStatusIR::Deprecated { note: "second", since: None }
-			// 	)
-			// ])),
-			DeprecationInfoIR::VariantsDeprecated(BTreeMap::from([(
-				codec::Compact(0),
-				DeprecationStatusIR::Deprecated { note: "first", since: None }
-			),])),
+			DeprecationInfoIR::VariantsDeprecated(BTreeMap::from([
+				(codec::Compact(0), DeprecationStatusIR::Deprecated { note: "first", since: None }),
+				(
+					codec::Compact(1),
+					DeprecationStatusIR::Deprecated { note: "second", since: None }
+				)
+			])),
 			meta.deprecation_info
 		);
 	}
-- 
GitLab