Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Remove support for stake redelegation (#7995) (#8024)
Browse files Browse the repository at this point in the history
automerge
  • Loading branch information
mergify[bot] authored Jan 30, 2020
1 parent f24d8e7 commit 43659d7
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 215 deletions.
5 changes: 3 additions & 2 deletions book/src/cluster/stake-delegation-and-rewards.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,13 @@ The Stakes and the RewardsPool are accounts that are owned by the same `Stake` p

### StakeInstruction::DelegateStake

The Stake account is moved from Ininitialized to StakeState::Stake form. This is how stakers choose their initial delegate validator node and activate their stake account lamports. The transaction must be signed by the stake's `authorized_staker`. If the stake account is already StakeState::Stake \(i.e. already activated\), the stake is re-delegated. Stakes may be re-delegated at any time, and updated stakes are reflected immediately, but only one re-delegation is permitted per epoch.
The Stake account is moved from Initialized to StakeState::Stake form, or from a deactivated (i.e. fully cooled-down) StakeState::Stake to activated StakeState::Stake. This is how stakers choose the vote account and validator node to which their stake account lamports are delegated. The transaction must be signed by the stake's `authorized_staker`.

* `account[0]` - RW - The StakeState::Stake instance. `StakeState::Stake::credits_observed` is initialized to `VoteState::credits`, `StakeState::Stake::voter_pubkey` is initialized to `account[1]`. If this is the initial delegation of stake, `StakeState::Stake::stake` is initialized to the account's balance in lamports, `StakeState::Stake::activated` is initialized to the current Bank epoch, and `StakeState::Stake::deactivated` is initialized to std::u64::MAX
* `account[1]` - R - The VoteState instance.
* `account[2]` - R - sysvar::clock account, carries information about current Bank epoch
* `account[3]` - R - stake::Config accoount, carries warmup, cooldown, and slashing configuration
* `account[3]` - R - sysvar::stakehistory account, carries information about stake history
* `account[4]` - R - stake::Config accoount, carries warmup, cooldown, and slashing configuration

### StakeInstruction::Authorize\(Pubkey, StakeAuthorize\)

Expand Down
13 changes: 11 additions & 2 deletions programs/stake/src/stake_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ pub fn delegate_stake(
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new_readonly(*vote_pubkey, false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
AccountMeta::new_readonly(crate::config::id(), false),
]
.with_signer(authorized_pubkey);
Expand Down Expand Up @@ -396,9 +397,10 @@ pub fn process_instruction(
StakeInstruction::DelegateStake => {
let vote = next_keyed_account(keyed_accounts)?;

me.delegate_stake(
me.delegate(
&vote,
&Clock::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
&StakeHistory::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
&config::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
&signers,
)
Expand All @@ -418,7 +420,7 @@ pub fn process_instruction(
&signers,
)
}
StakeInstruction::Deactivate => me.deactivate_stake(
StakeInstruction::Deactivate => me.deactivate(
&Clock::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
&signers,
),
Expand Down Expand Up @@ -658,6 +660,13 @@ mod tests {
false,
&RefCell::new(sysvar::clock::Clock::default().create_account(1))
),
KeyedAccount::new(
&sysvar::stake_history::id(),
false,
&RefCell::new(
sysvar::stake_history::StakeHistory::default().create_account(1)
)
),
KeyedAccount::new(
&config::id(),
false,
Expand Down
Loading

0 comments on commit 43659d7

Please sign in to comment.