From 545d0cbc27dc67e2aa28d7721b3b6346e6f6e2fb Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 24 Mar 2023 10:41:41 +0100 Subject: [PATCH 1/8] xcm remote lock consumers --- xcm/pallet-xcm/src/lib.rs | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/xcm/pallet-xcm/src/lib.rs b/xcm/pallet-xcm/src/lib.rs index f84c94a063e8..ec390c745e7a 100644 --- a/xcm/pallet-xcm/src/lib.rs +++ b/xcm/pallet-xcm/src/lib.rs @@ -244,6 +244,12 @@ pub mod pallet { /// The maximum number of local XCM locks that a single account may have. type MaxLockers: Get; + /// The maximum number of consumers a single remote lock may have. + type MaxRemoteLockConsumers: Get; + + /// The ID type for remote lock consumers. + type RemoteLockIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy; + /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; @@ -582,11 +588,20 @@ pub mod pallet { StorageValue<_, VersionMigrationStage, OptionQuery>; #[derive(Clone, Encode, Decode, Eq, PartialEq, Ord, PartialOrd, TypeInfo, MaxEncodedLen)] - pub struct RemoteLockedFungibleRecord { + #[scale_info(skip_type_params(MaxConsumers))] + pub struct RemoteLockedFungibleRecord> { pub amount: u128, pub owner: VersionedMultiLocation, pub locker: VersionedMultiLocation, - pub users: u32, + pub consumers: BoundedVec<(RemoteLockIdentifier, u128), MaxConsumers>, + } + + impl> RemoteLockedFungibleRecord { + /// Amount of the remote lock in use by consumers. + /// Returns zero if the remote lock has no consumers. + pub fn amount_held(&self) -> u128 { + self.consumers.iter().max_by(|x, y| x.1.cmp(&y.1)).map_or(0, |max| max.1) + } } /// Fungible assets which we know are locked on a remote chain. @@ -598,7 +613,7 @@ pub mod pallet { NMapKey, NMapKey, ), - RemoteLockedFungibleRecord, + RemoteLockedFungibleRecord, OptionQuery, >; @@ -1665,11 +1680,12 @@ impl xcm_executor::traits::Enact for ReduceTicket { use xcm_executor::traits::LockError::UnexpectedState; let mut record = RemoteLockedFungibles::::get(&self.key).ok_or(UnexpectedState)?; ensure!(self.locker == record.locker && self.owner == record.owner, UnexpectedState); - ensure!(record.users == 0, UnexpectedState); - record.amount = record.amount.checked_sub(self.amount).ok_or(UnexpectedState)?; - if record.amount == 0 { + let new_amount = record.amount.checked_sub(self.amount).ok_or(UnexpectedState)?; + ensure!(record.consumers.len() == 0 || new_amount >= record.amount_held(), UnexpectedState); + if new_amount == 0 { RemoteLockedFungibles::::remove(&self.key); } else { + record.amount = new_amount; RemoteLockedFungibles::::insert(&self.key, &record); } Ok(()) @@ -1729,11 +1745,12 @@ impl xcm_executor::traits::AssetLock for Pallet { let owner = owner.into(); let id: VersionedAssetId = asset.id.into(); let key = (XCM_VERSION, account, id); - let mut record = RemoteLockedFungibleRecord { amount, owner, locker, users: 0 }; + let mut record = + RemoteLockedFungibleRecord { amount, owner, locker, consumers: BoundedVec::default() }; if let Some(old) = RemoteLockedFungibles::::get(&key) { // Make sure that the new record wouldn't clobber any old data. ensure!(old.locker == record.locker && old.owner == record.owner, WouldClobber); - record.users = old.users; + record.consumers = old.consumers; record.amount = record.amount.max(old.amount); } RemoteLockedFungibles::::insert(&key, record); @@ -1760,8 +1777,12 @@ impl xcm_executor::traits::AssetLock for Pallet { let record = RemoteLockedFungibles::::get(&key).ok_or(NotLocked)?; // Make sure that the record contains what we expect and there's enough to unlock. ensure!(locker == record.locker && owner == record.owner, WouldClobber); - ensure!(record.users == 0, InUse); ensure!(record.amount >= amount, NotEnoughLocked); + ensure!( + record.consumers.len() == 0 || + record.amount.saturating_sub(amount) >= record.amount_held(), + InUse + ); Ok(ReduceTicket { key, amount, locker, owner }) } } From 75e1acc2d6e9ca7e849034c7bdadef704df53122 Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 24 Mar 2023 11:31:39 +0100 Subject: [PATCH 2/8] update xcm pallet config setups --- runtime/kusama/src/xcm_config.rs | 2 ++ runtime/polkadot/src/xcm_config.rs | 2 ++ runtime/rococo/src/xcm_config.rs | 2 ++ runtime/test-runtime/src/xcm_config.rs | 2 ++ runtime/westend/src/xcm_config.rs | 2 ++ 5 files changed, 10 insertions(+) diff --git a/runtime/kusama/src/xcm_config.rs b/runtime/kusama/src/xcm_config.rs index 5a8495ca7998..a7b9f5f99f44 100644 --- a/runtime/kusama/src/xcm_config.rs +++ b/runtime/kusama/src/xcm_config.rs @@ -396,6 +396,8 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = SovereignAccountOf; type MaxLockers = ConstU32<8>; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockIdentifier = (); type WeightInfo = crate::weights::pallet_xcm::WeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; diff --git a/runtime/polkadot/src/xcm_config.rs b/runtime/polkadot/src/xcm_config.rs index 585197a475fb..75c86bf523e5 100644 --- a/runtime/polkadot/src/xcm_config.rs +++ b/runtime/polkadot/src/xcm_config.rs @@ -423,6 +423,8 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = SovereignAccountOf; type MaxLockers = ConstU32<8>; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockIdentifier = (); type WeightInfo = crate::weights::pallet_xcm::WeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; diff --git a/runtime/rococo/src/xcm_config.rs b/runtime/rococo/src/xcm_config.rs index 73408566b408..f7b2a1390b8b 100644 --- a/runtime/rococo/src/xcm_config.rs +++ b/runtime/rococo/src/xcm_config.rs @@ -362,6 +362,8 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = LocationConverter; type MaxLockers = ConstU32<8>; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockIdentifier = (); type WeightInfo = crate::weights::pallet_xcm::WeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; diff --git a/runtime/test-runtime/src/xcm_config.rs b/runtime/test-runtime/src/xcm_config.rs index e346f54a1575..be03e10e5f0c 100644 --- a/runtime/test-runtime/src/xcm_config.rs +++ b/runtime/test-runtime/src/xcm_config.rs @@ -144,6 +144,8 @@ impl pallet_xcm::Config for crate::Runtime { type TrustedLockers = (); type SovereignAccountOf = (); type MaxLockers = frame_support::traits::ConstU32<8>; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockIdentifier = (); type WeightInfo = pallet_xcm::TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; diff --git a/runtime/westend/src/xcm_config.rs b/runtime/westend/src/xcm_config.rs index 411291c3e7f8..b005f2255ed4 100644 --- a/runtime/westend/src/xcm_config.rs +++ b/runtime/westend/src/xcm_config.rs @@ -277,6 +277,8 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = LocationConverter; type MaxLockers = ConstU32<8>; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockIdentifier = (); type WeightInfo = crate::weights::pallet_xcm::WeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; From a88d98c0ccb7b667dc8f7c2dc37577473166d3bc Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 24 Mar 2023 12:28:51 +0100 Subject: [PATCH 3/8] fix import --- runtime/test-runtime/src/xcm_config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/test-runtime/src/xcm_config.rs b/runtime/test-runtime/src/xcm_config.rs index be03e10e5f0c..8ef4fc34ebb8 100644 --- a/runtime/test-runtime/src/xcm_config.rs +++ b/runtime/test-runtime/src/xcm_config.rs @@ -144,7 +144,7 @@ impl pallet_xcm::Config for crate::Runtime { type TrustedLockers = (); type SovereignAccountOf = (); type MaxLockers = frame_support::traits::ConstU32<8>; - type MaxRemoteLockConsumers = ConstU32<0>; + type MaxRemoteLockConsumers = frame_support::traits::ConstU32<0>; type RemoteLockIdentifier = (); type WeightInfo = pallet_xcm::TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] From 5faca4861c83ba65c7b6d5271808e9d6d9a0bd5d Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 24 Mar 2023 12:48:48 +0100 Subject: [PATCH 4/8] update xcm pallet config setups --- xcm/pallet-xcm/src/mock.rs | 2 ++ xcm/xcm-builder/tests/mock/mod.rs | 2 ++ xcm/xcm-simulator/example/src/parachain.rs | 2 ++ xcm/xcm-simulator/example/src/relay_chain.rs | 2 ++ xcm/xcm-simulator/fuzzer/src/parachain.rs | 2 ++ xcm/xcm-simulator/fuzzer/src/relay_chain.rs | 2 ++ 6 files changed, 12 insertions(+) diff --git a/xcm/pallet-xcm/src/mock.rs b/xcm/pallet-xcm/src/mock.rs index 9544538ef280..bca786b23654 100644 --- a/xcm/pallet-xcm/src/mock.rs +++ b/xcm/pallet-xcm/src/mock.rs @@ -342,6 +342,8 @@ impl pallet_xcm::Config for Test { type Currency = Balances; type CurrencyMatcher = IsConcrete; type MaxLockers = frame_support::traits::ConstU32<8>; + type MaxRemoteLockConsumers = frame_support::traits::ConstU32<0>; + type RemoteLockIdentifier = (); type WeightInfo = TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; diff --git a/xcm/xcm-builder/tests/mock/mod.rs b/xcm/xcm-builder/tests/mock/mod.rs index 9c0086e34c90..8e727d74a137 100644 --- a/xcm/xcm-builder/tests/mock/mod.rs +++ b/xcm/xcm-builder/tests/mock/mod.rs @@ -233,6 +233,8 @@ impl pallet_xcm::Config for Runtime { type Currency = Balances; type CurrencyMatcher = IsConcrete; type MaxLockers = frame_support::traits::ConstU32<8>; + type MaxRemoteLockConsumers = frame_support::traits::ConstU32<0>; + type RemoteLockIdentifier = (); type WeightInfo = pallet_xcm::TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; diff --git a/xcm/xcm-simulator/example/src/parachain.rs b/xcm/xcm-simulator/example/src/parachain.rs index 4cd4094b3328..9443aaa9b3be 100644 --- a/xcm/xcm-simulator/example/src/parachain.rs +++ b/xcm/xcm-simulator/example/src/parachain.rs @@ -423,6 +423,8 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = LocationToAccountId; type MaxLockers = ConstU32<8>; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockIdentifier = (); type WeightInfo = pallet_xcm::TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; diff --git a/xcm/xcm-simulator/example/src/relay_chain.rs b/xcm/xcm-simulator/example/src/relay_chain.rs index 5db399717fc1..1a96e6f4f2f3 100644 --- a/xcm/xcm-simulator/example/src/relay_chain.rs +++ b/xcm/xcm-simulator/example/src/relay_chain.rs @@ -220,6 +220,8 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = LocationToAccountId; type MaxLockers = ConstU32<8>; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockIdentifier = (); type WeightInfo = pallet_xcm::TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; diff --git a/xcm/xcm-simulator/fuzzer/src/parachain.rs b/xcm/xcm-simulator/fuzzer/src/parachain.rs index 8480713347c0..d4f770d6bc44 100644 --- a/xcm/xcm-simulator/fuzzer/src/parachain.rs +++ b/xcm/xcm-simulator/fuzzer/src/parachain.rs @@ -338,6 +338,8 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = LocationToAccountId; type MaxLockers = frame_support::traits::ConstU32<8>; + type MaxRemoteLockConsumers = frame_support::traits::ConstU32<0>; + type RemoteLockIdentifier = (); type WeightInfo = pallet_xcm::TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; diff --git a/xcm/xcm-simulator/fuzzer/src/relay_chain.rs b/xcm/xcm-simulator/fuzzer/src/relay_chain.rs index 962c22297a8e..60f76950ec26 100644 --- a/xcm/xcm-simulator/fuzzer/src/relay_chain.rs +++ b/xcm/xcm-simulator/fuzzer/src/relay_chain.rs @@ -184,6 +184,8 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = SovereignAccountOf; type MaxLockers = ConstU32<8>; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockIdentifier = (); type WeightInfo = pallet_xcm::TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; From 9538c5ed992bd9c7306090036aeb5e2eb7dc13ac Mon Sep 17 00:00:00 2001 From: muharem Date: Wed, 29 Mar 2023 11:10:44 +0200 Subject: [PATCH 5/8] rename consumers to users --- runtime/kusama/src/xcm_config.rs | 2 +- runtime/polkadot/src/xcm_config.rs | 2 +- runtime/rococo/src/xcm_config.rs | 2 +- runtime/test-runtime/src/xcm_config.rs | 2 +- runtime/westend/src/xcm_config.rs | 2 +- xcm/pallet-xcm/src/lib.rs | 25 ++++++++++---------- xcm/pallet-xcm/src/mock.rs | 2 +- xcm/xcm-builder/tests/mock/mod.rs | 2 +- xcm/xcm-simulator/example/src/parachain.rs | 2 +- xcm/xcm-simulator/example/src/relay_chain.rs | 2 +- xcm/xcm-simulator/fuzzer/src/parachain.rs | 2 +- xcm/xcm-simulator/fuzzer/src/relay_chain.rs | 2 +- 12 files changed, 23 insertions(+), 24 deletions(-) diff --git a/runtime/kusama/src/xcm_config.rs b/runtime/kusama/src/xcm_config.rs index a7b9f5f99f44..d8519d8a5cf7 100644 --- a/runtime/kusama/src/xcm_config.rs +++ b/runtime/kusama/src/xcm_config.rs @@ -396,7 +396,7 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = SovereignAccountOf; type MaxLockers = ConstU32<8>; - type MaxRemoteLockConsumers = ConstU32<0>; + type MaxRemoteLockUsers = ConstU32<0>; type RemoteLockIdentifier = (); type WeightInfo = crate::weights::pallet_xcm::WeightInfo; #[cfg(feature = "runtime-benchmarks")] diff --git a/runtime/polkadot/src/xcm_config.rs b/runtime/polkadot/src/xcm_config.rs index 75c86bf523e5..8830bcd31c64 100644 --- a/runtime/polkadot/src/xcm_config.rs +++ b/runtime/polkadot/src/xcm_config.rs @@ -423,7 +423,7 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = SovereignAccountOf; type MaxLockers = ConstU32<8>; - type MaxRemoteLockConsumers = ConstU32<0>; + type MaxRemoteLockUsers = ConstU32<0>; type RemoteLockIdentifier = (); type WeightInfo = crate::weights::pallet_xcm::WeightInfo; #[cfg(feature = "runtime-benchmarks")] diff --git a/runtime/rococo/src/xcm_config.rs b/runtime/rococo/src/xcm_config.rs index f7b2a1390b8b..c49e5eb6a1be 100644 --- a/runtime/rococo/src/xcm_config.rs +++ b/runtime/rococo/src/xcm_config.rs @@ -362,7 +362,7 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = LocationConverter; type MaxLockers = ConstU32<8>; - type MaxRemoteLockConsumers = ConstU32<0>; + type MaxRemoteLockUsers = ConstU32<0>; type RemoteLockIdentifier = (); type WeightInfo = crate::weights::pallet_xcm::WeightInfo; #[cfg(feature = "runtime-benchmarks")] diff --git a/runtime/test-runtime/src/xcm_config.rs b/runtime/test-runtime/src/xcm_config.rs index 8ef4fc34ebb8..b4ec5f12252d 100644 --- a/runtime/test-runtime/src/xcm_config.rs +++ b/runtime/test-runtime/src/xcm_config.rs @@ -144,7 +144,7 @@ impl pallet_xcm::Config for crate::Runtime { type TrustedLockers = (); type SovereignAccountOf = (); type MaxLockers = frame_support::traits::ConstU32<8>; - type MaxRemoteLockConsumers = frame_support::traits::ConstU32<0>; + type MaxRemoteLockUsers = frame_support::traits::ConstU32<0>; type RemoteLockIdentifier = (); type WeightInfo = pallet_xcm::TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] diff --git a/runtime/westend/src/xcm_config.rs b/runtime/westend/src/xcm_config.rs index b005f2255ed4..b886cc496b78 100644 --- a/runtime/westend/src/xcm_config.rs +++ b/runtime/westend/src/xcm_config.rs @@ -277,7 +277,7 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = LocationConverter; type MaxLockers = ConstU32<8>; - type MaxRemoteLockConsumers = ConstU32<0>; + type MaxRemoteLockUsers = ConstU32<0>; type RemoteLockIdentifier = (); type WeightInfo = crate::weights::pallet_xcm::WeightInfo; #[cfg(feature = "runtime-benchmarks")] diff --git a/xcm/pallet-xcm/src/lib.rs b/xcm/pallet-xcm/src/lib.rs index ec390c745e7a..20d69d5086e4 100644 --- a/xcm/pallet-xcm/src/lib.rs +++ b/xcm/pallet-xcm/src/lib.rs @@ -244,10 +244,10 @@ pub mod pallet { /// The maximum number of local XCM locks that a single account may have. type MaxLockers: Get; - /// The maximum number of consumers a single remote lock may have. - type MaxRemoteLockConsumers: Get; + /// The maximum number of users a single remote lock may have. + type MaxRemoteLockUsers: Get; - /// The ID type for remote lock consumers. + /// The ID type for remote lock users. type RemoteLockIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy; /// Weight information for extrinsics in this pallet. @@ -593,14 +593,14 @@ pub mod pallet { pub amount: u128, pub owner: VersionedMultiLocation, pub locker: VersionedMultiLocation, - pub consumers: BoundedVec<(RemoteLockIdentifier, u128), MaxConsumers>, + pub users: BoundedVec<(RemoteLockIdentifier, u128), MaxConsumers>, } impl> RemoteLockedFungibleRecord { - /// Amount of the remote lock in use by consumers. - /// Returns zero if the remote lock has no consumers. + /// Amount of the remote lock in use by users. + /// Returns zero if the remote lock has no users. pub fn amount_held(&self) -> u128 { - self.consumers.iter().max_by(|x, y| x.1.cmp(&y.1)).map_or(0, |max| max.1) + self.users.iter().max_by(|x, y| x.1.cmp(&y.1)).map_or(0, |max| max.1) } } @@ -613,7 +613,7 @@ pub mod pallet { NMapKey, NMapKey, ), - RemoteLockedFungibleRecord, + RemoteLockedFungibleRecord, OptionQuery, >; @@ -1681,7 +1681,7 @@ impl xcm_executor::traits::Enact for ReduceTicket { let mut record = RemoteLockedFungibles::::get(&self.key).ok_or(UnexpectedState)?; ensure!(self.locker == record.locker && self.owner == record.owner, UnexpectedState); let new_amount = record.amount.checked_sub(self.amount).ok_or(UnexpectedState)?; - ensure!(record.consumers.len() == 0 || new_amount >= record.amount_held(), UnexpectedState); + ensure!(record.users.len() == 0 || new_amount >= record.amount_held(), UnexpectedState); if new_amount == 0 { RemoteLockedFungibles::::remove(&self.key); } else { @@ -1746,11 +1746,11 @@ impl xcm_executor::traits::AssetLock for Pallet { let id: VersionedAssetId = asset.id.into(); let key = (XCM_VERSION, account, id); let mut record = - RemoteLockedFungibleRecord { amount, owner, locker, consumers: BoundedVec::default() }; + RemoteLockedFungibleRecord { amount, owner, locker, users: BoundedVec::default() }; if let Some(old) = RemoteLockedFungibles::::get(&key) { // Make sure that the new record wouldn't clobber any old data. ensure!(old.locker == record.locker && old.owner == record.owner, WouldClobber); - record.consumers = old.consumers; + record.users = old.users; record.amount = record.amount.max(old.amount); } RemoteLockedFungibles::::insert(&key, record); @@ -1779,8 +1779,7 @@ impl xcm_executor::traits::AssetLock for Pallet { ensure!(locker == record.locker && owner == record.owner, WouldClobber); ensure!(record.amount >= amount, NotEnoughLocked); ensure!( - record.consumers.len() == 0 || - record.amount.saturating_sub(amount) >= record.amount_held(), + record.users.len() == 0 || record.amount.saturating_sub(amount) >= record.amount_held(), InUse ); Ok(ReduceTicket { key, amount, locker, owner }) diff --git a/xcm/pallet-xcm/src/mock.rs b/xcm/pallet-xcm/src/mock.rs index bca786b23654..f6b073e2bb72 100644 --- a/xcm/pallet-xcm/src/mock.rs +++ b/xcm/pallet-xcm/src/mock.rs @@ -342,7 +342,7 @@ impl pallet_xcm::Config for Test { type Currency = Balances; type CurrencyMatcher = IsConcrete; type MaxLockers = frame_support::traits::ConstU32<8>; - type MaxRemoteLockConsumers = frame_support::traits::ConstU32<0>; + type MaxRemoteLockUsers = frame_support::traits::ConstU32<0>; type RemoteLockIdentifier = (); type WeightInfo = TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] diff --git a/xcm/xcm-builder/tests/mock/mod.rs b/xcm/xcm-builder/tests/mock/mod.rs index 8e727d74a137..9bdb40037b55 100644 --- a/xcm/xcm-builder/tests/mock/mod.rs +++ b/xcm/xcm-builder/tests/mock/mod.rs @@ -233,7 +233,7 @@ impl pallet_xcm::Config for Runtime { type Currency = Balances; type CurrencyMatcher = IsConcrete; type MaxLockers = frame_support::traits::ConstU32<8>; - type MaxRemoteLockConsumers = frame_support::traits::ConstU32<0>; + type MaxRemoteLockUsers = frame_support::traits::ConstU32<0>; type RemoteLockIdentifier = (); type WeightInfo = pallet_xcm::TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] diff --git a/xcm/xcm-simulator/example/src/parachain.rs b/xcm/xcm-simulator/example/src/parachain.rs index 9443aaa9b3be..73a4a3e22e54 100644 --- a/xcm/xcm-simulator/example/src/parachain.rs +++ b/xcm/xcm-simulator/example/src/parachain.rs @@ -423,7 +423,7 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = LocationToAccountId; type MaxLockers = ConstU32<8>; - type MaxRemoteLockConsumers = ConstU32<0>; + type MaxRemoteLockUsers = ConstU32<0>; type RemoteLockIdentifier = (); type WeightInfo = pallet_xcm::TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] diff --git a/xcm/xcm-simulator/example/src/relay_chain.rs b/xcm/xcm-simulator/example/src/relay_chain.rs index 1a96e6f4f2f3..d2ecd331f1e4 100644 --- a/xcm/xcm-simulator/example/src/relay_chain.rs +++ b/xcm/xcm-simulator/example/src/relay_chain.rs @@ -220,7 +220,7 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = LocationToAccountId; type MaxLockers = ConstU32<8>; - type MaxRemoteLockConsumers = ConstU32<0>; + type MaxRemoteLockUsers = ConstU32<0>; type RemoteLockIdentifier = (); type WeightInfo = pallet_xcm::TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] diff --git a/xcm/xcm-simulator/fuzzer/src/parachain.rs b/xcm/xcm-simulator/fuzzer/src/parachain.rs index d4f770d6bc44..9ab1dc49305a 100644 --- a/xcm/xcm-simulator/fuzzer/src/parachain.rs +++ b/xcm/xcm-simulator/fuzzer/src/parachain.rs @@ -338,7 +338,7 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = LocationToAccountId; type MaxLockers = frame_support::traits::ConstU32<8>; - type MaxRemoteLockConsumers = frame_support::traits::ConstU32<0>; + type MaxRemoteLockUsers = frame_support::traits::ConstU32<0>; type RemoteLockIdentifier = (); type WeightInfo = pallet_xcm::TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] diff --git a/xcm/xcm-simulator/fuzzer/src/relay_chain.rs b/xcm/xcm-simulator/fuzzer/src/relay_chain.rs index 60f76950ec26..6166b888a7e8 100644 --- a/xcm/xcm-simulator/fuzzer/src/relay_chain.rs +++ b/xcm/xcm-simulator/fuzzer/src/relay_chain.rs @@ -184,7 +184,7 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = SovereignAccountOf; type MaxLockers = ConstU32<8>; - type MaxRemoteLockConsumers = ConstU32<0>; + type MaxRemoteLockUsers = ConstU32<0>; type RemoteLockIdentifier = (); type WeightInfo = pallet_xcm::TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] From a815d006e16dfdbfd650bb0ca01065f062edc40c Mon Sep 17 00:00:00 2001 From: muharem Date: Wed, 29 Mar 2023 11:15:08 +0200 Subject: [PATCH 6/8] rename --- xcm/pallet-xcm/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xcm/pallet-xcm/src/lib.rs b/xcm/pallet-xcm/src/lib.rs index 20d69d5086e4..00ef96a87e6e 100644 --- a/xcm/pallet-xcm/src/lib.rs +++ b/xcm/pallet-xcm/src/lib.rs @@ -588,15 +588,15 @@ pub mod pallet { StorageValue<_, VersionMigrationStage, OptionQuery>; #[derive(Clone, Encode, Decode, Eq, PartialEq, Ord, PartialOrd, TypeInfo, MaxEncodedLen)] - #[scale_info(skip_type_params(MaxConsumers))] - pub struct RemoteLockedFungibleRecord> { + #[scale_info(skip_type_params(MaxUsers))] + pub struct RemoteLockedFungibleRecord> { pub amount: u128, pub owner: VersionedMultiLocation, pub locker: VersionedMultiLocation, - pub users: BoundedVec<(RemoteLockIdentifier, u128), MaxConsumers>, + pub users: BoundedVec<(RemoteLockIdentifier, u128), MaxUsers>, } - impl> RemoteLockedFungibleRecord { + impl> RemoteLockedFungibleRecord { /// Amount of the remote lock in use by users. /// Returns zero if the remote lock has no users. pub fn amount_held(&self) -> u128 { From 0ced612cae09c8a3eb96b5f08d4692061f382701 Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 28 Apr 2023 15:16:44 +0200 Subject: [PATCH 7/8] rename users to consumers, more docs --- runtime/kusama/src/xcm_config.rs | 4 +- runtime/polkadot/src/xcm_config.rs | 4 +- runtime/rococo/src/xcm_config.rs | 4 +- runtime/test-runtime/src/xcm_config.rs | 4 +- runtime/westend/src/xcm_config.rs | 4 +- xcm/pallet-xcm/src/lib.rs | 42 +++++++++++--------- xcm/pallet-xcm/src/mock.rs | 4 +- xcm/xcm-builder/tests/mock/mod.rs | 4 +- xcm/xcm-simulator/example/src/parachain.rs | 4 +- xcm/xcm-simulator/example/src/relay_chain.rs | 4 +- xcm/xcm-simulator/fuzzer/src/parachain.rs | 4 +- xcm/xcm-simulator/fuzzer/src/relay_chain.rs | 4 +- 12 files changed, 46 insertions(+), 40 deletions(-) diff --git a/runtime/kusama/src/xcm_config.rs b/runtime/kusama/src/xcm_config.rs index f129f58c7cc7..9a070533a6dc 100644 --- a/runtime/kusama/src/xcm_config.rs +++ b/runtime/kusama/src/xcm_config.rs @@ -406,8 +406,8 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = SovereignAccountOf; type MaxLockers = ConstU32<8>; - type MaxRemoteLockUsers = ConstU32<0>; - type RemoteLockIdentifier = (); + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); type WeightInfo = crate::weights::pallet_xcm::WeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; diff --git a/runtime/polkadot/src/xcm_config.rs b/runtime/polkadot/src/xcm_config.rs index 1c3f8b69ea84..f0f2117f0d80 100644 --- a/runtime/polkadot/src/xcm_config.rs +++ b/runtime/polkadot/src/xcm_config.rs @@ -431,8 +431,8 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = SovereignAccountOf; type MaxLockers = ConstU32<8>; - type MaxRemoteLockUsers = ConstU32<0>; - type RemoteLockIdentifier = (); + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); type WeightInfo = crate::weights::pallet_xcm::WeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; diff --git a/runtime/rococo/src/xcm_config.rs b/runtime/rococo/src/xcm_config.rs index 885131ca2250..25995acc1d0e 100644 --- a/runtime/rococo/src/xcm_config.rs +++ b/runtime/rococo/src/xcm_config.rs @@ -370,8 +370,8 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = LocationConverter; type MaxLockers = ConstU32<8>; - type MaxRemoteLockUsers = ConstU32<0>; - type RemoteLockIdentifier = (); + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); type WeightInfo = crate::weights::pallet_xcm::WeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; diff --git a/runtime/test-runtime/src/xcm_config.rs b/runtime/test-runtime/src/xcm_config.rs index b6fe4858a8bc..8d7c57224ea6 100644 --- a/runtime/test-runtime/src/xcm_config.rs +++ b/runtime/test-runtime/src/xcm_config.rs @@ -144,8 +144,8 @@ impl pallet_xcm::Config for crate::Runtime { type TrustedLockers = (); type SovereignAccountOf = (); type MaxLockers = frame_support::traits::ConstU32<8>; - type MaxRemoteLockUsers = frame_support::traits::ConstU32<0>; - type RemoteLockIdentifier = (); + type MaxRemoteLockConsumers = frame_support::traits::ConstU32<0>; + type RemoteLockConsumerIdentifier = (); type WeightInfo = pallet_xcm::TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; diff --git a/runtime/westend/src/xcm_config.rs b/runtime/westend/src/xcm_config.rs index 06268b72d40a..cfeae2225cbd 100644 --- a/runtime/westend/src/xcm_config.rs +++ b/runtime/westend/src/xcm_config.rs @@ -287,8 +287,8 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = LocationConverter; type MaxLockers = ConstU32<8>; - type MaxRemoteLockUsers = ConstU32<0>; - type RemoteLockIdentifier = (); + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); type WeightInfo = crate::weights::pallet_xcm::WeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; diff --git a/xcm/pallet-xcm/src/lib.rs b/xcm/pallet-xcm/src/lib.rs index a90d8aa62737..9b055d29a0d8 100644 --- a/xcm/pallet-xcm/src/lib.rs +++ b/xcm/pallet-xcm/src/lib.rs @@ -244,11 +244,11 @@ pub mod pallet { /// The maximum number of local XCM locks that a single account may have. type MaxLockers: Get; - /// The maximum number of users a single remote lock may have. - type MaxRemoteLockUsers: Get; + /// The maximum number of consumers a single remote lock may have. + type MaxRemoteLockConsumers: Get; - /// The ID type for remote lock users. - type RemoteLockIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy; + /// The ID type for local consumers of remote locks. + type RemoteLockConsumerIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy; /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; @@ -445,7 +445,7 @@ pub mod pallet { FeesNotMet, /// A remote lock with the corresponding data could not be found. LockNotFound, - /// The unlock operation cannot succeed because there are still users of the lock. + /// The unlock operation cannot succeed because there are still consumers of the lock. InUse, } @@ -588,19 +588,25 @@ pub mod pallet { StorageValue<_, VersionMigrationStage, OptionQuery>; #[derive(Clone, Encode, Decode, Eq, PartialEq, Ord, PartialOrd, TypeInfo, MaxEncodedLen)] - #[scale_info(skip_type_params(MaxUsers))] - pub struct RemoteLockedFungibleRecord> { + #[scale_info(skip_type_params(MaxConsumers))] + pub struct RemoteLockedFungibleRecord> { + /// Total amount of the asset held by the remote lock. pub amount: u128, + /// The owner of the locked asset. pub owner: VersionedMultiLocation, + /// The location which holds the original lock. pub locker: VersionedMultiLocation, - pub users: BoundedVec<(RemoteLockIdentifier, u128), MaxUsers>, + /// Local consumers of the remote lock with consumer identifiers and the amount + /// of fungible asset every consumer holds. + /// Every consumer can hold up to total amount of the remote lock. + pub consumers: BoundedVec<(ConsumerIdentifier, u128), MaxConsumers>, } - impl> RemoteLockedFungibleRecord { - /// Amount of the remote lock in use by users. - /// Returns zero if the remote lock has no users. - pub fn amount_held(&self) -> u128 { - self.users.iter().max_by(|x, y| x.1.cmp(&y.1)).map_or(0, |max| max.1) + impl> RemoteLockedFungibleRecord { + /// Amount of the remote lock in use by consumers. + /// Returns `None` if the remote lock has no consumers. + pub fn amount_held(&self) -> Option { + self.consumers.iter().max_by(|x, y| x.1.cmp(&y.1)).map(|max| max.1) } } @@ -613,7 +619,7 @@ pub mod pallet { NMapKey, NMapKey, ), - RemoteLockedFungibleRecord, + RemoteLockedFungibleRecord, OptionQuery, >; @@ -1683,7 +1689,7 @@ impl xcm_executor::traits::Enact for ReduceTicket { let mut record = RemoteLockedFungibles::::get(&self.key).ok_or(UnexpectedState)?; ensure!(self.locker == record.locker && self.owner == record.owner, UnexpectedState); let new_amount = record.amount.checked_sub(self.amount).ok_or(UnexpectedState)?; - ensure!(record.users.len() == 0 || new_amount >= record.amount_held(), UnexpectedState); + ensure!(record.amount_held().map_or(true, |h| new_amount >= h), UnexpectedState); if new_amount == 0 { RemoteLockedFungibles::::remove(&self.key); } else { @@ -1748,11 +1754,11 @@ impl xcm_executor::traits::AssetLock for Pallet { let id: VersionedAssetId = asset.id.into(); let key = (XCM_VERSION, account, id); let mut record = - RemoteLockedFungibleRecord { amount, owner, locker, users: BoundedVec::default() }; + RemoteLockedFungibleRecord { amount, owner, locker, consumers: BoundedVec::default() }; if let Some(old) = RemoteLockedFungibles::::get(&key) { // Make sure that the new record wouldn't clobber any old data. ensure!(old.locker == record.locker && old.owner == record.owner, WouldClobber); - record.users = old.users; + record.consumers = old.consumers; record.amount = record.amount.max(old.amount); } RemoteLockedFungibles::::insert(&key, record); @@ -1781,7 +1787,7 @@ impl xcm_executor::traits::AssetLock for Pallet { ensure!(locker == record.locker && owner == record.owner, WouldClobber); ensure!(record.amount >= amount, NotEnoughLocked); ensure!( - record.users.len() == 0 || record.amount.saturating_sub(amount) >= record.amount_held(), + record.amount_held().map_or(true, |h| record.amount.saturating_sub(amount) >= h), InUse ); Ok(ReduceTicket { key, amount, locker, owner }) diff --git a/xcm/pallet-xcm/src/mock.rs b/xcm/pallet-xcm/src/mock.rs index 97c6d43dd191..30ad6457986b 100644 --- a/xcm/pallet-xcm/src/mock.rs +++ b/xcm/pallet-xcm/src/mock.rs @@ -342,8 +342,8 @@ impl pallet_xcm::Config for Test { type Currency = Balances; type CurrencyMatcher = IsConcrete; type MaxLockers = frame_support::traits::ConstU32<8>; - type MaxRemoteLockUsers = frame_support::traits::ConstU32<0>; - type RemoteLockIdentifier = (); + type MaxRemoteLockConsumers = frame_support::traits::ConstU32<0>; + type RemoteLockConsumerIdentifier = (); type WeightInfo = TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; diff --git a/xcm/xcm-builder/tests/mock/mod.rs b/xcm/xcm-builder/tests/mock/mod.rs index b76d7385e12c..023d3e2169e4 100644 --- a/xcm/xcm-builder/tests/mock/mod.rs +++ b/xcm/xcm-builder/tests/mock/mod.rs @@ -233,8 +233,8 @@ impl pallet_xcm::Config for Runtime { type Currency = Balances; type CurrencyMatcher = IsConcrete; type MaxLockers = frame_support::traits::ConstU32<8>; - type MaxRemoteLockUsers = frame_support::traits::ConstU32<0>; - type RemoteLockIdentifier = (); + type MaxRemoteLockConsumers = frame_support::traits::ConstU32<0>; + type RemoteLockConsumerIdentifier = (); type WeightInfo = pallet_xcm::TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; diff --git a/xcm/xcm-simulator/example/src/parachain.rs b/xcm/xcm-simulator/example/src/parachain.rs index d06fc7299ca9..1985c721765e 100644 --- a/xcm/xcm-simulator/example/src/parachain.rs +++ b/xcm/xcm-simulator/example/src/parachain.rs @@ -423,8 +423,8 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = LocationToAccountId; type MaxLockers = ConstU32<8>; - type MaxRemoteLockUsers = ConstU32<0>; - type RemoteLockIdentifier = (); + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); type WeightInfo = pallet_xcm::TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; diff --git a/xcm/xcm-simulator/example/src/relay_chain.rs b/xcm/xcm-simulator/example/src/relay_chain.rs index 6730e74ecd87..a6585b74c106 100644 --- a/xcm/xcm-simulator/example/src/relay_chain.rs +++ b/xcm/xcm-simulator/example/src/relay_chain.rs @@ -220,8 +220,8 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = LocationToAccountId; type MaxLockers = ConstU32<8>; - type MaxRemoteLockUsers = ConstU32<0>; - type RemoteLockIdentifier = (); + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); type WeightInfo = pallet_xcm::TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; diff --git a/xcm/xcm-simulator/fuzzer/src/parachain.rs b/xcm/xcm-simulator/fuzzer/src/parachain.rs index d9d20d4b709c..aace3b379c6a 100644 --- a/xcm/xcm-simulator/fuzzer/src/parachain.rs +++ b/xcm/xcm-simulator/fuzzer/src/parachain.rs @@ -338,8 +338,8 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = LocationToAccountId; type MaxLockers = frame_support::traits::ConstU32<8>; - type MaxRemoteLockUsers = frame_support::traits::ConstU32<0>; - type RemoteLockIdentifier = (); + type MaxRemoteLockConsumers = frame_support::traits::ConstU32<0>; + type RemoteLockConsumerIdentifier = (); type WeightInfo = pallet_xcm::TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; diff --git a/xcm/xcm-simulator/fuzzer/src/relay_chain.rs b/xcm/xcm-simulator/fuzzer/src/relay_chain.rs index 7a9e200f04f0..cb001d91f9b5 100644 --- a/xcm/xcm-simulator/fuzzer/src/relay_chain.rs +++ b/xcm/xcm-simulator/fuzzer/src/relay_chain.rs @@ -184,8 +184,8 @@ impl pallet_xcm::Config for Runtime { type TrustedLockers = (); type SovereignAccountOf = SovereignAccountOf; type MaxLockers = ConstU32<8>; - type MaxRemoteLockUsers = ConstU32<0>; - type RemoteLockIdentifier = (); + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); type WeightInfo = pallet_xcm::TestWeightInfo; #[cfg(feature = "runtime-benchmarks")] type ReachableDest = ReachableDest; From 841f1925d4f9f767d3d3e6086d1821e549ab2627 Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 28 Apr 2023 15:30:18 +0200 Subject: [PATCH 8/8] correct doc --- xcm/pallet-xcm/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcm/pallet-xcm/src/lib.rs b/xcm/pallet-xcm/src/lib.rs index 9b055d29a0d8..e38ce7c54e60 100644 --- a/xcm/pallet-xcm/src/lib.rs +++ b/xcm/pallet-xcm/src/lib.rs @@ -596,7 +596,7 @@ pub mod pallet { pub owner: VersionedMultiLocation, /// The location which holds the original lock. pub locker: VersionedMultiLocation, - /// Local consumers of the remote lock with consumer identifiers and the amount + /// Local consumers of the remote lock with a consumer identifier and the amount /// of fungible asset every consumer holds. /// Every consumer can hold up to total amount of the remote lock. pub consumers: BoundedVec<(ConsumerIdentifier, u128), MaxConsumers>,