From 9541faa9d8e67423315c7b89255644896a4ec378 Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 7 Jun 2024 15:59:50 +0200 Subject: [PATCH 1/7] restrict asset id for trusted assets --- .../asset-hubs/asset-hub-kusama/src/lib.rs | 26 ++++++++++++++++--- .../asset-hubs/asset-hub-polkadot/src/lib.rs | 26 ++++++++++++++++--- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs index fff90be3ff..689d637537 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs @@ -60,8 +60,8 @@ use frame_support::{ ord_parameter_types, parameter_types, traits::{ fungible, fungibles, tokens::imbalance::ResolveAssetTo, AsEnsureOriginWithArg, ConstBool, - ConstU128, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Equals, InstanceFilter, - TransformOrigin, WithdrawReasons, + ConstU128, ConstU32, ConstU64, ConstU8, EitherOfDiverse, EnsureOrigin, EnsureOriginWithArg, + Equals, InstanceFilter, TransformOrigin, WithdrawReasons, }, weights::{ConstantMultiplier, Weight}, BoundedVec, PalletId, @@ -278,11 +278,31 @@ parameter_types! { // https://github.com/paritytech/substrate/blob/069917b/frame/assets/src/lib.rs#L257L271 pub const MetadataDepositBase: Balance = system_para_deposit(1, 68); pub const MetadataDepositPerByte: Balance = system_para_deposit(0, 1); + /// The asset ID's auto increment for trusted assets planned with the next release. + pub const TrustAssetIdAutoIncrement: AssetIdForTrustBackedAssets = 50_000_000; } /// We allow root to execute privileged asset operations. pub type AssetsForceOrigin = EnsureRoot; +/// Ensure that the proposed asset id is less than the [`TrustAssetIdAutoIncrement`] and origin is +/// signed. +pub struct EnsureLessThanAutoIncrement; +impl EnsureOriginWithArg + for EnsureLessThanAutoIncrement +{ + type Success = AccountId; + fn try_origin( + o: RuntimeOrigin, + a: &AssetIdForTrustBackedAssets, + ) -> Result { + if a >= &TrustAssetIdAutoIncrement::get() { + return Err(o); + } + as EnsureOrigin>::try_origin(o) + } +} + // Called "Trust Backed" assets because these are generally registered by some account, and users of // the asset assume it has some claimed backing. The pallet is called `Assets` in // `construct_runtime` to avoid breaking changes on storage reads. @@ -294,7 +314,7 @@ impl pallet_assets::Config for Runtime { type AssetId = AssetIdForTrustBackedAssets; type AssetIdParameter = codec::Compact; type Currency = Balances; - type CreateOrigin = AsEnsureOriginWithArg>; + type CreateOrigin = EnsureLessThanAutoIncrement; type ForceOrigin = AssetsForceOrigin; type AssetDeposit = AssetDeposit; type MetadataDepositBase = MetadataDepositBase; diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index f52b4c6ea2..e38b9d3b59 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -94,8 +94,8 @@ use frame_support::{ parameter_types, traits::{ fungible, fungibles, tokens::imbalance::ResolveAssetTo, AsEnsureOriginWithArg, ConstBool, - ConstU32, ConstU64, ConstU8, EitherOfDiverse, Equals, InstanceFilter, NeverEnsureOrigin, - TransformOrigin, WithdrawReasons, + ConstU32, ConstU64, ConstU8, EitherOfDiverse, EnsureOrigin, EnsureOriginWithArg, Equals, + InstanceFilter, NeverEnsureOrigin, TransformOrigin, WithdrawReasons, }, weights::{ConstantMultiplier, Weight}, PalletId, @@ -296,11 +296,31 @@ parameter_types! { // https://github.com/paritytech/substrate/blob/069917b/frame/assets/src/lib.rs#L257L271 pub const MetadataDepositBase: Balance = system_para_deposit(1, 68); pub const MetadataDepositPerByte: Balance = system_para_deposit(0, 1); + /// The asset ID's auto increment for trusted assets planned with the next release. + pub const TrustAssetIdAutoIncrement: AssetIdForTrustBackedAssets = 50_000_000; } /// We allow root to execute privileged asset operations. pub type AssetsForceOrigin = EnsureRoot; +/// Ensure that the proposed asset id is less than the [`TrustAssetIdAutoIncrement`] and origin is +/// signed. +pub struct EnsureLessThanAutoIncrement; +impl EnsureOriginWithArg + for EnsureLessThanAutoIncrement +{ + type Success = AccountId; + fn try_origin( + o: RuntimeOrigin, + a: &AssetIdForTrustBackedAssets, + ) -> Result { + if a >= &TrustAssetIdAutoIncrement::get() { + return Err(o); + } + as EnsureOrigin>::try_origin(o) + } +} + // Called "Trust Backed" assets because these are generally registered by some account, and users of // the asset assume it has some claimed backing. The pallet is called `Assets` in // `construct_runtime` to avoid breaking changes on storage reads. @@ -312,7 +332,7 @@ impl pallet_assets::Config for Runtime { type AssetId = AssetIdForTrustBackedAssets; type AssetIdParameter = codec::Compact; type Currency = Balances; - type CreateOrigin = AsEnsureOriginWithArg>; + type CreateOrigin = EnsureLessThanAutoIncrement; type ForceOrigin = AssetsForceOrigin; type AssetDeposit = AssetDeposit; type MetadataDepositBase = MetadataDepositBase; From 193e5bdc440392a1755265e05aa7820bb653c995 Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 7 Jun 2024 16:29:42 +0200 Subject: [PATCH 2/7] fix --- system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs | 4 ++++ system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs index 689d637537..0eaffa9747 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs @@ -301,6 +301,10 @@ impl EnsureOriginWithArg } as EnsureOrigin>::try_origin(o) } + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin(_a: &AssetIdForTrustBackedAssets) -> Result { + as EnsureOrigin>::try_successful_origin() + } } // Called "Trust Backed" assets because these are generally registered by some account, and users of diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index e38b9d3b59..6bae1eeae1 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -319,6 +319,10 @@ impl EnsureOriginWithArg } as EnsureOrigin>::try_origin(o) } + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin(_a: &AssetIdForTrustBackedAssets) -> Result { + as EnsureOrigin>::try_successful_origin() + } } // Called "Trust Backed" assets because these are generally registered by some account, and users of From dd50dd862793003d3807bffe16e29811520371cb Mon Sep 17 00:00:00 2001 From: Muharem Date: Fri, 7 Jun 2024 16:31:25 +0200 Subject: [PATCH 3/7] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs | 4 +--- system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs index 0eaffa9747..ce7099a8f5 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs @@ -278,8 +278,6 @@ parameter_types! { // https://github.com/paritytech/substrate/blob/069917b/frame/assets/src/lib.rs#L257L271 pub const MetadataDepositBase: Balance = system_para_deposit(1, 68); pub const MetadataDepositPerByte: Balance = system_para_deposit(0, 1); - /// The asset ID's auto increment for trusted assets planned with the next release. - pub const TrustAssetIdAutoIncrement: AssetIdForTrustBackedAssets = 50_000_000; } /// We allow root to execute privileged asset operations. @@ -296,7 +294,7 @@ impl EnsureOriginWithArg o: RuntimeOrigin, a: &AssetIdForTrustBackedAssets, ) -> Result { - if a >= &TrustAssetIdAutoIncrement::get() { + if *a >= 50_000_000 { return Err(o); } as EnsureOrigin>::try_origin(o) diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index 6bae1eeae1..23b34cd802 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -296,8 +296,6 @@ parameter_types! { // https://github.com/paritytech/substrate/blob/069917b/frame/assets/src/lib.rs#L257L271 pub const MetadataDepositBase: Balance = system_para_deposit(1, 68); pub const MetadataDepositPerByte: Balance = system_para_deposit(0, 1); - /// The asset ID's auto increment for trusted assets planned with the next release. - pub const TrustAssetIdAutoIncrement: AssetIdForTrustBackedAssets = 50_000_000; } /// We allow root to execute privileged asset operations. @@ -314,7 +312,7 @@ impl EnsureOriginWithArg o: RuntimeOrigin, a: &AssetIdForTrustBackedAssets, ) -> Result { - if a >= &TrustAssetIdAutoIncrement::get() { + if *a >= 50_000_000 { return Err(o); } as EnsureOrigin>::try_origin(o) From ed828748c4b4b8aed34e61beff7c937ac905ca02 Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 7 Jun 2024 16:32:28 +0200 Subject: [PATCH 4/7] fix doc --- system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs | 3 +-- system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs index ce7099a8f5..1e0ad3b0a3 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs @@ -283,8 +283,7 @@ parameter_types! { /// We allow root to execute privileged asset operations. pub type AssetsForceOrigin = EnsureRoot; -/// Ensure that the proposed asset id is less than the [`TrustAssetIdAutoIncrement`] and origin is -/// signed. +/// Ensure that the proposed asset id is less than `50_000_000` and origin is signed. pub struct EnsureLessThanAutoIncrement; impl EnsureOriginWithArg for EnsureLessThanAutoIncrement diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index 23b34cd802..3f5d1a65bb 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -301,8 +301,7 @@ parameter_types! { /// We allow root to execute privileged asset operations. pub type AssetsForceOrigin = EnsureRoot; -/// Ensure that the proposed asset id is less than the [`TrustAssetIdAutoIncrement`] and origin is -/// signed. +/// Ensure that the proposed asset id is less than `50_000_000` and origin is signed. pub struct EnsureLessThanAutoIncrement; impl EnsureOriginWithArg for EnsureLessThanAutoIncrement From d0c35b362b1e777d9eeb3f4b5a72786098079f44 Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 7 Jun 2024 16:34:40 +0200 Subject: [PATCH 5/7] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1889ecc51..17f82c5481 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Transaction payments work via new `fungible` trait implementation ([polkadot-fellows/runtimes#332](https://github.com/polkadot-fellows/runtimes/pull/332)) - Block `request_judgement` calls on the Relay Chain ([polkadot-fellows/runtimes#338](https://github.com/polkadot-fellows/runtimes/pull/338)) +- Set max asset id restriction for the creation of trusted assets ([polkadot-fellows/runtimes#346](https://github.com/polkadot-fellows/runtimes/pull/346)) ### Fixed From 42f855d61c61d79c90f29f1e264baa740292adb9 Mon Sep 17 00:00:00 2001 From: joe petrowski <25483142+joepetrowski@users.noreply.github.com> Date: Fri, 7 Jun 2024 19:06:20 +0200 Subject: [PATCH 6/7] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17f82c5481..315030f18b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Transaction payments work via new `fungible` trait implementation ([polkadot-fellows/runtimes#332](https://github.com/polkadot-fellows/runtimes/pull/332)) - Block `request_judgement` calls on the Relay Chain ([polkadot-fellows/runtimes#338](https://github.com/polkadot-fellows/runtimes/pull/338)) -- Set max asset id restriction for the creation of trusted assets ([polkadot-fellows/runtimes#346](https://github.com/polkadot-fellows/runtimes/pull/346)) +- Set max asset ID restriction for the creation of trusted assets ([polkadot-fellows/runtimes#346](https://github.com/polkadot-fellows/runtimes/pull/346)) ### Fixed From 3ac35de7306b24b099d10950a2d3aa064543dab3 Mon Sep 17 00:00:00 2001 From: joe petrowski <25483142+joepetrowski@users.noreply.github.com> Date: Thu, 13 Jun 2024 12:41:01 +0200 Subject: [PATCH 7/7] Update CHANGELOG.md --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0263516aef..e0b1c75c2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Changed + +- Set max asset ID restriction for the creation of trusted assets ([polkadot-fellows/runtimes#346](https://github.com/polkadot-fellows/runtimes/pull/346)) + ### Fixed - Kusama People: clear requested judgements that do not have corresponding deposits reserved ([polkadot-fellows/runtimes#339](https://github.com/polkadot-fellows/runtimes/pull/339)) @@ -27,7 +31,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Transaction payments work via new `fungible` trait implementation ([polkadot-fellows/runtimes#332](https://github.com/polkadot-fellows/runtimes/pull/332)) - Block `request_judgement` calls on the Relay Chain ([polkadot-fellows/runtimes#338](https://github.com/polkadot-fellows/runtimes/pull/338)) -- Set max asset ID restriction for the creation of trusted assets ([polkadot-fellows/runtimes#346](https://github.com/polkadot-fellows/runtimes/pull/346)) ### Fixed