Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Try-runtime proper return types #7146

Merged
merged 9 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
372 changes: 186 additions & 186 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions runtime/common/src/crowdloan/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<T: Config> OnRuntimeUpgrade for MigrateToTrackInactiveV2<T> {
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
let total = Funds::<T>::iter_values()
.map(|item| {
CurrencyOf::<T>::total_balance(&Pallet::<T>::fund_account_id(item.fund_index))
Expand All @@ -56,11 +56,13 @@ impl<T: Config> OnRuntimeUpgrade for MigrateToTrackInactiveV2<T> {
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(total: Vec<u8>) -> Result<(), &'static str> {
let (total, active) = <(BalanceOf<T>, BalanceOf<T>)>::decode(&mut total.as_slice())
.expect("the state parameter should be something that was generated by pre_upgrade");
assert_eq!(active - total, CurrencyOf::<T>::active_issuance(), "the total be correct");
Ok(())
fn post_upgrade(total: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
if let Ok((total, active)) = <(BalanceOf<T>, BalanceOf<T>)>::decode(&mut total.as_slice()) {
ensure!(active - total == CurrencyOf::<T>::active_issuance(), "the total be correct");
Ok(())
} else {
Err("the state parameter should be something that was generated by pre_upgrade".into())
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions runtime/common/src/session/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use sp_std::vec::Vec;
pub struct ClearOldSessionStorage<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for ClearOldSessionStorage<T> {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
Ok(Vec::new())
}

Expand Down Expand Up @@ -64,7 +64,7 @@ impl<T: Config> OnRuntimeUpgrade for ClearOldSessionStorage<T> {
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
fn post_upgrade(_state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
Ok(())
}
}
4 changes: 2 additions & 2 deletions runtime/parachains/src/configuration/migration/v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl<BlockNumber: Default + From<u32>> Default for V5HostConfiguration<BlockNumb
pub struct MigrateToV5<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for MigrateToV5<T> {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
log::trace!(target: crate::configuration::LOG_TARGET, "Running pre_upgrade()");

ensure!(StorageVersion::get::<Pallet<T>>() == 4, "The migration requires version 4");
Expand All @@ -282,7 +282,7 @@ impl<T: Config> OnRuntimeUpgrade for MigrateToV5<T> {
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
fn post_upgrade(_state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
log::trace!(target: crate::configuration::LOG_TARGET, "Running post_upgrade()");
ensure!(
StorageVersion::get::<Pallet<T>>() == 5,
Expand Down
4 changes: 2 additions & 2 deletions runtime/parachains/src/configuration/migration/v6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub(crate) type V6PendingConfigs<T: Config> = StorageValue<
pub struct MigrateToV6<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for MigrateToV6<T> {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
log::trace!(target: crate::configuration::LOG_TARGET, "Running pre_upgrade()");

ensure!(StorageVersion::get::<Pallet<T>>() == 5, "The migration requires version 4");
Expand All @@ -81,7 +81,7 @@ impl<T: Config> OnRuntimeUpgrade for MigrateToV6<T> {
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
fn post_upgrade(_state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
log::trace!(target: crate::configuration::LOG_TARGET, "Running post_upgrade()");
ensure!(
StorageVersion::get::<Pallet<T>>() == 6,
Expand Down
11 changes: 5 additions & 6 deletions runtime/parachains/src/configuration/migration_ump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use parity_scale_codec::{Decode, Encode};

pub mod latest {
use super::*;
use frame_support::{pallet_prelude::Weight, traits::OnRuntimeUpgrade};
use frame_support::{ensure, pallet_prelude::Weight, traits::OnRuntimeUpgrade};

/// Force update the UMP limits in the parachain host config.
// NOTE: `OnRuntimeUpgrade` does not have a `self`, so everything must be compile time.
Expand Down Expand Up @@ -51,7 +51,7 @@ pub mod latest {
>
{
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, &'static str> {
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, sp_runtime::TryRuntimeError> {
log::info!(target: LOG_TARGET, "pre_upgrade");
let mut pending = PendingConfigs::<T>::get();
pending.sort_by_key(|(s, _)| *s);
Expand Down Expand Up @@ -88,7 +88,7 @@ pub mod latest {
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(state: sp_std::vec::Vec<u8>) -> Result<(), &'static str> {
fn post_upgrade(state: sp_std::vec::Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
log::info!(target: LOG_TARGET, "post_upgrade");
let old_pending: u32 = Decode::decode(&mut &state[..]).expect("Known good");
let mut pending = PendingConfigs::<T>::get();
Expand All @@ -99,9 +99,8 @@ pub mod latest {
"Last pending HostConfig upgrade:\n\n{:#?}\n",
pending.last()
);
assert_eq!(
pending.len(),
old_pending as usize + 1,
ensure!(
pending.len() == old_pending as usize + 1,
"There must be a new pending upgrade enqueued"
);

Expand Down
4 changes: 2 additions & 2 deletions runtime/parachains/src/disputes/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub mod v1 {
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
log::trace!(
target: crate::disputes::LOG_TARGET,
"SpamSlots before migration: {}",
Expand All @@ -65,7 +65,7 @@ pub mod v1 {
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
fn post_upgrade(_state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
log::trace!(target: crate::disputes::LOG_TARGET, "Running post_upgrade()");
ensure!(
StorageVersion::get::<Pallet<T>>() >= 1,
Expand Down
8 changes: 4 additions & 4 deletions runtime/parachains/src/disputes/slashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use sp_runtime::{
InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity,
TransactionValidityError, ValidTransaction,
},
DispatchResult, KeyTypeId, Perbill, RuntimeDebug,
KeyTypeId, Perbill, RuntimeDebug,
};
use sp_session::{GetSessionNumber, GetValidatorCount};
use sp_staking::offence::{DisableStrategy, Kind, Offence, OffenceError, ReportOffence};
Expand Down Expand Up @@ -382,7 +382,7 @@ pub trait HandleReports<T: Config> {
fn submit_unsigned_slashing_report(
dispute_proof: DisputeProof,
key_owner_proof: T::KeyOwnerProof,
) -> DispatchResult;
) -> Result<(), sp_runtime::TryRuntimeError>;
}

impl<T: Config> HandleReports<T> for () {
Expand All @@ -404,7 +404,7 @@ impl<T: Config> HandleReports<T> for () {
fn submit_unsigned_slashing_report(
_dispute_proof: DisputeProof,
_key_owner_proof: T::KeyOwnerProof,
) -> DispatchResult {
) -> Result<(), sp_runtime::TryRuntimeError> {
Ok(())
}
}
Expand Down Expand Up @@ -730,7 +730,7 @@ where
fn submit_unsigned_slashing_report(
dispute_proof: DisputeProof,
key_owner_proof: <T as Config>::KeyOwnerProof,
) -> DispatchResult {
) -> Result<(), sp_runtime::TryRuntimeError> {
use frame_system::offchain::SubmitTransaction;

let session_index = dispute_proof.time_slot.session_index;
Expand Down
4 changes: 2 additions & 2 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2059,7 +2059,7 @@ mod clean_state_migration {

impl OnRuntimeUpgrade for CleanMigrate {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
Ok(Default::default())
}

Expand All @@ -2071,7 +2071,7 @@ mod clean_state_migration {
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
fn post_upgrade(_state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
frame_support::ensure!(
!AutoLimits::exists() && !SignedMigrationMaxLimits::exists(),
"State migration clean.",
Expand Down
2 changes: 1 addition & 1 deletion xcm/pallet-xcm/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub mod v1 {
pub struct MigrateToV1<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, &'static str> {
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, sp_runtime::TryRuntimeError> {
ensure!(StorageVersion::get::<Pallet<T>>() == 0, "must upgrade linearly");

Ok(sp_std::vec::Vec::new())
Expand Down