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
@@ -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");
@@ -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,
@@ -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");
@@ -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,
@@ -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.
@@ -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);
@@ -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();
@@ -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"
);
@@ -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: {}",
@@ -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,
@@ -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};
@@ -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 () {
@@ -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(())
}
}
@@ -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;