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 5 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
4 changes: 2 additions & 2 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,7 +56,7 @@ impl<T: Config> OnRuntimeUpgrade for MigrateToTrackInactiveV2<T> {
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(total: Vec<u8>) -> Result<(), &'static str> {
fn post_upgrade(total: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
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");
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.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub mod v5 {
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 @@ -165,7 +165,7 @@ pub mod v5 {
}

#[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>>() == STORAGE_VERSION,
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 @@ -54,7 +54,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 @@ -68,7 +68,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>>() == STORAGE_VERSION,
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 @@ -1966,7 +1966,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 @@ -1978,7 +1978,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 @@ -31,7 +31,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