Add commitment flag to vote-account and validators commands (#8597)

This commit is contained in:
Michael Vines
2020-03-03 17:53:30 -07:00
committed by GitHub
parent d9b0490f72
commit abf33b3b3b
6 changed files with 104 additions and 58 deletions

View File

@ -211,12 +211,9 @@ impl Archiver {
let client = solana_core::gossip_service::get_client(&nodes); let client = solana_core::gossip_service::get_client(&nodes);
info!("Setting up mining account..."); info!("Setting up mining account...");
if let Err(e) = Self::setup_mining_account( if let Err(e) =
&client, Self::setup_mining_account(&client, &keypair, &storage_keypair, client_commitment)
&keypair, {
&storage_keypair,
client_commitment.clone(),
) {
//shutdown services before exiting //shutdown services before exiting
exit.store(true, Ordering::Relaxed); exit.store(true, Ordering::Relaxed);
gossip_service.join()?; gossip_service.join()?;
@ -358,7 +355,7 @@ impl Archiver {
&cluster_info, &cluster_info,
archiver_keypair, archiver_keypair,
storage_keypair, storage_keypair,
meta.client_commitment.clone(), meta.client_commitment,
); );
} }
exit.store(true, Ordering::Relaxed); exit.store(true, Ordering::Relaxed);
@ -374,7 +371,7 @@ impl Archiver {
let client = solana_core::gossip_service::get_client(&nodes); let client = solana_core::gossip_service::get_client(&nodes);
if let Ok(Some(account)) = if let Ok(Some(account)) =
client.get_account_with_commitment(&storage_keypair.pubkey(), client_commitment.clone()) client.get_account_with_commitment(&storage_keypair.pubkey(), client_commitment)
{ {
if let Ok(StorageContract::ArchiverStorage { validations, .. }) = account.state() { if let Ok(StorageContract::ArchiverStorage { validations, .. }) = account.state() {
if !validations.is_empty() { if !validations.is_empty() {
@ -415,7 +412,7 @@ impl Archiver {
slot_sender: Sender<u64>, slot_sender: Sender<u64>,
) -> Result<WindowService> { ) -> Result<WindowService> {
let slots_per_segment = let slots_per_segment =
match Self::get_segment_config(&cluster_info, meta.client_commitment.clone()) { match Self::get_segment_config(&cluster_info, meta.client_commitment) {
Ok(slots_per_segment) => slots_per_segment, Ok(slots_per_segment) => slots_per_segment,
Err(e) => { Err(e) => {
error!("unable to get segment size configuration, exiting..."); error!("unable to get segment size configuration, exiting...");
@ -581,7 +578,7 @@ impl Archiver {
&keypair.pubkey(), &keypair.pubkey(),
&Duration::from_millis(100), &Duration::from_millis(100),
&Duration::from_secs(5), &Duration::from_secs(5),
client_commitment.clone(), client_commitment,
)? == 0 )? == 0
{ {
return Err(ArchiverError::EmptyStorageAccountBalance); return Err(ArchiverError::EmptyStorageAccountBalance);
@ -589,16 +586,15 @@ impl Archiver {
info!("checking storage account keypair..."); info!("checking storage account keypair...");
// check if the storage account exists // check if the storage account exists
let balance = client let balance =
.poll_get_balance_with_commitment(&storage_keypair.pubkey(), client_commitment.clone()); client.poll_get_balance_with_commitment(&storage_keypair.pubkey(), client_commitment);
if balance.is_err() || balance.unwrap() == 0 { if balance.is_err() || balance.unwrap() == 0 {
let blockhash = let blockhash = match client.get_recent_blockhash_with_commitment(client_commitment) {
match client.get_recent_blockhash_with_commitment(client_commitment.clone()) { Ok((blockhash, _)) => blockhash,
Ok((blockhash, _)) => blockhash, Err(e) => {
Err(e) => { return Err(ArchiverError::TransportError(e));
return Err(ArchiverError::TransportError(e)); }
} };
};
let ix = storage_instruction::create_storage_account( let ix = storage_instruction::create_storage_account(
&keypair.pubkey(), &keypair.pubkey(),
@ -631,32 +627,27 @@ impl Archiver {
// No point if we've got no storage account... // No point if we've got no storage account...
let nodes = cluster_info.read().unwrap().tvu_peers(); let nodes = cluster_info.read().unwrap().tvu_peers();
let client = solana_core::gossip_service::get_client(&nodes); let client = solana_core::gossip_service::get_client(&nodes);
let storage_balance = client.poll_get_balance_with_commitment( let storage_balance = client
&storage_keypair.pubkey(), .poll_get_balance_with_commitment(&storage_keypair.pubkey(), meta.client_commitment);
meta.client_commitment.clone(),
);
if storage_balance.is_err() || storage_balance.unwrap() == 0 { if storage_balance.is_err() || storage_balance.unwrap() == 0 {
error!("Unable to submit mining proof, no storage account"); error!("Unable to submit mining proof, no storage account");
return; return;
} }
// ...or no lamports for fees // ...or no lamports for fees
let balance = client.poll_get_balance_with_commitment( let balance = client
&archiver_keypair.pubkey(), .poll_get_balance_with_commitment(&archiver_keypair.pubkey(), meta.client_commitment);
meta.client_commitment.clone(),
);
if balance.is_err() || balance.unwrap() == 0 { if balance.is_err() || balance.unwrap() == 0 {
error!("Unable to submit mining proof, insufficient Archiver Account balance"); error!("Unable to submit mining proof, insufficient Archiver Account balance");
return; return;
} }
let blockhash = let blockhash = match client.get_recent_blockhash_with_commitment(meta.client_commitment) {
match client.get_recent_blockhash_with_commitment(meta.client_commitment.clone()) { Ok((blockhash, _)) => blockhash,
Ok((blockhash, _)) => blockhash, Err(_) => {
Err(_) => { error!("unable to get recent blockhash, can't submit proof");
error!("unable to get recent blockhash, can't submit proof"); return;
return; }
} };
};
let instruction = storage_instruction::mining_proof( let instruction = storage_instruction::mining_proof(
&storage_keypair.pubkey(), &storage_keypair.pubkey(),
meta.sha_state, meta.sha_state,

View File

@ -208,6 +208,7 @@ pub enum CliCommand {
}, },
ShowValidators { ShowValidators {
use_lamports_unit: bool, use_lamports_unit: bool,
commitment_config: CommitmentConfig,
}, },
// Nonce commands // Nonce commands
AuthorizeNonceAccount { AuthorizeNonceAccount {
@ -353,6 +354,7 @@ pub enum CliCommand {
ShowVoteAccount { ShowVoteAccount {
pubkey: Pubkey, pubkey: Pubkey,
use_lamports_unit: bool, use_lamports_unit: bool,
commitment_config: CommitmentConfig,
}, },
VoteAuthorize { VoteAuthorize {
vote_account_pubkey: Pubkey, vote_account_pubkey: Pubkey,
@ -1559,13 +1561,13 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
CliCommand::GetBlockTime { slot } => process_get_block_time(&rpc_client, *slot), CliCommand::GetBlockTime { slot } => process_get_block_time(&rpc_client, *slot),
CliCommand::GetGenesisHash => process_get_genesis_hash(&rpc_client), CliCommand::GetGenesisHash => process_get_genesis_hash(&rpc_client),
CliCommand::GetEpochInfo { commitment_config } => { CliCommand::GetEpochInfo { commitment_config } => {
process_get_epoch_info(&rpc_client, commitment_config) process_get_epoch_info(&rpc_client, *commitment_config)
} }
CliCommand::GetSlot { commitment_config } => { CliCommand::GetSlot { commitment_config } => {
process_get_slot(&rpc_client, commitment_config) process_get_slot(&rpc_client, *commitment_config)
} }
CliCommand::GetTransactionCount { commitment_config } => { CliCommand::GetTransactionCount { commitment_config } => {
process_get_transaction_count(&rpc_client, commitment_config) process_get_transaction_count(&rpc_client, *commitment_config)
} }
CliCommand::LeaderSchedule => process_leader_schedule(&rpc_client), CliCommand::LeaderSchedule => process_leader_schedule(&rpc_client),
CliCommand::LiveSlots => process_live_slots(&config.websocket_url), CliCommand::LiveSlots => process_live_slots(&config.websocket_url),
@ -1582,7 +1584,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
interval, interval,
count, count,
timeout, timeout,
commitment_config, *commitment_config,
), ),
CliCommand::ShowBlockProduction { epoch, slot_limit } => { CliCommand::ShowBlockProduction { epoch, slot_limit } => {
process_show_block_production(&rpc_client, config, *epoch, *slot_limit) process_show_block_production(&rpc_client, config, *epoch, *slot_limit)
@ -1596,9 +1598,10 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
*use_lamports_unit, *use_lamports_unit,
vote_account_pubkeys.as_deref(), vote_account_pubkeys.as_deref(),
), ),
CliCommand::ShowValidators { use_lamports_unit } => { CliCommand::ShowValidators {
process_show_validators(&rpc_client, *use_lamports_unit) use_lamports_unit,
} commitment_config,
} => process_show_validators(&rpc_client, *use_lamports_unit, *commitment_config),
// Nonce Commands // Nonce Commands
@ -1910,11 +1913,13 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
CliCommand::ShowVoteAccount { CliCommand::ShowVoteAccount {
pubkey: vote_account_pubkey, pubkey: vote_account_pubkey,
use_lamports_unit, use_lamports_unit,
commitment_config,
} => process_show_vote_account( } => process_show_vote_account(
&rpc_client, &rpc_client,
config, config,
&vote_account_pubkey, &vote_account_pubkey,
*use_lamports_unit, *use_lamports_unit,
*commitment_config,
), ),
CliCommand::VoteAuthorize { CliCommand::VoteAuthorize {
vote_account_pubkey, vote_account_pubkey,

View File

@ -218,6 +218,14 @@ impl ClusterQuerySubCommands for App<'_, '_> {
SubCommand::with_name("validators") SubCommand::with_name("validators")
.about("Show summary information about the current validators") .about("Show summary information about the current validators")
.alias("show-validators") .alias("show-validators")
.arg(
Arg::with_name("confirmed")
.long("confirmed")
.takes_value(false)
.help(
"Return information at maximum-lockout commitment level",
),
)
.arg( .arg(
Arg::with_name("lamports") Arg::with_name("lamports")
.long("lamports") .long("lamports")
@ -330,9 +338,17 @@ pub fn parse_show_stakes(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, Cli
pub fn parse_show_validators(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> { pub fn parse_show_validators(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
let use_lamports_unit = matches.is_present("lamports"); let use_lamports_unit = matches.is_present("lamports");
let commitment_config = if matches.is_present("confirmed") {
CommitmentConfig::default()
} else {
CommitmentConfig::recent()
};
Ok(CliCommandInfo { Ok(CliCommandInfo {
command: CliCommand::ShowValidators { use_lamports_unit }, command: CliCommand::ShowValidators {
use_lamports_unit,
commitment_config,
},
signers: vec![], signers: vec![],
}) })
} }
@ -473,7 +489,7 @@ fn slot_to_human_time(slot: Slot) -> String {
pub fn process_get_epoch_info( pub fn process_get_epoch_info(
rpc_client: &RpcClient, rpc_client: &RpcClient,
commitment_config: &CommitmentConfig, commitment_config: CommitmentConfig,
) -> ProcessResult { ) -> ProcessResult {
let epoch_info = rpc_client.get_epoch_info_with_commitment(commitment_config.clone())?; let epoch_info = rpc_client.get_epoch_info_with_commitment(commitment_config.clone())?;
println!(); println!();
@ -519,7 +535,7 @@ pub fn process_get_genesis_hash(rpc_client: &RpcClient) -> ProcessResult {
pub fn process_get_slot( pub fn process_get_slot(
rpc_client: &RpcClient, rpc_client: &RpcClient,
commitment_config: &CommitmentConfig, commitment_config: CommitmentConfig,
) -> ProcessResult { ) -> ProcessResult {
let slot = rpc_client.get_slot_with_commitment(commitment_config.clone())?; let slot = rpc_client.get_slot_with_commitment(commitment_config.clone())?;
Ok(slot.to_string()) Ok(slot.to_string())
@ -708,7 +724,7 @@ pub fn process_show_block_production(
pub fn process_get_transaction_count( pub fn process_get_transaction_count(
rpc_client: &RpcClient, rpc_client: &RpcClient,
commitment_config: &CommitmentConfig, commitment_config: CommitmentConfig,
) -> ProcessResult { ) -> ProcessResult {
let transaction_count = let transaction_count =
rpc_client.get_transaction_count_with_commitment(commitment_config.clone())?; rpc_client.get_transaction_count_with_commitment(commitment_config.clone())?;
@ -722,7 +738,7 @@ pub fn process_ping(
interval: &Duration, interval: &Duration,
count: &Option<u64>, count: &Option<u64>,
timeout: &Duration, timeout: &Duration,
commitment_config: &CommitmentConfig, commitment_config: CommitmentConfig,
) -> ProcessResult { ) -> ProcessResult {
let to = Keypair::new().pubkey(); let to = Keypair::new().pubkey();
@ -1013,9 +1029,13 @@ pub fn process_show_stakes(
Ok("".to_string()) Ok("".to_string())
} }
pub fn process_show_validators(rpc_client: &RpcClient, use_lamports_unit: bool) -> ProcessResult { pub fn process_show_validators(
let epoch_info = rpc_client.get_epoch_info()?; rpc_client: &RpcClient,
let vote_accounts = rpc_client.get_vote_accounts()?; use_lamports_unit: bool,
commitment_config: CommitmentConfig,
) -> ProcessResult {
let epoch_info = rpc_client.get_epoch_info_with_commitment(commitment_config)?;
let vote_accounts = rpc_client.get_vote_accounts_with_commitment(commitment_config)?;
let total_active_stake = vote_accounts let total_active_stake = vote_accounts
.current .current
.iter() .iter()

View File

@ -9,6 +9,7 @@ use solana_client::rpc_client::RpcClient;
use solana_remote_wallet::remote_wallet::RemoteWalletManager; use solana_remote_wallet::remote_wallet::RemoteWalletManager;
use solana_sdk::{ use solana_sdk::{
account::Account, account::Account,
commitment_config::CommitmentConfig,
message::Message, message::Message,
pubkey::Pubkey, pubkey::Pubkey,
system_instruction::{create_address_with_seed, SystemError}, system_instruction::{create_address_with_seed, SystemError},
@ -158,6 +159,14 @@ impl VoteSubCommands for App<'_, '_> {
SubCommand::with_name("vote-account") SubCommand::with_name("vote-account")
.about("Show the contents of a vote account") .about("Show the contents of a vote account")
.alias("show-vote-account") .alias("show-vote-account")
.arg(
Arg::with_name("confirmed")
.long("confirmed")
.takes_value(false)
.help(
"Return information at maximum-lockout commitment level",
),
)
.arg( .arg(
Arg::with_name("vote_account_pubkey") Arg::with_name("vote_account_pubkey")
.index(1) .index(1)
@ -267,10 +276,16 @@ pub fn parse_vote_get_account_command(
) -> Result<CliCommandInfo, CliError> { ) -> Result<CliCommandInfo, CliError> {
let vote_account_pubkey = pubkey_of(matches, "vote_account_pubkey").unwrap(); let vote_account_pubkey = pubkey_of(matches, "vote_account_pubkey").unwrap();
let use_lamports_unit = matches.is_present("lamports"); let use_lamports_unit = matches.is_present("lamports");
let commitment_config = if matches.is_present("confirmed") {
CommitmentConfig::default()
} else {
CommitmentConfig::recent()
};
Ok(CliCommandInfo { Ok(CliCommandInfo {
command: CliCommand::ShowVoteAccount { command: CliCommand::ShowVoteAccount {
pubkey: vote_account_pubkey, pubkey: vote_account_pubkey,
use_lamports_unit, use_lamports_unit,
commitment_config,
}, },
signers: vec![], signers: vec![],
}) })
@ -423,8 +438,14 @@ pub fn process_vote_update_validator(
fn get_vote_account( fn get_vote_account(
rpc_client: &RpcClient, rpc_client: &RpcClient,
vote_account_pubkey: &Pubkey, vote_account_pubkey: &Pubkey,
commitment_config: CommitmentConfig,
) -> Result<(Account, VoteState), Box<dyn std::error::Error>> { ) -> Result<(Account, VoteState), Box<dyn std::error::Error>> {
let vote_account = rpc_client.get_account(vote_account_pubkey)?; let vote_account = rpc_client
.get_account_with_commitment(vote_account_pubkey, commitment_config)?
.value
.ok_or_else(|| {
CliError::RpcRequestError(format!("{:?} account does not exist", vote_account_pubkey))
})?;
if vote_account.owner != solana_vote_program::id() { if vote_account.owner != solana_vote_program::id() {
return Err(CliError::RpcRequestError(format!( return Err(CliError::RpcRequestError(format!(
@ -447,8 +468,10 @@ pub fn process_show_vote_account(
_config: &CliConfig, _config: &CliConfig,
vote_account_pubkey: &Pubkey, vote_account_pubkey: &Pubkey,
use_lamports_unit: bool, use_lamports_unit: bool,
commitment_config: CommitmentConfig,
) -> ProcessResult { ) -> ProcessResult {
let (vote_account, vote_state) = get_vote_account(rpc_client, vote_account_pubkey)?; let (vote_account, vote_state) =
get_vote_account(rpc_client, vote_account_pubkey, commitment_config)?;
let epoch_schedule = rpc_client.get_epoch_schedule()?; let epoch_schedule = rpc_client.get_epoch_schedule()?;

View File

@ -165,9 +165,16 @@ impl RpcClient {
} }
pub fn get_vote_accounts(&self) -> io::Result<RpcVoteAccountStatus> { pub fn get_vote_accounts(&self) -> io::Result<RpcVoteAccountStatus> {
self.get_vote_accounts_with_commitment(CommitmentConfig::default())
}
pub fn get_vote_accounts_with_commitment(
&self,
commitment_config: CommitmentConfig,
) -> io::Result<RpcVoteAccountStatus> {
let response = self let response = self
.client .client
.send(&RpcRequest::GetVoteAccounts, Value::Null, 0) .send(&RpcRequest::GetVoteAccounts, json!([commitment_config]), 0)
.map_err(|err| { .map_err(|err| {
io::Error::new( io::Error::new(
io::ErrorKind::Other, io::ErrorKind::Other,

View File

@ -1,4 +1,4 @@
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] #[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct CommitmentConfig { pub struct CommitmentConfig {
pub commitment: CommitmentLevel, pub commitment: CommitmentLevel,
@ -25,16 +25,16 @@ impl CommitmentConfig {
} }
} }
pub fn ok(&self) -> Option<Self> { pub fn ok(self) -> Option<Self> {
if self == &Self::default() { if self == Self::default() {
None None
} else { } else {
Some(self.clone()) Some(self)
} }
} }
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] #[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub enum CommitmentLevel { pub enum CommitmentLevel {
Max, Max,