Break up RPC API into three categories: minimal, full and admin

This commit is contained in:
Michael Vines
2021-02-26 21:42:09 -08:00
parent 81253c9956
commit 24ab84936e
28 changed files with 1784 additions and 1832 deletions

View File

@ -12,18 +12,21 @@ default-run = "solana-validator"
[dependencies]
base64 = "0.12.3"
bincode = "1.3.1"
clap = "2.33.1"
chrono = { version = "0.4.11", features = ["serde"] }
clap = "2.33.1"
console = "0.11.3"
core_affinity = "0.5.10"
fd-lock = "1.1.1"
indicatif = "0.15.0"
jsonrpc-core = "17.0.0"
jsonrpc-core-client = { version = "17.0.0", features = ["ipc", "ws"] }
jsonrpc-derive = "17.0.0"
jsonrpc-ipc-server = "17.0.0"
jsonrpc-server-utils= "17.0.0"
log = "0.4.11"
num_cpus = "1.13.0"
rand = "0.7.0"
serde = "1.0.112"
serde_derive = "1.0.103"
serde_yaml = "0.8.13"
solana-clap-utils = { path = "../clap-utils", version = "1.6.0" }
solana-cli-config = { path = "../cli-config", version = "1.6.0" }
solana-client = { path = "../client", version = "1.6.0" }
@ -32,9 +35,9 @@ solana-download-utils = { path = "../download-utils", version = "1.6.0" }
solana-faucet = { path = "../faucet", version = "1.6.0" }
solana-ledger = { path = "../ledger", version = "1.6.0" }
solana-logger = { path = "../logger", version = "1.6.0" }
solana-perf = { path = "../perf", version = "1.6.0" }
solana-metrics = { path = "../metrics", version = "1.6.0" }
solana-net-utils = { path = "../net-utils", version = "1.6.0" }
solana-perf = { path = "../perf", version = "1.6.0" }
solana-runtime = { path = "../runtime", version = "1.6.0" }
solana-sdk = { path = "../sdk", version = "1.6.0" }
solana-version = { path = "../version", version = "1.6.0" }

View File

@ -0,0 +1,133 @@
use {
jsonrpc_core::{MetaIoHandler, Metadata, Result},
jsonrpc_core_client::{transports::ipc, RpcError},
jsonrpc_derive::rpc,
jsonrpc_ipc_server::{RequestContext, ServerBuilder},
jsonrpc_server_utils::tokio,
log::*,
solana_core::validator::ValidatorExit,
std::{
net::SocketAddr,
path::Path,
sync::{Arc, RwLock},
thread::Builder,
time::SystemTime,
},
};
#[derive(Clone)]
pub struct AdminRpcRequestMetadata {
pub rpc_addr: Option<SocketAddr>,
pub start_time: SystemTime,
pub validator_exit: Arc<RwLock<ValidatorExit>>,
}
impl Metadata for AdminRpcRequestMetadata {}
#[rpc]
pub trait AdminRpc {
type Metadata;
#[rpc(meta, name = "exit")]
fn exit(&self, meta: Self::Metadata) -> Result<()>;
#[rpc(meta, name = "rpcAddress")]
fn rpc_addr(&self, meta: Self::Metadata) -> Result<Option<SocketAddr>>;
#[rpc(name = "setLogFilter")]
fn set_log_filter(&self, filter: String) -> Result<()>;
#[rpc(meta, name = "startTime")]
fn start_time(&self, meta: Self::Metadata) -> Result<SystemTime>;
}
pub struct AdminRpcImpl;
impl AdminRpc for AdminRpcImpl {
type Metadata = AdminRpcRequestMetadata;
fn exit(&self, meta: Self::Metadata) -> Result<()> {
info!("exit admin rpc request received");
// Delay exit signal until this RPC request completes, otherwise the caller of `exit` might
// receive a confusing error as the validator shuts down before a response is send back.
tokio::spawn(async move {
meta.validator_exit.write().unwrap().exit();
});
Ok(())
}
fn rpc_addr(&self, meta: Self::Metadata) -> Result<Option<SocketAddr>> {
info!("rpc_addr admin rpc request received");
Ok(meta.rpc_addr)
}
fn set_log_filter(&self, filter: String) -> Result<()> {
info!("set_log_filter admin rpc request received");
solana_logger::setup_with(&filter);
Ok(())
}
fn start_time(&self, meta: Self::Metadata) -> Result<SystemTime> {
info!("start_time admin rpc request received");
Ok(meta.start_time)
}
}
// Start the Admin RPC interface
pub fn run(ledger_path: &Path, metadata: AdminRpcRequestMetadata) {
let admin_rpc_path = ledger_path.join("admin.rpc");
let event_loop = tokio::runtime::Builder::new()
.threaded_scheduler()
.enable_all()
.thread_name("sol-adminrpc-el")
.build()
.unwrap();
Builder::new()
.name("solana-adminrpc".to_string())
.spawn(move || {
let mut io = MetaIoHandler::default();
io.extend_with(AdminRpcImpl.to_delegate());
let validator_exit = metadata.validator_exit.clone();
let server = ServerBuilder::with_meta_extractor(io, move |_req: &RequestContext| {
metadata.clone()
})
.event_loop_executor(event_loop.handle().clone())
.start(&format!("{}", admin_rpc_path.display()));
match server {
Err(err) => {
warn!("Unable to start admin rpc service: {:?}", err);
}
Ok(server) => {
let close_handle = server.close_handle();
validator_exit
.write()
.unwrap()
.register_exit(Box::new(move || {
close_handle.close();
}));
server.wait();
}
}
})
.unwrap();
}
// Connect to the Admin RPC interface
pub async fn connect(ledger_path: &Path) -> std::result::Result<gen_client::Client, RpcError> {
let admin_rpc_path = ledger_path.join("admin.rpc");
if !admin_rpc_path.exists() {
Err(RpcError::Client(format!(
"{} does not exist",
admin_rpc_path.display()
)))
} else {
ipc::connect::<_, gen_client::Client>(&format!("{}", admin_rpc_path.display())).await
}
}
pub fn runtime() -> jsonrpc_server_utils::tokio::runtime::Runtime {
jsonrpc_server_utils::tokio::runtime::Runtime::new().expect("new tokio runtime")
}

View File

@ -21,7 +21,7 @@ use {
system_program,
},
solana_validator::{
dashboard::Dashboard, record_start, redirect_stderr_to_file, test_validator::*,
admin_rpc_service, dashboard::Dashboard, redirect_stderr_to_file, test_validator::*,
},
std::{
collections::HashSet,
@ -126,7 +126,7 @@ fn main() {
.takes_value(true)
.default_value(&default_rpc_port)
.validator(solana_validator::port_validator)
.help("Use this port for JSON RPC and the next port for the RPC websocket"),
.help("Enable JSON RPC on this port, and the next port for the RPC websocket"),
)
.arg(
Arg::with_name("bpf_program")
@ -205,6 +205,7 @@ fn main() {
Output::Dashboard
};
let rpc_port = value_t_or_exit!(matches, "rpc_port", u16);
let faucet_addr = Some(SocketAddr::new(
IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)),
FAUCET_PORT,
@ -353,60 +354,68 @@ fn main() {
});
}
record_start(
&ledger_path,
Some(&SocketAddr::new(
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
rpc_port,
)),
)
.unwrap_or_else(|err| println!("Error: failed to record validator start: {}", err));
let mut genesis = TestValidatorGenesis::default();
admin_rpc_service::run(
&ledger_path,
admin_rpc_service::AdminRpcRequestMetadata {
rpc_addr: Some(SocketAddr::new(
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
rpc_port,
)),
start_time: std::time::SystemTime::now(),
validator_exit: genesis.validator_exit.clone(),
},
);
let dashboard = if output == Output::Dashboard {
Some(Dashboard::new(&ledger_path, Some(&validator_log_symlink)).unwrap())
Some(
Dashboard::new(
&ledger_path,
Some(&validator_log_symlink),
Some(&mut genesis.validator_exit.write().unwrap()),
)
.unwrap(),
)
} else {
None
};
let test_validator = {
let mut genesis = TestValidatorGenesis::default();
genesis
.ledger_path(&ledger_path)
.add_account(
faucet_pubkey,
Account::new(faucet_lamports, 0, &system_program::id()),
)
.rpc_config(JsonRpcConfig {
enable_validator_exit: true,
enable_rpc_transaction_history: true,
enable_cpi_and_log_storage: true,
faucet_addr,
..JsonRpcConfig::default()
})
.bpf_jit(bpf_jit)
.rpc_port(rpc_port)
.add_programs_with_path(&programs);
genesis
.ledger_path(&ledger_path)
.add_account(
faucet_pubkey,
Account::new(faucet_lamports, 0, &system_program::id()),
)
.rpc_config(JsonRpcConfig {
enable_rpc_transaction_history: true,
enable_cpi_and_log_storage: true,
faucet_addr,
..JsonRpcConfig::default()
})
.bpf_jit(bpf_jit)
.rpc_port(rpc_port)
.add_programs_with_path(&programs);
if !clone_accounts.is_empty() {
genesis.clone_accounts(
clone_accounts,
cluster_rpc_client
.as_ref()
.expect("bug: --url argument missing?"),
);
if !clone_accounts.is_empty() {
genesis.clone_accounts(
clone_accounts,
cluster_rpc_client
.as_ref()
.expect("bug: --url argument missing?"),
);
}
if let Some(warp_slot) = warp_slot {
genesis.warp_slot(warp_slot);
}
match genesis.start_with_mint_address(mint_address) {
Ok(test_validator) => {
if let Some(dashboard) = dashboard {
dashboard.run();
}
test_validator.join();
}
if let Some(warp_slot) = warp_slot {
genesis.warp_slot(warp_slot);
}
genesis.start_with_mint_address(mint_address)
};
match test_validator {
Ok(_test_validator) => match dashboard {
Some(dashboard) => dashboard.run(),
None => std::thread::park(),
},
Err(err) => {
drop(dashboard);
println!("Error: failed to start validator: {}", err);
@ -418,10 +427,10 @@ fn main() {
fn remove_directory_contents(ledger_path: &Path) -> Result<(), io::Error> {
for entry in fs::read_dir(&ledger_path)? {
let entry = entry?;
if entry.metadata()?.is_file() {
fs::remove_file(&entry.path())?
} else {
if entry.metadata()?.is_dir() {
fs::remove_dir_all(&entry.path())?
} else {
fs::remove_file(&entry.path())?
}
}
Ok(())

View File

@ -1,8 +1,5 @@
use {
crate::{
get_validator_rpc_addr, get_validator_start_time, new_spinner_progress_bar,
println_name_value,
},
crate::{admin_rpc_service, new_spinner_progress_bar, println_name_value},
console::style,
indicatif::ProgressBar,
solana_client::{
@ -17,6 +14,10 @@ use {
std::{
io,
path::{Path, PathBuf},
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
thread,
time::Duration,
},
@ -25,136 +26,121 @@ use {
pub struct Dashboard {
progress_bar: ProgressBar,
ledger_path: PathBuf,
exit: Arc<AtomicBool>,
}
impl Dashboard {
pub fn new(ledger_path: &Path, log_path: Option<&Path>) -> Result<Self, io::Error> {
pub fn new(
ledger_path: &Path,
log_path: Option<&Path>,
validator_exit: Option<&mut solana_core::validator::ValidatorExit>,
) -> Result<Self, io::Error> {
println_name_value("Ledger location:", &format!("{}", ledger_path.display()));
if let Some(log_path) = log_path {
println_name_value("Log:", &format!("{}", log_path.display()));
}
let rpc_addr = get_validator_rpc_addr(&ledger_path)?;
if rpc_addr.is_none() {
return Err(io::Error::new(io::ErrorKind::Other, "RPC not available"));
}
let progress_bar = new_spinner_progress_bar();
progress_bar.set_message("Initializing...");
let exit = Arc::new(AtomicBool::new(false));
if let Some(validator_exit) = validator_exit {
let exit = exit.clone();
validator_exit.register_exit(Box::new(move || exit.store(true, Ordering::Relaxed)));
}
Ok(Self {
progress_bar,
exit,
ledger_path: ledger_path.to_path_buf(),
progress_bar,
})
}
pub fn run(self) -> ! {
pub fn run(self) {
let Self {
progress_bar,
exit,
ledger_path,
progress_bar,
..
} = self;
progress_bar.set_message("Connecting...");
let rpc_addr = get_validator_rpc_addr(&ledger_path).unwrap().unwrap();
let rpc_client = RpcClient::new_socket(rpc_addr);
// Wait until RPC starts responding...
loop {
match rpc_client.get_identity() {
Ok(_) => break,
Err(err) => {
progress_bar.set_message(&format!("{}", err));
thread::sleep(Duration::from_millis(500));
}
}
}
drop(progress_bar);
let identity = &rpc_client.get_identity().expect("get_identity");
let mut runtime = admin_rpc_service::runtime();
while !exit.load(Ordering::Relaxed) {
let progress_bar = new_spinner_progress_bar();
progress_bar.set_message("Connecting...");
let (start_time, rpc_client, identity) = loop {
if exit.load(Ordering::Relaxed) {
return;
}
println_name_value("Identity:", &identity.to_string());
let admin_client = admin_rpc_service::connect(&ledger_path);
let (rpc_addr, start_time) = match runtime.block_on(async move {
let admin_client = admin_client.await.map_err(|err| {
format!("Unable to connect to validator process: {}", err)
})?;
fn get_contact_info(rpc_client: &RpcClient, identity: &Pubkey) -> Option<RpcContactInfo> {
rpc_client
.get_cluster_nodes()
.ok()
.unwrap_or_default()
.into_iter()
.find(|node| node.pubkey == identity.to_string())
}
let rpc_addr = admin_client
.rpc_addr()
.await
.map_err(|err| format!("Unable to get validator RPC address: {}", err))?
.ok_or_else(|| "RPC not available".to_string())?;
if let Some(contact_info) = get_contact_info(&rpc_client, &identity) {
println_name_value(
"Version:",
&contact_info.version.unwrap_or_else(|| "?".to_string()),
);
if let Some(gossip) = contact_info.gossip {
println_name_value("Gossip Address:", &gossip.to_string());
}
if let Some(tpu) = contact_info.tpu {
println_name_value("TPU Address:", &tpu.to_string());
}
if let Some(rpc) = contact_info.rpc {
println_name_value("JSON RPC URL:", &format!("http://{}", rpc.to_string()));
}
}
let start_time = admin_client
.start_time()
.await
.map_err(|err| format!("Unable to get validator start time: {}", err))?;
let progress_bar = new_spinner_progress_bar();
Ok::<_, String>((rpc_addr, start_time))
}) {
Ok((rpc_addr, start_time)) => (rpc_addr, start_time),
Err(err) => {
progress_bar.set_message(&format!("Connecting... ({})", err));
thread::sleep(Duration::from_millis(500));
continue;
}
};
fn get_validator_stats(
rpc_client: &RpcClient,
identity: &Pubkey,
) -> client_error::Result<(Slot, Slot, Slot, u64, Sol, String)> {
let processed_slot =
rpc_client.get_slot_with_commitment(CommitmentConfig::processed())?;
let confirmed_slot =
rpc_client.get_slot_with_commitment(CommitmentConfig::confirmed())?;
let finalized_slot =
rpc_client.get_slot_with_commitment(CommitmentConfig::finalized())?;
let transaction_count =
rpc_client.get_transaction_count_with_commitment(CommitmentConfig::processed())?;
let identity_balance = rpc_client
.get_balance_with_commitment(identity, CommitmentConfig::confirmed())?
.value;
let rpc_client = RpcClient::new_socket(rpc_addr);
let health = match rpc_client.get_health() {
Ok(()) => "ok".to_string(),
Err(err) => {
if let client_error::ClientErrorKind::RpcError(
rpc_request::RpcError::RpcResponseError {
code: _,
message: _,
data:
rpc_request::RpcResponseErrorData::NodeUnhealthy {
num_slots_behind: Some(num_slots_behind),
},
},
) = &err.kind
{
format!("{} slots behind", num_slots_behind)
} else {
"unhealthy".to_string()
// Wait until RPC starts responding...
match rpc_client.get_identity() {
Ok(identity) => break (start_time, rpc_client, identity),
Err(err) => {
progress_bar.set_message(&format!("Waiting for RPC... ({})", err));
}
}
};
Ok((
processed_slot,
confirmed_slot,
finalized_slot,
transaction_count,
Sol(identity_balance),
health,
))
}
drop(progress_bar);
println_name_value("Identity:", &identity.to_string());
let mut start_time = get_validator_start_time(&ledger_path).ok();
loop {
let snapshot_slot = rpc_client.get_snapshot_slot().ok();
if let Some(contact_info) = get_contact_info(&rpc_client, &identity) {
println_name_value(
"Version:",
&contact_info.version.unwrap_or_else(|| "?".to_string()),
);
if let Some(gossip) = contact_info.gossip {
println_name_value("Gossip Address:", &gossip.to_string());
}
if let Some(tpu) = contact_info.tpu {
println_name_value("TPU Address:", &tpu.to_string());
}
if let Some(rpc) = contact_info.rpc {
println_name_value("JSON RPC URL:", &format!("http://{}", rpc.to_string()));
}
}
let progress_bar = new_spinner_progress_bar();
let mut snapshot_slot = None;
for i in 0.. {
if exit.load(Ordering::Relaxed) {
break;
}
if i % 10 == 0 {
snapshot_slot = rpc_client.get_snapshot_slot().ok();
}
for _i in 0..10 {
match get_validator_stats(&rpc_client, &identity) {
Ok((
processed_slot,
@ -164,27 +150,23 @@ impl Dashboard {
identity_balance,
health,
)) => {
let uptime = match start_time {
Some(start_time) => {
let uptime =
chrono::Duration::from_std(start_time.elapsed().unwrap())
.unwrap();
let uptime = {
let uptime =
chrono::Duration::from_std(start_time.elapsed().unwrap()).unwrap();
format!(
"{:02}:{:02}:{:02} ",
uptime.num_hours(),
uptime.num_minutes() % 60,
uptime.num_seconds() % 60
)
}
None => " ".to_string(),
format!(
"{:02}:{:02}:{:02} ",
uptime.num_hours(),
uptime.num_minutes() % 60,
uptime.num_seconds() % 60
)
};
progress_bar.set_message(&format!(
"{}{}| \
Processed Slot: {} | Confirmed Slot: {} | Finalized Slot: {} | \
Snapshot Slot: {} | \
Transactions: {} | {}",
Processed Slot: {} | Confirmed Slot: {} | Finalized Slot: {} | \
Snapshot Slot: {} | \
Transactions: {} | {}",
uptime,
if health == "ok" {
"".to_string()
@ -200,16 +182,70 @@ impl Dashboard {
transaction_count,
identity_balance
));
thread::sleep(Duration::from_millis(
MS_PER_TICK * DEFAULT_TICKS_PER_SLOT / 2,
));
}
Err(err) => {
start_time = get_validator_start_time(&ledger_path).ok();
progress_bar.set_message(&format!("{}", err));
progress_bar
.abandon_with_message(&format!("RPC connection failure: {}", err));
break;
}
}
thread::sleep(Duration::from_millis(
MS_PER_TICK * DEFAULT_TICKS_PER_SLOT / 2,
));
}
}
}
}
fn get_contact_info(rpc_client: &RpcClient, identity: &Pubkey) -> Option<RpcContactInfo> {
rpc_client
.get_cluster_nodes()
.ok()
.unwrap_or_default()
.into_iter()
.find(|node| node.pubkey == identity.to_string())
}
fn get_validator_stats(
rpc_client: &RpcClient,
identity: &Pubkey,
) -> client_error::Result<(Slot, Slot, Slot, u64, Sol, String)> {
let processed_slot = rpc_client.get_slot_with_commitment(CommitmentConfig::processed())?;
let confirmed_slot = rpc_client.get_slot_with_commitment(CommitmentConfig::confirmed())?;
let finalized_slot = rpc_client.get_slot_with_commitment(CommitmentConfig::finalized())?;
let transaction_count =
rpc_client.get_transaction_count_with_commitment(CommitmentConfig::processed())?;
let identity_balance = rpc_client
.get_balance_with_commitment(identity, CommitmentConfig::confirmed())?
.value;
let health = match rpc_client.get_health() {
Ok(()) => "ok".to_string(),
Err(err) => {
if let client_error::ClientErrorKind::RpcError(
rpc_request::RpcError::RpcResponseError {
code: _,
message: _,
data:
rpc_request::RpcResponseErrorData::NodeUnhealthy {
num_slots_behind: Some(num_slots_behind),
},
},
) = &err.kind
{
format!("{} slots behind", num_slots_behind)
} else {
"unhealthy".to_string()
}
}
};
Ok((
processed_slot,
confirmed_slot,
finalized_slot,
transaction_count,
Sol(identity_balance),
health,
))
}

View File

@ -4,19 +4,10 @@ use {
console::style,
indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle},
log::*,
serde_derive::{Deserialize, Serialize},
std::{
env,
fs::{self, File},
io::{self, Write},
net::SocketAddr,
path::Path,
process::exit,
thread::JoinHandle,
time::{Duration, SystemTime},
},
std::{env, process::exit, thread::JoinHandle},
};
pub mod admin_rpc_service;
pub mod dashboard;
#[cfg(unix)]
@ -91,52 +82,6 @@ pub fn port_validator(port: String) -> Result<(), String> {
.map_err(|e| format!("{:?}", e))
}
#[derive(Serialize, Deserialize, Clone, Debug)]
struct ProcessInfo {
rpc_addr: Option<SocketAddr>, // RPC port to contact the validator at
start_time: u64, // Seconds since the UNIX_EPOCH for when the validator was started
}
pub fn record_start(ledger_path: &Path, rpc_addr: Option<&SocketAddr>) -> Result<(), io::Error> {
if !ledger_path.exists() {
fs::create_dir_all(&ledger_path)?;
}
let start_info = ProcessInfo {
rpc_addr: rpc_addr.cloned(),
start_time: SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_secs(),
};
let serialized = serde_yaml::to_string(&start_info)
.map_err(|err| io::Error::new(io::ErrorKind::Other, format!("{:?}", err)))?;
let mut file = File::create(ledger_path.join("process-info.yml"))?;
file.write_all(&serialized.into_bytes())?;
Ok(())
}
fn get_validator_process_info(
ledger_path: &Path,
) -> Result<(Option<SocketAddr>, SystemTime), io::Error> {
let file = File::open(ledger_path.join("process-info.yml"))?;
let config: ProcessInfo = serde_yaml::from_reader(file)
.map_err(|err| io::Error::new(io::ErrorKind::Other, format!("{:?}", err)))?;
let start_time = SystemTime::UNIX_EPOCH + Duration::from_secs(config.start_time);
Ok((config.rpc_addr, start_time))
}
pub fn get_validator_rpc_addr(ledger_path: &Path) -> Result<Option<SocketAddr>, io::Error> {
get_validator_process_info(ledger_path).map(|process_info| process_info.0)
}
pub fn get_validator_start_time(ledger_path: &Path) -> Result<SystemTime, io::Error> {
get_validator_process_info(ledger_path).map(|process_info| process_info.1)
}
/// Creates a new process bar for processing that will take an unknown amount of time
pub fn new_spinner_progress_bar() -> ProgressBar {
let progress_bar = ProgressBar::new(42);

View File

@ -46,8 +46,8 @@ use solana_sdk::{
signature::{Keypair, Signer},
};
use solana_validator::{
dashboard::Dashboard, get_validator_rpc_addr, new_spinner_progress_bar, println_name_value,
record_start, redirect_stderr_to_file,
admin_rpc_service, dashboard::Dashboard, new_spinner_progress_bar, println_name_value,
redirect_stderr_to_file,
};
use std::{
collections::{HashSet, VecDeque},
@ -67,9 +67,11 @@ use std::{
#[derive(Debug, PartialEq)]
enum Operation {
Exit,
Initialize,
Monitor,
Run,
SetLogFilter { filter: String },
WaitForRestartWindow { min_idle_time_in_minutes: usize },
}
@ -82,13 +84,10 @@ fn wait_for_restart_window(
let min_idle_slots = (min_idle_time_in_minutes as f64 * 60. / DEFAULT_S_PER_SLOT) as Slot;
let rpc_addr = get_validator_rpc_addr(&ledger_path).map_err(|err| {
format!(
"Unable to read validator RPC address from {}: {}",
ledger_path.display(),
err
)
})?;
let admin_client = admin_rpc_service::connect(&ledger_path);
let rpc_addr = admin_rpc_service::runtime()
.block_on(async move { admin_client.await?.rpc_addr().await })
.map_err(|err| format!("Unable to get validator RPC address: {}", err))?;
let rpc_client = match rpc_addr {
None => return Err("RPC not available".into()),
@ -1085,7 +1084,13 @@ pub fn main() {
.value_name("PORT")
.takes_value(true)
.validator(solana_validator::port_validator)
.help("Use this port for JSON RPC and the next port for the RPC websocket"),
.help("Enable JSON RPC on this port, and the next port for the RPC websocket"),
)
.arg(
Arg::with_name("minimal_rpc_api")
.long("--minimal-rpc-api")
.takes_value(false)
.help("Only expose the RPC methods required to serve snapshots to other nodes"),
)
.arg(
Arg::with_name("private_rpc")
@ -1099,20 +1104,6 @@ pub fn main() {
.takes_value(false)
.help("Do not perform TCP/UDP reachable port checks at start-up")
)
.arg(
Arg::with_name("enable_rpc_exit")
.long("enable-rpc-exit")
.takes_value(false)
.help("Enable the JSON RPC 'validatorExit' API. \
Only enable in a debug environment"),
)
.arg(
Arg::with_name("enable_rpc_set_log_filter")
.long("enable-rpc-set-log-filter")
.takes_value(false)
.help("Enable the JSON RPC 'setLogFilter' API. \
Only enable in a debug environment"),
)
.arg(
Arg::with_name("enable_rpc_transaction_history")
.long("enable-rpc-transaction-history")
@ -1645,17 +1636,32 @@ pub fn main() {
.hidden(true),
)
.after_help("The default subcommand is run")
.subcommand(
SubCommand::with_name("exit")
.about("Send an exit request to the validator")
)
.subcommand(
SubCommand::with_name("init")
.about("Initialize the ledger directory then exit")
)
.subcommand(
SubCommand::with_name("monitor")
.about("Monitor the validator")
)
.subcommand(
SubCommand::with_name("run")
.about("Run the validator")
)
.subcommand(
SubCommand::with_name("monitor")
.about("Monitor the validator")
SubCommand::with_name("set-log-filter")
.about("Adjust the validator log filter")
.arg(
Arg::with_name("filter")
.takes_value(true)
.index(1)
.help("New filter using the same format as the RUST_LOG environment variable")
)
.after_help("Note: the new filter only applies to the currently running validator instance")
)
.subcommand(
SubCommand::with_name("wait-for-restart-window")
@ -1675,8 +1681,12 @@ pub fn main() {
let operation = match matches.subcommand() {
("", _) | ("run", _) => Operation::Run,
("exit", _) => Operation::Exit,
("init", _) => Operation::Initialize,
("monitor", _) => Operation::Monitor,
("set-log-filter", Some(subcommand_matches)) => Operation::SetLogFilter {
filter: value_t_or_exit!(subcommand_matches, "filter", String),
},
("wait-for-restart-window", Some(subcommand_matches)) => Operation::WaitForRestartWindow {
min_idle_time_in_minutes: value_t_or_exit!(
subcommand_matches,
@ -1792,8 +1802,6 @@ pub fn main() {
expected_shred_version: value_t!(matches, "expected_shred_version", u16).ok(),
new_hard_forks: hardforks_of(&matches, "hard_forks"),
rpc_config: JsonRpcConfig {
enable_validator_exit: matches.is_present("enable_rpc_exit"),
enable_set_log_filter: matches.is_present("enable_rpc_set_log_filter"),
enable_rpc_transaction_history: matches.is_present("enable_rpc_transaction_history"),
enable_cpi_and_log_storage: matches.is_present("enable_cpi_and_log_storage"),
enable_bigtable_ledger_storage: matches
@ -1803,6 +1811,7 @@ pub fn main() {
faucet_addr: matches.value_of("rpc_faucet_addr").map(|address| {
solana_net_utils::parse_host_port(address).expect("failed to parse faucet address")
}),
minimal_api: matches.is_present("minimal_rpc_api"),
max_multiple_accounts: Some(value_t_or_exit!(
matches,
"rpc_max_multiple_accounts",
@ -2038,8 +2047,28 @@ pub fn main() {
});
match operation {
Operation::Exit => {
let admin_client = admin_rpc_service::connect(&ledger_path);
admin_rpc_service::runtime()
.block_on(async move { admin_client.await?.exit().await })
.unwrap_or_else(|err| {
println!("exit request failed: {}", err);
exit(1);
});
exit(0);
}
Operation::SetLogFilter { filter } => {
let admin_client = admin_rpc_service::connect(&ledger_path);
admin_rpc_service::runtime()
.block_on(async move { admin_client.await?.set_log_filter(filter).await })
.unwrap_or_else(|err| {
println!("set log filter failed: {}", err);
exit(1);
});
exit(0);
}
Operation::Monitor => {
let dashboard = Dashboard::new(&ledger_path, None).unwrap_or_else(|err| {
let dashboard = Dashboard::new(&ledger_path, None, None).unwrap_or_else(|err| {
println!(
"Error: Unable to connect to validator at {}: {:?}",
ledger_path.display(),
@ -2070,15 +2099,6 @@ pub fn main() {
exit(1);
});
record_start(
&ledger_path,
validator_config
.rpc_addrs
.as_ref()
.map(|(rpc_addr, _)| rpc_addr),
)
.unwrap_or_else(|err| println!("Error: failed to record validator start: {}", err));
let logfile = {
let logfile = matches
.value_of("logfile")
@ -2098,6 +2118,15 @@ pub fn main() {
info!("{} {}", crate_name!(), solana_version::version!());
info!("Starting validator with: {:#?}", std::env::args_os());
admin_rpc_service::run(
&ledger_path,
admin_rpc_service::AdminRpcRequestMetadata {
rpc_addr: validator_config.rpc_addrs.map(|(rpc_addr, _)| rpc_addr),
start_time: std::time::SystemTime::now(),
validator_exit: validator_config.validator_exit.clone(),
},
);
let gossip_host: IpAddr = matches
.value_of("gossip_host")
.map(|gossip_host| {