mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 19:47:59 +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:
@@ -22,6 +22,9 @@ use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};
|
||||
use frame_support::{pallet_prelude::*, storage_alias, traits::OnRuntimeUpgrade};
|
||||
use log;
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
use sp_runtime::TryRuntimeError;
|
||||
|
||||
/// Initial version of storage types.
|
||||
pub mod v0 {
|
||||
use super::*;
|
||||
@@ -95,9 +98,9 @@ pub mod v1 {
|
||||
pub struct MigrateV0ToV1<T, I = ()>(PhantomData<(T, I)>);
|
||||
impl<T: Config<I>, I: 'static> OnRuntimeUpgrade for MigrateV0ToV1<T, I> {
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
|
||||
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
|
||||
let onchain_version = Pallet::<T, I>::on_chain_storage_version();
|
||||
assert_eq!(onchain_version, 0, "migration from version 0 to 1.");
|
||||
ensure!(onchain_version == 0, "migration from version 0 to 1.");
|
||||
let referendum_count = v0::ReferendumInfoFor::<T, I>::iter().count();
|
||||
log::info!(
|
||||
target: TARGET,
|
||||
@@ -147,16 +150,13 @@ pub mod v1 {
|
||||
}
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn post_upgrade(state: Vec<u8>) -> Result<(), &'static str> {
|
||||
fn post_upgrade(state: Vec<u8>) -> Result<(), TryRuntimeError> {
|
||||
let onchain_version = Pallet::<T, I>::on_chain_storage_version();
|
||||
assert_eq!(onchain_version, 1, "must upgrade from version 0 to 1.");
|
||||
ensure!(onchain_version == 1, "must upgrade from version 0 to 1.");
|
||||
let pre_referendum_count: u32 = Decode::decode(&mut &state[..])
|
||||
.expect("failed to decode the state from pre-upgrade.");
|
||||
let post_referendum_count = ReferendumInfoFor::<T, I>::iter().count() as u32;
|
||||
assert_eq!(
|
||||
post_referendum_count, pre_referendum_count,
|
||||
"must migrate all referendums."
|
||||
);
|
||||
ensure!(post_referendum_count == pre_referendum_count, "must migrate all referendums.");
|
||||
log::info!(target: TARGET, "migrated all referendums.");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user