mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 07:41:08 +00:00
Rewrap all comments to 100 line width (#9490)
* reformat everything again * manual formatting * last manual fix * Fix build
This commit is contained in:
@@ -25,8 +25,8 @@ use sp_runtime::{curve::PiecewiseLinear, traits::AtLeast32BitUnsigned, Perbill};
|
||||
/// The total payout to all validators (and their nominators) per era and maximum payout.
|
||||
///
|
||||
/// Defined as such:
|
||||
/// `staker-payout = yearly_inflation(npos_token_staked / total_tokens) * total_tokens / era_per_year`
|
||||
/// `maximum-payout = max_yearly_inflation * total_tokens / era_per_year`
|
||||
/// `staker-payout = yearly_inflation(npos_token_staked / total_tokens) * total_tokens /
|
||||
/// era_per_year` `maximum-payout = max_yearly_inflation * total_tokens / era_per_year`
|
||||
///
|
||||
/// `era_duration` is expressed in millisecond.
|
||||
pub fn compute_total_payout<N>(
|
||||
|
||||
@@ -163,8 +163,9 @@ impl<T: Config> Pallet<T> {
|
||||
Self::deposit_event(Event::<T>::Rewarded(ledger.stash, imbalance.peek()));
|
||||
}
|
||||
|
||||
// Track the number of payout ops to nominators. Note: `WeightInfo::payout_stakers_alive_staked`
|
||||
// always assumes at least a validator is paid out, so we do not need to count their payout op.
|
||||
// Track the number of payout ops to nominators. Note:
|
||||
// `WeightInfo::payout_stakers_alive_staked` always assumes at least a validator is paid
|
||||
// out, so we do not need to count their payout op.
|
||||
let mut nominator_payout_count: u32 = 0;
|
||||
|
||||
// Lets now calculate how this is split to the nominators.
|
||||
@@ -306,6 +307,7 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// * Increment `active_era.index`,
|
||||
/// * reset `active_era.start`,
|
||||
/// * update `BondedEras` and apply slashes.
|
||||
@@ -674,7 +676,8 @@ impl<T: Config> Pallet<T> {
|
||||
all_voters
|
||||
}
|
||||
|
||||
/// This is a very expensive function and result should be cached versus being called multiple times.
|
||||
/// This is a very expensive function and result should be cached versus being called multiple
|
||||
/// times.
|
||||
pub fn get_npos_targets() -> Vec<T::AccountId> {
|
||||
Validators::<T>::iter().map(|(v, _)| v).collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
@@ -62,12 +62,12 @@ pub mod pallet {
|
||||
|
||||
/// Time used for computing era duration.
|
||||
///
|
||||
/// It is guaranteed to start being called from the first `on_finalize`. Thus value at genesis
|
||||
/// is not used.
|
||||
/// It is guaranteed to start being called from the first `on_finalize`. Thus value at
|
||||
/// genesis is not used.
|
||||
type UnixTime: UnixTime;
|
||||
|
||||
/// Convert a balance into a number used for election calculation. This must fit into a `u64`
|
||||
/// but is allowed to be sensibly lossy. The `u64` is used to communicate with the
|
||||
/// Convert a balance into a number used for election calculation. This must fit into a
|
||||
/// `u64` but is allowed to be sensibly lossy. The `u64` is used to communicate with the
|
||||
/// [`sp_npos_elections`] crate which accepts u64 numbers and does operations in 128.
|
||||
/// Consequently, the backward convert is used convert the u128s from sp-elections back to a
|
||||
/// [`BalanceOf`].
|
||||
@@ -129,13 +129,14 @@ pub mod pallet {
|
||||
/// See [Era payout](./index.html#era-payout).
|
||||
type EraPayout: EraPayout<BalanceOf<Self>>;
|
||||
|
||||
/// Something that can estimate the next session change, accurately or as a best effort guess.
|
||||
/// Something that can estimate the next session change, accurately or as a best effort
|
||||
/// guess.
|
||||
type NextNewSession: EstimateNextNewSession<Self::BlockNumber>;
|
||||
|
||||
/// The maximum number of nominators rewarded for each validator.
|
||||
///
|
||||
/// For each validator only the `$MaxNominatorRewardedPerValidator` biggest stakers can claim
|
||||
/// their reward. This used to limit the i/o cost for the nominator payout.
|
||||
/// For each validator only the `$MaxNominatorRewardedPerValidator` biggest stakers can
|
||||
/// claim their reward. This used to limit the i/o cost for the nominator payout.
|
||||
#[pallet::constant]
|
||||
type MaxNominatorRewardedPerValidator: Get<u32>;
|
||||
|
||||
@@ -437,9 +438,9 @@ pub mod pallet {
|
||||
#[pallet::storage]
|
||||
pub(crate) type StorageVersion<T: Config> = StorageValue<_, Releases, ValueQuery>;
|
||||
|
||||
/// The threshold for when users can start calling `chill_other` for other validators / nominators.
|
||||
/// The threshold is compared to the actual number of validators / nominators (`CountFor*`) in
|
||||
/// the system compared to the configured max (`Max*Count`).
|
||||
/// The threshold for when users can start calling `chill_other` for other validators /
|
||||
/// nominators. The threshold is compared to the actual number of validators / nominators
|
||||
/// (`CountFor*`) in the system compared to the configured max (`Max*Count`).
|
||||
#[pallet::storage]
|
||||
pub(crate) type ChillThreshold<T: Config> = StorageValue<_, Percent, OptionQuery>;
|
||||
|
||||
@@ -598,11 +599,11 @@ pub mod pallet {
|
||||
BadTarget,
|
||||
/// The user has enough bond and thus cannot be chilled forcefully by an external person.
|
||||
CannotChillOther,
|
||||
/// There are too many nominators in the system. Governance needs to adjust the staking settings
|
||||
/// to keep things safe for the runtime.
|
||||
/// There are too many nominators in the system. Governance needs to adjust the staking
|
||||
/// settings to keep things safe for the runtime.
|
||||
TooManyNominators,
|
||||
/// There are too many validators in the system. Governance needs to adjust the staking settings
|
||||
/// to keep things safe for the runtime.
|
||||
/// There are too many validators in the system. Governance needs to adjust the staking
|
||||
/// settings to keep things safe for the runtime.
|
||||
TooManyValidators,
|
||||
}
|
||||
|
||||
@@ -636,7 +637,8 @@ pub mod pallet {
|
||||
if active_era.start.is_none() {
|
||||
let now_as_millis_u64 = T::UnixTime::now().as_millis().saturated_into::<u64>();
|
||||
active_era.start = Some(now_as_millis_u64);
|
||||
// This write only ever happens once, we don't include it in the weight in general
|
||||
// This write only ever happens once, we don't include it in the weight in
|
||||
// general
|
||||
ActiveEra::<T>::put(active_era);
|
||||
}
|
||||
}
|
||||
@@ -731,8 +733,8 @@ pub mod pallet {
|
||||
/// The dispatch origin for this call must be _Signed_ by the stash, not the controller.
|
||||
///
|
||||
/// Use this if there are additional funds in your stash account that you wish to bond.
|
||||
/// Unlike [`bond`](Self::bond) or [`unbond`](Self::unbond) this function does not impose any limitation
|
||||
/// on the amount that can be added.
|
||||
/// Unlike [`bond`](Self::bond) or [`unbond`](Self::unbond) this function does not impose
|
||||
/// any limitation on the amount that can be added.
|
||||
///
|
||||
/// Emits `Bonded`.
|
||||
///
|
||||
@@ -854,23 +856,24 @@ pub mod pallet {
|
||||
ledger = ledger.consolidate_unlocked(current_era)
|
||||
}
|
||||
|
||||
let post_info_weight =
|
||||
if ledger.unlocking.is_empty() && ledger.active < T::Currency::minimum_balance() {
|
||||
// This account must have called `unbond()` with some value that caused the active
|
||||
// portion to fall below existential deposit + will have no more unlocking chunks
|
||||
// left. We can now safely remove all staking-related information.
|
||||
Self::kill_stash(&stash, num_slashing_spans)?;
|
||||
// Remove the lock.
|
||||
T::Currency::remove_lock(STAKING_ID, &stash);
|
||||
// This is worst case scenario, so we use the full weight and return None
|
||||
None
|
||||
} else {
|
||||
// This was the consequence of a partial unbond. just update the ledger and move on.
|
||||
Self::update_ledger(&controller, &ledger);
|
||||
let post_info_weight = if ledger.unlocking.is_empty() &&
|
||||
ledger.active < T::Currency::minimum_balance()
|
||||
{
|
||||
// This account must have called `unbond()` with some value that caused the active
|
||||
// portion to fall below existential deposit + will have no more unlocking chunks
|
||||
// left. We can now safely remove all staking-related information.
|
||||
Self::kill_stash(&stash, num_slashing_spans)?;
|
||||
// Remove the lock.
|
||||
T::Currency::remove_lock(STAKING_ID, &stash);
|
||||
// This is worst case scenario, so we use the full weight and return None
|
||||
None
|
||||
} else {
|
||||
// This was the consequence of a partial unbond. just update the ledger and move on.
|
||||
Self::update_ledger(&controller, &ledger);
|
||||
|
||||
// This is only an update, so we use less overall weight.
|
||||
Some(T::WeightInfo::withdraw_unbonded_update(num_slashing_spans))
|
||||
};
|
||||
// This is only an update, so we use less overall weight.
|
||||
Some(T::WeightInfo::withdraw_unbonded_update(num_slashing_spans))
|
||||
};
|
||||
|
||||
// `old_total` should never be less than the new total because
|
||||
// `consolidate_unlocked` strictly subtracts balance.
|
||||
@@ -898,8 +901,9 @@ pub mod pallet {
|
||||
|
||||
// Only check limits if they are not already a validator.
|
||||
if !Validators::<T>::contains_key(stash) {
|
||||
// If this error is reached, we need to adjust the `MinValidatorBond` and start calling `chill_other`.
|
||||
// Until then, we explicitly block new validators to protect the runtime.
|
||||
// If this error is reached, we need to adjust the `MinValidatorBond` and start
|
||||
// calling `chill_other`. Until then, we explicitly block new validators to protect
|
||||
// the runtime.
|
||||
if let Some(max_validators) = MaxValidatorsCount::<T>::get() {
|
||||
ensure!(
|
||||
CounterForValidators::<T>::get() < max_validators,
|
||||
@@ -937,8 +941,9 @@ pub mod pallet {
|
||||
|
||||
// Only check limits if they are not already a nominator.
|
||||
if !Nominators::<T>::contains_key(stash) {
|
||||
// If this error is reached, we need to adjust the `MinNominatorBond` and start calling `chill_other`.
|
||||
// Until then, we explicitly block new nominators to protect the runtime.
|
||||
// If this error is reached, we need to adjust the `MinNominatorBond` and start
|
||||
// calling `chill_other`. Until then, we explicitly block new nominators to protect
|
||||
// the runtime.
|
||||
if let Some(max_nominators) = MaxNominatorsCount::<T>::get() {
|
||||
ensure!(
|
||||
CounterForNominators::<T>::get() < max_nominators,
|
||||
@@ -1180,8 +1185,8 @@ pub mod pallet {
|
||||
/// # <weight>
|
||||
/// O(S) where S is the number of slashing spans to be removed
|
||||
/// Reads: Bonded, Slashing Spans, Account, Locks
|
||||
/// Writes: Bonded, Slashing Spans (if S > 0), Ledger, Payee, Validators, Nominators, Account, Locks
|
||||
/// Writes Each: SpanSlash * S
|
||||
/// Writes: Bonded, Slashing Spans (if S > 0), Ledger, Payee, Validators, Nominators,
|
||||
/// Account, Locks Writes Each: SpanSlash * S
|
||||
/// # </weight>
|
||||
#[pallet::weight(T::WeightInfo::force_unstake(*num_slashing_spans))]
|
||||
pub fn force_unstake(
|
||||
@@ -1327,10 +1332,10 @@ pub mod pallet {
|
||||
///
|
||||
/// Parameters:
|
||||
/// - `new_history_depth`: The new history depth you would like to set.
|
||||
/// - `era_items_deleted`: The number of items that will be deleted by this dispatch.
|
||||
/// This should report all the storage items that will be deleted by clearing old
|
||||
/// era history. Needed to report an accurate weight for the dispatch. Trusted by
|
||||
/// `Root` to report an accurate number.
|
||||
/// - `era_items_deleted`: The number of items that will be deleted by this dispatch. This
|
||||
/// should report all the storage items that will be deleted by clearing old era history.
|
||||
/// Needed to report an accurate weight for the dispatch. Trusted by `Root` to report an
|
||||
/// accurate number.
|
||||
///
|
||||
/// Origin must be root.
|
||||
///
|
||||
@@ -1341,7 +1346,8 @@ pub mod pallet {
|
||||
/// - Reads: Current Era, History Depth
|
||||
/// - Writes: History Depth
|
||||
/// - Clear Prefix Each: Era Stakers, EraStakersClipped, ErasValidatorPrefs
|
||||
/// - Writes Each: ErasValidatorReward, ErasRewardPoints, ErasTotalStake, ErasStartSessionIndex
|
||||
/// - Writes Each: ErasValidatorReward, ErasRewardPoints, ErasTotalStake,
|
||||
/// ErasStartSessionIndex
|
||||
/// # </weight>
|
||||
#[pallet::weight(T::WeightInfo::set_history_depth(*_era_items_deleted))]
|
||||
pub fn set_history_depth(
|
||||
@@ -1375,7 +1381,8 @@ pub mod pallet {
|
||||
/// Complexity: O(S) where S is the number of slashing spans on the account.
|
||||
/// DB Weight:
|
||||
/// - Reads: Stash Account, Bonded, Slashing Spans, Locks
|
||||
/// - Writes: Bonded, Slashing Spans (if S > 0), Ledger, Payee, Validators, Nominators, Stash Account, Locks
|
||||
/// - Writes: Bonded, Slashing Spans (if S > 0), Ledger, Payee, Validators, Nominators,
|
||||
/// Stash Account, Locks
|
||||
/// - Writes Each: SpanSlash * S
|
||||
/// # </weight>
|
||||
#[pallet::weight(T::WeightInfo::reap_stash(*num_slashing_spans))]
|
||||
@@ -1437,10 +1444,10 @@ pub mod pallet {
|
||||
///
|
||||
/// * `min_nominator_bond`: The minimum active bond needed to be a nominator.
|
||||
/// * `min_validator_bond`: The minimum active bond needed to be a validator.
|
||||
/// * `max_nominator_count`: The max number of users who can be a nominator at once.
|
||||
/// When set to `None`, no limit is enforced.
|
||||
/// * `max_validator_count`: The max number of users who can be a validator at once.
|
||||
/// When set to `None`, no limit is enforced.
|
||||
/// * `max_nominator_count`: The max number of users who can be a nominator at once. When
|
||||
/// set to `None`, no limit is enforced.
|
||||
/// * `max_validator_count`: The max number of users who can be a validator at once. When
|
||||
/// set to `None`, no limit is enforced.
|
||||
///
|
||||
/// Origin must be Root to call this function.
|
||||
///
|
||||
|
||||
@@ -572,13 +572,15 @@ fn nominating_and_rewards_should_work() {
|
||||
mock::make_all_reward_payment(1);
|
||||
let payout_for_10 = total_payout_1 / 3;
|
||||
let payout_for_20 = 2 * total_payout_1 / 3;
|
||||
// Nominator 2: has [400/1800 ~ 2/9 from 10] + [600/2200 ~ 3/11 from 20]'s reward. ==> 2/9 + 3/11
|
||||
// Nominator 2: has [400/1800 ~ 2/9 from 10] + [600/2200 ~ 3/11 from 20]'s reward. ==>
|
||||
// 2/9 + 3/11
|
||||
assert_eq_error_rate!(
|
||||
Balances::total_balance(&2),
|
||||
initial_balance + (2 * payout_for_10 / 9 + 3 * payout_for_20 / 11),
|
||||
2,
|
||||
);
|
||||
// Nominator 4: has [400/1800 ~ 2/9 from 10] + [600/2200 ~ 3/11 from 20]'s reward. ==> 2/9 + 3/11
|
||||
// Nominator 4: has [400/1800 ~ 2/9 from 10] + [600/2200 ~ 3/11 from 20]'s reward. ==>
|
||||
// 2/9 + 3/11
|
||||
assert_eq_error_rate!(
|
||||
Balances::total_balance(&4),
|
||||
initial_balance + (2 * payout_for_10 / 9 + 3 * payout_for_20 / 11),
|
||||
@@ -591,7 +593,8 @@ fn nominating_and_rewards_should_work() {
|
||||
initial_balance + 5 * payout_for_10 / 9,
|
||||
2,
|
||||
);
|
||||
// Validator 20: got `1200/2200` external stake => 12/22 =? 6/11 => Validator's share = 5/11
|
||||
// Validator 20: got 1200 / 2200 external stake => 12/22 =? 6/11 => Validator's share =
|
||||
// 5/11
|
||||
assert_eq_error_rate!(
|
||||
Balances::total_balance(&20),
|
||||
initial_balance_20 + 5 * payout_for_20 / 11,
|
||||
@@ -684,7 +687,8 @@ fn double_staking_should_fail() {
|
||||
#[test]
|
||||
fn double_controlling_should_fail() {
|
||||
// should test (in the same order):
|
||||
// * an account already bonded as controller CANNOT be reused as the controller of another account.
|
||||
// * an account already bonded as controller CANNOT be reused as the controller of another
|
||||
// account.
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let arbitrary_value = 5;
|
||||
// 2 = controller, 1 stashed => ok
|
||||
@@ -1116,6 +1120,7 @@ fn bond_extra_works() {
|
||||
|
||||
#[test]
|
||||
fn bond_extra_and_withdraw_unbonded_works() {
|
||||
//
|
||||
// * Should test
|
||||
// * Given an account being bonded [and chosen as a validator](not mandatory)
|
||||
// * It can add extra funds to the bonded account.
|
||||
@@ -1282,6 +1287,7 @@ fn too_many_unbond_calls_should_not_work() {
|
||||
|
||||
#[test]
|
||||
fn rebond_works() {
|
||||
//
|
||||
// * Should test
|
||||
// * Given an account being bonded [and chosen as a validator](not mandatory)
|
||||
// * it can unbond a portion of its funds from the stash account.
|
||||
@@ -1683,7 +1689,8 @@ fn on_free_balance_zero_stash_removes_nominator() {
|
||||
|
||||
#[test]
|
||||
fn switching_roles() {
|
||||
// Test that it should be possible to switch between roles (nominator, validator, idle) with minimal overhead.
|
||||
// Test that it should be possible to switch between roles (nominator, validator, idle) with
|
||||
// minimal overhead.
|
||||
ExtBuilder::default().nominate(false).build_and_execute(|| {
|
||||
// Reset reward destination
|
||||
for i in &[10, 20] {
|
||||
@@ -3354,7 +3361,8 @@ fn payout_stakers_handles_weight_refund() {
|
||||
assert_ok!(result);
|
||||
assert_eq!(extract_actual_weight(&result, &info), zero_nom_payouts_weight);
|
||||
|
||||
// The validator is not rewarded in this era; so there will be zero payouts to claim for this era.
|
||||
// The validator is not rewarded in this era; so there will be zero payouts to claim for
|
||||
// this era.
|
||||
|
||||
// Era 3
|
||||
start_active_era(3);
|
||||
@@ -4118,7 +4126,8 @@ fn chill_other_works() {
|
||||
assert_eq!(CounterForNominators::<Test>::get(), 15 + initial_nominators);
|
||||
assert_eq!(CounterForValidators::<Test>::get(), 15 + initial_validators);
|
||||
|
||||
// Users can now be chilled down to 7 people, so we try to remove 9 of them (starting with 16)
|
||||
// Users can now be chilled down to 7 people, so we try to remove 9 of them (starting
|
||||
// with 16)
|
||||
for i in 6..15 {
|
||||
let b = 4 * i + 1;
|
||||
let d = 4 * i + 3;
|
||||
|
||||
Reference in New Issue
Block a user