Skip to content

Commit

Permalink
Mesh 2063 disable investor uniqueness migration (#1492)
Browse files Browse the repository at this point in the history
* Migrate IU assets to non-IU.

* Bump version 5.4.2.
  • Loading branch information
Neopallium authored Aug 23, 2023
1 parent f1f1bc4 commit 9301b52
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polymesh"
version = "5.4.1"
version = "5.4.2"
authors = ["Polymesh Association"]
build = "build.rs"
edition = "2021"
Expand Down
1 change: 1 addition & 0 deletions pallets/asset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ serde_json = "1.0.48"
rustc-hex = { version = "2.1.0", default-features = false }
hex-literal = "0.2.1"
arrayvec = { version = "0.7.1", default-features = false }
log = "0.4"

# Substrate
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
Expand Down
52 changes: 49 additions & 3 deletions pallets/asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ use core::result::Result as StdResult;
use currency::*;
use frame_support::{
decl_error, decl_module, decl_storage,
dispatch::{DispatchError, DispatchResult},
dispatch::{DispatchError, DispatchResult, Weight},
ensure, fail,
traits::Get,
};
Expand Down Expand Up @@ -216,7 +216,7 @@ pub struct ClassicTickerRegistration {
pub is_created: bool,
}

storage_migration_ver!(1);
storage_migration_ver!(2);

decl_storage! {
trait Store for Module<T: Config> as Asset {
Expand Down Expand Up @@ -327,7 +327,7 @@ decl_storage! {
pub AssetMetadataNextGlobalKey get(fn asset_metadata_next_global_key): AssetMetadataGlobalKey;

/// Storage version.
StorageVersion get(fn storage_version) build(|_| Version::new(1)): Version;
StorageVersion get(fn storage_version) build(|_| Version::new(2)): Version;
}
add_extra_genesis {
config(classic_migration_tickers): Vec<ClassicTickerImport>;
Expand Down Expand Up @@ -373,6 +373,52 @@ decl_module! {
const AssetMetadataValueMaxLength: u32 = T::AssetMetadataValueMaxLength::get();
const AssetMetadataTypeDefMaxLength: u32 = T::AssetMetadataTypeDefMaxLength::get();

fn on_runtime_upgrade() -> Weight {
use polymesh_primitives::storage_migrate_on;

storage_migrate_on!(StorageVersion, 2, {
log::info!("Migrating Investor Uniqueness assets.");
let iu_tickers = DisableInvestorUniqueness::iter()
.filter_map(|(ticker, disable_iu)| match disable_iu {
true => None,
false => Some(ticker),
})
.collect::<Vec<_>>();
// Update the scope balances.
for ticker in &iu_tickers {
for (target_did, old_scope_id) in ScopeIdOf::iter_prefix(ticker) {
// Cleanup old scope id.
// Delete the balance of target_did at old_scope_id.
BalanceOfAtScope::take(old_scope_id, target_did);
// Cleanup `AggregateBalance` by removing values for old scope ids.
AggregateBalance::take(ticker, old_scope_id);

// scope_id will now be the same as the did.
let scope_id = target_did;

// Update `BalanceOfAtScope` and `AggregateBalance`.
// These will be the same value as `BalanceOf`.
let balance = Self::balance_of(ticker, target_did);
// Update the balance of `target_did` under `scope_id`.
BalanceOfAtScope::insert(scope_id, target_did, balance);
// `AggregateBalance` is the same as `BalanceOf` for non-IU assets.
AggregateBalance::insert(ticker, scope_id, balance);
// Caches the `ScopeId` for a given IdentityId and ticker.
// this is needed to avoid the on-chain iteration of the claims to find the ScopeId.
ScopeIdOf::insert(ticker, target_did, scope_id);
}
// Disable investor uniqueness.
DisableInvestorUniqueness::insert(ticker, true);
}

log::info!("Migrated {} Investor Uniqueness assets.", iu_tickers.len());

let count = ClassicTickers::drain().count();
log::info!("Removed {count} ClassicTickers.");
});

Weight::zero()
}
/// Registers a new ticker or extends validity of an existing ticker.
/// NB: Ticker validity does not get carry forward when renewing ticker.
///
Expand Down
2 changes: 1 addition & 1 deletion pallets/runtime/develop/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
authoring_version: 1,
// `spec_version: aaa_bbb_ccd` should match node version v`aaa.bbb.cc`
// N.B. `d` is unpinned from the binary version
spec_version: 5_004_001,
spec_version: 5_004_002,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 3,
Expand Down
2 changes: 1 addition & 1 deletion pallets/runtime/mainnet/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
authoring_version: 1,
// `spec_version: aaa_bbb_ccd` should match node version v`aaa.bbb.cc`
// N.B. `d` is unpinned from the binary version
spec_version: 5_004_001,
spec_version: 5_004_002,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 3,
Expand Down
2 changes: 1 addition & 1 deletion pallets/runtime/testnet/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
authoring_version: 1,
// `spec_version: aaa_bbb_ccd` should match node version v`aaa.bbb.cc`
// N.B. `d` is unpinned from the binary version
spec_version: 5_004_001,
spec_version: 5_004_002,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 3,
Expand Down

0 comments on commit 9301b52

Please sign in to comment.