Skip to content

Commit

Permalink
FIX: Tech Comm storage version is set to v4 (#354)
Browse files Browse the repository at this point in the history
## Description
<!-- Describe what change this PR is implementing -->
This PR sets the `StorageVersion` of the `TechComm` Pallet to
[v4](https://github.com/paritytech/polkadot-sdk/blob/release-polkadot-v1.1.0/substrate/frame/collective/src/migrations/v4.rs)
which was set by the latest migration available for the
`CollectivePallet`. We don't need to execute the original migration as
we are introducing a new instance of the `CollectivePallet` and don't do
any renaming. This makes the `try-runtime` check happy.

## Types of Changes
Please select the branch type you are merging and fill in the relevant
template.
<!--- Check the following box with an x if the following applies: -->
- [ ] Hotfix
- [ ] Release
- [x] Fix or Feature

## Fix or Feature
<!--- Check the following box with an x if the following applies: -->

### Types of Changes
<!--- What types of changes does your code introduce? -->
- [ ] Tech Debt (Code improvements)
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Dependency upgrade (A change in substrate or any 3rd party crate
version)

### Migrations and Hooks
<!--- Check the following box with an x if the following applies: -->
- [x] This change requires a runtime migration.
- [ ] Modifies `on_initialize`
- [ ] Modifies `on_finalize`

### Checklist for Fix or Feature
<!--- All boxes need to be checked. Follow this checklist before
requiring PR review -->
- [x] Change has been tested locally.
- [ ] Change adds / updates tests if applicable.
- [ ] Changelog doc updated.
- [x] `spec_version` has been incremented.
- [ ] `network-relayer`'s
[events](https://github.com/Cerebellum-Network/network-relayer/blob/dev-cere/shared/substrate/events.go)
have been updated according to the blockchain events if applicable.
- [ ] All CI checks have been passed successfully

## Checklist for Hotfix
<!--- All boxes need to be checked. Follow this checklist before
requiring PR review -->
- [ ] Changelog has been updated.
- [ ] Crate version has been updated.
- [ ] `spec_version` has been incremented.
- [ ] Transaction version has been updated if required.
- [ ] Pull Request to `dev` has been created.
- [ ] Pull Request to `staging` has been created.
- [ ] `network-relayer`'s
[events](https://github.com/Cerebellum-Network/network-relayer/blob/dev-cere/shared/substrate/events.go)
have been updated according to the blockchain events if applicable.
- [ ] All CI checks have been passed successfully

## Checklist for Release
<!--- All boxes need to be checked. Follow this checklist before
requiring PR review -->
- [ ] Change has been deployed to Devnet.
- [ ] Change has been tested in Devnet.
- [ ] Change has been deployed to Qanet.
- [ ] Change has been tested in Qanet.
- [ ] Change has been deployed to Testnet.
- [ ] Change has been tested in Testnet.
- [ ] Changelog has been updated.
- [ ] Crate version has been updated.
- [ ] Spec version has been updated.
- [ ] Transaction version has been updated if required.
- [ ] All CI checks have been passed successfully
  • Loading branch information
yahortsaryk authored Jun 6, 2024
1 parent 2cc56b5 commit 4169061
Showing 1 changed file with 47 additions and 3 deletions.
50 changes: 47 additions & 3 deletions runtime/cere/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ use frame_support::{
parameter_types,
traits::{
ConstBool, ConstU128, ConstU16, ConstU32, Currency, EitherOf, EitherOfDiverse,
EqualPrivilegeOnly, Everything, Imbalance, InstanceFilter, KeyOwnerProofSystem, Nothing,
OnUnbalanced, WithdrawReasons,
EqualPrivilegeOnly, Everything, GetStorageVersion, Imbalance, InstanceFilter,
KeyOwnerProofSystem, Nothing, OnRuntimeUpgrade, OnUnbalanced, StorageVersion,
WithdrawReasons,
},
weights::{
constants::{
Expand Down Expand Up @@ -134,7 +135,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// and set impl_version to 0. If only runtime
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 53100,
spec_version: 53101,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 17,
Expand Down Expand Up @@ -1299,6 +1300,8 @@ type Migrations = migrations::Unreleased;
pub mod migrations {
use frame_support::traits::LockIdentifier;
use frame_system::pallet_prelude::BlockNumberFor;
#[cfg(feature = "try-runtime")]
use sp_runtime::DispatchError;

use super::*;

Expand Down Expand Up @@ -1369,7 +1372,48 @@ pub mod migrations {
<Runtime as frame_system::Config>::DbWeight>,
frame_support::migrations::RemovePallet<TipsPalletName,
<Runtime as frame_system::Config>::DbWeight>,
TechCommSetV4Storage
);

pub struct TechCommSetV4Storage;
impl OnRuntimeUpgrade for TechCommSetV4Storage {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
let log_target = "tech-comm-v4-migration";
let on_chain_storage_version =
<TechComm as GetStorageVersion>::on_chain_storage_version();
if on_chain_storage_version == 0 {
log::info!(
target: log_target,
"Upgrading storage version to v4",
);
StorageVersion::new(4).put::<TechComm>();
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 1)
} else {
log::warn!(
target: log_target,
"Attempted to apply migration to v4 but failed because storage version is {:?}",
on_chain_storage_version,
);
<Runtime as frame_system::Config>::DbWeight::get().reads(1)
}
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, DispatchError> {
let on_chain_storage_version =
<TechComm as GetStorageVersion>::on_chain_storage_version();
assert_eq!(on_chain_storage_version, 0, "Tech Comm version is not v0");
Ok(Vec::new())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_prev_state: Vec<u8>) -> Result<(), DispatchError> {
let on_chain_storage_version =
<TechComm as GetStorageVersion>::on_chain_storage_version();
assert_eq!(on_chain_storage_version, 4, "Tech Comm version is not v4");
Ok(())
}
}
}

/// Executive: handles dispatch to the various modules.
Expand Down

0 comments on commit 4169061

Please sign in to comment.