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

Commit b51213d

Browse files
committed
single-pool: rename ReactivatePool to ReactivatePoolStake
1 parent 195ceba commit b51213d

File tree

7 files changed

+49
-38
lines changed

7 files changed

+49
-38
lines changed

single-pool/cli/src/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub enum ManageCommand {
110110
/// Permissionlessly re-stake the pool stake account in the case when it has been deactivated.
111111
/// This may happen if the validator is force-deactivated, and then later reactivated using
112112
/// the same address for its vote account.
113-
Reactivate(ReactivateCli),
113+
ReactivatePoolStake(ReactivateCli),
114114

115115
/// Permissionlessly create default MPL token metadata for the pool mint. Normally this is done
116116
/// automatically upon initialization, so this does not need to be called.
@@ -145,7 +145,7 @@ pub struct ReactivateCli {
145145

146146
// backdoor for testing, theres no reason to ever use this
147147
#[clap(long, hide = true)]
148-
pub yolo: bool,
148+
pub skip_deactivation_check: bool,
149149
}
150150

151151
#[derive(Clone, Debug, Args)]

single-pool/cli/src/main.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ impl Command {
6464
ManageCommand::Initialize(command_config) => {
6565
command_initialize(config, command_config).await
6666
}
67-
ManageCommand::Reactivate(command_config) => {
68-
command_reactivate(config, command_config).await
67+
ManageCommand::ReactivatePoolStake(command_config) => {
68+
command_reactivate_pool_stake(config, command_config).await
6969
}
7070
ManageCommand::CreateTokenMetadata(command_config) => {
7171
command_create_metadata(config, command_config).await
@@ -164,8 +164,11 @@ async fn command_initialize(config: &Config, command_config: InitializeCli) -> C
164164
))
165165
}
166166

167-
// reactivate stake account
168-
async fn command_reactivate(config: &Config, command_config: ReactivateCli) -> CommandResult {
167+
// reactivate pool stake account
168+
async fn command_reactivate_pool_stake(
169+
config: &Config,
170+
command_config: ReactivateCli,
171+
) -> CommandResult {
169172
let payer = config.fee_payer()?;
170173
let pool_address = pool_address_from_args(
171174
command_config.pool_address,
@@ -185,7 +188,7 @@ async fn command_reactivate(config: &Config, command_config: ReactivateCli) -> C
185188
};
186189

187190
// the only reason this check is skippable is for testing, otherwise theres no reason
188-
if !command_config.yolo {
191+
if !command_config.skip_deactivation_check {
189192
let current_epoch = config.rpc_client.get_epoch_info().await?.epoch;
190193
let pool_stake_address = find_pool_stake_address(&single_pool::id(), &pool_address);
191194
let pool_stake_deactivated = quarantine::get_stake_info(config, &pool_stake_address)
@@ -194,15 +197,15 @@ async fn command_reactivate(config: &Config, command_config: ReactivateCli) -> C
194197
.1
195198
.delegation
196199
.deactivation_epoch
197-
< current_epoch;
200+
<= current_epoch;
198201

199202
if !pool_stake_deactivated {
200-
return Err("Pool stake account is not deactivated".into());
203+
return Err("Pool stake account is neither deactivating nor deactivated".into());
201204
}
202205
}
203206

204207
let instruction =
205-
single_pool::instruction::reactivate_pool(&single_pool::id(), &vote_account_address);
208+
single_pool::instruction::reactivate_pool_stake(&single_pool::id(), &vote_account_address);
206209
let transaction = Transaction::new_signed_with_payer(
207210
&[instruction],
208211
Some(&payer.pubkey()),
@@ -214,7 +217,7 @@ async fn command_reactivate(config: &Config, command_config: ReactivateCli) -> C
214217

215218
Ok(format_output(
216219
config,
217-
"Reactivate".to_string(),
220+
"ReactivatePoolStake".to_string(),
218221
SignatureOutput { signature },
219222
))
220223
}

single-pool/cli/tests/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,20 +253,20 @@ async fn create_and_delegate_stake_account(
253253

254254
#[tokio::test]
255255
#[serial]
256-
async fn reactivate() {
256+
async fn reactivate_pool_stake() {
257257
let env = setup(true).await;
258258

259259
// setting up a test validator for this to succeed is hell, and success is tested in program tests
260260
// so we just make sure the cli can send a well-formed instruction
261261
let output = Command::new(SVSP_CLI)
262262
.args([
263263
"manage",
264-
"reactivate",
264+
"reactivate-pool-stake",
265265
"-C",
266266
&env.config_file_path,
267267
"--vote-account",
268268
&env.vote_account.to_string(),
269-
"--yolo",
269+
"--skip-deactivation-check",
270270
])
271271
.output()
272272
.unwrap();

single-pool/program/src/instruction.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ pub enum SinglePoolInstruction {
4343
/// 12. `[]` Stake program
4444
InitializePool,
4545

46-
/// Restake the pool stake account if its validator is force-deactivated and later
47-
/// recreated with the same vote account.
46+
/// Restake the pool stake account if it was deactivated. This can happen through the
47+
/// stake program's `DeactivateDelinquent` instruction, or during a cluster restart.
4848
///
4949
/// 0. `[]` Validator vote account
5050
/// 1. `[]` Pool account
@@ -54,7 +54,7 @@ pub enum SinglePoolInstruction {
5454
/// 5. `[]` Stake history sysvar
5555
/// 6. `[]` Stake config sysvar
5656
/// 7. `[]` Stake program
57-
ReactivatePool,
57+
ReactivatePoolStake,
5858

5959
/// Deposit stake into the pool. The output is a "pool" token representing fractional
6060
/// ownership of the pool stake. Inputs are converted to the current ratio.
@@ -190,11 +190,13 @@ pub fn initialize_pool(program_id: &Pubkey, vote_account_address: &Pubkey) -> In
190190
}
191191
}
192192

193-
/// Creates a `ReactivatePool` instruction.
194-
pub fn reactivate_pool(program_id: &Pubkey, vote_account_address: &Pubkey) -> Instruction {
193+
/// Creates a `ReactivatePoolStake` instruction.
194+
pub fn reactivate_pool_stake(program_id: &Pubkey, vote_account_address: &Pubkey) -> Instruction {
195195
let pool_address = find_pool_address(program_id, vote_account_address);
196196

197-
let data = SinglePoolInstruction::ReactivatePool.try_to_vec().unwrap();
197+
let data = SinglePoolInstruction::ReactivatePoolStake
198+
.try_to_vec()
199+
.unwrap();
198200
let accounts = vec![
199201
AccountMeta::new_readonly(*vote_account_address, false),
200202
AccountMeta::new_readonly(pool_address, false),

single-pool/program/src/processor.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,10 @@ impl Processor {
707707
Ok(())
708708
}
709709

710-
fn process_reactivate_pool(program_id: &Pubkey, accounts: &[AccountInfo]) -> ProgramResult {
710+
fn process_reactivate_pool_stake(
711+
program_id: &Pubkey,
712+
accounts: &[AccountInfo],
713+
) -> ProgramResult {
711714
let account_info_iter = &mut accounts.iter();
712715
let vote_account_info = next_account_info(account_info_iter)?;
713716
let pool_info = next_account_info(account_info_iter)?;
@@ -733,7 +736,7 @@ impl Processor {
733736
check_stake_program(stake_program_info.key)?;
734737

735738
let (_, pool_stake_state) = get_stake_state(pool_stake_info)?;
736-
if pool_stake_state.delegation.deactivation_epoch >= clock.epoch {
739+
if pool_stake_state.delegation.deactivation_epoch > clock.epoch {
737740
return Err(SinglePoolError::WrongStakeState.into());
738741
}
739742

@@ -1178,9 +1181,9 @@ impl Processor {
11781181
msg!("Instruction: InitializePool");
11791182
Self::process_initialize_pool(program_id, accounts)
11801183
}
1181-
SinglePoolInstruction::ReactivatePool => {
1182-
msg!("Instruction: ReactivatePool");
1183-
Self::process_reactivate_pool(program_id, accounts)
1184+
SinglePoolInstruction::ReactivatePoolStake => {
1185+
msg!("Instruction: ReactivatePoolStake");
1186+
Self::process_reactivate_pool_stake(program_id, accounts)
11841187
}
11851188
SinglePoolInstruction::DepositStake => {
11861189
msg!("Instruction: DepositStake");

single-pool/program/tests/accounts.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ fn make_basic_instruction(
205205
SinglePoolInstruction::InitializePool => {
206206
instruction::initialize_pool(&id(), &accounts.vote_account.pubkey())
207207
}
208-
SinglePoolInstruction::ReactivatePool => {
209-
instruction::reactivate_pool(&id(), &accounts.vote_account.pubkey())
208+
SinglePoolInstruction::ReactivatePoolStake => {
209+
instruction::reactivate_pool_stake(&id(), &accounts.vote_account.pubkey())
210210
}
211211
SinglePoolInstruction::DepositStake => instruction::deposit_stake(
212212
&id(),
@@ -262,7 +262,7 @@ fn consistent_account_order() {
262262

263263
let instructions = vec![
264264
make_basic_instruction(&accounts, SinglePoolInstruction::InitializePool),
265-
make_basic_instruction(&accounts, SinglePoolInstruction::ReactivatePool),
265+
make_basic_instruction(&accounts, SinglePoolInstruction::ReactivatePoolStake),
266266
make_basic_instruction(&accounts, SinglePoolInstruction::DepositStake),
267267
make_basic_instruction(
268268
&accounts,

single-pool/program/tests/reactivate.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
mod helpers;
55

66
use {
7-
bincode::serialize,
87
helpers::*,
98
solana_program_test::*,
109
solana_sdk::{
@@ -34,13 +33,17 @@ async fn success() {
3433
deactivation_epoch: 0,
3534
..stake.unwrap().delegation
3635
};
37-
let account_data = serialize(&StakeState::Stake(
38-
meta,
39-
Stake {
40-
delegation,
41-
..stake.unwrap()
42-
},
43-
))
36+
let mut account_data = vec![0; std::mem::size_of::<StakeState>()];
37+
bincode::serialize_into(
38+
&mut account_data[..],
39+
&StakeState::Stake(
40+
meta,
41+
Stake {
42+
delegation,
43+
..stake.unwrap()
44+
},
45+
),
46+
)
4447
.unwrap();
4548

4649
let mut stake_account = get_account(&mut context.banks_client, &accounts.stake_account).await;
@@ -74,7 +77,7 @@ async fn success() {
7477
check_error(e, SinglePoolError::WrongStakeState);
7578

7679
// reactivate
77-
let instruction = instruction::reactivate_pool(&id(), &accounts.vote_account.pubkey());
80+
let instruction = instruction::reactivate_pool_stake(&id(), &accounts.vote_account.pubkey());
7881
let transaction = Transaction::new_signed_with_payer(
7982
&[instruction],
8083
Some(&context.payer.pubkey()),
@@ -132,7 +135,7 @@ async fn fail_not_deactivated(activate: bool) {
132135
advance_epoch(&mut context).await;
133136
}
134137

135-
let instruction = instruction::reactivate_pool(&id(), &accounts.vote_account.pubkey());
138+
let instruction = instruction::reactivate_pool_stake(&id(), &accounts.vote_account.pubkey());
136139
let transaction = Transaction::new_signed_with_payer(
137140
&[instruction],
138141
Some(&context.payer.pubkey()),

0 commit comments

Comments
 (0)