Try-runtime proper return types (#7146)

* Try-runtime proper return types

* update

* oops

* use ensure

* update lockfile for {"substrate"}

---------

Co-authored-by: parity-processbot <>
This commit is contained in:
Sergej Sakac
2023-05-23 09:40:37 +02:00
committed by GitHub
parent 23a737257d
commit 2b6f0b0194
10 changed files with 214 additions and 213 deletions
+186 -186
View File
File diff suppressed because it is too large Load Diff
@@ -46,7 +46,7 @@ impl<T: Config> OnRuntimeUpgrade for MigrateToTrackInactiveV2<T> {
} }
#[cfg(feature = "try-runtime")] #[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() let total = Funds::<T>::iter_values()
.map(|item| { .map(|item| {
CurrencyOf::<T>::total_balance(&Pallet::<T>::fund_account_id(item.fund_index)) CurrencyOf::<T>::total_balance(&Pallet::<T>::fund_account_id(item.fund_index))
@@ -56,11 +56,13 @@ impl<T: Config> OnRuntimeUpgrade for MigrateToTrackInactiveV2<T> {
} }
#[cfg(feature = "try-runtime")] #[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()) if let Ok((total, active)) = <(BalanceOf<T>, BalanceOf<T>)>::decode(&mut total.as_slice()) {
.expect("the state parameter should be something that was generated by pre_upgrade"); ensure!(active - total == CurrencyOf::<T>::active_issuance(), "the total be correct");
assert_eq!(active - total, CurrencyOf::<T>::active_issuance(), "the total be correct"); Ok(())
Ok(()) } else {
Err("the state parameter should be something that was generated by pre_upgrade".into())
}
} }
} }
@@ -30,7 +30,7 @@ use sp_std::vec::Vec;
pub struct ClearOldSessionStorage<T>(sp_std::marker::PhantomData<T>); pub struct ClearOldSessionStorage<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for ClearOldSessionStorage<T> { impl<T: Config> OnRuntimeUpgrade for ClearOldSessionStorage<T> {
#[cfg(feature = "try-runtime")] #[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> { fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
Ok(Vec::new()) Ok(Vec::new())
} }
@@ -64,7 +64,7 @@ impl<T: Config> OnRuntimeUpgrade for ClearOldSessionStorage<T> {
} }
#[cfg(feature = "try-runtime")] #[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> { fn post_upgrade(_state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
Ok(()) Ok(())
} }
} }
@@ -260,7 +260,7 @@ impl<BlockNumber: Default + From<u32>> Default for V5HostConfiguration<BlockNumb
pub struct MigrateToV5<T>(sp_std::marker::PhantomData<T>); pub struct MigrateToV5<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for MigrateToV5<T> { impl<T: Config> OnRuntimeUpgrade for MigrateToV5<T> {
#[cfg(feature = "try-runtime")] #[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()"); log::trace!(target: crate::configuration::LOG_TARGET, "Running pre_upgrade()");
ensure!(StorageVersion::get::<Pallet<T>>() == 4, "The migration requires version 4"); ensure!(StorageVersion::get::<Pallet<T>>() == 4, "The migration requires version 4");
@@ -282,7 +282,7 @@ impl<T: Config> OnRuntimeUpgrade for MigrateToV5<T> {
} }
#[cfg(feature = "try-runtime")] #[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()"); log::trace!(target: crate::configuration::LOG_TARGET, "Running post_upgrade()");
ensure!( ensure!(
StorageVersion::get::<Pallet<T>>() == 5, StorageVersion::get::<Pallet<T>>() == 5,
@@ -59,7 +59,7 @@ pub(crate) type V6PendingConfigs<T: Config> = StorageValue<
pub struct MigrateToV6<T>(sp_std::marker::PhantomData<T>); pub struct MigrateToV6<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for MigrateToV6<T> { impl<T: Config> OnRuntimeUpgrade for MigrateToV6<T> {
#[cfg(feature = "try-runtime")] #[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()"); log::trace!(target: crate::configuration::LOG_TARGET, "Running pre_upgrade()");
ensure!(StorageVersion::get::<Pallet<T>>() == 5, "The migration requires version 4"); ensure!(StorageVersion::get::<Pallet<T>>() == 5, "The migration requires version 4");
@@ -81,7 +81,7 @@ impl<T: Config> OnRuntimeUpgrade for MigrateToV6<T> {
} }
#[cfg(feature = "try-runtime")] #[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()"); log::trace!(target: crate::configuration::LOG_TARGET, "Running post_upgrade()");
ensure!( ensure!(
StorageVersion::get::<Pallet<T>>() == 6, StorageVersion::get::<Pallet<T>>() == 6,
@@ -23,7 +23,7 @@ use parity_scale_codec::{Decode, Encode};
pub mod latest { pub mod latest {
use super::*; 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. /// Force update the UMP limits in the parachain host config.
// NOTE: `OnRuntimeUpgrade` does not have a `self`, so everything must be compile time. // NOTE: `OnRuntimeUpgrade` does not have a `self`, so everything must be compile time.
@@ -51,7 +51,7 @@ pub mod latest {
> >
{ {
#[cfg(feature = "try-runtime")] #[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"); log::info!(target: LOG_TARGET, "pre_upgrade");
let mut pending = PendingConfigs::<T>::get(); let mut pending = PendingConfigs::<T>::get();
pending.sort_by_key(|(s, _)| *s); pending.sort_by_key(|(s, _)| *s);
@@ -88,7 +88,7 @@ pub mod latest {
} }
#[cfg(feature = "try-runtime")] #[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"); log::info!(target: LOG_TARGET, "post_upgrade");
let old_pending: u32 = Decode::decode(&mut &state[..]).expect("Known good"); let old_pending: u32 = Decode::decode(&mut &state[..]).expect("Known good");
let mut pending = PendingConfigs::<T>::get(); let mut pending = PendingConfigs::<T>::get();
@@ -99,9 +99,8 @@ pub mod latest {
"Last pending HostConfig upgrade:\n\n{:#?}\n", "Last pending HostConfig upgrade:\n\n{:#?}\n",
pending.last() pending.last()
); );
assert_eq!( ensure!(
pending.len(), pending.len() == old_pending as usize + 1,
old_pending as usize + 1,
"There must be a new pending upgrade enqueued" "There must be a new pending upgrade enqueued"
); );
@@ -51,7 +51,7 @@ pub mod v1 {
} }
#[cfg(feature = "try-runtime")] #[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> { fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
log::trace!( log::trace!(
target: crate::disputes::LOG_TARGET, target: crate::disputes::LOG_TARGET,
"SpamSlots before migration: {}", "SpamSlots before migration: {}",
@@ -65,7 +65,7 @@ pub mod v1 {
} }
#[cfg(feature = "try-runtime")] #[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()"); log::trace!(target: crate::disputes::LOG_TARGET, "Running post_upgrade()");
ensure!( ensure!(
StorageVersion::get::<Pallet<T>>() >= 1, StorageVersion::get::<Pallet<T>>() >= 1,
@@ -58,7 +58,7 @@ use sp_runtime::{
InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity, InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity,
TransactionValidityError, ValidTransaction, TransactionValidityError, ValidTransaction,
}, },
DispatchResult, KeyTypeId, Perbill, RuntimeDebug, KeyTypeId, Perbill, RuntimeDebug,
}; };
use sp_session::{GetSessionNumber, GetValidatorCount}; use sp_session::{GetSessionNumber, GetValidatorCount};
use sp_staking::offence::{DisableStrategy, Kind, Offence, OffenceError, ReportOffence}; use sp_staking::offence::{DisableStrategy, Kind, Offence, OffenceError, ReportOffence};
@@ -382,7 +382,7 @@ pub trait HandleReports<T: Config> {
fn submit_unsigned_slashing_report( fn submit_unsigned_slashing_report(
dispute_proof: DisputeProof, dispute_proof: DisputeProof,
key_owner_proof: T::KeyOwnerProof, key_owner_proof: T::KeyOwnerProof,
) -> DispatchResult; ) -> Result<(), sp_runtime::TryRuntimeError>;
} }
impl<T: Config> HandleReports<T> for () { impl<T: Config> HandleReports<T> for () {
@@ -404,7 +404,7 @@ impl<T: Config> HandleReports<T> for () {
fn submit_unsigned_slashing_report( fn submit_unsigned_slashing_report(
_dispute_proof: DisputeProof, _dispute_proof: DisputeProof,
_key_owner_proof: T::KeyOwnerProof, _key_owner_proof: T::KeyOwnerProof,
) -> DispatchResult { ) -> Result<(), sp_runtime::TryRuntimeError> {
Ok(()) Ok(())
} }
} }
@@ -730,7 +730,7 @@ where
fn submit_unsigned_slashing_report( fn submit_unsigned_slashing_report(
dispute_proof: DisputeProof, dispute_proof: DisputeProof,
key_owner_proof: <T as Config>::KeyOwnerProof, key_owner_proof: <T as Config>::KeyOwnerProof,
) -> DispatchResult { ) -> Result<(), sp_runtime::TryRuntimeError> {
use frame_system::offchain::SubmitTransaction; use frame_system::offchain::SubmitTransaction;
let session_index = dispute_proof.time_slot.session_index; let session_index = dispute_proof.time_slot.session_index;
+2 -2
View File
@@ -2059,7 +2059,7 @@ mod clean_state_migration {
impl OnRuntimeUpgrade for CleanMigrate { impl OnRuntimeUpgrade for CleanMigrate {
#[cfg(feature = "try-runtime")] #[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> { fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
Ok(Default::default()) Ok(Default::default())
} }
@@ -2071,7 +2071,7 @@ mod clean_state_migration {
} }
#[cfg(feature = "try-runtime")] #[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!( frame_support::ensure!(
!AutoLimits::exists() && !SignedMigrationMaxLimits::exists(), !AutoLimits::exists() && !SignedMigrationMaxLimits::exists(),
"State migration clean.", "State migration clean.",
+1 -1
View File
@@ -29,7 +29,7 @@ pub mod v1 {
pub struct MigrateToV1<T>(sp_std::marker::PhantomData<T>); pub struct MigrateToV1<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> { impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> {
#[cfg(feature = "try-runtime")] #[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"); ensure!(StorageVersion::get::<Pallet<T>>() == 0, "must upgrade linearly");
Ok(sp_std::vec::Vec::new()) Ok(sp_std::vec::Vec::new())