mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 21:41:12 +00:00
return error instead of expect in feasibility_check (#12745)
* Update lib.rs * make defensive * fmt * fix batching migration * fix * fix Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -237,7 +237,7 @@ use frame_election_provider_support::{
|
|||||||
use frame_support::{
|
use frame_support::{
|
||||||
dispatch::DispatchClass,
|
dispatch::DispatchClass,
|
||||||
ensure,
|
ensure,
|
||||||
traits::{Currency, Get, OnUnbalanced, ReservableCurrency},
|
traits::{Currency, DefensiveResult, Get, OnUnbalanced, ReservableCurrency},
|
||||||
weights::Weight,
|
weights::Weight,
|
||||||
DefaultNoBound, EqNoBound, PartialEqNoBound,
|
DefaultNoBound, EqNoBound, PartialEqNoBound,
|
||||||
};
|
};
|
||||||
@@ -547,6 +547,10 @@ pub enum FeasibilityError {
|
|||||||
UntrustedScoreTooLow,
|
UntrustedScoreTooLow,
|
||||||
/// Data Provider returned too many desired targets
|
/// Data Provider returned too many desired targets
|
||||||
TooManyDesiredTargets,
|
TooManyDesiredTargets,
|
||||||
|
/// Conversion into bounded types failed.
|
||||||
|
///
|
||||||
|
/// Should never happen under correct configurations.
|
||||||
|
BoundedConversionFailed,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<sp_npos_elections::Error> for FeasibilityError {
|
impl From<sp_npos_elections::Error> for FeasibilityError {
|
||||||
@@ -560,10 +564,7 @@ pub use pallet::*;
|
|||||||
pub mod pallet {
|
pub mod pallet {
|
||||||
use super::*;
|
use super::*;
|
||||||
use frame_election_provider_support::{InstantElectionProvider, NposSolver};
|
use frame_election_provider_support::{InstantElectionProvider, NposSolver};
|
||||||
use frame_support::{
|
use frame_support::{pallet_prelude::*, traits::EstimateCallFee};
|
||||||
pallet_prelude::*,
|
|
||||||
traits::{DefensiveResult, EstimateCallFee},
|
|
||||||
};
|
|
||||||
use frame_system::pallet_prelude::*;
|
use frame_system::pallet_prelude::*;
|
||||||
|
|
||||||
#[pallet::config]
|
#[pallet::config]
|
||||||
@@ -1549,7 +1550,9 @@ impl<T: Config> Pallet<T> {
|
|||||||
ensure!(known_score == score, FeasibilityError::InvalidScore);
|
ensure!(known_score == score, FeasibilityError::InvalidScore);
|
||||||
|
|
||||||
// Size of winners in miner solution is equal to `desired_targets` <= `MaxWinners`.
|
// 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 })
|
Ok(ReadySolution { supports, compute, score })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ pub mod v1 {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if current == 1 && onchain == 0 {
|
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 a head exists, then we put them back into the queue.
|
||||||
if Head::<T>::exists() {
|
if Head::<T>::exists() {
|
||||||
if let Some((stash, _, deposit)) =
|
if let Some((stash, _, deposit)) =
|
||||||
@@ -48,7 +51,6 @@ pub mod v1 {
|
|||||||
.defensive()
|
.defensive()
|
||||||
{
|
{
|
||||||
Queue::<T>::insert(stash, deposit);
|
Queue::<T>::insert(stash, deposit);
|
||||||
current.put::<Pallet<T>>();
|
|
||||||
} else {
|
} else {
|
||||||
// not much we can do here -- head is already deleted.
|
// not much we can do here -- head is already deleted.
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user