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

Introduce Payees and PayoutDestination with Split variant #14451

Open
wants to merge 123 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 96 commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
49afbb8
new storage + enum, update both
Jun 23, 2023
035d3d3
comments
Jun 23, 2023
bd81a16
to_payee_destination & update_payee & benchmark
Jun 23, 2023
0177e16
Clone
Jun 23, 2023
05b7f59
re-order enum
Jun 23, 2023
f174e0c
fix
Jun 23, 2023
39464e3
Merge branch 'master' of https://github.com/paritytech/substrate into…
Jun 23, 2023
e2294bd
".git/.scripts/commands/bench/bench.sh" pallet dev pallet_staking
Jun 23, 2023
189ec01
insert weight
Jun 24, 2023
6649a5f
set_payee_also_updates_payee_destination
Jun 24, 2023
b576b60
+ update_payees_works test
Jun 24, 2023
9a0ee29
fixes & test RewardDestination::Account migration
Jun 24, 2023
20917d5
add tracking issue for migration
Jun 24, 2023
6477371
set_payee inserts fresh `Payees`
Jun 24, 2023
11e090a
use auto link
Jun 24, 2023
872b2f3
use auto link
Jun 24, 2023
54f8c31
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Jun 24, 2023
4c8459f
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Jun 26, 2023
2ddd9bb
comments
Jun 27, 2023
453adcf
update_payee queries Ledger
Jun 27, 2023
772a209
fix
Jun 27, 2023
0171ef1
rm clone
Jun 27, 2023
5b21689
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Jun 27, 2023
7504756
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Jul 7, 2023
d22cf19
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Jul 17, 2023
584228c
payout_destination
Jul 17, 2023
d3e35de
simplify `PayoutDestination`
Jul 17, 2023
6173886
fix benches
Jul 17, 2023
d051545
comment
Jul 17, 2023
066efdf
comment
Jul 17, 2023
959cb8d
text
Jul 17, 2023
8582237
Update frame/staking/src/tests.rs
Jul 20, 2023
a9f7157
separate update_payee tests
Jul 20, 2023
4b9aed2
add back Free variant
Jul 20, 2023
fcef79d
fix
Jul 20, 2023
29ae76d
update comment
Jul 20, 2023
1dc6f10
waive tx fee on successful migrate
Jul 20, 2023
54e6ef7
comment
Jul 20, 2023
34376ac
use PayoutDestination
Jul 20, 2023
8593c65
insert to Payees
Jul 20, 2023
b30f54f
fmt
Jul 20, 2023
05fefa1
rm clone
Jul 20, 2023
e15b790
fmt
Jul 20, 2023
474344c
subsume zero
Jul 20, 2023
9ccf4c5
use unwrap_or
Jul 20, 2023
734ed8c
Stake, Free fallbacks
Jul 20, 2023
c3cccdc
fmt
Jul 20, 2023
047421d
comment
Jul 20, 2023
3a88897
Update frame/staking/src/lib.rs
Jul 20, 2023
c39b9bd
Free -> Credit
Jul 20, 2023
bd12a7a
Update frame/staking/src/pallet/impls.rs
Jul 20, 2023
1f80dd4
use saturating_accrue
Jul 20, 2023
d606a05
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Jul 20, 2023
05c77a8
use Split
Jul 21, 2023
ddadf10
fix up update_payee & tests
Jul 21, 2023
1dc3979
add get_destination_payout_migrates_payee test
Jul 21, 2023
7605e89
fix test
Jul 21, 2023
c59c2bf
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Jul 21, 2023
9b353ba
Update frame/staking/src/pallet/mod.rs
Jul 22, 2023
a003a5e
@gpestana feedback
Jul 22, 2023
2dc7bb4
fix tuple
Jul 22, 2023
cdc1ae0
Credit -> Deposit
Jul 25, 2023
df9efe0
+ payout_destination_stake closure
Jul 25, 2023
25884ac
renames and format
Jul 25, 2023
d76d82b
renames
Jul 25, 2023
3761ce9
comment
Jul 25, 2023
8234a9e
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Jul 25, 2023
4c8bfbd
comments
Jul 25, 2023
4a5a0b8
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Jul 26, 2023
70117ca
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Jul 27, 2023
adab51c
replace expect
Jul 31, 2023
7d41deb
worst case
Jul 31, 2023
5f947c6
PayoutDestinationOpt to alias unknown accounts
Jul 31, 2023
2d7778f
use testing_utils
Jul 31, 2023
9135008
fix
Jul 31, 2023
088467d
fix
Jul 31, 2023
51689e7
clone
Jul 31, 2023
9832993
fix
Jul 31, 2023
98f5d23
comment
Jul 31, 2023
78d2fd3
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Jul 31, 2023
38afc4b
add CHANGELOG
Aug 1, 2023
ab50eb3
comment
Aug 1, 2023
69745ab
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Aug 1, 2023
e37b29a
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Aug 2, 2023
b4e4d89
get_payout_destination_migrate
Aug 2, 2023
c91a017
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Aug 2, 2023
20f99e2
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Aug 2, 2023
cc24251
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Aug 3, 2023
341b520
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Aug 4, 2023
a54a28a
Merge branch 'master' into rb-payee-destination
Aug 6, 2023
84de89d
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Aug 10, 2023
fb68087
Merge branch 'master' into rb-payee-destination
Aug 12, 2023
7ecd0b5
lint
Aug 12, 2023
58ced37
fix
Aug 12, 2023
963e1ba
lint
Aug 12, 2023
474218b
another merge fix
Aug 12, 2023
55c32be
Update frame/staking/CHANGELOG.md
Aug 15, 2023
21f9605
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Aug 15, 2023
f65d246
PayoutDestination::from_opt, move Opt to sp
Aug 16, 2023
758f76d
combine from impls
Aug 16, 2023
b609639
fix StakerStatus
Aug 16, 2023
5dd8c2b
use destiantion
Aug 16, 2023
5b29b62
amend comment
Aug 16, 2023
aa7fc8a
don't use default
Aug 16, 2023
6fd52f0
fix args
Aug 16, 2023
6af6146
fix session
Aug 16, 2023
70b6d6d
use Direct and Alias payout model
Aug 16, 2023
caa5296
PayoutDestinationOpt -> PayoutRoute, comments
Aug 16, 2023
2d43c90
fix typo
Aug 16, 2023
10511bf
add comments
Aug 16, 2023
d509515
comment
Aug 16, 2023
488b7b1
fix syntax error
Aug 16, 2023
6d048b2
add derives
Aug 16, 2023
fa8b675
another syntax fix
Aug 16, 2023
49bb802
rm use
Aug 16, 2023
16cf061
fixes
Aug 16, 2023
4883f61
".git/.scripts/commands/fmt/fmt.sh"
Aug 16, 2023
32cbf81
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Aug 16, 2023
be099e8
add comments
Aug 17, 2023
cbe94a4
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Aug 17, 2023
ffcdb2c
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Aug 17, 2023
711dfc8
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Aug 20, 2023
8296d85
Merge remote-tracking branch 'origin/master' into rb-payee-destination
Aug 23, 2023
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
28 changes: 21 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions frame/fast-unstake/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use frame_support::{
};
use sp_runtime::{
traits::{Convert, IdentityLookup},
BuildStorage,
BuildStorage, Perbill,
};

use pallet_staking::{Exposure, IndividualExposure, StakerStatus};
Expand Down Expand Up @@ -369,7 +369,7 @@ pub fn create_exposed_nominator(exposed: AccountId, era: u32) {
assert_ok!(Staking::bond(
RuntimeOrigin::signed(exposed),
10,
pallet_staking::RewardDestination::Staked
pallet_staking::PayoutDestination::Split((Perbill::from_percent(50), exposed))
));
assert_ok!(Staking::nominate(RuntimeOrigin::signed(exposed), vec![exposed]));
// register the exposed one.
Expand Down
10 changes: 7 additions & 3 deletions frame/fast-unstake/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
use super::*;
use crate::{mock::*, types::*, Event};
use frame_support::{pallet_prelude::*, testing_prelude::*, traits::Currency};
use pallet_staking::{CurrentEra, RewardDestination};
use pallet_staking::{CurrentEra, PayoutDestination};

use sp_runtime::traits::BadOrigin;
use sp_runtime::{traits::BadOrigin, Perbill};
use sp_staking::StakingInterface;

#[test]
Expand Down Expand Up @@ -815,7 +815,11 @@ mod on_idle {

// create a new validator that 100% not exposed.
Balances::make_free_balance_be(&42, 100 + Deposit::get());
assert_ok!(Staking::bond(RuntimeOrigin::signed(42), 10, RewardDestination::Staked));
assert_ok!(Staking::bond(
RuntimeOrigin::signed(42),
10,
PayoutDestination::Split((Perbill::from_percent(50), 42))
));
assert_ok!(Staking::validate(RuntimeOrigin::signed(42), Default::default()));

// let them register:
Expand Down
4 changes: 2 additions & 2 deletions frame/nomination-pools/test-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use pallet_nomination_pools::{
BondedPools, Error as PoolsError, Event as PoolsEvent, LastPoolId, PoolMember, PoolMembers,
PoolState,
};
use pallet_staking::{CurrentEra, Event as StakingEvent, Payee, RewardDestination};
use pallet_staking::{CurrentEra, Event as StakingEvent, Payees, PayoutDestination};
use sp_runtime::traits::Zero;

#[test]
Expand Down Expand Up @@ -214,7 +214,7 @@ fn pool_slash_e2e() {
]
);

assert_eq!(Payee::<Runtime>::get(POOL1_BONDED), RewardDestination::Account(POOL1_REWARD));
assert_eq!(Payees::<Runtime>::get(POOL1_BONDED), PayoutDestination::Deposit(POOL1_REWARD));

// have two members join
assert_ok!(Pools::join(RuntimeOrigin::signed(20), 20, 1));
Expand Down
8 changes: 4 additions & 4 deletions frame/offences/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use pallet_session::{
use pallet_staking::Event as StakingEvent;
use pallet_staking::{
Config as StakingConfig, Exposure, IndividualExposure, MaxNominationsOf, Pallet as Staking,
RewardDestination, ValidatorPrefs,
PayoutDestination, ValidatorPrefs,
};

const SEED: u32 = 0;
Expand Down Expand Up @@ -108,15 +108,15 @@ fn bond_amount<T: Config>() -> BalanceOf<T> {
fn create_offender<T: Config>(n: u32, nominators: u32) -> Result<Offender<T>, &'static str> {
let stash: T::AccountId = account("stash", n, SEED);
let stash_lookup: LookupSourceOf<T> = T::Lookup::unlookup(stash.clone());
let reward_destination = RewardDestination::Staked;
let payout_destination = PayoutDestination::Stake;
let amount = bond_amount::<T>();
// add twice as much balance to prevent the account from being killed.
let free_amount = amount.saturating_mul(2u32.into());
T::Currency::make_free_balance_be(&stash, free_amount);
Staking::<T>::bond(
RawOrigin::Signed(stash.clone()).into(),
amount,
reward_destination.clone(),
payout_destination.clone(),
)?;

let validator_prefs =
Expand All @@ -134,7 +134,7 @@ fn create_offender<T: Config>(n: u32, nominators: u32) -> Result<Offender<T>, &'
Staking::<T>::bond(
RawOrigin::Signed(nominator_stash.clone()).into(),
amount,
reward_destination.clone(),
payout_destination.clone(),
)?;

let selected_validators: Vec<LookupSourceOf<T>> = vec![stash_lookup.clone()];
Expand Down
9 changes: 5 additions & 4 deletions frame/session/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ use frame_support::{
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
use pallet_session::{historical::Pallet as Historical, Pallet as Session, *};
use pallet_staking::{
benchmarking::create_validator_with_nominators, testing_utils::create_validators,
MaxNominationsOf, RewardDestination,
benchmarking::create_validator_with_nominators,
testing_utils::{create_validators, PayoutDestinationOpt},
MaxNominationsOf,
};

const MAX_VALIDATORS: u32 = 1000;
Expand All @@ -60,7 +61,7 @@ benchmarks! {
MaxNominationsOf::<T>::get(),
false,
true,
RewardDestination::Staked,
PayoutDestinationOpt::Stake,
)?;
let v_controller = pallet_staking::Pallet::<T>::bonded(&v_stash).ok_or("not stash")?;

Expand All @@ -78,7 +79,7 @@ benchmarks! {
MaxNominationsOf::<T>::get(),
false,
true,
RewardDestination::Staked,
PayoutDestinationOpt::Stake,
)?;
let v_controller = pallet_staking::Pallet::<T>::bonded(&v_stash).ok_or("not stash")?;
let keys = T::Keys::decode(&mut TrailingZeroInput::zeroes()).unwrap();
Expand Down
20 changes: 20 additions & 0 deletions frame/staking/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Changelog

All notable changes to this pallet will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this pallet adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

The semantic versioning guarantees cover the interface to the substrate runtime which
includes this pallet as a dependency. This module will also add storage migrations whenever
changes require it. Stability with regard to offchain tooling is explicitly excluded from
this guarantee: For example adding a new field to an in-storage data structure will require
changes to frontends to properly display it. However, those changes will still be regarded
as a minor version bump.

## [Unreleased]

### Added

- Introduce `Payees`` and `PayoutDestination` with `Split` variant, which starts a lazy migration to move existing `Payee` items to a new `Payees` storage item.
rossbulat marked this conversation as resolved.
Show resolved Hide resolved
[#14451](https://github.com/paritytech/substrate/pull/14451)
48 changes: 33 additions & 15 deletions frame/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ pub fn create_validator_with_nominators<T: Config>(
upper_bound: u32,
dead_controller: bool,
unique_controller: bool,
destination: RewardDestination<T::AccountId>,
destination_opt: PayoutDestinationOpt<T::AccountId>,
) -> Result<(T::AccountId, Vec<(T::AccountId, T::AccountId)>), &'static str> {
// Clean up any existing state.
clear_validators_and_nominators::<T>();
let mut points_total = 0;
let mut points_individual = Vec::new();

let (v_stash, v_controller) = if unique_controller {
create_unique_stash_controller::<T>(0, 100, destination.clone(), false)?
create_unique_stash_controller::<T>(0, 100, destination_opt.clone(), false)?
} else {
create_stash_controller::<T>(0, 100, destination.clone())?
create_stash_controller::<T>(0, 100, destination_opt.clone())?
};

let validator_prefs =
Expand All @@ -100,9 +100,9 @@ pub fn create_validator_with_nominators<T: Config>(
// Give the validator n nominators, but keep total users in the system the same.
for i in 0..upper_bound {
let (n_stash, n_controller) = if !dead_controller {
create_stash_controller::<T>(u32::MAX - i, 100, destination.clone())?
create_stash_controller::<T>(u32::MAX - i, 100, destination_opt.clone())?
} else {
create_unique_stash_controller::<T>(u32::MAX - i, 100, destination.clone(), true)?
create_unique_stash_controller::<T>(u32::MAX - i, 100, destination_opt.clone(), true)?
};
if i < n {
Staking::<T>::nominate(
Expand Down Expand Up @@ -223,10 +223,10 @@ const USER_SEED: u32 = 999666;
benchmarks! {
bond {
let stash = create_funded_user::<T>("stash", USER_SEED, 100);
let reward_destination = RewardDestination::Staked;
let payout_destination = PayoutDestination::Split((Perbill::from_percent(50), stash.clone()));
let amount = T::Currency::minimum_balance() * 10u32.into();
whitelist_account!(stash);
}: _(RawOrigin::Signed(stash.clone()), amount, reward_destination)
}: _(RawOrigin::Signed(stash.clone()), amount, payout_destination)
verify {
assert!(Bonded::<T>::contains_key(stash.clone()));
assert!(Ledger::<T>::contains_key(stash));
Expand Down Expand Up @@ -466,11 +466,28 @@ benchmarks! {

set_payee {
let (stash, controller) = create_stash_controller::<T>(USER_SEED, 100, Default::default())?;
assert_eq!(Payee::<T>::get(&stash), RewardDestination::Staked);
assert_eq!(Payees::<T>::get(&stash), PayoutDestination::Stake);

// Payee should exist to be migrated on `update_payee`.
Payee::<T>::insert(&stash,RewardDestination::Staked);

whitelist_account!(controller);
}: _(RawOrigin::Signed(controller.clone()), PayoutDestination::Split((Perbill::from_percent(50), controller.clone())))
verify {
assert!(!Payee::<T>::contains_key(&stash));
assert_eq!(Payees::<T>::get(&stash), PayoutDestination::Split((Perbill::from_percent(50), controller.clone())));
}

update_payee {
let (stash, controller) = create_stash_controller::<T>(USER_SEED, 100, Default::default())?;
// Payee should exist to be migrated on `update_payee`.
Payee::<T>::insert(&stash,RewardDestination::Staked);
Payees::<T>::remove(&stash);
assert!(!Payees::<T>::contains_key(&stash));
whitelist_account!(controller);
}: _(RawOrigin::Signed(controller), RewardDestination::Controller)
}: _(RawOrigin::Signed(stash.clone()), controller)
verify {
assert_eq!(Payee::<T>::get(&stash), RewardDestination::Controller);
assert_eq!(Payees::<T>::get(&stash), PayoutDestination::Stake);
}

set_controller {
Expand Down Expand Up @@ -559,9 +576,10 @@ benchmarks! {
T::MaxNominatorRewardedPerValidator::get() as u32,
true,
true,
RewardDestination::Controller,
PayoutDestinationOpt::Split((Perbill::from_percent(50), PayoutSplitOpt::Controller)),
)?;

let validator_controller = <Bonded<T>>::get(&validator).unwrap();
let current_era = CurrentEra::<T>::get().unwrap();
// set the commission for this particular era as well.
<ErasValidatorPrefs<T>>::insert(current_era, validator.clone(), <Staking<T>>::validators(&validator));
Expand Down Expand Up @@ -593,7 +611,7 @@ benchmarks! {
T::MaxNominatorRewardedPerValidator::get() as u32,
false,
true,
RewardDestination::Staked,
PayoutDestinationOpt::Split((Perbill::from_percent(50), PayoutSplitOpt::Stash)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this matters but I would write my observation here.

We had limited the maximum nominators to be rewarded to 512 to limit i/o for payout_stakers call. With the split enabled, in worst case, there would be 1024 payments. Not sure how we came to the number 512 but would be good to get a second opinion about this from @kianenigma?

Also, payout_stakers_alive_staked is now benchmarked with worst case scenario of 2 payouts per nominator. This means the fees that will be charged would be a bit higher than before, even if the nominator payout type is not split. The ideal way to do this would be to benchmark this on n = number of payouts counting split payments as 2 instead of n = count of nominators. Although admittedly, may be I am being too pedantic and it might be totally okay to charge a bit higher fee (lower would be a bigger concern).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is relatively easy to get the number of payouts from PayoutDestination, something like:

fn num_payouts (&self) -> u32 {
		match self {
			PayoutDestination::Stake => 1,
			PayoutDestination::Deposit(_) => 1,
			PayoutDestination::Split(_) => 2,
			PayoutDestination::Forgo => 0,
		}
	}

But the benchmark function would need to know the total num_payouts value of all the ns to get a precise weight - and this info is not available in the call data. I would assume this is only possible if we are only making the payout for 1 PayoutDestination where we could easily derive num_payouts.

Paged payouts will also eventually lead to a much smaller estimated fee, that will minimise this worst case weight.

)?;

let current_era = CurrentEra::<T>::get().unwrap();
Expand Down Expand Up @@ -910,7 +928,7 @@ benchmarks! {

// Create a validator with a commission of 50%
let (stash, controller) =
create_stash_controller::<T>(1, 1, RewardDestination::Staked)?;
create_stash_controller::<T>(1, 1, Default::default())?;
let validator_prefs =
ValidatorPrefs { commission: Perbill::from_percent(50), ..Default::default() };
Staking::<T>::validate(RawOrigin::Signed(controller).into(), validator_prefs)?;
Expand Down Expand Up @@ -990,7 +1008,7 @@ mod tests {
<<Test as Config>::MaxNominatorRewardedPerValidator as Get<_>>::get(),
false,
false,
RewardDestination::Staked,
PayoutDestinationOpt::Stake,
)
.unwrap();

Expand Down Expand Up @@ -1020,7 +1038,7 @@ mod tests {
<<Test as Config>::MaxNominatorRewardedPerValidator as Get<_>>::get(),
false,
false,
RewardDestination::Staked,
PayoutDestinationOpt::Stake,
)
.unwrap();

Expand Down
45 changes: 44 additions & 1 deletion frame/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,34 @@ impl<AccountId: Ord> Default for EraRewardPoints<AccountId> {
}
}

/// The payout destination for an account.
///
/// NOTE: Being lazily migrated to. Logic pertaining to this enum will be introduced to `set_payee`
/// and payout logic in a future update, and will replace `RewardDestination`, once all records have
/// been lazily migrated to this enum.
#[derive(PartialEq, Eq, Copy, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub enum PayoutDestination<AccountId> {
/// Payout goes into the stash account and is added to bond.
Stake,
/// Deposit the specified percentage of payout to the specified account as free balance, and
/// pay the rest into the stash account and add to bond. 0% and 100% should be disallowed and
/// handled as `Stake` and `Deposit` respectively.
Split((Perbill, AccountId)),
/// Deposit payout as free balance to an account.
Deposit(AccountId),
/// Receive no payout.
Forgo,
}

impl<AccountId> Default for PayoutDestination<AccountId> {
fn default() -> Self {
PayoutDestination::Stake
}
}

/// A destination account for payment.
/// NOTE: Being lazily migrated and deprecated in favour of `PayoutDestination`.
/// Tracking at <https://github.com/paritytech/substrate/issues/14438>
#[derive(PartialEq, Eq, Copy, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub enum RewardDestination<AccountId> {
/// Pay into the stash account, increasing the amount at stake accordingly.
Expand All @@ -402,12 +429,28 @@ pub enum RewardDestination<AccountId> {
None,
}

impl<AccountId> Default for RewardDestination<AccountId> {
impl<AccountId: Clone> Default for RewardDestination<AccountId> {
fn default() -> Self {
RewardDestination::Staked
}
}

impl<AccountId: Clone> RewardDestination<AccountId> {
fn to_payout_destination(
KiChjang marked this conversation as resolved.
Show resolved Hide resolved
&self,
stash: AccountId,
controller: AccountId,
) -> PayoutDestination<AccountId> {
match self {
RewardDestination::Staked => PayoutDestination::Stake,
RewardDestination::Stash => PayoutDestination::Deposit(stash),
RewardDestination::Controller => PayoutDestination::Deposit(controller),
RewardDestination::Account(a) => PayoutDestination::Deposit(a.clone()),
RewardDestination::None => PayoutDestination::Forgo,
}
}
}

/// Preference of what happens regarding validation.
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, Default, MaxEncodedLen)]
pub struct ValidatorPrefs {
Expand Down
Loading