mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 15:51:12 +00:00
Commission is stated as percent of rewards (#4243)
This commit is contained in:
@@ -187,7 +187,7 @@
|
|||||||
//! The validator and its nominator split their reward as following:
|
//! The validator and its nominator split their reward as following:
|
||||||
//!
|
//!
|
||||||
//! The validator can declare an amount, named
|
//! The validator can declare an amount, named
|
||||||
//! [`validator_payment`](./struct.ValidatorPrefs.html#structfield.validator_payment), that does not
|
//! [`commission`](./struct.ValidatorPrefs.html#structfield.commission), that does not
|
||||||
//! get shared with the nominators at each reward payout through its
|
//! get shared with the nominators at each reward payout through its
|
||||||
//! [`ValidatorPrefs`](./struct.ValidatorPrefs.html). This value gets deducted from the total reward
|
//! [`ValidatorPrefs`](./struct.ValidatorPrefs.html). This value gets deducted from the total reward
|
||||||
//! that is paid to the validator and its nominators. The remaining portion is split among the
|
//! that is paid to the validator and its nominators. The remaining portion is split among the
|
||||||
@@ -347,19 +347,19 @@ impl Default for RewardDestination {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Preference of what happens on a slash event.
|
/// Preference of what happens regarding validation.
|
||||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
|
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
|
||||||
pub struct ValidatorPrefs<Balance: HasCompact> {
|
pub struct ValidatorPrefs {
|
||||||
/// Reward that validator takes up-front; only the rest is split between themselves and
|
/// Reward that validator takes up-front; only the rest is split between themselves and
|
||||||
/// nominators.
|
/// nominators.
|
||||||
#[codec(compact)]
|
#[codec(compact)]
|
||||||
pub validator_payment: Balance,
|
pub commission: Perbill,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: Default + HasCompact + Copy> Default for ValidatorPrefs<B> {
|
impl Default for ValidatorPrefs {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
ValidatorPrefs {
|
ValidatorPrefs {
|
||||||
validator_payment: Default::default(),
|
commission: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -657,7 +657,7 @@ decl_storage! {
|
|||||||
pub Payee get(fn payee): map T::AccountId => RewardDestination;
|
pub Payee get(fn payee): map T::AccountId => RewardDestination;
|
||||||
|
|
||||||
/// The map from (wannabe) validator stash key to the preferences of that validator.
|
/// The map from (wannabe) validator stash key to the preferences of that validator.
|
||||||
pub Validators get(fn validators): linked_map T::AccountId => ValidatorPrefs<BalanceOf<T>>;
|
pub Validators get(fn validators): linked_map T::AccountId => ValidatorPrefs;
|
||||||
|
|
||||||
/// The map from nominator stash key to the set of stash keys of all validators to nominate.
|
/// The map from nominator stash key to the set of stash keys of all validators to nominate.
|
||||||
///
|
///
|
||||||
@@ -982,7 +982,7 @@ decl_module! {
|
|||||||
/// - Writes are limited to the `origin` account key.
|
/// - Writes are limited to the `origin` account key.
|
||||||
/// # </weight>
|
/// # </weight>
|
||||||
#[weight = SimpleDispatchInfo::FixedNormal(750_000)]
|
#[weight = SimpleDispatchInfo::FixedNormal(750_000)]
|
||||||
fn validate(origin, prefs: ValidatorPrefs<BalanceOf<T>>) {
|
fn validate(origin, prefs: ValidatorPrefs) {
|
||||||
Self::ensure_storage_upgraded();
|
Self::ensure_storage_upgraded();
|
||||||
|
|
||||||
let controller = ensure_signed(origin)?;
|
let controller = ensure_signed(origin)?;
|
||||||
@@ -1252,8 +1252,8 @@ impl<T: Trait> Module<T> {
|
|||||||
/// nominators' balance, pro-rata based on their exposure, after having removed the validator's
|
/// nominators' balance, pro-rata based on their exposure, after having removed the validator's
|
||||||
/// pre-payout cut.
|
/// pre-payout cut.
|
||||||
fn reward_validator(stash: &T::AccountId, reward: BalanceOf<T>) -> PositiveImbalanceOf<T> {
|
fn reward_validator(stash: &T::AccountId, reward: BalanceOf<T>) -> PositiveImbalanceOf<T> {
|
||||||
let off_the_table = reward.min(Self::validators(stash).validator_payment);
|
let off_the_table = Self::validators(stash).commission * reward;
|
||||||
let reward = reward - off_the_table;
|
let reward = reward.saturating_sub(off_the_table);
|
||||||
let mut imbalance = <PositiveImbalanceOf<T>>::zero();
|
let mut imbalance = <PositiveImbalanceOf<T>>::zero();
|
||||||
let validator_cut = if reward.is_zero() {
|
let validator_cut = if reward.is_zero() {
|
||||||
Zero::zero()
|
Zero::zero()
|
||||||
|
|||||||
@@ -965,7 +965,6 @@ fn validator_payment_prefs_work() {
|
|||||||
// This test will focus on validator payment.
|
// This test will focus on validator payment.
|
||||||
ExtBuilder::default().build().execute_with(|| {
|
ExtBuilder::default().build().execute_with(|| {
|
||||||
// Initial config
|
// Initial config
|
||||||
let validator_cut = 5;
|
|
||||||
let stash_initial_balance = Balances::total_balance(&11);
|
let stash_initial_balance = Balances::total_balance(&11);
|
||||||
|
|
||||||
// check the balance of a validator accounts.
|
// check the balance of a validator accounts.
|
||||||
@@ -983,7 +982,7 @@ fn validator_payment_prefs_work() {
|
|||||||
});
|
});
|
||||||
<Payee<Test>>::insert(&2, RewardDestination::Stash);
|
<Payee<Test>>::insert(&2, RewardDestination::Stash);
|
||||||
<Validators<Test>>::insert(&11, ValidatorPrefs {
|
<Validators<Test>>::insert(&11, ValidatorPrefs {
|
||||||
validator_payment: validator_cut
|
commission: Perbill::from_percent(50),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Compute total payout now for whole duration as other parameter won't change
|
// Compute total payout now for whole duration as other parameter won't change
|
||||||
@@ -994,9 +993,9 @@ fn validator_payment_prefs_work() {
|
|||||||
start_era(1);
|
start_era(1);
|
||||||
|
|
||||||
// whats left to be shared is the sum of 3 rounds minus the validator's cut.
|
// whats left to be shared is the sum of 3 rounds minus the validator's cut.
|
||||||
let shared_cut = total_payout_0 - validator_cut;
|
let shared_cut = total_payout_0 / 2;
|
||||||
// Validator's payee is Staked account, 11, reward will be paid here.
|
// Validator's payee is Staked account, 11, reward will be paid here.
|
||||||
assert_eq!(Balances::total_balance(&11), stash_initial_balance + shared_cut / 2 + validator_cut);
|
assert_eq!(Balances::total_balance(&11), stash_initial_balance + shared_cut / 2 + shared_cut);
|
||||||
// Controller account will not get any reward.
|
// Controller account will not get any reward.
|
||||||
assert_eq!(Balances::total_balance(&10), 1);
|
assert_eq!(Balances::total_balance(&10), 1);
|
||||||
// Rest of the reward will be shared and paid to the nominator in stake.
|
// Rest of the reward will be shared and paid to the nominator in stake.
|
||||||
|
|||||||
Reference in New Issue
Block a user