mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 09:47:56 +00:00
BREAKING - Try-runtime: Use proper error types (#13993)
* Try-state: DispatchResult as return type * try_state for the rest of the pallets * pre_upgrade * post_upgrade * try_runtime_upgrade * fixes * bags-list fix * fix * update test * warning fix * ... * final fixes 🤞 * warning.. * frame-support * warnings * Update frame/staking/src/migrations.rs Co-authored-by: Liam Aharon <liam.aharon@hotmail.com> * fix * fix warning * nit fix * merge fixes * small fix * should be good now * missed these ones * introduce TryRuntimeError and TryRuntimeResult * fixes * fix * removed TryRuntimeResult & made some fixes * fix testsg * tests passing * unnecessary imports * Update frame/assets/src/migration.rs Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> --------- Co-authored-by: Liam Aharon <liam.aharon@hotmail.com> Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
@@ -23,6 +23,11 @@ use frame_support::{
|
||||
traits::OnRuntimeUpgrade,
|
||||
};
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
use frame_support::ensure;
|
||||
#[cfg(feature = "try-runtime")]
|
||||
use sp_runtime::TryRuntimeError;
|
||||
|
||||
/// Used for release versioning upto v12.
|
||||
///
|
||||
/// Obsolete from v13. Keeping around to make encoding/decoding of old migration code easier.
|
||||
@@ -58,7 +63,7 @@ pub mod v13 {
|
||||
pub struct MigrateToV13<T>(sp_std::marker::PhantomData<T>);
|
||||
impl<T: Config> OnRuntimeUpgrade for MigrateToV13<T> {
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
|
||||
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
|
||||
frame_support::ensure!(
|
||||
StorageVersion::<T>::get() == ObsoleteReleases::V12_0_0,
|
||||
"Required v12 before upgrading to v13"
|
||||
@@ -84,7 +89,7 @@ pub mod v13 {
|
||||
}
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
|
||||
fn post_upgrade(_state: Vec<u8>) -> Result<(), TryRuntimeError> {
|
||||
frame_support::ensure!(
|
||||
Pallet::<T>::on_chain_storage_version() == 13,
|
||||
"v13 not applied"
|
||||
@@ -114,7 +119,7 @@ pub mod v12 {
|
||||
pub struct MigrateToV12<T>(sp_std::marker::PhantomData<T>);
|
||||
impl<T: Config> OnRuntimeUpgrade for MigrateToV12<T> {
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
|
||||
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
|
||||
frame_support::ensure!(
|
||||
StorageVersion::<T>::get() == ObsoleteReleases::V11_0_0,
|
||||
"Expected v11 before upgrading to v12"
|
||||
@@ -146,7 +151,7 @@ pub mod v12 {
|
||||
}
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
|
||||
fn post_upgrade(_state: Vec<u8>) -> Result<(), TryRuntimeError> {
|
||||
frame_support::ensure!(
|
||||
StorageVersion::<T>::get() == ObsoleteReleases::V12_0_0,
|
||||
"v12 not applied"
|
||||
@@ -170,7 +175,7 @@ pub mod v11 {
|
||||
for MigrateToV11<T, P, N>
|
||||
{
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
|
||||
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
|
||||
frame_support::ensure!(
|
||||
StorageVersion::<T>::get() == ObsoleteReleases::V10_0_0,
|
||||
"must upgrade linearly"
|
||||
@@ -217,7 +222,7 @@ pub mod v11 {
|
||||
}
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
|
||||
fn post_upgrade(_state: Vec<u8>) -> Result<(), TryRuntimeError> {
|
||||
frame_support::ensure!(
|
||||
StorageVersion::<T>::get() == ObsoleteReleases::V11_0_0,
|
||||
"wrong version after the upgrade"
|
||||
@@ -332,7 +337,7 @@ pub mod v9 {
|
||||
}
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
|
||||
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
|
||||
frame_support::ensure!(
|
||||
StorageVersion::<T>::get() == ObsoleteReleases::V8_0_0,
|
||||
"must upgrade linearly"
|
||||
@@ -343,17 +348,21 @@ pub mod v9 {
|
||||
}
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn post_upgrade(prev_count: Vec<u8>) -> Result<(), &'static str> {
|
||||
fn post_upgrade(prev_count: Vec<u8>) -> Result<(), TryRuntimeError> {
|
||||
let prev_count: u32 = Decode::decode(&mut prev_count.as_slice()).expect(
|
||||
"the state parameter should be something that was generated by pre_upgrade",
|
||||
);
|
||||
let post_count = T::VoterList::count();
|
||||
let validators = Validators::<T>::count();
|
||||
assert!(post_count == prev_count + validators);
|
||||
ensure!(
|
||||
post_count == prev_count + validators,
|
||||
"`VoterList` count after the migration must equal to the sum of \
|
||||
previous count and the current number of validators"
|
||||
);
|
||||
|
||||
frame_support::ensure!(
|
||||
StorageVersion::<T>::get() == ObsoleteReleases::V9_0_0,
|
||||
"must upgrade "
|
||||
"must upgrade"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user