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

Commit 833ea93

Browse files
authored
stake-pool-cli: Fix update command, add verbosity (#1345)
* stake-pool-cli: Fix update command, add verbosity The update command in the stake pool CLI was passing the validator vote account instead of the associated stake account from the pool, causing it to fail. Additionally, add more verbose logging, and a dry-run mode to get simulate transaction information, useful for debugging CLI failures. * Run cargo fmt
1 parent 26a3c62 commit 833ea93

File tree

2 files changed

+64
-10
lines changed

2 files changed

+64
-10
lines changed

stake-pool/cli/src/main.rs

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct Config {
5353
verbose: bool,
5454
owner: Box<dyn Signer>,
5555
fee_payer: Box<dyn Signer>,
56+
dry_run: bool,
5657
}
5758

5859
type Error = Box<dyn std::error::Error>;
@@ -511,6 +512,9 @@ fn command_deposit(
511512
let stake_data = config.rpc_client.get_account_data(&stake)?;
512513
let stake_data: StakeState =
513514
deserialize(stake_data.as_slice()).or(Err("Invalid stake account data"))?;
515+
if config.verbose {
516+
println!("Depositing stake account {:?}", stake_data);
517+
}
514518
let validator: Pubkey = match stake_data {
515519
StakeState::Stake(_, stake) => Ok(stake.delegation.voter_pubkey),
516520
_ => Err("Wrong stake account state, must be delegated to validator"),
@@ -529,7 +533,16 @@ fn command_deposit(
529533
// Calculate validator stake account address linked to the pool
530534
let (validator_stake_account, _) =
531535
PoolProcessor::find_stake_address_for_validator(&spl_stake_pool::id(), &validator, pool);
532-
println!("Depositing into stake account {}", validator_stake_account);
536+
let validator_stake_data = config
537+
.rpc_client
538+
.get_account_data(&validator_stake_account)?;
539+
let validator_stake_data: StakeState =
540+
deserialize(validator_stake_data.as_slice()).or(Err("Invalid stake account data"))?;
541+
if config.verbose {
542+
println!("Depositing into stake account {:?}", validator_stake_data);
543+
} else {
544+
println!("Depositing into stake account {}", validator_stake_account);
545+
}
533546

534547
let mut instructions: Vec<Instruction> = vec![];
535548
let mut signers = vec![config.fee_payer.as_ref(), config.owner.as_ref()];
@@ -617,6 +630,21 @@ fn command_list(config: &Config, pool: &Pubkey) -> CommandResult {
617630
let pool_data = config.rpc_client.get_account_data(&pool)?;
618631
let pool_data = StakePool::deserialize(pool_data.as_slice()).unwrap();
619632

633+
if config.verbose {
634+
let validator_list = config
635+
.rpc_client
636+
.get_account_data(&pool_data.validator_stake_list)?;
637+
let validator_stake_list_data =
638+
ValidatorStakeList::deserialize(&validator_list.as_slice())?;
639+
println!("Current validator list");
640+
for validator in validator_stake_list_data.validators {
641+
println!(
642+
"Vote: {}\tBalance: {}\tEpoch: {}",
643+
validator.validator_account, validator.balance, validator.last_update_epoch
644+
);
645+
}
646+
}
647+
620648
let pool_withdraw_authority: Pubkey = PoolProcessor::authority_id(
621649
&spl_stake_pool::id(),
622650
pool,
@@ -633,9 +661,16 @@ fn command_list(config: &Config, pool: &Pubkey) -> CommandResult {
633661

634662
let mut total_balance: u64 = 0;
635663
for (pubkey, account) in accounts {
664+
let stake_data: StakeState =
665+
deserialize(account.data.as_slice()).or(Err("Invalid stake account data"))?;
636666
let balance = account.lamports;
637667
total_balance += balance;
638-
println!("{}\t{} SOL", pubkey, lamports_to_sol(balance));
668+
println!(
669+
"Pubkey: {}\tVote: {}\t{} SOL",
670+
pubkey,
671+
stake_data.delegation().unwrap().voter_pubkey,
672+
lamports_to_sol(balance)
673+
);
639674
}
640675
println!("Total: {} SOL", lamports_to_sol(total_balance));
641676

@@ -654,14 +689,19 @@ fn command_update(config: &Config, pool: &Pubkey) -> CommandResult {
654689

655690
let epoch_info = config.rpc_client.get_epoch_info()?;
656691

657-
let accounts_to_update: Vec<&Pubkey> = validator_stake_list_data
692+
let accounts_to_update: Vec<Pubkey> = validator_stake_list_data
658693
.validators
659694
.iter()
660695
.filter_map(|item| {
661696
if item.last_update_epoch >= epoch_info.epoch {
662697
None
663698
} else {
664-
Some(&item.validator_account)
699+
let (stake_account, _) = PoolProcessor::find_stake_address_for_validator(
700+
&spl_stake_pool::id(),
701+
&item.validator_account,
702+
&pool,
703+
);
704+
Some(stake_account)
665705
}
666706
})
667707
.collect();
@@ -1033,6 +1073,13 @@ fn main() {
10331073
.global(true)
10341074
.help("Show additional information"),
10351075
)
1076+
.arg(
1077+
Arg::with_name("dry_run")
1078+
.long("dry-run")
1079+
.takes_value(false)
1080+
.global(true)
1081+
.help("Simluate transaction instead of executing"),
1082+
)
10361083
.arg(
10371084
Arg::with_name("json_rpc_url")
10381085
.long("url")
@@ -1354,12 +1401,14 @@ fn main() {
13541401
exit(1);
13551402
});
13561403
let verbose = matches.is_present("verbose");
1404+
let dry_run = matches.is_present("dry_run");
13571405

13581406
Config {
13591407
rpc_client: RpcClient::new_with_commitment(json_rpc_url, CommitmentConfig::confirmed()),
13601408
verbose,
13611409
owner,
13621410
fee_payer,
1411+
dry_run,
13631412
}
13641413
};
13651414

@@ -1439,10 +1488,15 @@ fn main() {
14391488
}
14401489
.and_then(|transaction| {
14411490
if let Some(transaction) = transaction {
1442-
let signature = config
1443-
.rpc_client
1444-
.send_and_confirm_transaction_with_spinner(&transaction)?;
1445-
println!("Signature: {}", signature);
1491+
if config.dry_run {
1492+
let result = config.rpc_client.simulate_transaction(&transaction)?;
1493+
println!("Simulate result: {:?}", result);
1494+
} else {
1495+
let signature = config
1496+
.rpc_client
1497+
.send_and_confirm_transaction_with_spinner(&transaction)?;
1498+
println!("Signature: {}", signature);
1499+
}
14461500
}
14471501
Ok(())
14481502
})

stake-pool/program/src/instruction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,11 @@ pub fn remove_validator_stake_account(
377377
pub fn update_list_balance(
378378
program_id: &Pubkey,
379379
validator_stake_list_storage: &Pubkey,
380-
validator_stake_list: &[&Pubkey],
380+
validator_stake_list: &[Pubkey],
381381
) -> Result<Instruction, ProgramError> {
382382
let mut accounts: Vec<AccountMeta> = validator_stake_list
383383
.iter()
384-
.map(|pubkey| AccountMeta::new_readonly(**pubkey, false))
384+
.map(|pubkey| AccountMeta::new_readonly(*pubkey, false))
385385
.collect();
386386
accounts.insert(0, AccountMeta::new(*validator_stake_list_storage, false));
387387
accounts.insert(1, AccountMeta::new_readonly(sysvar::clock::id(), false));

0 commit comments

Comments
 (0)