diff --git a/multinode-demo/common.sh b/multinode-demo/common.sh index bf7d3264f6..bcade120d6 100644 --- a/multinode-demo/common.sh +++ b/multinode-demo/common.sh @@ -148,19 +148,15 @@ setup_vote_account() { if [[ -f "$vote_id_path".configured ]]; then echo "Vote account has already been configured" - return 0 + else + airdrop "$node_id_path" "$drone_address" "$stake" || return $? + + # Fund the vote account from the node, with the node as the node_id + $solana_wallet --keypair "$node_id_path" --host "$drone_address" \ + create-vote-account "$vote_id" "$node_id" $((stake - 1)) || return $? fi - # A fullnode requires 43 lamports to function: - # - one lamport to keep the node identity public key valid. TODO: really?? - # - 42 more for the vote account we fund - airdrop "$node_id_path" "$drone_address" "$stake" || return $? - - # Fund the vote account from the node, with the node as the node_id - $solana_wallet --keypair "$node_id_path" --host "$drone_address" \ - create-vote-account "$vote_id" "$node_id" $((stake - 1)) || return $? - - touch "$vote_id_path".configured + $solana_wallet --host "$drone_address" show-vote-account "$vote_id" return 0 } diff --git a/wallet/src/main.rs b/wallet/src/main.rs index 02c32c716c..786d7b35f3 100644 --- a/wallet/src/main.rs +++ b/wallet/src/main.rs @@ -268,6 +268,19 @@ fn main() -> Result<(), Box> { ), ) + .subcommand( + SubCommand::with_name("show-vote-account") + .about("Show the contents of a vote account") + .arg( + Arg::with_name("voting_account_id") + .index(1) + .value_name("PUBKEY") + .takes_value(true) + .required(true) + .validator(is_pubkey) + .help("Vote account pubkey"), + ) + ) .subcommand( SubCommand::with_name("deploy") .about("Deploy a program") diff --git a/wallet/src/wallet.rs b/wallet/src/wallet.rs index e93ac01d6e..751e5ed083 100644 --- a/wallet/src/wallet.rs +++ b/wallet/src/wallet.rs @@ -38,6 +38,7 @@ pub enum WalletCommand { // ConfigureStakingAccount(delegate_id, authorized_voter_id) AuthorizeVoter(Pubkey), CreateVoteAccount(Pubkey, Pubkey, u32, u64), + ShowVoteAccount(Pubkey), Deploy(String), GetTransactionCount, // Pay(lamports, to, timestamp, timestamp_pubkey, witness(es), cancelable) @@ -184,6 +185,10 @@ pub fn parse_command( lamports, )) } + ("show-vote-account", Some(matches)) => { + let voting_account_id = pubkey_of(matches, "voting_account_id").unwrap(); + Ok(WalletCommand::ShowVoteAccount(voting_account_id)) + } ("deploy", Some(deploy_matches)) => Ok(WalletCommand::Deploy( deploy_matches .value_of("program_location") @@ -368,6 +373,43 @@ fn process_create_staking( Ok(signature_str.to_string()) } +fn process_show_staking( + rpc_client: &RpcClient, + _config: &WalletConfig, + voting_account_id: &Pubkey, +) -> ProcessResult { + use solana_vote_api::vote_state::VoteState; + let vote_account_lamports = rpc_client.retry_get_balance(voting_account_id, 5)?; + let vote_account_data = rpc_client.get_account_data(voting_account_id)?; + let vote_state = VoteState::deserialize(&vote_account_data).unwrap(); + + println!("account lamports: {}", vote_account_lamports.unwrap()); + println!("node id: {}", vote_state.node_id); + println!("authorized voter id: {}", vote_state.authorized_voter_id); + println!("credits: {}", vote_state.credits()); + println!( + "commission: {}%", + f64::from(vote_state.commission) / f64::from(std::u32::MAX) + ); + println!( + "root slot: {}", + match vote_state.root_slot { + Some(slot) => slot.to_string(), + None => "~".to_string(), + } + ); + if !vote_state.votes.is_empty() { + println!("votes:"); + for vote in vote_state.votes { + println!( + "- slot={}, confirmation count={}", + vote.slot, vote.confirmation_count + ); + } + } + Ok("".to_string()) +} + fn process_deploy( rpc_client: &RpcClient, config: &WalletConfig, @@ -635,6 +677,10 @@ pub fn process_command(config: &WalletConfig) -> ProcessResult { ) } + WalletCommand::ShowVoteAccount(voting_account_id) => { + process_show_staking(&rpc_client, config, &voting_account_id) + } + // Deploy a custom program to the chain WalletCommand::Deploy(ref program_location) => { process_deploy(&rpc_client, config, program_location)