Skip to content

Commit

Permalink
stake: Remove redelegate instruction (#2213)
Browse files Browse the repository at this point in the history
* stake: Remove redelegate code and tests

* Mark stake flags as deprecated

* Remove usage of feature gate

* Add a changelog entry for the removal

* Remove repeated #[allow(deprecated)]s

* Re-add "redelegate-stake" command

* Remove feature

* Make CI happy -> `hidden_unless_forced()`
  • Loading branch information
joncinque authored Jul 29, 2024
1 parent 93a4e45 commit 576fa44
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 1,456 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Release channels have their own copy of this changelog:
* SDK:
* `cargo-build-sbf` and `cargo-build-bpf` have been deprecated for two years and have now been definitely removed.
Use `cargo-build-sbf` and `cargo-test-sbf` instead.
* Stake:
* removed the unreleased `redelegate` instruction processor and CLI commands (#2213)
* Changes
* SDK: removed the `respan` macro. This was marked as "internal use only" and was no longer used internally.

Expand Down
9 changes: 4 additions & 5 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ pub enum CliCommand {
nonce_authority: SignerIndex,
memo: Option<String>,
fee_payer: SignerIndex,
redelegation_stake_account: Option<SignerIndex>,
compute_unit_price: Option<u64>,
},
SplitStake {
Expand Down Expand Up @@ -718,8 +717,10 @@ pub fn parse_command(
("delegate-stake", Some(matches)) => {
parse_stake_delegate_stake(matches, default_signer, wallet_manager)
}
("redelegate-stake", Some(matches)) => {
parse_stake_delegate_stake(matches, default_signer, wallet_manager)
("redelegate-stake", _) => {
Err(CliError::CommandNotRecognized(
"`redelegate-stake` no longer exists and will be completely removed in a future release".to_string(),
))
}
("withdraw-stake", Some(matches)) => {
parse_stake_withdraw_stake(matches, default_signer, wallet_manager)
Expand Down Expand Up @@ -1242,7 +1243,6 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
nonce_authority,
memo,
fee_payer,
redelegation_stake_account,
compute_unit_price,
} => process_delegate_stake(
&rpc_client,
Expand All @@ -1258,7 +1258,6 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
*nonce_authority,
memo.as_ref(),
*fee_payer,
*redelegation_stake_account,
*compute_unit_price,
),
CliCommand::SplitStake {
Expand Down
145 changes: 12 additions & 133 deletions cli/src/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use {
nonce::check_nonce_account,
spend_utils::{resolve_spend_tx_and_check_account_balances, SpendAmount},
},
clap::{value_t, App, Arg, ArgGroup, ArgMatches, SubCommand},
clap::{value_t, App, AppSettings, Arg, ArgGroup, ArgMatches, SubCommand},
solana_clap_utils::{
compute_budget::{compute_unit_price_arg, ComputeUnitLimit, COMPUTE_UNIT_PRICE_ARG},
fee_payer::{fee_payer_arg, FEE_PAYER_ARG},
Expand Down Expand Up @@ -328,49 +328,13 @@ impl StakeSubCommands for App<'_, '_> {
)
.subcommand(
SubCommand::with_name("redelegate-stake")
.about("Redelegate active stake to another vote account")
.setting(AppSettings::Hidden)
.arg(
Arg::with_name("force")
.long("force")
.takes_value(false)
.hidden(hidden_unless_forced()) // Don't document this argument to discourage its use
.help("Override vote account sanity checks (use carefully!)"),
)
.arg(pubkey!(
Arg::with_name("stake_account_pubkey")
.index(1)
.value_name("STAKE_ACCOUNT_ADDRESS")
.required(true),
"Existing delegated stake account that has been fully activated. On success \
this stake account will be scheduled for deactivation and the rent-exempt \
balance may be withdrawn once fully deactivated."
))
.arg(pubkey!(
Arg::with_name("vote_account_pubkey")
.index(2)
.value_name("REDELEGATED_VOTE_ACCOUNT_ADDRESS")
.required(true),
"Vote account to which the stake will be redelegated."
))
.arg(
Arg::with_name("redelegation_stake_account")
.index(3)
.value_name("REDELEGATION_STAKE_ACCOUNT")
.takes_value(true)
.required(true)
.validator(is_valid_signer)
.help(
"Stake account to create for the redelegation. On success this stake \
account will be created and scheduled for activation with all the \
stake in the existing stake account, exclusive of the rent-exempt \
balance retained in the existing account",
),
)
.arg(stake_authority_arg())
.offline_args()
.nonce_args(false)
.arg(fee_payer_arg())
.arg(memo_arg()),
// Consume all positional arguments
Arg::with_name("arg")
.multiple(true)
.hidden(hidden_unless_forced()),
),
)
.subcommand(
SubCommand::with_name("stake-authorize")
Expand Down Expand Up @@ -911,8 +875,6 @@ pub fn parse_stake_delegate_stake(
pubkey_of_signer(matches, "stake_account_pubkey", wallet_manager)?.unwrap();
let vote_account_pubkey =
pubkey_of_signer(matches, "vote_account_pubkey", wallet_manager)?.unwrap();
let (redelegation_stake_account, redelegation_stake_account_pubkey) =
signer_of(matches, "redelegation_stake_account", wallet_manager)?;
let force = matches.is_present("force");
let sign_only = matches.is_present(SIGN_ONLY_ARG.name);
let dump_transaction_message = matches.is_present(DUMP_TRANSACTION_MESSAGE.name);
Expand All @@ -929,9 +891,6 @@ pub fn parse_stake_delegate_stake(
if nonce_account.is_some() {
bulk_signers.push(nonce_authority);
}
if redelegation_stake_account.is_some() {
bulk_signers.push(redelegation_stake_account);
}
let signer_info =
default_signer.generate_unique_signers(bulk_signers, matches, wallet_manager)?;
let compute_unit_price = value_of(matches, COMPUTE_UNIT_PRICE_ARG.name);
Expand All @@ -949,8 +908,6 @@ pub fn parse_stake_delegate_stake(
nonce_authority: signer_info.index_of(nonce_authority_pubkey).unwrap(),
memo,
fee_payer: signer_info.index_of(fee_payer_pubkey).unwrap(),
redelegation_stake_account: redelegation_stake_account_pubkey
.and_then(|_| signer_info.index_of(redelegation_stake_account_pubkey)),
compute_unit_price,
},
signers: signer_info.signers,
Expand Down Expand Up @@ -2681,30 +2638,12 @@ pub fn process_delegate_stake(
nonce_authority: SignerIndex,
memo: Option<&String>,
fee_payer: SignerIndex,
redelegation_stake_account: Option<SignerIndex>,
compute_unit_price: Option<u64>,
) -> ProcessResult {
check_unique_pubkeys(
(&config.signers[0].pubkey(), "cli keypair".to_string()),
(stake_account_pubkey, "stake_account_pubkey".to_string()),
)?;
let redelegation_stake_account = redelegation_stake_account.map(|index| config.signers[index]);
if let Some(redelegation_stake_account) = &redelegation_stake_account {
check_unique_pubkeys(
(stake_account_pubkey, "stake_account_pubkey".to_string()),
(
&redelegation_stake_account.pubkey(),
"redelegation_stake_account".to_string(),
),
)?;
check_unique_pubkeys(
(&config.signers[0].pubkey(), "cli keypair".to_string()),
(
&redelegation_stake_account.pubkey(),
"redelegation_stake_account".to_string(),
),
)?;
}
let stake_authority = config.signers[stake_authority];

if !sign_only {
Expand Down Expand Up @@ -2758,20 +2697,11 @@ pub fn process_delegate_stake(

let recent_blockhash = blockhash_query.get_blockhash(rpc_client, config.commitment)?;

let ixs = if let Some(redelegation_stake_account) = &redelegation_stake_account {
stake_instruction::redelegate(
stake_account_pubkey,
&stake_authority.pubkey(),
vote_account_pubkey,
&redelegation_stake_account.pubkey(),
)
} else {
vec![stake_instruction::delegate_stake(
stake_account_pubkey,
&stake_authority.pubkey(),
vote_account_pubkey,
)]
}
let ixs = vec![stake_instruction::delegate_stake(
stake_account_pubkey,
&stake_authority.pubkey(),
vote_account_pubkey,
)]
.with_memo(memo)
.with_compute_unit_config(&ComputeUnitConfig {
compute_unit_price,
Expand Down Expand Up @@ -4173,7 +4103,6 @@ mod tests {
nonce_authority: 0,
memo: None,
fee_payer: 0,
redelegation_stake_account: None,
compute_unit_price: None,
},
signers: vec![Box::new(read_keypair_file(&default_keypair_file).unwrap())],
Expand Down Expand Up @@ -4206,7 +4135,6 @@ mod tests {
nonce_authority: 0,
memo: None,
fee_payer: 0,
redelegation_stake_account: None,
compute_unit_price: None,
},
signers: vec![
Expand Down Expand Up @@ -4239,7 +4167,6 @@ mod tests {
nonce_authority: 0,
memo: None,
fee_payer: 0,
redelegation_stake_account: None,
compute_unit_price: None,
},
signers: vec![Box::new(read_keypair_file(&default_keypair_file).unwrap())],
Expand Down Expand Up @@ -4275,7 +4202,6 @@ mod tests {
nonce_authority: 0,
memo: None,
fee_payer: 0,
redelegation_stake_account: None,
compute_unit_price: None,
},
signers: vec![Box::new(read_keypair_file(&default_keypair_file).unwrap())],
Expand Down Expand Up @@ -4306,7 +4232,6 @@ mod tests {
nonce_authority: 0,
memo: None,
fee_payer: 0,
redelegation_stake_account: None,
compute_unit_price: None,
},
signers: vec![Box::new(read_keypair_file(&default_keypair_file).unwrap())],
Expand Down Expand Up @@ -4347,7 +4272,6 @@ mod tests {
nonce_authority: 0,
memo: None,
fee_payer: 1,
redelegation_stake_account: None,
compute_unit_price: None,
},
signers: vec![
Expand Down Expand Up @@ -4397,7 +4321,6 @@ mod tests {
nonce_authority: 2,
memo: None,
fee_payer: 1,
redelegation_stake_account: None,
compute_unit_price: None,
},
signers: vec![
Expand Down Expand Up @@ -4435,7 +4358,6 @@ mod tests {
nonce_authority: 0,
memo: None,
fee_payer: 1,
redelegation_stake_account: None,
compute_unit_price: None,
},
signers: vec![
Expand All @@ -4445,49 +4367,6 @@ mod tests {
}
);

// Test RedelegateStake Subcommand (minimal test due to the significant implementation
// overlap with DelegateStake)
let (redelegation_stake_account_keypair_file, mut redelegation_stake_account_tmp_file) =
make_tmp_file();
let redelegation_stake_account_keypair = Keypair::new();
write_keypair(
&redelegation_stake_account_keypair,
redelegation_stake_account_tmp_file.as_file_mut(),
)
.unwrap();

let test_redelegate_stake = test_commands.clone().get_matches_from(vec![
"test",
"redelegate-stake",
&stake_account_string,
&vote_account_string,
&redelegation_stake_account_keypair_file,
]);
assert_eq!(
parse_command(&test_redelegate_stake, &default_signer, &mut None).unwrap(),
CliCommandInfo {
command: CliCommand::DelegateStake {
stake_account_pubkey,
vote_account_pubkey,
stake_authority: 0,
force: false,
sign_only: false,
dump_transaction_message: false,
blockhash_query: BlockhashQuery::default(),
nonce_account: None,
nonce_authority: 0,
memo: None,
fee_payer: 0,
redelegation_stake_account: Some(1),
compute_unit_price: None,
},
signers: vec![
Box::new(read_keypair_file(&default_keypair_file).unwrap()),
Box::new(read_keypair_file(&redelegation_stake_account_keypair_file).unwrap())
],
}
);

// Test WithdrawStake Subcommand
let test_withdraw_stake = test_commands.clone().get_matches_from(vec![
"test",
Expand Down
Loading

0 comments on commit 576fa44

Please sign in to comment.