Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Fixed logic of the storage migration to triple reference counting.#10337

Merged
paritytech-processbot[bot] merged 5 commits into
paritytech:masterfrom
remzrn:master
Dec 9, 2021
Merged

Fixed logic of the storage migration to triple reference counting.#10337
paritytech-processbot[bot] merged 5 commits into
paritytech:masterfrom
remzrn:master

Conversation

@remzrn
Copy link
Copy Markdown
Contributor

@remzrn remzrn commented Nov 22, 2021

The previous behaviour made it impossible for any chain not already upgraded to dual reference counting to upgrade the runtime.

This proposed change is minimal, but attempts to fix this logical issue for runtime upgrades. Currently, migrations from single or u8 reference counting do not seem to be possible even with custom migrations, due to an enforced behaviour of the pallet migration. I tried to detail examples in the issue.

fixes #10336

@cla-bot-2021
Copy link
Copy Markdown

cla-bot-2021 Bot commented Nov 22, 2021

User @remzrn, please sign the CLA here.

Copy link
Copy Markdown
Contributor

@gui1117 gui1117 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 to me

@gui1117 gui1117 added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit labels Nov 23, 2021
@remzrn
Copy link
Copy Markdown
Contributor Author

remzrn commented Nov 24, 2021

Not sure whether it is relevant to mention here, but I signed the CLA, and yet, it does not seem to update that status. I cannot sign a second time, since the link does not work anymore.
If there is indeed still an issue with CLA please provide me with another link and I will attempt to sign again.

@bkchr
Copy link
Copy Markdown
Member

bkchr commented Nov 25, 2021

Not sure whether it is relevant to mention here, but I signed the CLA, and yet, it does not seem to update that status. I cannot sign a second time, since the link does not work anymore. If there is indeed still an issue with CLA please provide me with another link and I will attempt to sign again.

I think the problem is that you created the commit with an email that isn't linked to your github account. So, the tool can not connect you as a user to the commit. Could you please force push with a different email for the commit?

…e previous behaviour made it impossible for any chain not already upgraded to dual reference counting to upgrade the runtime.
@kianenigma kianenigma changed the title Fixed logic of the storage migration to triple reference counting. Th… Fixed logic of the storage migration to triple reference counting. Nov 26, 2021
Copy link
Copy Markdown
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

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

Sorry for blocking, the code is correct but at least make a step toward the right direction (#10308 #8713). The correct thing here is to make functions migrate_from_single_to_triple_ref_count and migrate_from_dual_to_triple_ref_count standalone and remove any automatic migration in on_runtime_upgrade. Then, in your own runtime file you can pass either of the above two functions to type Executive to do your upgrade.

@remzrn
Copy link
Copy Markdown
Contributor Author

remzrn commented Nov 28, 2021

Thanks for pointing this out! I think it totally makes sense to require that the migration logic can get controlled fully at runtime level.

I was unaware of those discussions and It just took me a bit of time to grok all this also because I am unfamiliar with substrate. I tried to stick to the example, so I hope I am not misusing anything.

I have tentatively implemented the changes you asked for, but unfortunately, I am unsure about the logic, and I have not been able to find out how to write tests for those. I would need help or pointers about how to do this. For Edgeware, we can try to see if that works during the testnet phase, but I guess there is a cleaner and more reliable way that just iterating version accross all testnet nodes to test and debug this.

One issue I have is that there is now a storage variable that flags whether the migration to triple reference counting has been performed, but it seems to be a renaming of a previous variable that flagged whether the status was upgraded to dual reference counting. Does it mean that it theory I could still fetch out the previous storage flag using generate_storage_alias? In which case I would know which migration to apply with reasonable certainty.
At the moment, I am relying on the fact that the translate() function from storage maps skips the elements it cannot decode, and assuming that if anything has been translated, the migration was the right one, otherwise, trying another one.
This is not ideal but runtime engineers can still choose to apply specific functions related to their exact state if they know where they are.

+Removed the specific migration .anciallaries from the frame-system pallet level.
+Introducted a new module that hosts self-contained ancillary functions and logic to perform the storage migration. The current logic attempts to infer the state of the storage based on whether or not a given migration can be conducted.
@gui1117
Copy link
Copy Markdown
Contributor

gui1117 commented Nov 29, 2021

One issue I have is that there is now a storage variable that flags whether the migration to triple reference counting has been performed, but it seems to be a renaming of a previous variable that flagged whether the status was upgraded to dual reference counting. Does it mean that it theory I could still fetch out the previous storage flag using generate_storage_alias? In which case I would know which migration to apply with reasonable certainty. At the moment, I am relying on the fact that the translate() function from storage maps skips the elements it cannot decode, and assuming that if anything has been translated, the migration was the right one, otherwise, trying another one. This is not ideal but runtime engineers can still choose to apply specific functions related to their exact state if they know where they are.

I think it is better to just let the user call the correct function from the on_runtime_upgrade implementation when declaring the runtime.

Comment thread frame/system/src/migrations/mod.rs
Comment thread frame/system/src/migrations/mod.rs
Comment thread frame/system/src/migrations/mod.rs Outdated
Comment thread frame/system/src/migrations/mod.rs Outdated
Comment thread frame/system/src/migrations/mod.rs Outdated
Comment thread frame/system/src/migrations/mod.rs Outdated
/// (u32) to triple reference counting.
///
/// If unsure about the behaviour, the standalone functions below have to be preferred.
pub fn apply<T: V2ToV3>() -> Weight {
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.

personally I would just force user to use the correct migration explicitly.
Also iterating on storage is very heavy so I'm not sure it is good for any chain to try multiple migration.

Copy link
Copy Markdown
Contributor Author

@remzrn remzrn Nov 30, 2021

Choose a reason for hiding this comment

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

Right. I removed applied and update the booleans, return weight, etc. on each individual function instead. Is there a reason why the weight should be maxvalue? I saw it done this way everywhere, but I don't understand the logic behind this. Is it just because migrations have a massive cost so we always assume maximum weight regardless of what is done?

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.

Is it just because migrations have a massive cost so we always assume maximum weight regardless of what is done?

Yes this was the assumption, but it is a bad practice, because some chain must not go beyond max_block (like parachains), in those case having the exact weight is important.

@remzrn
Copy link
Copy Markdown
Contributor Author

remzrn commented Nov 29, 2021

I think it is better to just let the user call the correct function from the on_runtime_upgrade implementation when declaring the runtime.

Would you then suggest to remove apply overall and then maybe add weights in each of them?

@gui1117
Copy link
Copy Markdown
Contributor

gui1117 commented Nov 30, 2021

I think it is better to just let the user call the correct function from the on_runtime_upgrade implementation when declaring the runtime.

Would you then suggest to remove apply overall and then maybe add weights in each of them?

Yes, I personally think we can remove apply. About weight we can add some weight or let user benchmark the runtime migration on their own. I'm ok with both.

…ed during the runtime implementation of the trait V2ToV3.

+ Removed apply function.
+ Made the individual translation function self-sufficient.
Copy link
Copy Markdown
Contributor

@gui1117 gui1117 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 to me

Comment thread frame/system/src/migrations/mod.rs Outdated
Comment thread frame/system/src/migrations/mod.rs Outdated
Comment thread frame/system/src/migrations/mod.rs Outdated
@bkchr bkchr requested a review from kianenigma December 1, 2021 21:19
@shawntabrizi
Copy link
Copy Markdown
Member

/tip small

@substrate-tip-bot
Copy link
Copy Markdown

Please fix the following problems before calling the tip bot again:

  • Contributor did not properly post their Polkadot or Kusama address. Make sure the pull request has: "{network} address: {address}".

@shawntabrizi
Copy link
Copy Markdown
Member

bot merge

@paritytech-processbot paritytech-processbot Bot merged commit b45359a into paritytech:master Dec 9, 2021
@shawntabrizi
Copy link
Copy Markdown
Member

@remzrn you can still get a tip, just update your first post in this PR

grishasobol pushed a commit to gear-tech/substrate that referenced this pull request Mar 28, 2022
…aritytech#10337)

* Fixed logic of the storage migration to triple reference counting. The previous behaviour made it impossible for any chain not already upgraded to dual reference counting to upgrade the runtime.

* +Removed the on_runtime_upgrade() function from frame-system.
+Removed the specific migration .anciallaries from the frame-system pallet level.
+Introducted a new module that hosts self-contained ancillary functions and logic to perform the storage migration. The current logic attempts to infer the state of the storage based on whether or not a given migration can be conducted.

* Formatting.

* + Removed specific AccountData struct. AccountData must now be provided during the runtime implementation of the trait V2ToV3.
+ Removed apply function.
+ Made the individual translation function self-sufficient.

* + Removed unused decorators.
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
…aritytech#10337)

* Fixed logic of the storage migration to triple reference counting. The previous behaviour made it impossible for any chain not already upgraded to dual reference counting to upgrade the runtime.

* +Removed the on_runtime_upgrade() function from frame-system.
+Removed the specific migration .anciallaries from the frame-system pallet level.
+Introducted a new module that hosts self-contained ancillary functions and logic to perform the storage migration. The current logic attempts to infer the state of the storage based on whether or not a given migration can be conducted.

* Formatting.

* + Removed specific AccountData struct. AccountData must now be provided during the runtime implementation of the trait V2ToV3.
+ Removed apply function.
+ Made the individual translation function self-sufficient.

* + Removed unused decorators.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Storage migration to triple reference counting will always fail for chains that are not already upgraded to dual reference counting.

5 participants