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

return error instead of expect in feasibility_check #12745

Merged
merged 7 commits into from
Nov 23, 2022
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
15 changes: 9 additions & 6 deletions frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ use frame_election_provider_support::{
use frame_support::{
dispatch::DispatchClass,
ensure,
traits::{Currency, Get, OnUnbalanced, ReservableCurrency},
traits::{Currency, DefensiveResult, Get, OnUnbalanced, ReservableCurrency},
weights::Weight,
DefaultNoBound, EqNoBound, PartialEqNoBound,
};
Expand Down Expand Up @@ -547,6 +547,10 @@ pub enum FeasibilityError {
UntrustedScoreTooLow,
/// Data Provider returned too many desired targets
TooManyDesiredTargets,
/// Conversion into bounded types failed.
///
/// Should never happen under correct configurations.
BoundedConversionFailed,
}

impl From<sp_npos_elections::Error> for FeasibilityError {
Expand All @@ -560,10 +564,7 @@ pub use pallet::*;
pub mod pallet {
use super::*;
use frame_election_provider_support::{InstantElectionProvider, NposSolver};
use frame_support::{
pallet_prelude::*,
traits::{DefensiveResult, EstimateCallFee},
};
use frame_support::{pallet_prelude::*, traits::EstimateCallFee};
use frame_system::pallet_prelude::*;

#[pallet::config]
Expand Down Expand Up @@ -1549,7 +1550,9 @@ impl<T: Config> Pallet<T> {
ensure!(known_score == score, FeasibilityError::InvalidScore);

// Size of winners in miner solution is equal to `desired_targets` <= `MaxWinners`.
let supports = supports.try_into().expect("checked desired_targets <= MaxWinners; qed");
let supports = supports
.try_into()
.defensive_map_err(|_| FeasibilityError::BoundedConversionFailed)?;
Ok(ReadySolution { supports, compute, score })
}

Expand Down
4 changes: 3 additions & 1 deletion frame/fast-unstake/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ pub mod v1 {
);

if current == 1 && onchain == 0 {
// update the version nonetheless.
current.put::<Pallet<T>>();

// if a head exists, then we put them back into the queue.
if Head::<T>::exists() {
if let Some((stash, _, deposit)) =
Expand All @@ -48,7 +51,6 @@ pub mod v1 {
.defensive()
{
Queue::<T>::insert(stash, deposit);
current.put::<Pallet<T>>();
} else {
// not much we can do here -- head is already deleted.
}
Expand Down