From d569e728ca710c64392e524c9ccd4ec10c370269 Mon Sep 17 00:00:00 2001
From: Branislav Kontur <bkontur@gmail.com>
Date: Mon, 18 Sep 2023 11:11:08 +0200
Subject: [PATCH] "Common good" vs "System" parachain clean up (#1406)

## Summary
The term "common good parachain" has been abandoned in favor of "system
parachain" - e.g. [Joe's speech at
Decoded2023](https://youtu.be/CSO-ERHK2gY?t=456). This pull request
tries to fix and align code with this vision.

## Impact

The important change is implementation of `trait IsSystem` for `Id`
[here](https://github.com/paritytech/polkadot-sdk/pull/1406/files#diff-0b7b4f5b962a18ce980354592b55ab2a27b5a2e9f6f8089ec803ca73853e8583R225-R229)
where we changed condition from `< 1000` to `<= 1999`, which means that
all parachain IDs bellow 1999 (included) are considered as "system
parachain" IDs. This change has a direct impact on the following
components:

####
[ChildSystemParachainAsSuperuser](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/xcm/xcm-builder/src/origin_conversion.rs#L72-L88)
This origin converter is used for allowing to process XCM `Transact`
from "system parachain" on the relay chain - e.g. see [configuration for
Kusama](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/kusama/src/xcm_config.rs#L92-L101).
Only configured for Kusama, Westend, Rococo runtimes.

**No need for this feature anymore.** See
[comment](https://github.com/paritytech/polkadot-sdk/pull/1406#issuecomment-1708218715).

####
[IsChildSystemParachain](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/xcm/xcm-builder/src/barriers.rs#L310-L317)
`IsChildSystemParachain` is used with `AllowExplicitUnpaidExecutionFrom`
barrier for checking XCM programs (they have to start with
`UnpaidExecution` instruction).
Only configured for Kusama, Westend, Rococo runtimes.

**Overall the impact is low or mostly ok because it only allows unpaid
execution for "system parachains" (e.g. AssetHub, BridgeHub...) on the
relay chain.**

####
[SiblingSystemParachainAsSuperuser](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/xcm/xcm-builder/src/origin_conversion.rs#L94-L114)

Not used anywhere in `polkadot-sdk` repo.


## Unresolved Questions
- [ ] constants `LOWEST_USER_ID` and `LOWEST_PUBLIC_ID` seem to express
the same thing now, do we want to keep them both or deprecated one of
them? If so, which one?
- [x] determine impact for `ChildSystemParachainAsSuperuser`

## TODO

- [ ] when merged here, open PR to the `polkadot-fellows`

## Related Material
https://youtu.be/CSO-ERHK2gY?t=456

https://forum.polkadot.network/t/polkadot-protocol-and-common-good-parachains/866
https://wiki.polkadot.network/docs/learn-system-chains
---
 .../collectives/collectives-polkadot/src/lib.rs       |  2 +-
 .../runtimes/testing/penpal/src/xcm_config.rs         |  2 +-
 polkadot/parachain/src/primitives.rs                  | 10 ++++------
 polkadot/primitives/src/v5/mod.rs                     |  2 +-
 polkadot/runtime/kusama/src/lib.rs                    |  2 +-
 polkadot/runtime/kusama/src/xcm_config.rs             | 11 ++++-------
 polkadot/runtime/polkadot/src/lib.rs                  |  2 +-
 polkadot/runtime/rococo/src/xcm_config.rs             | 11 ++++-------
 polkadot/runtime/westend/src/xcm_config.rs            |  9 ++++-----
 9 files changed, 21 insertions(+), 30 deletions(-)

diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs
index d9125c2645e..70e62a4dcdf 100644
--- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs
+++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs
@@ -20,7 +20,7 @@
 //!
 //! ### Governance
 //!
-//! As a common good parachain, Collectives defers its governance (namely, its `Root` origin), to
+//! As a system parachain, Collectives defers its governance (namely, its `Root` origin), to
 //! its Relay Chain parent, Polkadot.
 //!
 //! ### Collator Selection
diff --git a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs
index 97d2e63370e..f2ffc451b10 100644
--- a/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs
+++ b/cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs
@@ -163,7 +163,7 @@ pub type Barrier = TrailingSetTopicAsId<
 					// If the message is one that immediately attemps to pay for execution, then
 					// allow it.
 					AllowTopLevelPaidExecutionFrom<Everything>,
-					// Common Good Assets parachain, parent and its exec plurality get free
+					// System Assets parachain, parent and its exec plurality get free
 					// execution
 					AllowExplicitUnpaidExecutionFrom<(
 						CommonGoodAssetsParachain,
diff --git a/polkadot/parachain/src/primitives.rs b/polkadot/parachain/src/primitives.rs
index 5cea9d3bbf4..5f77810f5c2 100644
--- a/polkadot/parachain/src/primitives.rs
+++ b/polkadot/parachain/src/primitives.rs
@@ -199,13 +199,11 @@ impl From<i32> for Id {
 	}
 }
 
-const USER_INDEX_START: u32 = 1000;
+// System parachain ID is considered `< 2000`.
+const SYSTEM_INDEX_END: u32 = 1999;
 const PUBLIC_INDEX_START: u32 = 2000;
 
-/// The ID of the first user (non-system) parachain.
-pub const LOWEST_USER_ID: Id = Id(USER_INDEX_START);
-
-/// The ID of the first publicly registerable parachain.
+/// The ID of the first publicly registrable parachain.
 pub const LOWEST_PUBLIC_ID: Id = Id(PUBLIC_INDEX_START);
 
 impl Id {
@@ -223,7 +221,7 @@ pub trait IsSystem {
 
 impl IsSystem for Id {
 	fn is_system(&self) -> bool {
-		self.0 < USER_INDEX_START
+		self.0 <= SYSTEM_INDEX_END
 	}
 }
 
diff --git a/polkadot/primitives/src/v5/mod.rs b/polkadot/primitives/src/v5/mod.rs
index 30782f95611..81743225403 100644
--- a/polkadot/primitives/src/v5/mod.rs
+++ b/polkadot/primitives/src/v5/mod.rs
@@ -44,7 +44,7 @@ pub use polkadot_core_primitives::v2::{
 // Export some polkadot-parachain primitives
 pub use polkadot_parachain_primitives::primitives::{
 	HeadData, HorizontalMessages, HrmpChannelId, Id, UpwardMessage, UpwardMessages, ValidationCode,
-	ValidationCodeHash, LOWEST_PUBLIC_ID, LOWEST_USER_ID,
+	ValidationCodeHash, LOWEST_PUBLIC_ID,
 };
 
 use serde::{Deserialize, Serialize};
diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs
index fc9fd61790e..0681db23bc2 100644
--- a/polkadot/runtime/kusama/src/lib.rs
+++ b/polkadot/runtime/kusama/src/lib.rs
@@ -643,7 +643,7 @@ impl pallet_staking::EraPayout<Balance> for EraPayout {
 		// all para-ids that are currently active.
 		let auctioned_slots = Paras::parachains()
 			.into_iter()
-			// all active para-ids that do not belong to a system or common good chain is the number
+			// all active para-ids that do not belong to a system chain is the number
 			// of parachains that we should take into account for inflation.
 			.filter(|i| *i >= LOWEST_PUBLIC_ID)
 			.count() as u64;
diff --git a/polkadot/runtime/kusama/src/xcm_config.rs b/polkadot/runtime/kusama/src/xcm_config.rs
index 6a9cea22bbc..59ea937e11c 100644
--- a/polkadot/runtime/kusama/src/xcm_config.rs
+++ b/polkadot/runtime/kusama/src/xcm_config.rs
@@ -37,11 +37,10 @@ use xcm::latest::prelude::*;
 use xcm_builder::{
 	AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
 	AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative,
-	ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
-	CurrencyAdapter as XcmCurrencyAdapter, IsChildSystemParachain, IsConcrete, MintLocation,
-	OriginToPluralityVoice, SignedAccountId32AsNative, SignedToAccountId32,
-	SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
-	WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
+	ChildParachainConvertsVia, CurrencyAdapter as XcmCurrencyAdapter, IsChildSystemParachain,
+	IsConcrete, MintLocation, OriginToPluralityVoice, SignedAccountId32AsNative,
+	SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId,
+	UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
 };
 
 parameter_types! {
@@ -95,8 +94,6 @@ type LocalOriginConverter = (
 	ChildParachainAsNative<parachains_origin::Origin, RuntimeOrigin>,
 	// The AccountId32 location type can be expressed natively as a `Signed` origin.
 	SignedAccountId32AsNative<ThisNetwork, RuntimeOrigin>,
-	// A system child parachain, expressed as a Superuser, converts to the `Root` origin.
-	ChildSystemParachainAsSuperuser<ParaId, RuntimeOrigin>,
 );
 
 parameter_types! {
diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs
index 6d06ee46933..441a5132eda 100644
--- a/polkadot/runtime/polkadot/src/lib.rs
+++ b/polkadot/runtime/polkadot/src/lib.rs
@@ -552,7 +552,7 @@ impl pallet_staking::EraPayout<Balance> for EraPayout {
 		// all para-ids that are not active.
 		let auctioned_slots = Paras::parachains()
 			.into_iter()
-			// all active para-ids that do not belong to a system or common good chain is the number
+			// all active para-ids that do not belong to a system chain is the number
 			// of parachains that we should take into account for inflation.
 			.filter(|i| *i >= LOWEST_PUBLIC_ID)
 			.count() as u64;
diff --git a/polkadot/runtime/rococo/src/xcm_config.rs b/polkadot/runtime/rococo/src/xcm_config.rs
index d561df14a02..288ee8400dc 100644
--- a/polkadot/runtime/rococo/src/xcm_config.rs
+++ b/polkadot/runtime/rococo/src/xcm_config.rs
@@ -36,11 +36,10 @@ use xcm::latest::prelude::*;
 use xcm_builder::{
 	AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
 	AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative,
-	ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
-	CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsChildSystemParachain, IsConcrete,
-	MintLocation, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
-	TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin,
-	WithUniqueTopic,
+	ChildParachainConvertsVia, CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds,
+	IsChildSystemParachain, IsConcrete, MintLocation, SignedAccountId32AsNative,
+	SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId,
+	UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
 };
 use xcm_executor::XcmExecutor;
 
@@ -80,8 +79,6 @@ type LocalOriginConverter = (
 	ChildParachainAsNative<parachains_origin::Origin, RuntimeOrigin>,
 	// The AccountId32 location type can be expressed natively as a `Signed` origin.
 	SignedAccountId32AsNative<ThisNetwork, RuntimeOrigin>,
-	// A system child parachain, expressed as a Superuser, converts to the `Root` origin.
-	ChildSystemParachainAsSuperuser<ParaId, RuntimeOrigin>,
 );
 
 parameter_types! {
diff --git a/polkadot/runtime/westend/src/xcm_config.rs b/polkadot/runtime/westend/src/xcm_config.rs
index 264830c693e..afa0733b4c9 100644
--- a/polkadot/runtime/westend/src/xcm_config.rs
+++ b/polkadot/runtime/westend/src/xcm_config.rs
@@ -35,10 +35,10 @@ use xcm::latest::prelude::*;
 use xcm_builder::{
 	AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
 	AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative,
-	ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
-	CurrencyAdapter as XcmCurrencyAdapter, IsChildSystemParachain, IsConcrete, MintLocation,
-	SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
-	TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
+	ChildParachainConvertsVia, CurrencyAdapter as XcmCurrencyAdapter, IsChildSystemParachain,
+	IsConcrete, MintLocation, SignedAccountId32AsNative, SignedToAccountId32,
+	SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
+	WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
 };
 use xcm_executor::XcmExecutor;
 
@@ -74,7 +74,6 @@ type LocalOriginConverter = (
 	SovereignSignedViaLocation<LocationConverter, RuntimeOrigin>,
 	ChildParachainAsNative<parachains_origin::Origin, RuntimeOrigin>,
 	SignedAccountId32AsNative<ThisNetwork, RuntimeOrigin>,
-	ChildSystemParachainAsSuperuser<ParaId, RuntimeOrigin>,
 );
 
 /// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our
-- 
GitLab