validator: add contact-info query to admin port
This commit is contained in:
committed by
mergify[bot]
parent
d06c04d02c
commit
b93ab5d295
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -5970,6 +5970,8 @@ dependencies = [
|
|||||||
"log 0.4.14",
|
"log 0.4.14",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"rand 0.7.3",
|
"rand 0.7.3",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"signal-hook",
|
"signal-hook",
|
||||||
"solana-clap-utils",
|
"solana-clap-utils",
|
||||||
"solana-cli-config",
|
"solana-cli-config",
|
||||||
|
@ -25,6 +25,8 @@ jsonrpc-server-utils= "18.0.0"
|
|||||||
log = "0.4.14"
|
log = "0.4.14"
|
||||||
num_cpus = "1.13.1"
|
num_cpus = "1.13.1"
|
||||||
rand = "0.7.0"
|
rand = "0.7.0"
|
||||||
|
serde = "1.0.132"
|
||||||
|
serde_json = "1.0.73"
|
||||||
solana-clap-utils = { path = "../clap-utils", version = "=1.10.0" }
|
solana-clap-utils = { path = "../clap-utils", version = "=1.10.0" }
|
||||||
solana-cli-config = { path = "../cli-config", version = "=1.10.0" }
|
solana-cli-config = { path = "../cli-config", version = "=1.10.0" }
|
||||||
solana-client = { path = "../client", version = "=1.10.0" }
|
solana-client = { path = "../client", version = "=1.10.0" }
|
||||||
|
@ -5,15 +5,17 @@ use {
|
|||||||
jsonrpc_ipc_server::{RequestContext, ServerBuilder},
|
jsonrpc_ipc_server::{RequestContext, ServerBuilder},
|
||||||
jsonrpc_server_utils::tokio,
|
jsonrpc_server_utils::tokio,
|
||||||
log::*,
|
log::*,
|
||||||
|
serde::{Deserialize, Serialize},
|
||||||
solana_core::{
|
solana_core::{
|
||||||
consensus::Tower, tower_storage::TowerStorage, validator::ValidatorStartProgress,
|
consensus::Tower, tower_storage::TowerStorage, validator::ValidatorStartProgress,
|
||||||
},
|
},
|
||||||
solana_gossip::cluster_info::ClusterInfo,
|
solana_gossip::{cluster_info::ClusterInfo, contact_info::ContactInfo},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
exit::Exit,
|
exit::Exit,
|
||||||
signature::{read_keypair_file, Keypair, Signer},
|
signature::{read_keypair_file, Keypair, Signer},
|
||||||
},
|
},
|
||||||
std::{
|
std::{
|
||||||
|
fmt::{self, Display},
|
||||||
net::SocketAddr,
|
net::SocketAddr,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::{Arc, RwLock},
|
sync::{Arc, RwLock},
|
||||||
@ -34,6 +36,76 @@ pub struct AdminRpcRequestMetadata {
|
|||||||
}
|
}
|
||||||
impl Metadata for AdminRpcRequestMetadata {}
|
impl Metadata for AdminRpcRequestMetadata {}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
pub struct AdminRpcContactInfo {
|
||||||
|
pub id: String,
|
||||||
|
pub gossip: SocketAddr,
|
||||||
|
pub tvu: SocketAddr,
|
||||||
|
pub tvu_forwards: SocketAddr,
|
||||||
|
pub repair: SocketAddr,
|
||||||
|
pub tpu: SocketAddr,
|
||||||
|
pub tpu_forwards: SocketAddr,
|
||||||
|
pub tpu_vote: SocketAddr,
|
||||||
|
pub rpc: SocketAddr,
|
||||||
|
pub rpc_pubsub: SocketAddr,
|
||||||
|
pub serve_repair: SocketAddr,
|
||||||
|
pub last_updated_timestamp: u64,
|
||||||
|
pub shred_version: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ContactInfo> for AdminRpcContactInfo {
|
||||||
|
fn from(contact_info: ContactInfo) -> Self {
|
||||||
|
let ContactInfo {
|
||||||
|
id,
|
||||||
|
gossip,
|
||||||
|
tvu,
|
||||||
|
tvu_forwards,
|
||||||
|
repair,
|
||||||
|
tpu,
|
||||||
|
tpu_forwards,
|
||||||
|
tpu_vote,
|
||||||
|
rpc,
|
||||||
|
rpc_pubsub,
|
||||||
|
serve_repair,
|
||||||
|
wallclock,
|
||||||
|
shred_version,
|
||||||
|
} = contact_info;
|
||||||
|
Self {
|
||||||
|
id: id.to_string(),
|
||||||
|
last_updated_timestamp: wallclock,
|
||||||
|
gossip,
|
||||||
|
tvu,
|
||||||
|
tvu_forwards,
|
||||||
|
repair,
|
||||||
|
tpu,
|
||||||
|
tpu_forwards,
|
||||||
|
tpu_vote,
|
||||||
|
rpc,
|
||||||
|
rpc_pubsub,
|
||||||
|
serve_repair,
|
||||||
|
shred_version,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for AdminRpcContactInfo {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
writeln!(f, "Identity: {}", self.id)?;
|
||||||
|
writeln!(f, "Gossip: {}", self.gossip)?;
|
||||||
|
writeln!(f, "TVU: {}", self.tvu)?;
|
||||||
|
writeln!(f, "TVU Forwards: {}", self.tvu_forwards)?;
|
||||||
|
writeln!(f, "Repair: {}", self.repair)?;
|
||||||
|
writeln!(f, "TPU: {}", self.tpu)?;
|
||||||
|
writeln!(f, "TPU Forwards: {}", self.tpu_forwards)?;
|
||||||
|
writeln!(f, "TPU Votes: {}", self.tpu_vote)?;
|
||||||
|
writeln!(f, "RPC: {}", self.rpc)?;
|
||||||
|
writeln!(f, "RPC Pubsub: {}", self.rpc_pubsub)?;
|
||||||
|
writeln!(f, "Serve Repair: {}", self.serve_repair)?;
|
||||||
|
writeln!(f, "Last Updated Timestamp: {}", self.last_updated_timestamp)?;
|
||||||
|
writeln!(f, "Shred Version: {}", self.shred_version)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[rpc]
|
#[rpc]
|
||||||
pub trait AdminRpc {
|
pub trait AdminRpc {
|
||||||
type Metadata;
|
type Metadata;
|
||||||
@ -61,6 +133,9 @@ pub trait AdminRpc {
|
|||||||
|
|
||||||
#[rpc(meta, name = "setIdentity")]
|
#[rpc(meta, name = "setIdentity")]
|
||||||
fn set_identity(&self, meta: Self::Metadata, keypair_file: String) -> Result<()>;
|
fn set_identity(&self, meta: Self::Metadata, keypair_file: String) -> Result<()>;
|
||||||
|
|
||||||
|
#[rpc(meta, name = "contactInfo")]
|
||||||
|
fn contact_info(&self, meta: Self::Metadata) -> Result<AdminRpcContactInfo>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AdminRpcImpl;
|
pub struct AdminRpcImpl;
|
||||||
@ -167,6 +242,16 @@ impl AdminRpc for AdminRpcImpl {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn contact_info(&self, meta: Self::Metadata) -> Result<AdminRpcContactInfo> {
|
||||||
|
if let Some(cluster_info) = meta.cluster_info.read().unwrap().as_ref() {
|
||||||
|
Ok(cluster_info.my_contact_info().into())
|
||||||
|
} else {
|
||||||
|
Err(jsonrpc_core::error::Error::invalid_params(
|
||||||
|
"Retry once validator start up is complete",
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the Admin RPC interface
|
// Start the Admin RPC interface
|
||||||
|
@ -1682,6 +1682,18 @@ pub fn main() {
|
|||||||
currently running validator instance")
|
currently running validator instance")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("contact-info")
|
||||||
|
.about("Display the validator's contact info")
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("output")
|
||||||
|
.long("output")
|
||||||
|
.takes_value(true)
|
||||||
|
.value_name("MODE")
|
||||||
|
.possible_values(&["json", "json-compact"])
|
||||||
|
.help("Output display mode")
|
||||||
|
)
|
||||||
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("init")
|
SubCommand::with_name("init")
|
||||||
.about("Initialize the ledger directory then exit")
|
.about("Initialize the ledger directory then exit")
|
||||||
@ -1809,6 +1821,26 @@ pub fn main() {
|
|||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
("contact-info", Some(subcommand_matches)) => {
|
||||||
|
let output_mode = subcommand_matches.value_of("output");
|
||||||
|
let admin_client = admin_rpc_service::connect(&ledger_path);
|
||||||
|
let contact_info = admin_rpc_service::runtime()
|
||||||
|
.block_on(async move { admin_client.await?.contact_info().await })
|
||||||
|
.unwrap_or_else(|err| {
|
||||||
|
eprintln!("Contact info query failed: {}", err);
|
||||||
|
exit(1);
|
||||||
|
});
|
||||||
|
if let Some(mode) = output_mode {
|
||||||
|
match mode {
|
||||||
|
"json" => println!("{}", serde_json::to_string_pretty(&contact_info).unwrap()),
|
||||||
|
"json-compact" => print!("{}", serde_json::to_string(&contact_info).unwrap()),
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print!("{}", contact_info);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
("init", _) => Operation::Initialize,
|
("init", _) => Operation::Initialize,
|
||||||
("exit", Some(subcommand_matches)) => {
|
("exit", Some(subcommand_matches)) => {
|
||||||
let min_idle_time = value_t_or_exit!(subcommand_matches, "min_idle_time", usize);
|
let min_idle_time = value_t_or_exit!(subcommand_matches, "min_idle_time", usize);
|
||||||
|
Reference in New Issue
Block a user