Fix up a couple cli commands that fail when a node is in the --wait-for-supermajority
state (#9985) (#9991)
automerge
(cherry picked from commit 3b9dc50541
)
Co-authored-by: Michael Vines <mvines@gmail.com>
This commit is contained in:
@ -8,11 +8,15 @@ pub const COMMITMENT_ARG: ArgConstant<'static> = ArgConstant {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub fn commitment_arg<'a, 'b>() -> Arg<'a, 'b> {
|
pub fn commitment_arg<'a, 'b>() -> Arg<'a, 'b> {
|
||||||
|
commitment_arg_with_default("recent")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn commitment_arg_with_default<'a, 'b>(default_value: &'static str) -> Arg<'a, 'b> {
|
||||||
Arg::with_name(COMMITMENT_ARG.name)
|
Arg::with_name(COMMITMENT_ARG.name)
|
||||||
.long(COMMITMENT_ARG.long)
|
.long(COMMITMENT_ARG.long)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.possible_values(&["recent", "root", "max"])
|
.possible_values(&["recent", "root", "max"])
|
||||||
.default_value("recent")
|
.default_value(default_value)
|
||||||
.value_name("COMMITMENT_LEVEL")
|
.value_name("COMMITMENT_LEVEL")
|
||||||
.help(COMMITMENT_ARG.help)
|
.help(COMMITMENT_ARG.help)
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,11 @@ use num_traits::FromPrimitive;
|
|||||||
use serde_json::{self, json, Value};
|
use serde_json::{self, json, Value};
|
||||||
use solana_budget_program::budget_instruction::{self, BudgetError};
|
use solana_budget_program::budget_instruction::{self, BudgetError};
|
||||||
use solana_clap_utils::{
|
use solana_clap_utils::{
|
||||||
input_parsers::*, input_validators::*, keypair::signer_from_path, offline::SIGN_ONLY_ARG,
|
commitment::{commitment_arg_with_default, COMMITMENT_ARG},
|
||||||
|
input_parsers::*,
|
||||||
|
input_validators::*,
|
||||||
|
keypair::signer_from_path,
|
||||||
|
offline::SIGN_ONLY_ARG,
|
||||||
ArgConstant,
|
ArgConstant,
|
||||||
};
|
};
|
||||||
use solana_client::{
|
use solana_client::{
|
||||||
@ -409,6 +413,7 @@ pub enum CliCommand {
|
|||||||
Balance {
|
Balance {
|
||||||
pubkey: Option<Pubkey>,
|
pubkey: Option<Pubkey>,
|
||||||
use_lamports_unit: bool,
|
use_lamports_unit: bool,
|
||||||
|
commitment_config: CommitmentConfig,
|
||||||
},
|
},
|
||||||
Cancel(Pubkey),
|
Cancel(Pubkey),
|
||||||
Confirm(Signature),
|
Confirm(Signature),
|
||||||
@ -573,6 +578,7 @@ impl Default for CliConfig<'_> {
|
|||||||
command: CliCommand::Balance {
|
command: CliCommand::Balance {
|
||||||
pubkey: Some(Pubkey::default()),
|
pubkey: Some(Pubkey::default()),
|
||||||
use_lamports_unit: false,
|
use_lamports_unit: false,
|
||||||
|
commitment_config: CommitmentConfig::default(),
|
||||||
},
|
},
|
||||||
json_rpc_url: Self::default_json_rpc_url(),
|
json_rpc_url: Self::default_json_rpc_url(),
|
||||||
websocket_url: Self::default_websocket_url(),
|
websocket_url: Self::default_websocket_url(),
|
||||||
@ -787,6 +793,7 @@ pub fn parse_command(
|
|||||||
}
|
}
|
||||||
("balance", Some(matches)) => {
|
("balance", Some(matches)) => {
|
||||||
let pubkey = pubkey_of_signer(matches, "pubkey", wallet_manager)?;
|
let pubkey = pubkey_of_signer(matches, "pubkey", wallet_manager)?;
|
||||||
|
let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
|
||||||
let signers = if pubkey.is_some() {
|
let signers = if pubkey.is_some() {
|
||||||
vec![]
|
vec![]
|
||||||
} else {
|
} else {
|
||||||
@ -801,6 +808,7 @@ pub fn parse_command(
|
|||||||
command: CliCommand::Balance {
|
command: CliCommand::Balance {
|
||||||
pubkey,
|
pubkey,
|
||||||
use_lamports_unit: matches.is_present("lamports"),
|
use_lamports_unit: matches.is_present("lamports"),
|
||||||
|
commitment_config,
|
||||||
},
|
},
|
||||||
signers,
|
signers,
|
||||||
})
|
})
|
||||||
@ -1183,19 +1191,17 @@ fn process_balance(
|
|||||||
config: &CliConfig,
|
config: &CliConfig,
|
||||||
pubkey: &Option<Pubkey>,
|
pubkey: &Option<Pubkey>,
|
||||||
use_lamports_unit: bool,
|
use_lamports_unit: bool,
|
||||||
|
commitment_config: CommitmentConfig,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let pubkey = if let Some(pubkey) = pubkey {
|
let pubkey = if let Some(pubkey) = pubkey {
|
||||||
*pubkey
|
*pubkey
|
||||||
} else {
|
} else {
|
||||||
config.pubkey()?
|
config.pubkey()?
|
||||||
};
|
};
|
||||||
let balance = rpc_client.retry_get_balance(&pubkey, 5)?;
|
let balance = rpc_client
|
||||||
match balance {
|
.get_balance_with_commitment(&pubkey, commitment_config)?
|
||||||
Some(lamports) => Ok(build_balance_message(lamports, use_lamports_unit, true)),
|
.value;
|
||||||
None => Err(
|
Ok(build_balance_message(balance, use_lamports_unit, true))
|
||||||
CliError::RpcRequestError("Received result of an unexpected type".to_string()).into(),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_confirm(
|
fn process_confirm(
|
||||||
@ -2131,7 +2137,14 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
|||||||
CliCommand::Balance {
|
CliCommand::Balance {
|
||||||
pubkey,
|
pubkey,
|
||||||
use_lamports_unit,
|
use_lamports_unit,
|
||||||
} => process_balance(&rpc_client, config, &pubkey, *use_lamports_unit),
|
commitment_config,
|
||||||
|
} => process_balance(
|
||||||
|
&rpc_client,
|
||||||
|
config,
|
||||||
|
&pubkey,
|
||||||
|
*use_lamports_unit,
|
||||||
|
*commitment_config,
|
||||||
|
),
|
||||||
// Cancel a contract by contract Pubkey
|
// Cancel a contract by contract Pubkey
|
||||||
CliCommand::Cancel(pubkey) => process_cancel(&rpc_client, config, &pubkey),
|
CliCommand::Cancel(pubkey) => process_cancel(&rpc_client, config, &pubkey),
|
||||||
// Confirm the last client transaction by signature
|
// Confirm the last client transaction by signature
|
||||||
@ -2400,7 +2413,8 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, '
|
|||||||
.long("lamports")
|
.long("lamports")
|
||||||
.takes_value(false)
|
.takes_value(false)
|
||||||
.help("Display balance in lamports instead of SOL"),
|
.help("Display balance in lamports instead of SOL"),
|
||||||
),
|
)
|
||||||
|
.arg(commitment_arg_with_default("max")),
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("cancel")
|
SubCommand::with_name("cancel")
|
||||||
@ -2811,7 +2825,8 @@ mod tests {
|
|||||||
CliCommandInfo {
|
CliCommandInfo {
|
||||||
command: CliCommand::Balance {
|
command: CliCommand::Balance {
|
||||||
pubkey: Some(keypair.pubkey()),
|
pubkey: Some(keypair.pubkey()),
|
||||||
use_lamports_unit: false
|
use_lamports_unit: false,
|
||||||
|
commitment_config: CommitmentConfig::default(),
|
||||||
},
|
},
|
||||||
signers: vec![],
|
signers: vec![],
|
||||||
}
|
}
|
||||||
@ -2827,7 +2842,8 @@ mod tests {
|
|||||||
CliCommandInfo {
|
CliCommandInfo {
|
||||||
command: CliCommand::Balance {
|
command: CliCommand::Balance {
|
||||||
pubkey: Some(keypair.pubkey()),
|
pubkey: Some(keypair.pubkey()),
|
||||||
use_lamports_unit: true
|
use_lamports_unit: true,
|
||||||
|
commitment_config: CommitmentConfig::default(),
|
||||||
},
|
},
|
||||||
signers: vec![],
|
signers: vec![],
|
||||||
}
|
}
|
||||||
@ -2841,7 +2857,8 @@ mod tests {
|
|||||||
CliCommandInfo {
|
CliCommandInfo {
|
||||||
command: CliCommand::Balance {
|
command: CliCommand::Balance {
|
||||||
pubkey: None,
|
pubkey: None,
|
||||||
use_lamports_unit: true
|
use_lamports_unit: true,
|
||||||
|
commitment_config: CommitmentConfig::default(),
|
||||||
},
|
},
|
||||||
signers: vec![read_keypair_file(&keypair_file).unwrap().into()],
|
signers: vec![read_keypair_file(&keypair_file).unwrap().into()],
|
||||||
}
|
}
|
||||||
@ -3311,12 +3328,14 @@ mod tests {
|
|||||||
config.command = CliCommand::Balance {
|
config.command = CliCommand::Balance {
|
||||||
pubkey: None,
|
pubkey: None,
|
||||||
use_lamports_unit: true,
|
use_lamports_unit: true,
|
||||||
|
commitment_config: CommitmentConfig::default(),
|
||||||
};
|
};
|
||||||
assert_eq!(process_command(&config).unwrap(), "50 lamports");
|
assert_eq!(process_command(&config).unwrap(), "50 lamports");
|
||||||
|
|
||||||
config.command = CliCommand::Balance {
|
config.command = CliCommand::Balance {
|
||||||
pubkey: None,
|
pubkey: None,
|
||||||
use_lamports_unit: false,
|
use_lamports_unit: false,
|
||||||
|
commitment_config: CommitmentConfig::default(),
|
||||||
};
|
};
|
||||||
assert_eq!(process_command(&config).unwrap(), "0.00000005 SOL");
|
assert_eq!(process_command(&config).unwrap(), "0.00000005 SOL");
|
||||||
|
|
||||||
@ -3550,6 +3569,7 @@ mod tests {
|
|||||||
config.command = CliCommand::Balance {
|
config.command = CliCommand::Balance {
|
||||||
pubkey: None,
|
pubkey: None,
|
||||||
use_lamports_unit: false,
|
use_lamports_unit: false,
|
||||||
|
commitment_config: CommitmentConfig::default(),
|
||||||
};
|
};
|
||||||
assert!(process_command(&config).is_err());
|
assert!(process_command(&config).is_err());
|
||||||
|
|
||||||
|
@ -676,7 +676,7 @@ pub fn process_show_block_production(
|
|||||||
slot_limit: Option<u64>,
|
slot_limit: Option<u64>,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let epoch_schedule = rpc_client.get_epoch_schedule()?;
|
let epoch_schedule = rpc_client.get_epoch_schedule()?;
|
||||||
let epoch_info = rpc_client.get_epoch_info_with_commitment(CommitmentConfig::max())?;
|
let epoch_info = rpc_client.get_epoch_info_with_commitment(CommitmentConfig::root())?;
|
||||||
|
|
||||||
let epoch = epoch.unwrap_or(epoch_info.epoch);
|
let epoch = epoch.unwrap_or(epoch_info.epoch);
|
||||||
if epoch > epoch_info.epoch {
|
if epoch > epoch_info.epoch {
|
||||||
@ -735,7 +735,7 @@ pub fn process_show_block_production(
|
|||||||
|
|
||||||
progress_bar.set_message(&format!("Fetching leader schedule for epoch {}...", epoch));
|
progress_bar.set_message(&format!("Fetching leader schedule for epoch {}...", epoch));
|
||||||
let leader_schedule = rpc_client
|
let leader_schedule = rpc_client
|
||||||
.get_leader_schedule_with_commitment(Some(start_slot), CommitmentConfig::max())?;
|
.get_leader_schedule_with_commitment(Some(start_slot), CommitmentConfig::root())?;
|
||||||
if leader_schedule.is_none() {
|
if leader_schedule.is_none() {
|
||||||
return Err(format!("Unable to fetch leader schedule for slot {}", start_slot).into());
|
return Err(format!("Unable to fetch leader schedule for slot {}", start_slot).into());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user