-
Notifications
You must be signed in to change notification settings - Fork 504
Enable pallet contracts storage migration #774
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
Changes from all commits
4b5d8fc
8197adc
fbe40f0
9c0fae1
93e1d81
e3ce231
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,7 @@ pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; | |
| pub use sp_runtime::BuildStorage; | ||
|
|
||
| mod chain_extensions; | ||
| mod migration; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Imo, no need for this. It's few lines of code. Just putting this where we usually place custom OnRuntimeUpgrade hooks is fine. We'll have to delete this anyhow later on.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's preference matter. I thought deleting a file can remove unnecessary stuffs later on, and it's clear to understand. Anywau, I'll stop using separated file.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's fine if it's your personal preference, no need to change. |
||
| mod precompiles; | ||
| mod weights; | ||
| mod xcm_config; | ||
|
|
@@ -67,6 +68,7 @@ pub use precompiles::{ShibuyaNetworkPrecompiles, ASSET_PRECOMPILE_ADDRESS_PREFIX | |
| pub type Precompiles = ShibuyaNetworkPrecompiles<Runtime, ShibuyaAssetLocationIdConverter>; | ||
|
|
||
| use chain_extensions::*; | ||
| use migration::*; | ||
|
|
||
| /// Constant values used within the runtime. | ||
| pub const MILLISDN: Balance = 1_000_000_000_000_000; | ||
|
|
@@ -1121,6 +1123,10 @@ pub type Executive = frame_executive::Executive< | |
| frame_system::ChainContext<Runtime>, | ||
| Runtime, | ||
| AllPalletsWithSystem, | ||
| ( | ||
| ContractsStorageVersionMigration<Runtime>, | ||
| pallet_contracts::Migration<Runtime>, | ||
| ), | ||
| >; | ||
|
|
||
| impl fp_self_contained::SelfContainedCall for RuntimeCall { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| use frame_support::{traits::StorageVersion, weights::Weight}; | ||
| use sp_core::Get; | ||
| use sp_std::{marker::PhantomData, prelude::Vec, vec}; | ||
|
|
||
| pub struct ContractsStorageVersionMigration<T: pallet_contracts::Config>(PhantomData<T>); | ||
|
|
||
| impl<T: pallet_contracts::Config> frame_support::traits::OnRuntimeUpgrade | ||
| for ContractsStorageVersionMigration<T> | ||
| { | ||
| fn on_runtime_upgrade() -> Weight { | ||
| let version = StorageVersion::get::<pallet_contracts::Pallet<T>>(); | ||
| let mut weight = Weight::zero(); | ||
|
|
||
| if version < 7 { | ||
| StorageVersion::new(7).put::<pallet_contracts::Pallet<T>>(); | ||
| weight = weight.saturating_add(T::DbWeight::get().writes(1)); | ||
| } | ||
|
|
||
| weight | ||
| } | ||
|
|
||
| #[cfg(feature = "try-runtime")] | ||
| fn pre_upgrade() -> Result<Vec<u8>, &'static str> { | ||
| let version = StorageVersion::get::<pallet_contracts::Pallet<T>>(); | ||
| log::info!("Pre upgrade StorageVersion: {:?}", version); | ||
| Ok(vec![]) | ||
| } | ||
|
|
||
| #[cfg(feature = "try-runtime")] | ||
| fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> { | ||
| let version = StorageVersion::get::<pallet_contracts::Pallet<T>>(); | ||
| log::info!("Post upgrade StorageVersion: {:?}", version); | ||
| Ok(()) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| use frame_support::{traits::StorageVersion, weights::Weight}; | ||
| use sp_core::Get; | ||
| use sp_std::{marker::PhantomData, prelude::Vec, vec}; | ||
|
|
||
| pub struct ContractsStorageVersionMigration<T: pallet_contracts::Config>(PhantomData<T>); | ||
|
|
||
| impl<T: pallet_contracts::Config> frame_support::traits::OnRuntimeUpgrade | ||
| for ContractsStorageVersionMigration<T> | ||
| { | ||
| fn on_runtime_upgrade() -> Weight { | ||
| let version = StorageVersion::get::<pallet_contracts::Pallet<T>>(); | ||
| let mut weight = Weight::zero(); | ||
|
|
||
| if version < 7 { | ||
| StorageVersion::new(7).put::<pallet_contracts::Pallet<T>>(); | ||
| weight = weight.saturating_add(T::DbWeight::get().writes(1)); | ||
| } | ||
|
|
||
| weight | ||
| } | ||
|
|
||
| #[cfg(feature = "try-runtime")] | ||
| fn pre_upgrade() -> Result<Vec<u8>, &'static str> { | ||
| let version = StorageVersion::get::<pallet_contracts::Pallet<T>>(); | ||
| log::info!("Pre upgrade StorageVersion: {:?}", version); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, I'd advise using asserts in pre/post upgrade hooks. That way you'll get a clear fail when running it. |
||
| Ok(vec![]) | ||
| } | ||
|
|
||
| #[cfg(feature = "try-runtime")] | ||
| fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> { | ||
| let version = StorageVersion::get::<pallet_contracts::Pallet<T>>(); | ||
| log::info!("Post upgrade StorageVersion: {:?}", version); | ||
| Ok(()) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't
log3rd party product? It shouldn't have any deps with try-runtime.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just would like to show storage version in pre and post runtime upgrade.
Is there any reason? even though it won't be included in node binary and wasm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will, this is just related to features. You'd have to make it optinal or a dev dependency for it to be excluded.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log dependency is already optional
Astar/runtime/shiden/Cargo.toml
Line 11 in 9c0fae1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must have missed it. 👍