mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 04:11:07 +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:
@@ -257,6 +257,9 @@ use sp_runtime::{
|
||||
};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
use sp_runtime::TryRuntimeError;
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
mod benchmarking;
|
||||
#[cfg(test)]
|
||||
@@ -883,7 +886,7 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn try_state(_n: T::BlockNumber) -> Result<(), &'static str> {
|
||||
fn try_state(_n: T::BlockNumber) -> Result<(), TryRuntimeError> {
|
||||
Self::do_try_state()
|
||||
}
|
||||
}
|
||||
@@ -1579,7 +1582,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
impl<T: Config> Pallet<T> {
|
||||
fn do_try_state() -> Result<(), &'static str> {
|
||||
fn do_try_state() -> Result<(), TryRuntimeError> {
|
||||
Self::try_state_snapshot()?;
|
||||
Self::try_state_signed_submissions_map()?;
|
||||
Self::try_state_phase_off()
|
||||
@@ -1588,7 +1591,7 @@ impl<T: Config> Pallet<T> {
|
||||
// [`Snapshot`] state check. Invariants:
|
||||
// - [`DesiredTargets`] exists if and only if [`Snapshot`] is present.
|
||||
// - [`SnapshotMetadata`] exist if and only if [`Snapshot`] is present.
|
||||
fn try_state_snapshot() -> Result<(), &'static str> {
|
||||
fn try_state_snapshot() -> Result<(), TryRuntimeError> {
|
||||
if <Snapshot<T>>::exists() &&
|
||||
<SnapshotMetadata<T>>::exists() &&
|
||||
<DesiredTargets<T>>::exists()
|
||||
@@ -1600,7 +1603,7 @@ impl<T: Config> Pallet<T> {
|
||||
{
|
||||
Ok(())
|
||||
} else {
|
||||
Err("If snapshot exists, metadata and desired targets should be set too. Otherwise, none should be set.")
|
||||
Err("If snapshot exists, metadata and desired targets should be set too. Otherwise, none should be set.".into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1608,28 +1611,34 @@ impl<T: Config> Pallet<T> {
|
||||
// - All [`SignedSubmissionIndices`] are present in [`SignedSubmissionsMap`], and no more;
|
||||
// - [`SignedSubmissionNextIndex`] is not present in [`SignedSubmissionsMap`];
|
||||
// - [`SignedSubmissionIndices`] is sorted by election score.
|
||||
fn try_state_signed_submissions_map() -> Result<(), &'static str> {
|
||||
fn try_state_signed_submissions_map() -> Result<(), TryRuntimeError> {
|
||||
let mut last_score: ElectionScore = Default::default();
|
||||
let indices = <SignedSubmissionIndices<T>>::get();
|
||||
|
||||
for (i, indice) in indices.iter().enumerate() {
|
||||
let submission = <SignedSubmissionsMap<T>>::get(indice.2);
|
||||
if submission.is_none() {
|
||||
return Err("All signed submissions indices must be part of the submissions map")
|
||||
return Err(
|
||||
"All signed submissions indices must be part of the submissions map".into()
|
||||
)
|
||||
}
|
||||
|
||||
if i == 0 {
|
||||
last_score = indice.0
|
||||
} else {
|
||||
if last_score.strict_threshold_better(indice.0, Perbill::zero()) {
|
||||
return Err("Signed submission indices vector must be ordered by election score")
|
||||
return Err(
|
||||
"Signed submission indices vector must be ordered by election score".into()
|
||||
)
|
||||
}
|
||||
last_score = indice.0;
|
||||
}
|
||||
}
|
||||
|
||||
if <SignedSubmissionsMap<T>>::iter().nth(indices.len()).is_some() {
|
||||
return Err("Signed submissions map length should be the same as the indices vec length")
|
||||
return Err(
|
||||
"Signed submissions map length should be the same as the indices vec length".into()
|
||||
)
|
||||
}
|
||||
|
||||
match <SignedSubmissionNextIndex<T>>::get() {
|
||||
@@ -1637,7 +1646,8 @@ impl<T: Config> Pallet<T> {
|
||||
next =>
|
||||
if <SignedSubmissionsMap<T>>::get(next).is_some() {
|
||||
return Err(
|
||||
"The next submissions index should not be in the submissions maps already",
|
||||
"The next submissions index should not be in the submissions maps already"
|
||||
.into(),
|
||||
)
|
||||
} else {
|
||||
Ok(())
|
||||
@@ -1647,12 +1657,12 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
// [`Phase::Off`] state check. Invariants:
|
||||
// - If phase is `Phase::Off`, [`Snapshot`] must be none.
|
||||
fn try_state_phase_off() -> Result<(), &'static str> {
|
||||
fn try_state_phase_off() -> Result<(), TryRuntimeError> {
|
||||
match Self::current_phase().is_off() {
|
||||
false => Ok(()),
|
||||
true =>
|
||||
if <Snapshot<T>>::get().is_some() {
|
||||
Err("Snapshot must be none when in Phase::Off")
|
||||
Err("Snapshot must be none when in Phase::Off".into())
|
||||
} else {
|
||||
Ok(())
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user