Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ pub enum CliCommand {
nonce_account: Option<Pubkey>,
nonce_authority: SignerIndex,
memo: Option<String>,
seed: Option<String>,
fee_payer: SignerIndex,
},
DelegateStake {
Expand Down Expand Up @@ -300,6 +301,7 @@ pub enum CliCommand {
nonce_account: Option<Pubkey>,
nonce_authority: SignerIndex,
memo: Option<String>,
seed: Option<String>,
fee_payer: SignerIndex,
},
// Validator Info Commands
Expand Down Expand Up @@ -1556,6 +1558,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
nonce_account,
nonce_authority,
memo,
seed,
fee_payer,
} => process_deactivate_stake_account(
&rpc_client,
Expand All @@ -1568,6 +1571,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
*nonce_account,
*nonce_authority,
memo.as_ref(),
seed.as_ref(),
*fee_payer,
),
CliCommand::DelegateStake {
Expand Down Expand Up @@ -1728,6 +1732,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
ref nonce_account,
nonce_authority,
memo,
seed,
fee_payer,
} => process_withdraw_stake(
&rpc_client,
Expand All @@ -1743,6 +1748,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
nonce_account.as_ref(),
*nonce_authority,
memo.as_ref(),
seed.as_ref(),
*fee_payer,
),

Expand Down Expand Up @@ -2709,6 +2715,7 @@ mod tests {
nonce_account: None,
nonce_authority: 0,
memo: None,
seed: None,
fee_payer: 0,
};
config.signers = vec![&keypair];
Expand All @@ -2725,6 +2732,7 @@ mod tests {
nonce_account: None,
nonce_authority: 0,
memo: None,
seed: None,
fee_payer: 0,
};
let result = process_command(&config);
Expand Down
67 changes: 58 additions & 9 deletions cli/src/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
nonce::check_nonce_account,
spend_utils::{resolve_spend_tx_and_check_account_balances, SpendAmount},
};
use clap::{App, Arg, ArgGroup, ArgMatches, SubCommand};
use clap::{value_t, App, Arg, ArgGroup, ArgMatches, SubCommand};
use solana_clap_utils::{
fee_payer::{fee_payer_arg, FEE_PAYER_ARG},
input_parsers::*,
Expand Down Expand Up @@ -107,7 +107,7 @@ impl StakeSubCommands for App<'_, '_> {
.arg(
Arg::with_name("stake_account")
.index(1)
.value_name("ACCOUNT_KEYPAIR")
.value_name("STAKE_ACCOUNT_KEYPAIR")
.takes_value(true)
.required(true)
.validator(is_valid_signer)
Expand All @@ -133,7 +133,8 @@ impl StakeSubCommands for App<'_, '_> {
.long("seed")
.value_name("STRING")
.takes_value(true)
.help("Seed for address generation; if specified, the resulting account will be at a derived address of the stake_account pubkey")
.help("Seed for address generation; if specified, the resulting account \
will be at a derived address of the STAKE_ACCOUNT_KEYPAIR pubkey")
)
.arg(
Arg::with_name("lockup_epoch")
Expand Down Expand Up @@ -246,7 +247,15 @@ impl StakeSubCommands for App<'_, '_> {
.index(1)
.value_name("STAKE_ACCOUNT_ADDRESS")
.required(true),
"Stake account to be deactivated. ")
"Stake account to be deactivated (or base of derived address if --seed is used). ")
)
.arg(
Arg::with_name("seed")
.long("seed")
.value_name("STRING")
.takes_value(true)
.help("Seed for address generation; if specified, the resulting account \
will be at a derived address of STAKE_ACCOUNT_ADDRESS")
)
.arg(stake_authority_arg())
.offline_args()
Expand Down Expand Up @@ -286,7 +295,8 @@ impl StakeSubCommands for App<'_, '_> {
.long("seed")
.value_name("STRING")
.takes_value(true)
.help("Seed for address generation; if specified, the resulting account will be at a derived address of the SPLIT_STAKE_ACCOUNT pubkey")
.help("Seed for address generation; if specified, the resulting account \
will be at a derived address of SPLIT_STAKE_ACCOUNT")
)
.arg(stake_authority_arg())
.offline_args()
Expand All @@ -308,7 +318,8 @@ impl StakeSubCommands for App<'_, '_> {
.index(2)
.value_name("SOURCE_STAKE_ACCOUNT_ADDRESS")
.required(true),
"Source stake account for the merge. If successful, this stake account will no longer exist after the merge")
"Source stake account for the merge. If successful, this stake account \
will no longer exist after the merge")
)
.arg(stake_authority_arg())
.offline_args()
Expand All @@ -323,7 +334,7 @@ impl StakeSubCommands for App<'_, '_> {
.index(1)
.value_name("STAKE_ACCOUNT_ADDRESS")
.required(true),
"Stake account from which to withdraw")
"Stake account from which to withdraw (or base of derived address if --seed is used). ")
)
.arg(
pubkey!(Arg::with_name("destination_account_pubkey")
Expand All @@ -341,6 +352,14 @@ impl StakeSubCommands for App<'_, '_> {
.required(true)
.help("The amount to withdraw from the stake account, in SOL")
)
.arg(
Arg::with_name("seed")
.long("seed")
.value_name("STRING")
.takes_value(true)
.help("Seed for address generation; if specified, the resulting account \
will be at a derived address of STAKE_ACCOUNT_ADDRESS")
)
.arg(withdraw_authority_arg())
.offline_args()
.nonce_args(false)
Expand Down Expand Up @@ -755,6 +774,7 @@ pub fn parse_stake_deactivate_stake(
let blockhash_query = BlockhashQuery::new_from_matches(matches);
let nonce_account = pubkey_of(matches, NONCE_ARG.name);
let memo = matches.value_of(MEMO_ARG.name).map(String::from);
let seed = value_t!(matches, "seed", String).ok();
let (stake_authority, stake_authority_pubkey) =
signer_of(matches, STAKE_AUTHORITY_ARG.name, wallet_manager)?;
let (nonce_authority, nonce_authority_pubkey) =
Expand All @@ -778,6 +798,7 @@ pub fn parse_stake_deactivate_stake(
nonce_account,
nonce_authority: signer_info.index_of(nonce_authority_pubkey).unwrap(),
memo,
seed,
fee_payer: signer_info.index_of(fee_payer_pubkey).unwrap(),
},
signers: signer_info.signers,
Expand All @@ -799,6 +820,7 @@ pub fn parse_stake_withdraw_stake(
let blockhash_query = BlockhashQuery::new_from_matches(matches);
let nonce_account = pubkey_of(matches, NONCE_ARG.name);
let memo = matches.value_of(MEMO_ARG.name).map(String::from);
let seed = value_t!(matches, "seed", String).ok();
let (withdraw_authority, withdraw_authority_pubkey) =
signer_of(matches, WITHDRAW_AUTHORITY_ARG.name, wallet_manager)?;
let (nonce_authority, nonce_authority_pubkey) =
Expand Down Expand Up @@ -828,6 +850,7 @@ pub fn parse_stake_withdraw_stake(
nonce_account,
nonce_authority: signer_info.index_of(nonce_authority_pubkey).unwrap(),
memo,
seed,
fee_payer: signer_info.index_of(fee_payer_pubkey).unwrap(),
custodian: custodian_pubkey.and_then(|_| signer_info.index_of(custodian_pubkey)),
},
Expand Down Expand Up @@ -1151,13 +1174,21 @@ pub fn process_deactivate_stake_account(
nonce_account: Option<Pubkey>,
nonce_authority: SignerIndex,
memo: Option<&String>,
seed: Option<&String>,
fee_payer: SignerIndex,
) -> ProcessResult {
let (recent_blockhash, fee_calculator) =
blockhash_query.get_blockhash_and_fee_calculator(rpc_client, config.commitment)?;
let stake_authority = config.signers[stake_authority];

let stake_account_address = if let Some(seed) = seed {
Pubkey::create_with_seed(&stake_account_pubkey, seed, &solana_stake_program::id())?
} else {
*stake_account_pubkey
};

let ixs = vec![stake_instruction::deactivate_stake(
stake_account_pubkey,
&stake_account_address,
&stake_authority.pubkey(),
)]
.with_memo(memo);
Expand Down Expand Up @@ -1222,15 +1253,22 @@ pub fn process_withdraw_stake(
nonce_account: Option<&Pubkey>,
nonce_authority: SignerIndex,
memo: Option<&String>,
seed: Option<&String>,
fee_payer: SignerIndex,
) -> ProcessResult {
let (recent_blockhash, fee_calculator) =
blockhash_query.get_blockhash_and_fee_calculator(rpc_client, config.commitment)?;
let withdraw_authority = config.signers[withdraw_authority];
let custodian = custodian.map(|index| config.signers[index]);

let stake_account_address = if let Some(seed) = seed {
Pubkey::create_with_seed(&stake_account_pubkey, seed, &solana_stake_program::id())?
} else {
*stake_account_pubkey
};

let ixs = vec![stake_instruction::withdraw(
stake_account_pubkey,
&stake_account_address,
&withdraw_authority.pubkey(),
destination_account_pubkey,
lamports,
Expand Down Expand Up @@ -3067,6 +3105,7 @@ mod tests {
nonce_account: None,
nonce_authority: 0,
memo: None,
seed: None,
fee_payer: 0,
},
signers: vec![read_keypair_file(&default_keypair_file).unwrap().into()],
Expand Down Expand Up @@ -3099,6 +3138,7 @@ mod tests {
nonce_account: None,
nonce_authority: 0,
memo: None,
seed: None,
fee_payer: 0,
},
signers: vec![
Expand Down Expand Up @@ -3136,6 +3176,7 @@ mod tests {
nonce_account: None,
nonce_authority: 0,
memo: None,
seed: None,
fee_payer: 0,
},
signers: vec![
Expand Down Expand Up @@ -3184,6 +3225,7 @@ mod tests {
nonce_account: Some(nonce_account),
nonce_authority: 1,
memo: None,
seed: None,
fee_payer: 1,
},
signers: vec![
Expand Down Expand Up @@ -3213,6 +3255,7 @@ mod tests {
nonce_account: None,
nonce_authority: 0,
memo: None,
seed: None,
fee_payer: 0,
},
signers: vec![read_keypair_file(&default_keypair_file).unwrap().into()],
Expand All @@ -3239,6 +3282,7 @@ mod tests {
nonce_account: None,
nonce_authority: 0,
memo: None,
seed: None,
fee_payer: 0,
},
signers: vec![
Expand Down Expand Up @@ -3275,6 +3319,7 @@ mod tests {
nonce_account: None,
nonce_authority: 0,
memo: None,
seed: None,
fee_payer: 0,
},
signers: vec![read_keypair_file(&default_keypair_file).unwrap().into()],
Expand All @@ -3301,6 +3346,7 @@ mod tests {
nonce_account: None,
nonce_authority: 0,
memo: None,
seed: None,
fee_payer: 0,
},
signers: vec![read_keypair_file(&default_keypair_file).unwrap().into()],
Expand Down Expand Up @@ -3337,6 +3383,7 @@ mod tests {
nonce_account: None,
nonce_authority: 0,
memo: None,
seed: None,
fee_payer: 1,
},
signers: vec![
Expand Down Expand Up @@ -3382,6 +3429,7 @@ mod tests {
nonce_account: Some(nonce_account),
nonce_authority: 2,
memo: None,
seed: None,
fee_payer: 1,
},
signers: vec![
Expand Down Expand Up @@ -3412,6 +3460,7 @@ mod tests {
nonce_account: None,
nonce_authority: 0,
memo: None,
seed: None,
fee_payer: 1,
},
signers: vec![
Expand Down
7 changes: 7 additions & 0 deletions cli/tests/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ fn test_seed_stake_delegation_and_deactivation() {
nonce_account: None,
nonce_authority: 0,
memo: None,
seed: None,
fee_payer: 0,
};
process_command(&config_validator).unwrap();
Expand Down Expand Up @@ -269,6 +270,7 @@ fn test_stake_delegation_and_deactivation() {
nonce_account: None,
nonce_authority: 0,
memo: None,
seed: None,
fee_payer: 0,
};
process_command(&config_validator).unwrap();
Expand Down Expand Up @@ -391,6 +393,7 @@ fn test_offline_stake_delegation_and_deactivation() {
nonce_account: None,
nonce_authority: 0,
memo: None,
seed: None,
fee_payer: 0,
};
let sig_response = process_command(&config_offline).unwrap();
Expand All @@ -409,6 +412,7 @@ fn test_offline_stake_delegation_and_deactivation() {
nonce_account: None,
nonce_authority: 0,
memo: None,
seed: None,
fee_payer: 0,
};
process_command(&config_payer).unwrap();
Expand Down Expand Up @@ -524,6 +528,7 @@ fn test_nonced_stake_delegation_and_deactivation() {
nonce_account: Some(nonce_account.pubkey()),
nonce_authority: 0,
memo: None,
seed: None,
fee_payer: 0,
};
process_command(&config).unwrap();
Expand Down Expand Up @@ -1459,6 +1464,7 @@ fn test_offline_nonced_create_stake_account_and_withdraw() {
nonce_account: Some(nonce_pubkey),
nonce_authority: 0,
memo: None,
seed: None,
fee_payer: 0,
};
let sig_response = process_command(&config_offline).unwrap();
Expand All @@ -1480,6 +1486,7 @@ fn test_offline_nonced_create_stake_account_and_withdraw() {
nonce_account: Some(nonce_pubkey),
nonce_authority: 0,
memo: None,
seed: None,
fee_payer: 0,
};
process_command(&config).unwrap();
Expand Down
1 change: 1 addition & 0 deletions core/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4788,6 +4788,7 @@ mod tests {

#[test]
#[serial]
#[ignore]
fn test_pull_request_time_pruning() {
let node = Node::new_localhost();
let cluster_info = Arc::new(ClusterInfo::new_with_invalid_keypair(node.info));
Expand Down