Skip to content

Add migration for ForeignAssetCreator#581

Merged
ParthDesai merged 6 commits intotanssi-update-1.11.0from
add-foreign-asset-creator-migration
Jun 6, 2024
Merged

Add migration for ForeignAssetCreator#581
ParthDesai merged 6 commits intotanssi-update-1.11.0from
add-foreign-asset-creator-migration

Conversation

@ParthDesai
Copy link
Copy Markdown
Contributor

No description provided.

// Write to the new storage with removed and added fields
for (asset_id, old_location) in asset_id_to_foreign_asset_data {
if let Ok(new_location) = Runtime::ForeignAsset::try_from(old_location) {
AssetIdToForeignAsset::<Runtime>::insert(asset_id, new_location);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

YOu can probably do both migrations here and not iterate twice

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm. But, that would mean I am assuming the semantics of these two storage items in runtime.

Runtime::DbWeight::get()
.reads(migrated_count as u64)
.saturating_add(Runtime::DbWeight::get().writes(migrated_count as u64 + 3u64))
.saturating_add(Runtime::DbWeight::get().writes(foreign_asset_to_asset_id_count as u64))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Dont you need to multiply by 2 here? (as you are writing twice per foreign_asset_to_asset_id_count

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The other write is calculated above in migrated_count

@ParthDesai ParthDesai force-pushed the add-foreign-asset-creator-migration branch from 9f08bab to 076476e Compare June 6, 2024 09:46
Comment on lines +630 to +642
// Removing older entries with old location as key
let mut removal_result = storage::unhashed::clear_prefix(
&ForeignAssetToAssetId::<Runtime>::final_prefix(),
None,
None,
);
while removal_result.maybe_cursor.is_some() {
removal_result = storage::unhashed::clear_prefix(
&ForeignAssetToAssetId::<Runtime>::final_prefix(),
None,
removal_result.maybe_cursor.as_deref(),
);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This may not be needed because storage_key_iter().drain() above already removes from storage

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh. I did not know that drain also removes the item from storage.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed this call in next commit.

@ParthDesai ParthDesai force-pushed the add-foreign-asset-creator-migration branch from 8ef4430 to cb15a21 Compare June 6, 2024 10:00
Copy link
Copy Markdown
Contributor

@tmpolaczyk tmpolaczyk left a comment

Choose a reason for hiding this comment

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

Looks good so far!

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jun 6, 2024

Coverage Report

(master)

@@                                  Coverage Diff                                  @@
##           tanssi-update-1.11.0   add-foreign-asset-creator-migration      +/-   ##
=====================================================================================
+ Coverage                 69.32%                                69.53%   +0.21%     
  Files                       224                                   224              
+ Lines                     39347                                 39741     +394     
=====================================================================================
+ Hits                      27274                                 27632     +358     
+ Misses                    12073                                 12109      +36     
Files Changed Coverage
/client/manual-xcm/src/lib.rs 40.43% (+0.85%) 🔼
/client/node-common/src/service.rs 48.16% (+0.63%) 🔼
/client/services-payment/src/lib.rs 74.19% (+4.49%) 🔼
/container-chains/nodes/frontier/src/command.rs 35.04% (-0.10%) 🔽
/container-chains/nodes/frontier/src/service.rs 79.50% (+1.10%) 🔼
/container-chains/nodes/simple/src/command.rs 30.96% (-0.08%) 🔽
/container-chains/nodes/simple/src/service.rs 86.43% (+2.08%) 🔼
/container-chains/runtime-templates/frontier/src/lib.rs 60.82% (+0.60%) 🔼
/container-chains/runtime-templates/frontier/src/migrations.rs 89.29% (-10.71%) 🔽
/container-chains/runtime-templates/frontier/src/weights/xcm/mod.rs 16.39% (+1.31%) 🔼
/container-chains/runtime-templates/simple/src/lib.rs 73.43% (+0.52%) 🔼
/container-chains/runtime-templates/simple/src/migrations.rs 89.29% (-10.71%) 🔽
/container-chains/runtime-templates/simple/src/weights/xcm/mod.rs 16.39% (+1.31%) 🔼
/node/src/command.rs 27.96% (-0.05%) 🔽
/node/src/service.rs 21.63% (-0.02%) 🔽
/pallets/author-noting/src/lib.rs 87.96% (+1.39%) 🔼
/pallets/registrar/src/weights.rs 25.00% (+0.83%) 🔼
/pallets/services-payment/src/lib.rs 94.27% (+1.59%) 🔼
/primitives/author-noting-inherent/src/client_side.rs 87.50% (+8.01%) 🔼
/runtime/common/src/migrations.rs 87.73% (+41.61%) 🔼
/runtime/dancebox/src/lib.rs 89.17% (-0.15%) 🔽
/runtime/dancebox/src/weights/pallet_balances.rs 21.95% (-2.05%) 🔽
/runtime/dancebox/src/weights/pallet_xcm.rs 10.47% (-0.64%) 🔽
/runtime/dancebox/src/weights/xcm/mod.rs 43.17% (-1.55%) 🔽
/runtime/dancebox/src/xcm_config.rs 84.54% (+0.87%) 🔼
/runtime/dancebox/tests/integration_test.rs 99.70% (+0.01%) 🔼
/runtime/flashbox/src/lib.rs 45.52% (-0.21%) 🔽

Coverage generated Thu Jun 6 17:34:22 UTC 2024

@girazoki girazoki added B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes D5-nicetohaveaudit⚠️ PR contains trivial changes to logic that should be properly reviewed. breaking Needs to be mentioned in breaking changes labels Jun 6, 2024
//! This module acts as a registry where each migration is defined. Each migration should implement
//! the "Migration" trait declared in the pallet-migrations crate.

use frame_support::__private::log;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
use frame_support::__private::log;

}

// One db read and one db write per element, plus the on-chain storage
Runtime::DbWeight::get().reads_writes(migrated_count as u64, 2 * migrated_count as u64)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see, 1 write when using drain, and another write when using insert...

@ParthDesai ParthDesai merged commit 88af7e5 into tanssi-update-1.11.0 Jun 6, 2024
@ParthDesai ParthDesai deleted the add-foreign-asset-creator-migration branch June 6, 2024 18:39
girazoki added a commit that referenced this pull request Jun 7, 2024
* first branches

* removfe try runtime and start updating

* start working on fixes

* advances

* fixes before rt

* dancebox compiles

* flashbox compiles

* fix a million things

* node changes

* update lock

* fixes2

* fix xcm-primtiives

* remove from dancebox

* add primitive-types to cargo.toml

* fix cargo.lock

* add primitive-types/std to dancebox

* Add PoV size host function to runtimes

* Fix zombienet config

* let's see if now tomls are fixed

* fix currencyAdapter

* Update mocks

* Rest of mocks and unit tests fixes

* fix dev tests execution

* remove build output

* FMT

* chopsticks

* fix custom policy test

* fix scripts typescript api gen

* base fee

* update packageS

* fmt

* use ResolveTo, although we lose the event

* resolveto

* fmt

* Update polkadot-sdk commit, solving dup import

* fix different message when invalid params returned from rpc

* Fix XCMv4 types in tests

* XCM

* FMT

* Update lock

* Config get

* fmt

* VersionedXcmV4

* different fixes

* fmt

* brings back event for on demand

* left overs from merge

* Fix xcm-core-buyer tests

* start putting migrations in

* lock file update

Signed-off-by: girazoki <gorka.irazoki@gmail.com>

* fix zombienet upgrade jobs

* Add migration for ForeignAssetCreator (#581)

* Add migration for ForeignAssetCreator

* use accurate weight

---------

Signed-off-by: girazoki <gorka.irazoki@gmail.com>
Co-authored-by: Agusrodri <agusrodriguez2456@gmail.com>
Co-authored-by: Tomasz Polaczyk <tmpolaczyk@gmail.com>
Co-authored-by: Francisco Gamundi <francisco@moonsonglabs.com>
Co-authored-by: Parth <desaiparth08@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes breaking Needs to be mentioned in breaking changes D5-nicetohaveaudit⚠️ PR contains trivial changes to logic that should be properly reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants