Skip to content

Commit

Permalink
clippy nits
Browse files Browse the repository at this point in the history
  • Loading branch information
gpestana committed May 10, 2024
1 parent 3d4452f commit d225176
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ use pallet_election_provider_multi_phase::{
unsigned::MinerConfig, Call, ElectionCompute, GeometricDepositBase, QueuedSolution,
SolutionAccuracyOf,
};
use pallet_stake_tracker::VoterUpdateMode;
use pallet_staking::StakerStatus;
use parking_lot::RwLock;
use std::sync::Arc;
Expand Down Expand Up @@ -83,7 +84,7 @@ frame_support::construct_runtime!(
pub(crate) type AccountId = u64;
pub(crate) type AccountIndex = u32;
pub(crate) type BlockNumber = u32;
pub(crate) type Balance = u64;
pub(crate) type Balance = u128;
pub(crate) type VoterIndex = u16;
pub(crate) type TargetIndex = u16;
pub(crate) type Moment = u32;
Expand Down Expand Up @@ -232,11 +233,11 @@ impl MinerConfig for Runtime {
}

const VOTERS_THRESHOLDS: [VoteWeight; 9] = [10, 20, 30, 40, 50, 60, 1_000, 2_000, 10_000];
const TARGETS_THRESHOLDS: [Balance; 9] = [10, 20, 30, 40, 50, 60, 1_000, 2_000, 10_000];
const TARGETS_THRESHOLDS: [u128; 9] = [10, 20, 30, 40, 50, 60, 1_000, 2_000, 10_000];

parameter_types! {
pub static VoterBagThresholds: &'static [VoteWeight] = &VOTERS_THRESHOLDS;
pub static TargetBagThresholds: &'static [Balance] = &TARGETS_THRESHOLDS;
pub static TargetBagThresholds: &'static [u128] = &TARGETS_THRESHOLDS;
pub const SessionsPerEra: sp_staking::SessionIndex = 2;
pub static BondingDuration: sp_staking::EraIndex = 28;
pub const SlashDeferDuration: sp_staking::EraIndex = 7; // 1/4 the bonding duration.
Expand All @@ -256,17 +257,21 @@ type TargetBagsListInstance = pallet_bags_list::Instance2;
impl pallet_bags_list::Config<TargetBagsListInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type ScoreProvider = Staking;
type ScoreProvider = pallet_bags_list::Pallet<Runtime, TargetBagsListInstance>;
type BagThresholds = TargetBagThresholds;
type Score = VoteWeight;
type Score = u128;
}

parameter_types! {
pub static UpdateMode: VoterUpdateMode = VoterUpdateMode::Strict;
}

impl pallet_stake_tracker::Config for Runtime {
type Currency = Balances;
type RuntimeEvent = RuntimeEvent;
type Staking = Staking;
type VoterList = VoterBagsList;
type TargetList = TargetBagsList;
type VoterUpdateMode = UpdateMode;
}

pub struct BalanceToU256;
Expand Down
8 changes: 6 additions & 2 deletions substrate/frame/election-provider-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,11 +570,15 @@ pub trait SortedListProvider<AccountId> {
///
/// Returns a boolean and it is only available in the context of `try-runtime` checks.
#[cfg(feature = "try-runtime")]
fn in_position(id: &AccountId) -> Result<bool, Self::Error>;
fn in_position(_id: &AccountId) -> Result<bool, Self::Error> {
unimplemented!()
}

/// Check internal state of the list. Only meant for debugging.
#[cfg(feature = "try-runtime")]
fn try_state() -> Result<(), TryRuntimeError>;
fn try_state() -> Result<(), TryRuntimeError> {
Ok(())
}

/// If `who` changes by the returned amount they are guaranteed to have a worst case change
/// in their list position.
Expand Down
1 change: 0 additions & 1 deletion substrate/frame/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ impl crate::pallet::pallet::Config for Test {
type MaxExposurePageSize = MaxExposurePageSize;
type ElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
type GenesisElectionProvider = Self::ElectionProvider;
// NOTE: consider a macro and use `UseNominatorsAndValidatorsMap<Self>` as well.
type VoterList = VoterBagsList;
type TargetList = TargetBagsList;
type NominationsQuota = WeightedNominationsQuota<16>;
Expand Down
19 changes: 0 additions & 19 deletions substrate/frame/staking/src/pallet/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1750,15 +1750,6 @@ impl<T: Config> SortedListProvider<T::AccountId> for UseValidatorsMap<T> {
// nothing to do upon regenerate.
0
}
#[cfg(feature = "try-runtime")]
fn in_position(_: &T::AccountId) -> Result<bool, Self::Error> {
unimplemented!()
}
#[cfg(feature = "try-runtime")]
fn try_state() -> Result<(), TryRuntimeError> {
Ok(())
}

fn unsafe_clear() {
#[allow(deprecated)]
Validators::<T>::remove_all();
Expand Down Expand Up @@ -1830,16 +1821,6 @@ impl<T: Config> SortedListProvider<T::AccountId> for UseNominatorsAndValidatorsM
// nothing to do upon regenerate.
0
}

#[cfg(feature = "try-runtime")]
fn in_position(_: &T::AccountId) -> Result<bool, Self::Error> {
unimplemented!()
}
#[cfg(feature = "try-runtime")]
fn try_state() -> Result<(), TryRuntimeError> {
Ok(())
}

fn unsafe_clear() {
// NOTE: Caller must ensure this doesn't lead to too many storage accesses. This is a
// condition of SortedListProvider::unsafe_clear.
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,7 @@ fn reap_stash_works_with_existential_deposit_zero() {
ExtBuilder::default()
.existential_deposit(0)
.balance_factor(10)
.stake_tracker_try_state(false)
.build_and_execute(|| {
// given
assert_eq!(Balances::balance_locked(STAKING_ID, &11), 10 * 1000);
Expand Down
9 changes: 4 additions & 5 deletions substrate/frame/staking/stake-tracker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,11 +770,10 @@ impl<T: Config> OnStakingUpdate<T::AccountId, BalanceOf<T>> for Pallet<T> {
.active
.saturating_sub(slashed_total);

match (active_after_slash.is_zero(), T::Staking::status(stash)) {
(true, Ok(StakerStatus::Nominator(_))) => {
let _ = T::Staking::chill(stash).defensive();
},
_ => (), // do nothing.
if let (true, Ok(StakerStatus::Nominator(_))) =
(active_after_slash.is_zero(), T::Staking::status(stash))
{
let _ = T::Staking::chill(stash).defensive();
};
}

Expand Down

0 comments on commit d225176

Please sign in to comment.