Skip to content

Commit

Permalink
Fix sto migration (#1730)
Browse files Browse the repository at this point in the history
* Fix sto migration

* Fix identity migrations

* Improve log messages

* Remove migration for new storage

* Bump RC spec_version

---------

Co-authored-by: Adam Dossa <[email protected]>
  • Loading branch information
HenriqueNogara and adamdossa authored Oct 10, 2024
1 parent 4ba8aad commit d454888
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 114 deletions.
71 changes: 49 additions & 22 deletions pallets/asset/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub(crate) fn migrate_to_v5<T: Config>() {
ticker_to_asset_id.insert(ticker, asset_id);
UniqueTickerRegistration::<T>::insert(ticker, ticker_registration);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Asset.Tickers entries.", count);

let mut count = 0;
log::info!("Moving items from Tokens to Assets");
Expand All @@ -126,7 +126,7 @@ pub(crate) fn migrate_to_v5<T: Config>() {
.or_insert(AssetID::from(ticker));
Assets::insert(asset_id, asset_details);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Asset.Tokens entries.", count);

let mut count = 0;
log::info!("Updating types for the AssetNames storage");
Expand All @@ -141,7 +141,7 @@ pub(crate) fn migrate_to_v5<T: Config>() {
.or_insert(AssetID::from(ticker));
AssetNames::insert(asset_id, asset_name);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Asset.AssetNames entries.", count);

let mut count = 0;
log::info!("Updating types for the BalanceOf storage");
Expand All @@ -156,7 +156,7 @@ pub(crate) fn migrate_to_v5<T: Config>() {
.or_insert(AssetID::from(ticker));
BalanceOf::insert(asset_id, identity, balance);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Asset.BalanceOf entries.", count);

let mut count = 0;
log::info!("Moving items from Identifiers to AssetIdentifiers");
Expand All @@ -167,7 +167,7 @@ pub(crate) fn migrate_to_v5<T: Config>() {
.or_insert(AssetID::from(ticker));
AssetIdentifiers::insert(asset_id, identifiers);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Asset.Identifiers entries.", count);

let mut count = 0;
log::info!("Updating types for the FundingRound storage");
Expand All @@ -182,7 +182,7 @@ pub(crate) fn migrate_to_v5<T: Config>() {
.or_insert(AssetID::from(ticker));
FundingRound::insert(asset_id, name);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Asset.FundingRound entries.", count);

let mut count = 0;
log::info!("Updating types for the IssuedInFundingRound storage");
Expand All @@ -197,7 +197,7 @@ pub(crate) fn migrate_to_v5<T: Config>() {
.or_insert(AssetID::from(ticker));
IssuedInFundingRound::insert((asset_id, name), balance);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Asset.IssuedInFundingRound entries.", count);

let mut count = 0;
log::info!("Updating types for the Frozen storage");
Expand All @@ -209,7 +209,7 @@ pub(crate) fn migrate_to_v5<T: Config>() {
.or_insert(AssetID::from(ticker));
Frozen::insert(asset_id, frozen);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Asset.Frozen entries.", count);

let mut count = 0;
log::info!("Moving items from AssetOwnershipRelations to TickersOwnedByUser and SecurityTokensOwnedByUser");
Expand All @@ -230,7 +230,7 @@ pub(crate) fn migrate_to_v5<T: Config>() {
AssetOwnershipRelation::NotOwned => {}
}
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Asset.AssetOwnershipRelation entries.", count);

let mut count = 0;
log::info!("Updating types for the AssetDocuments storage");
Expand All @@ -246,7 +246,7 @@ pub(crate) fn migrate_to_v5<T: Config>() {

AssetDocuments::insert(asset_id, doc_id, doc);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Asset.AssetDocuments entries.", count);

let mut count = 0;
log::info!("Updating types for the AssetDocumentsIdSequence storage");
Expand All @@ -262,7 +262,10 @@ pub(crate) fn migrate_to_v5<T: Config>() {

AssetDocumentsIdSequence::insert(asset_id, seq);
});
log::info!("{:?} items migrated", count);
log::info!(
"Migrated {:?} Asset.AssetDocumentsIdSequence entries.",
count
);

let mut count = 0;
log::info!("Updating types for the AssetMetadataValues storage");
Expand All @@ -278,7 +281,7 @@ pub(crate) fn migrate_to_v5<T: Config>() {

AssetMetadataValues::insert(asset_id, key, value);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Asset.AssetMetadataValues entries.", count);

let mut count = 0;
log::info!("Updating types for the AssetMetadataValueDetails storage");
Expand All @@ -294,7 +297,10 @@ pub(crate) fn migrate_to_v5<T: Config>() {

AssetMetadataValueDetails::<T>::insert(asset_id, key, value);
});
log::info!("{:?} items migrated", count);
log::info!(
"Migrated {:?} Asset.AssetMetadataValueDetails entries.",
count
);

let mut count = 0;
log::info!("Updating types for the AssetMetadataLocalNameToKey storage");
Expand All @@ -310,7 +316,10 @@ pub(crate) fn migrate_to_v5<T: Config>() {

AssetMetadataLocalNameToKey::insert(asset_id, name, local_key);
});
log::info!("{:?} items migrated", count);
log::info!(
"Migrated {:?} Asset.AssetMetadataLocalNameToKey entries.",
count
);

let mut count = 0;
log::info!("Updating types for the AssetMetadataLocalKeyToName storage");
Expand All @@ -326,7 +335,10 @@ pub(crate) fn migrate_to_v5<T: Config>() {

AssetMetadataLocalKeyToName::insert(asset_id, local_key, name);
});
log::info!("{:?} items migrated", count);
log::info!(
"Migrated {:?} Asset.AssetMetadataLocalKeyToName entries.",
count
);

let mut count = 0;
log::info!("Updating types for the AssetMetadataLocalSpecs storage");
Expand All @@ -342,11 +354,17 @@ pub(crate) fn migrate_to_v5<T: Config>() {

AssetMetadataLocalSpecs::insert(asset_id, local_key, spec);
});
log::info!("{:?} items migrated", count);
log::info!(
"Migrated {:?} Asset.AssetMetadataLocalSpecs entries.",
count
);

log::info!("Removing old AssetMetadataNextLocalKey storage");
let res = v4::AssetMetadataNextLocalKey::clear(u32::max_value(), None);
log::info!("{:?} items have been cleared", res.unique);
log::info!(
"Cleared {:?} items from Asset.AssetMetadataNextLocalKey",
res.unique
);

let mut count = 0;
log::info!("Moving items from TickersExemptFromAffirmation to AssetsExemptFromAffirmation");
Expand All @@ -358,7 +376,10 @@ pub(crate) fn migrate_to_v5<T: Config>() {

AssetsExemptFromAffirmation::insert(asset_id, exempt);
});
log::info!("{:?} items migrated", count);
log::info!(
"Migrated {:?} Asset.TickersExemptFromAffirmation entries.",
count
);

let mut count = 0;
log::info!("Moving items from PreApprovedTicker to PreApprovedAsset");
Expand All @@ -370,7 +391,7 @@ pub(crate) fn migrate_to_v5<T: Config>() {

PreApprovedAsset::insert(did, asset_id, approved);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Asset.PreApprovedTicker entries.", count);

let mut count = 0;
log::info!("Updating types for the MandatoryMediators storage");
Expand All @@ -386,7 +407,7 @@ pub(crate) fn migrate_to_v5<T: Config>() {

MandatoryMediators::<T>::insert(asset_id, mediators);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Asset.MandatoryMediators entries.", count);

let mut count = 0;
log::info!("Updating types for the CurrentAssetMetadataLocalKey storage");
Expand All @@ -402,7 +423,10 @@ pub(crate) fn migrate_to_v5<T: Config>() {

CurrentAssetMetadataLocalKey::insert(asset_id, current_key);
});
log::info!("{:?} items migrated", count);
log::info!(
"Migrated {:?} Asset.CurrentAssetMetadataLocalKey entries.",
count
);

let mut count = 0;
log::info!("Adding link from legacy tickers to an asset_id");
Expand All @@ -411,7 +435,10 @@ pub(crate) fn migrate_to_v5<T: Config>() {
AssetIDTicker::insert(asset_id, ticker);
TickerAssetID::insert(ticker, asset_id);
}
log::info!("{:?} items migrated", count);
log::info!(
"Added {:?} Asset.TickerAssetID/AssetIDTicker entries",
count
);

log::info!("AssetMetadataNextGlobalKey has been cleared");
v4::AssetMetadataNextGlobalKey::kill();
Expand Down
7 changes: 5 additions & 2 deletions pallets/compliance-manager/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub(crate) fn migrate_to_v1<T: Config>() {
.or_insert(AssetID::from(ticker));
AssetCompliances::insert(asset_id, AssetCompliance::from(compliance));
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Compliance.AssetCompliances entries.", count);

let mut count = 0;
log::info!("Updating types for the TrustedClaimIssuer storage");
Expand All @@ -197,5 +197,8 @@ pub(crate) fn migrate_to_v1<T: Config>() {
.or_insert(AssetID::from(ticker));
TrustedClaimIssuer::insert(asset_id, trusted_issuers);
});
log::info!("{:?} items migrated", count);
log::info!(
"Migrated {:?} Compliance.TrustedClaimIssuer entries.",
count
);
}
12 changes: 6 additions & 6 deletions pallets/corporate-actions/src/ballot/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub(crate) fn migrate_to_v1<T: Config>() {
count += 1;
Metas::insert(CAId::from(ca_id), ballot);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Ballot.Metas entries.", count);

let mut count = 0;
log::info!("Updating types for the TimeRanges storage");
Expand All @@ -60,7 +60,7 @@ pub(crate) fn migrate_to_v1<T: Config>() {
count += 1;
TimeRanges::insert(CAId::from(ca_id), range);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Ballot.TimeRanges entries.", count);

let mut count = 0;
log::info!("Updating types for the MotionNumChoices storage");
Expand All @@ -72,7 +72,7 @@ pub(crate) fn migrate_to_v1<T: Config>() {
count += 1;
MotionNumChoices::insert(CAId::from(ca_id), choices);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Ballot.MotionNumChoices entries.", count);

let mut count = 0;
log::info!("Updating types for the RCV storage");
Expand All @@ -81,7 +81,7 @@ pub(crate) fn migrate_to_v1<T: Config>() {
count += 1;
RCV::insert(CAId::from(ca_id), rcv);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Ballot.RCV entries.", count);

let mut count = 0;
log::info!("Updating types for the Results storage");
Expand All @@ -90,7 +90,7 @@ pub(crate) fn migrate_to_v1<T: Config>() {
count += 1;
Results::insert(CAId::from(ca_id), balances);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Ballot.Results entries.", count);

let mut count = 0;
log::info!("Updating types for the Votes storage");
Expand All @@ -99,5 +99,5 @@ pub(crate) fn migrate_to_v1<T: Config>() {
count += 1;
Votes::insert(CAId::from(ca_id), did, vote);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Ballot.Votes entries.", count);
}
4 changes: 2 additions & 2 deletions pallets/corporate-actions/src/distribution/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub(crate) fn migrate_to_v1<T: Config>() {
count += 1;
Distributions::insert(CAId::from(ca_id), Distribution::from(distribution));
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Distribution.Distributions entries.", count);

let mut count = 0;
log::info!("Updating types for the HolderPaid storage");
Expand All @@ -76,5 +76,5 @@ pub(crate) fn migrate_to_v1<T: Config>() {
count += 1;
HolderPaid::insert((CAId::from(ca_id), did), paid);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} Distribution.HolderPaid entries.", count);
}
14 changes: 7 additions & 7 deletions pallets/corporate-actions/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub(crate) fn migrate_to_v1<T: Config>() {
.or_insert(AssetID::from(ticker));
DefaultTargetIdentities::insert(asset_id, target_identities);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} CA.DefaultTargetIdentities entries.", count);

let mut count = 0;
log::info!("Updating types for the DefaultWithholdingTax storage");
Expand All @@ -92,7 +92,7 @@ pub(crate) fn migrate_to_v1<T: Config>() {
.or_insert(AssetID::from(ticker));
DefaultWithholdingTax::insert(asset_id, tax);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} CA.DefaultWithholdingTax entries.", count);

let mut count = 0;
log::info!("Updating types for the DidWithholdingTax storage");
Expand All @@ -107,7 +107,7 @@ pub(crate) fn migrate_to_v1<T: Config>() {
.or_insert(AssetID::from(ticker));
DidWithholdingTax::insert(asset_id, id_tax);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} CA.DidWithholdingTax entries.", count);

let mut count = 0;
log::info!("Updating types for the CAIdSequence storage");
Expand All @@ -122,7 +122,7 @@ pub(crate) fn migrate_to_v1<T: Config>() {
.or_insert(AssetID::from(ticker));
CAIdSequence::insert(asset_id, id_tax);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} CA.CAIdSequence entries.", count);

let mut count = 0;
log::info!("Updating types for the CorporateActions storage");
Expand All @@ -137,7 +137,7 @@ pub(crate) fn migrate_to_v1<T: Config>() {
.or_insert(AssetID::from(ticker));
CorporateActions::insert(asset_id, local_id, ca);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} CA.CorporateActions entries.", count);

let mut count = 0;
log::info!("Updating types for the CADocLink storage");
Expand All @@ -149,7 +149,7 @@ pub(crate) fn migrate_to_v1<T: Config>() {
count += 1;
CADocLink::insert(CAId::from(ca_id), docs);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} CA.CADocLink entries.", count);

let mut count = 0;
log::info!("Updating types for the Details storage");
Expand All @@ -158,5 +158,5 @@ pub(crate) fn migrate_to_v1<T: Config>() {
count += 1;
Details::insert(CAId::from(ca_id), details);
});
log::info!("{:?} items migrated", count);
log::info!("Migrated {:?} CA.Details entries.", count);
}
Loading

0 comments on commit d454888

Please sign in to comment.