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

Improve handling of unset StorageVersion #13417

Merged
merged 16 commits into from
May 4, 2023
Merged

Conversation

bkchr
Copy link
Member

@bkchr bkchr commented Feb 19, 2023

When a user is forgetting to set the storage version in a pallet and calls current_storage_version to compare it against the on_chain_storage_version it will now fail to compile the code. Before the pallet macro just returned StorageVersion::default() for current_storage_version leading to potential issues with migrations. Besides that it also checks in post_upgrade that the pallet storage version was upgraded and thus, no migration was missed.

Closes: #13062

Failing try-runtime tests

After this pr it can happen that try-runtime tests are failing, because pallets don't have the proper StorageVersion set on chain. This can either mean that a migration was missed or that a pallet was added after genesis and it was missed to set the storage version. To fix the later, it just requires a simple migration that does:

fn on_runtime_upgrade() {
    StorageVersion::new(EXPECTED_VERSION).put::<Pallet_That_Is_failing>();
}

After that try-runtime will be happy and everything should work.

When a user is forgetting to set the storage version in a pallet and calls
`current_storage_version` to compare it against the `on_chain_storage_version` it will now fail to
compile the code. Before the pallet macro just returned `StorageVersion::default()` for
`current_storage_version` leading to potential issues with migrations. Besides that it also checks
in `post_upgrade` that the pallet storage version was upgraded and thus, no migration was missed.
@bkchr bkchr added 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 B1-note_worthy Changes should be noted in the release notes T1-runtime This PR/Issue is related to the topic “runtime”. A0-pleasereview labels Feb 19, 2023
@bkchr bkchr requested a review from ggwpez February 19, 2023 22:16
@bkchr bkchr requested a review from a team as a code owner February 19, 2023 22:16
@paritytech-ci paritytech-ci requested a review from a team February 20, 2023 09:37
Copy link
Member

@ggwpez ggwpez left a comment

Choose a reason for hiding this comment

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

Okay your approach is completely from what I used on rococo 😛

frame/support/src/traits/metadata.rs Show resolved Hide resolved
frame/support/test/tests/pallet.rs Outdated Show resolved Hide resolved
frame/support/src/migrations.rs Show resolved Hide resolved
Copy link
Member

@ggwpez ggwpez left a comment

Choose a reason for hiding this comment

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

Did you test it with the try-runtime CLI yet on a live network?

Copy link
Contributor

@ruseinov ruseinov 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. I’m still worried about the multi-block stuff, but since we can’t properly test it via try-runtime either it seems - makes no difference. The one scenario in which it could become annoying is when we have some CI check that would either fail try-runtime or we’d have to set the new StorageVersion before the storage has been fully migrated.
Just going to leave this concern here, perhaps we’ll get back to it when the solution is needed.

@ggwpez
Copy link
Member

ggwpez commented Feb 28, 2023

Ouch… https://substrate.stackexchange.com/questions/7396
Can we merge this soon please?

@stale
Copy link

stale bot commented Apr 6, 2023

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A3-stale label Apr 6, 2023
@bkchr bkchr removed the A3-stale label Apr 11, 2023
Co-authored-by: Roman Useinov <roman.useinov@gmail.com>
@ggwpez
Copy link
Member

ggwpez commented Apr 28, 2023

It works now on Polkadot. Did we fix that version mismatch in pallet Historical?

@liamaharon liamaharon self-requested a review April 28, 2023 11:13
on_chain_version,
);

return Err("On chain storage version set, while the pallet doesn't \
Copy link
Member

Choose a reason for hiding this comment

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

Just one nit: you could collect all those errors in a vector and return them at the end. Then we can debug multiple erroneous pallets at once, like in Rococo.

frame/support/src/migrations.rs Show resolved Hide resolved
frame/support/src/migrations.rs Show resolved Hide resolved
@bkchr
Copy link
Member Author

bkchr commented Apr 29, 2023

It works now on Polkadot. Did we fix that version mismatch in pallet Historical?

Good point. Should have been done as part of paritytech/polkadot@ccffb73

@gupnik could you please open a pr for your migration to set the storage version to 1 as well?

bkchr and others added 3 commits May 2, 2023 10:54
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@bkchr
Copy link
Member Author

bkchr commented May 4, 2023

bot rebase

@paritytech-processbot
Copy link

Rebased

@bkchr bkchr merged commit 133157a into master May 4, 2023
@bkchr bkchr deleted the bkchr-something-storage-version branch May 4, 2023 19:18
nathanwhit pushed a commit to nathanwhit/substrate that referenced this pull request Jul 19, 2023
* Improve handling of unset `StorageVersion`

When a user is forgetting to set the storage version in a pallet and calls
`current_storage_version` to compare it against the `on_chain_storage_version` it will now fail to
compile the code. Before the pallet macro just returned `StorageVersion::default()` for
`current_storage_version` leading to potential issues with migrations. Besides that it also checks
in `post_upgrade` that the pallet storage version was upgraded and thus, no migration was missed.

* Use correct `Cargo.lock`

* Fixes

* Fix test

* Update frame/support/test/tests/pallet.rs

* Ensure we don't set a storage version when the pallet is missing the attribute

* Fix merge conflict

* Update frame/support/procedural/src/pallet/expand/hooks.rs

Co-authored-by: Roman Useinov <roman.useinov@gmail.com>

* Update frame/support/procedural/src/pallet/expand/hooks.rs

Co-authored-by: Roman Useinov <roman.useinov@gmail.com>

* Fix compilation

* Do not run everything with `try-runtime`

* Fix test

* Apply suggestions from code review

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix `no-metadata-docs`

---------

Co-authored-by: Roman Useinov <roman.useinov@gmail.com>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: parity-processbot <>
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. B1-note_worthy Changes should be noted in the 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 T1-runtime This PR/Issue is related to the topic “runtime”.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent pallet version inconsistency
8 participants