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

fix(contracts): migrate CodeInfoOf<T> from Twox64Concat hashing to Identity as defined in pallet-contracts #1200

Merged
merged 7 commits into from
Mar 14, 2024

Conversation

ashutoshvarma
Copy link
Member

@ashutoshvarma ashutoshvarma commented Mar 13, 2024

Pull Request Summary
The release v5.33.0 included a faulty pallet-contracts migration v12 where CodeInfoOf<T> storage item had incorrect alias.

/// was
pub type CodeInfoOf<T: Config> = StorageMap<Pallet<T>, Twox64Concat, CodeHash<T>, CodeInfo<T>>;

/// needed to be
pub type CodeInfoOf<T: Config> = StorageMap<Pallet<T>, Identity, CodeHash<T>, CodeInfo<T>>;

This PR includes a new migration to fix this issue. Also in order to run the migration properly we need to bring down pallet's storage version to 14.

TODO

  • More extensive testing
  • Vendor and fixed v12, v14 migrations for Astar

Check list

  • added or updated unit tests
  • updated Astar official documentation
  • added OnRuntimeUpgrade hook for precompile revert code registration
  • added benchmarks & weights for any modified runtime logics.

@ashutoshvarma ashutoshvarma added shiden related to shiden runtime shibuya related to shibuya runtime This PR/Issue is related to the topic “runtime”. astar Related to Astar labels Mar 14, 2024
Copy link
Member

@Dinonard Dinonard left a comment

Choose a reason for hiding this comment

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

LGTM so far

impl<T: pallet_contracts::Config, const V: u16> OnRuntimeUpgrade for ForceContractsVersion<T, V> {
fn on_runtime_upgrade() -> Weight {
StorageVersion::new(V).put::<pallet_contracts::Pallet<T>>();
<T as frame_system::Config>::DbWeight::get().reads_writes(1, 1)
Copy link
Member

Choose a reason for hiding this comment

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

Not a big deal, but isn't this a single write only?

Copy link
Member Author

Choose a reason for hiding this comment

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

you are right, I'l change this

Comment on lines 1118 to 1120
// [contracts fix] Part of shiden-121 (added after v5.33.0 release)
astar_primitives::migrations::ForceContractsVersion<Runtime, 14>,
pallet_contracts::Migration<Runtime>,
Copy link
Member

Choose a reason for hiding this comment

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

If I understood correctly, this will downgrade storage version by 1, to ensure we bump it back to the correct one with the new migration, right?

Might be an overkill, but I'd add another dummy struct here that checks in try-runtime hooks that version was bumped back up to the expected one. Just a suggestion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that's correct.
I'll add that.

Dinonard
Dinonard previously approved these changes Mar 14, 2024
Copy link
Member

@Dinonard Dinonard left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link

Code Coverage

Package Line Rate Branch Rate Health
pallets/xc-asset-config/src 64% 0%
primitives/src/migrations 0% 0%
primitives/src 29% 0%
chain-extensions/pallet-assets/src 56% 0%
primitives/src/xcm 65% 0%
chain-extensions/types/assets/src 0% 0%
precompiles/dapp-staking-v3/src 90% 0%
pallets/dapp-staking-v3/rpc/runtime-api/src 0% 0%
pallets/dapps-staking/src/pallet 86% 0%
chain-extensions/types/xvm/src 0% 0%
pallets/astar-xcm-benchmarks/src/generic 100% 0%
precompiles/xvm/src 74% 0%
pallets/block-rewards-hybrid/src 91% 0%
pallets/collator-selection/src 91% 0%
pallets/astar-xcm-benchmarks/src/fungible 100% 0%
precompiles/sr25519/src 64% 0%
chain-extensions/types/unified-accounts/src 0% 0%
pallets/xvm/src 51% 0%
precompiles/substrate-ecdsa/src 74% 0%
pallets/dapp-staking-migration/src 48% 0%
precompiles/dapps-staking/src 93% 0%
pallets/astar-xcm-benchmarks/src 87% 0%
pallets/dapp-staking-v3/src/benchmarking 99% 0%
pallets/unified-accounts/src 85% 0%
pallets/dynamic-evm-base-fee/src 92% 0%
precompiles/dapp-staking-v3/src/test 0% 0%
pallets/dapps-staking/src 89% 0%
precompiles/assets-erc20/src 81% 0%
pallets/static-price-provider/src 58% 0%
pallets/ethereum-checked/src 79% 0%
precompiles/dispatch-lockdrop/src 86% 0%
precompiles/unified-accounts/src 100% 0%
pallets/inflation/src 83% 0%
pallets/dapp-staking-v3/src 91% 0%
chain-extensions/unified-accounts/src 0% 0%
pallets/dapp-staking-v3/src/test 0% 0%
chain-extensions/xvm/src 0% 0%
precompiles/xcm/src 73% 0%
Summary 76% (4423 / 5811) 0% (0 / 0)

Minimum allowed line rate is 50%

Copy link
Member

@Dinonard Dinonard left a comment

Choose a reason for hiding this comment

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

LGTM

@ashutoshvarma ashutoshvarma merged commit 208e233 into master Mar 14, 2024
10 checks passed
@ashutoshvarma ashutoshvarma deleted the fix/contacts-migration branch March 14, 2024 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astar Related to Astar runtime This PR/Issue is related to the topic “runtime”. shibuya related to shibuya shiden related to shiden runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants