Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset Conversion: Pool Account ID derivation with additional Pallet ID seed #3250

Merged
merged 52 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
21d1df4
account id converter with pallet id salt
muharem Feb 2, 2024
ebbad9f
migration for pool account
muharem Feb 2, 2024
1e2a925
refund trait and impl
muharem Feb 7, 2024
a45b298
drop super trait for reset team trait
muharem Feb 7, 2024
d8f7b4e
account id types
muharem Feb 8, 2024
1d30b89
fungibles
muharem Feb 8, 2024
cb3b79d
migration
muharem Feb 8, 2024
9f2c71a
setup migration for asset hubs
muharem Feb 8, 2024
f9a0edc
doc fixes
muharem Feb 8, 2024
61245e3
Merge remote-tracking branch 'origin/master' into muharem-asset-conve…
muharem Feb 8, 2024
6fce4bf
prdoc
muharem Feb 8, 2024
2321031
try runtime imports
muharem Feb 8, 2024
3d3e5b3
change account id format for logs
muharem Feb 8, 2024
ff19ff1
import
muharem Feb 8, 2024
4dd4334
rename deposit fn to deposit_held
muharem Feb 8, 2024
3537f90
migration adjustments
muharem Feb 9, 2024
0eee02e
migration asserts reduce to zero instead success
muharem Feb 9, 2024
11e3004
correct doc
muharem Feb 9, 2024
03363c8
balance for destroying asset cannot be increased/decreased
muharem Feb 12, 2024
58f0a66
migration
muharem Feb 12, 2024
d14b412
make migration idempotent
muharem Feb 12, 2024
10713ad
Merge branch 'master' into muharem-asset-conversion-pool-account
muharem Feb 12, 2024
979ae0c
asset conversion ops pallet
muharem Feb 16, 2024
3be3789
Revert "balance for destroying asset cannot be increased/decreased"
muharem Feb 16, 2024
f3ea112
Merge remote-tracking branch 'origin/master' into muharem-asset-conve…
muharem Feb 16, 2024
086198c
todos and unused import
muharem Feb 16, 2024
0e12b1f
clippy fix: remove clone
muharem Feb 16, 2024
6deee7f
format fixes
muharem Feb 17, 2024
c21ca3b
Merge branch 'master' into muharem-asset-conversion-pool-account
muharem Feb 20, 2024
4d4db89
Merge remote-tracking branch 'origin/master' into muharem-asset-conve…
muharem Feb 26, 2024
02a38f0
review fixes
muharem Feb 26, 2024
66b7573
test
muharem Feb 26, 2024
30b9a39
transfer total balance
muharem Feb 26, 2024
5f65481
Merge remote-tracking branch 'origin/master' into muharem-asset-conve…
muharem Mar 13, 2024
414205c
review fixes
muharem Mar 13, 2024
9f3acde
style fixes
muharem Mar 18, 2024
4300625
Merge remote-tracking branch 'origin/master' into muharem-asset-conve…
muharem Mar 18, 2024
4f2b973
Merge branch 'master' into muharem-asset-conversion-pool-account
muharem Mar 20, 2024
05e639d
Merge branch 'master' into muharem-asset-conversion-pool-account
muharem Mar 24, 2024
c8cda18
Merge remote-tracking branch 'origin/master' into muharem-asset-conve…
muharem Apr 13, 2024
b756f5f
folder for weights
muharem Apr 13, 2024
71c09ee
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Apr 13, 2024
41b9f9e
weights
muharem Apr 13, 2024
8ce6f7c
update reset team trait
muharem Apr 15, 2024
9247584
update refund trait
muharem Apr 15, 2024
6915afe
remove unused imports
muharem Apr 15, 2024
7398696
Revert "update refund trait"
muharem Apr 15, 2024
7bfd1ff
Revert "remove unused imports"
muharem Apr 15, 2024
7a579a9
update doc
muharem Apr 15, 2024
fba27bf
update pr doc and use default configs for pallets in test env
muharem Apr 16, 2024
82b0aca
update docs
muharem Apr 16, 2024
496e2d7
move reset team trait to roles module
muharem Apr 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 47 additions & 2 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,24 @@ pub type NativeAndAssets = fungible::UnionOf<
AccountId,
>;

pub type PoolIdToAccountId = pallet_asset_conversion::AccountIdConverter<
AssetConversionPalletId,
(xcm::v3::Location, xcm::v3::Location),
>;

impl pallet_asset_conversion::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type HigherPrecisionBalance = sp_core::U256;
type AssetKind = xcm::v3::Location;
type Assets = NativeAndAssets;
type PoolId = (Self::AssetKind, Self::AssetKind);
type PoolLocator =
pallet_asset_conversion::WithFirstAsset<TokenLocationV3, AccountId, Self::AssetKind>;
type PoolLocator = pallet_asset_conversion::WithFirstAsset<
TokenLocationV3,
AccountId,
Self::AssetKind,
PoolIdToAccountId,
>;
type PoolAssetId = u32;
type PoolAssets = PoolAssets;
type PoolSetupFee = ConstU128<0>; // Asset class deposit fees are sufficient to prevent spam
Expand Down Expand Up @@ -962,14 +971,50 @@ pub type SignedExtra = (
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;

parameter_types! {
pub PerAccountMigrationWeight: Weight = {
// 2 balance + 2 deposit
<Runtime as frame_system::Config>::DbWeight::get().reads(5)
.saturating_add(
<weights::pallet_assets_local::WeightInfo<Runtime> as pallet_assets::WeightInfo>::transfer()
).saturating_add(
<weights::pallet_assets_foreign::WeightInfo<Runtime> as pallet_assets::WeightInfo>::transfer()
).saturating_add(
<weights::pallet_assets_local::WeightInfo<Runtime> as pallet_assets::WeightInfo>::refund_other()
).saturating_add(
<weights::pallet_assets_foreign::WeightInfo<Runtime> as pallet_assets::WeightInfo>::refund_other()
).saturating_add( // team reset
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 1)
)
};
}

/// Migrations to apply on runtime upgrade.
#[allow(deprecated)]
pub type Migrations = (
pallet_collator_selection::migration::v1::MigrateToV1<Runtime>,
InitStorageVersions,
// unreleased
cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4<Runtime>,
// permanent
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
// unreleased
pallet_asset_conversion::migration::new_pool_account_id::Migrate<
Runtime,
pallet_asset_conversion::WithFirstAsset<
TokenLocationV3,
AccountId,
xcm::v3::Location,
pallet_asset_conversion::AccountIdConverterNoSeed<(
xcm::v3::Location,
xcm::v3::Location,
)>,
>,
<Runtime as pallet_asset_conversion::Config>::PoolAssets,
<Runtime as pallet_asset_conversion::Config>::Assets,
PerAccountMigrationWeight,
>,
);

/// Migration to initialize storage versions for pallets added after genesis.
Expand Down
47 changes: 45 additions & 2 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,24 @@ pub type NativeAndAssets = fungible::UnionOf<
AccountId,
>;

pub type PoolIdToAccountId = pallet_asset_conversion::AccountIdConverter<
AssetConversionPalletId,
(xcm::v3::Location, xcm::v3::Location),
>;

impl pallet_asset_conversion::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type HigherPrecisionBalance = sp_core::U256;
type AssetKind = xcm::v3::Location;
type Assets = NativeAndAssets;
type PoolId = (Self::AssetKind, Self::AssetKind);
type PoolLocator =
pallet_asset_conversion::WithFirstAsset<WestendLocationV3, AccountId, Self::AssetKind>;
type PoolLocator = pallet_asset_conversion::WithFirstAsset<
WestendLocationV3,
AccountId,
Self::AssetKind,
PoolIdToAccountId,
>;
type PoolAssetId = u32;
type PoolAssets = PoolAssets;
type PoolSetupFee = ConstU128<0>; // Asset class deposit fees are sufficient to prevent spam
Expand Down Expand Up @@ -935,6 +944,24 @@ pub type SignedExtra = (
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;

parameter_types! {
pub PerAccountMigrationWeight: Weight = {
// 2 balance + 2 deposit
<Runtime as frame_system::Config>::DbWeight::get().reads(5)
.saturating_add(
<weights::pallet_assets_local::WeightInfo<Runtime> as pallet_assets::WeightInfo>::transfer()
).saturating_add(
<weights::pallet_assets_foreign::WeightInfo<Runtime> as pallet_assets::WeightInfo>::transfer()
).saturating_add(
<weights::pallet_assets_local::WeightInfo<Runtime> as pallet_assets::WeightInfo>::refund_other()
).saturating_add(
<weights::pallet_assets_foreign::WeightInfo<Runtime> as pallet_assets::WeightInfo>::refund_other()
).saturating_add( // team reset
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 1)
)
};
}

/// Migrations to apply on runtime upgrade.
pub type Migrations = (
// v9420
Expand All @@ -951,6 +978,22 @@ pub type Migrations = (
cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4<Runtime>,
// permanent
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
// unreleased
pallet_asset_conversion::migration::new_pool_account_id::Migrate<
Runtime,
pallet_asset_conversion::WithFirstAsset<
WestendLocationV3,
AccountId,
xcm::v3::Location,
pallet_asset_conversion::AccountIdConverterNoSeed<(
xcm::v3::Location,
xcm::v3::Location,
)>,
>,
<Runtime as pallet_asset_conversion::Config>::PoolAssets,
<Runtime as pallet_asset_conversion::Config>::Assets,
PerAccountMigrationWeight,
>,
);

/// Asset Hub Westend has some undecodable storage, delete it.
Expand Down
14 changes: 14 additions & 0 deletions prdoc/pr_3250.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 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: "Asset Conversion: Pool Account ID derivation with additional Pallet ID seed"

doc:
- audience: Runtime Dev
description: |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you mention the migration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can improve this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Introduce PalletId as an additional seed parameter for pool's account id derivation.
The PR also introduces the fungibles::lifetime::ResetTeam and fungible::lifetime::Refund traits,
which facilitate the migration of pools to the new account IDs.

crates:
- name: pallet-asset-conversion
15 changes: 12 additions & 3 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use frame_system::{
};
pub use node_primitives::{AccountId, Signature};
use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Moment, Nonce};
use pallet_asset_conversion::{Ascending, Chain, WithFirstAsset};
use pallet_asset_conversion::{AccountIdConverter, Ascending, Chain, WithFirstAsset};
use pallet_broker::{CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600};
use pallet_election_provider_multi_phase::{GeometricDepositBase, SolutionAccuracyOf};
use pallet_identity::legacy::IdentityInfo;
Expand Down Expand Up @@ -1693,8 +1693,17 @@ impl pallet_asset_conversion::Config for Runtime {
type Assets = UnionOf<Balances, Assets, NativeFromLeft, NativeOrWithId<u32>, AccountId>;
type PoolId = (Self::AssetKind, Self::AssetKind);
type PoolLocator = Chain<
WithFirstAsset<Native, AccountId, NativeOrWithId<u32>>,
Ascending<AccountId, NativeOrWithId<u32>>,
WithFirstAsset<
Native,
AccountId,
NativeOrWithId<u32>,
AccountIdConverter<AssetConversionPalletId, Self::PoolId>,
>,
Ascending<
AccountId,
NativeOrWithId<u32>,
AccountIdConverter<AssetConversionPalletId, Self::PoolId>,
>,
>;
type PoolAssetId = <Self as pallet_assets::Config<Instance2>>::AssetId;
type PoolAssets = PoolAssets;
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/asset-conversion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false }
log = { version = "0.4.20", default-features = false }
frame-support = { path = "../support", default-features = false }
frame-system = { path = "../system", default-features = false }
frame-benchmarking = { path = "../benchmarking", default-features = false, optional = true }
Expand All @@ -40,6 +41,7 @@ std = [
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-assets/std",
"pallet-balances/std",
"primitive-types/std",
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/asset-conversion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pub mod migration;
#[cfg(test)]
mod mock;
mod swap;
Expand Down
Loading
Loading