Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contracts: Fix incorrect storage alias in mirgration #1687

Merged
merged 3 commits into from
Sep 25, 2023

Conversation

kvinwang
Copy link
Contributor

@kvinwang kvinwang commented Sep 25, 2023

Description

We are recently trying to upgrade our Substrate version from polkadot-v0.9.43 to polkadot-v1.0.0 and we noticed a critical issue: all deployed contracts seem to be experiencing a CodeNotFound error. After a thorough investigation, it appears that the root cause of this issue lies in the mismatch between the storage alias of CodeInfoOf<T> in the migration and its original definition.

This PR corrects the storage alias to align it with its original definition

I am uncertain about the proper approach for adding tests to this change. Would the team consider taking over this PR to bring it to completion?

@kvinwang kvinwang requested a review from a team September 25, 2023 00:54
Copy link
Contributor

@pgherveou pgherveou left a comment

Choose a reason for hiding this comment

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

This might break everyone else
Looks like you might have deployed a sha in between these 2 commits where the regression was introduced

introduced here: paritytech/substrate#14661
rolled back here paritytech/substrate#14079

Let's discuss to find the best way to fix that

-- my bad fix looks good I was looking at the wrong storage

pgherveou
pgherveou approved these changes Sep 25, 2023
Copy link
Contributor

@agryaznov agryaznov left a comment

Choose a reason for hiding this comment

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

Thanks!

I am uncertain about the proper approach for adding tests to this change. Would the team consider taking over this PR to bring it to completion?

This is an interesting question. try-runtime testing of the migrations currently can't catch this. We should think on how to improve this.

@agryaznov agryaznov added R0-silent Changes should not be mentioned in any release notes I2-bug The node fails to follow expected behavior. T2-pallets This PR/Issue is related to a particular pallet. T7-smart_contracts This PR/Issue is related to smart contracts. D0-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder. labels Sep 25, 2023
@pgherveou
Copy link
Contributor

Thanks!

I am uncertain about the proper approach for adding tests to this change. Would the team consider taking over this PR to bring it to completion?

This is an interesting question. try-runtime testing of the migrations currently can't catch this. We should think on how to improve this.

Added some integrity check in the last commit, to ensure that storage map items are encoded with the proper hashing algorithm

@pgherveou pgherveou merged commit e8da320 into paritytech:master Sep 25, 2023
6 checks passed
@jasl
Copy link
Contributor

jasl commented Sep 25, 2023

@pgherveou could you backport to the release-polkadot-v1.1.0 branch? so we can avoid monkey patching it

@pgherveou
Copy link
Contributor

sure let met push a PR for this

pgherveou added a commit that referenced this pull request Sep 25, 2023
# Description

We are recently trying to upgrade our Substrate version from
`polkadot-v0.9.43` to `polkadot-v1.0.0` and we noticed a critical issue:
all deployed contracts seem to be experiencing a `CodeNotFound` error.
After a thorough investigation, it appears that the root cause of this
issue lies in the mismatch between the storage alias of `CodeInfoOf<T>`
in the migration and its original definition.

This PR corrects the storage alias to align it with its original
definition

I am uncertain about the proper approach for adding tests to this
change. Would the team consider taking over this PR to bring it to
completion?

---------

Co-authored-by: pgherveou <pgherveou@gmail.com>
@pgherveou
Copy link
Contributor

@jasl made a PR here, waiting for the release team to approve and merge it

@jasl
Copy link
Contributor

jasl commented Sep 25, 2023

@jasl made a PR here, waiting for the release team to approve and merge it

Thank you!

log::info!(target: LOG_TARGET, "=== POST UPGRADE CHECKS ===");

// Ensure that the hashing algorithm is correct for each storage map.
if let Some(hash) = crate::CodeInfoOf::<T>::iter_keys().next() {
Copy link
Contributor Author

@kvinwang kvinwang Sep 26, 2023

Choose a reason for hiding this comment

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

Would the iter_keys().next() returns an incorrect hash or just returns None in case of a hash algorithm mismatching?

Copy link
Contributor

Choose a reason for hiding this comment

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

it would return an incorrect hash since keys have been hashed with Twox64Concat during the migration

ordian added a commit that referenced this pull request Sep 27, 2023
* master: (61 commits)
  OpenGov in Westend and Rococo (#1177)
  Associated type Hasher for `QueryPreimage`, `StorePreimage` and `Bounded` (#1720)
  Migrate polkadot-primitives to v6 (#1543)
  genesis-builder: implemented for all runtimes (#1492)
  `BlockId` removal: `tx-pool` refactor (#1678)
  Bump directories from 4.0.1 to 5.0.1 (#1656)
  Allow debug_assertions in short-benchmarks CI job (#1711)
  chainHead/storage: Fix storage iteration using the query key (#1665)
  Implement more useful traits in `Slot` type (#1595)
  Make downloads in parallel and give more time to complete (#1699)
  Bump actions/checkout from 4.0.0 to 4.1.0 (#1688)
  contracts: Fix incorrect storage alias in mirgration (#1687)
  Fix documentation about justification and `finalized == true` requirement (#1607)
  tweak pallet macro (genesis_config etc) to cater for RA users as well. (#1689)
  Uncoupling pallet-xcm from frame-system's RuntimeCall (#1684)
  Bump aes-gcm from 0.10.2 to 0.10.3 (#1681)
  docs / Update PR template to reflect monorepo (#1674)
  update contributing guide and ui-tests scripts (#1668)
  pallet epm: add `TrimmingStatus` to the mined solution (#1659)
  Update HRMP pallet benchmarking to use benchmarks v2 (#1676)
  ...
ordian added a commit that referenced this pull request Oct 10, 2023
* tsv-disabling-node-side: (69 commits)
  runtime-api: cleanup after v7 stabilization (#1729)
  Move requests-responses and polling from `ChainSync` to `SyncingEngine` (#1650)
  Add custom error message for `StorageNoopGuard` (#1727)
  Clarify docs
  cargo fmt
  add a CAVEAT comment
  implement disabled_validators correctly
  remove unnecessary hash string (#1722)
  OpenGov in Westend and Rococo (#1177)
  Associated type Hasher for `QueryPreimage`, `StorePreimage` and `Bounded` (#1720)
  Migrate polkadot-primitives to v6 (#1543)
  genesis-builder: implemented for all runtimes (#1492)
  `BlockId` removal: `tx-pool` refactor (#1678)
  Bump directories from 4.0.1 to 5.0.1 (#1656)
  Allow debug_assertions in short-benchmarks CI job (#1711)
  chainHead/storage: Fix storage iteration using the query key (#1665)
  Implement more useful traits in `Slot` type (#1595)
  Make downloads in parallel and give more time to complete (#1699)
  Bump actions/checkout from 4.0.0 to 4.1.0 (#1688)
  contracts: Fix incorrect storage alias in mirgration (#1687)
  ...
bgallois pushed a commit to duniter/duniter-polkadot-sdk that referenced this pull request Mar 25, 2024
# Description

We are recently trying to upgrade our Substrate version from
`polkadot-v0.9.43` to `polkadot-v1.0.0` and we noticed a critical issue:
all deployed contracts seem to be experiencing a `CodeNotFound` error.
After a thorough investigation, it appears that the root cause of this
issue lies in the mismatch between the storage alias of `CodeInfoOf<T>`
in the migration and its original definition.

This PR corrects the storage alias to align it with its original
definition

I am uncertain about the proper approach for adding tests to this
change. Would the team consider taking over this PR to bring it to
completion?

---------

Co-authored-by: pgherveou <pgherveou@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D0-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder. I2-bug The node fails to follow expected behavior. R0-silent Changes should not be mentioned in any release notes T2-pallets This PR/Issue is related to a particular pallet. T7-smart_contracts This PR/Issue is related to smart contracts.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants