Break up RPC API into three categories: minimal, full and admin
This commit is contained in:
41
Cargo.lock
generated
41
Cargo.lock
generated
@ -2000,7 +2000,9 @@ dependencies = [
|
|||||||
"futures 0.3.8",
|
"futures 0.3.8",
|
||||||
"jsonrpc-core",
|
"jsonrpc-core",
|
||||||
"jsonrpc-pubsub",
|
"jsonrpc-pubsub",
|
||||||
|
"jsonrpc-server-utils",
|
||||||
"log 0.4.11",
|
"log 0.4.11",
|
||||||
|
"parity-tokio-ipc",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tokio 0.2.22",
|
"tokio 0.2.22",
|
||||||
@ -2059,6 +2061,21 @@ dependencies = [
|
|||||||
"unicase 2.6.0",
|
"unicase 2.6.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "jsonrpc-ipc-server"
|
||||||
|
version = "17.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "14c4cd89e5ea7e7f0884e828fc35bb83591a371b92439675eae28efa66c24a97"
|
||||||
|
dependencies = [
|
||||||
|
"futures 0.3.8",
|
||||||
|
"jsonrpc-core",
|
||||||
|
"jsonrpc-server-utils",
|
||||||
|
"log 0.4.11",
|
||||||
|
"parity-tokio-ipc",
|
||||||
|
"parking_lot 0.11.0",
|
||||||
|
"tower-service",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jsonrpc-pubsub"
|
name = "jsonrpc-pubsub"
|
||||||
version = "17.0.0"
|
version = "17.0.0"
|
||||||
@ -2667,6 +2684,22 @@ dependencies = [
|
|||||||
"syn 1.0.60",
|
"syn 1.0.60",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parity-tokio-ipc"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fd7f6c69d7687501b2205fe51ade1d7b8797bb3aa141fe5bf13dd78c0483bc89"
|
||||||
|
dependencies = [
|
||||||
|
"futures 0.3.8",
|
||||||
|
"libc",
|
||||||
|
"log 0.4.11",
|
||||||
|
"mio-named-pipes",
|
||||||
|
"miow 0.3.6",
|
||||||
|
"rand 0.7.3",
|
||||||
|
"tokio 0.2.22",
|
||||||
|
"winapi 0.3.8",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parity-ws"
|
name = "parity-ws"
|
||||||
version = "0.10.0"
|
version = "0.10.0"
|
||||||
@ -4590,7 +4623,6 @@ version = "1.6.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"solana-clap-utils",
|
"solana-clap-utils",
|
||||||
"solana-client",
|
|
||||||
"solana-core",
|
"solana-core",
|
||||||
"solana-logger 1.6.0",
|
"solana-logger 1.6.0",
|
||||||
"solana-net-utils",
|
"solana-net-utils",
|
||||||
@ -5465,13 +5497,16 @@ dependencies = [
|
|||||||
"core_affinity",
|
"core_affinity",
|
||||||
"fd-lock",
|
"fd-lock",
|
||||||
"indicatif",
|
"indicatif",
|
||||||
|
"jsonrpc-core",
|
||||||
|
"jsonrpc-core-client",
|
||||||
|
"jsonrpc-derive",
|
||||||
|
"jsonrpc-ipc-server",
|
||||||
|
"jsonrpc-server-utils",
|
||||||
"libc",
|
"libc",
|
||||||
"log 0.4.11",
|
"log 0.4.11",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"rand 0.7.3",
|
"rand 0.7.3",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
|
||||||
"serde_yaml",
|
|
||||||
"signal-hook",
|
"signal-hook",
|
||||||
"solana-clap-utils",
|
"solana-clap-utils",
|
||||||
"solana-cli-config",
|
"solana-cli-config",
|
||||||
|
@ -78,7 +78,6 @@ nodes=(
|
|||||||
--init-complete-file init-complete-node0.log \
|
--init-complete-file init-complete-node0.log \
|
||||||
--dynamic-port-range 8000-8050"
|
--dynamic-port-range 8000-8050"
|
||||||
"multinode-demo/validator.sh \
|
"multinode-demo/validator.sh \
|
||||||
--enable-rpc-exit \
|
|
||||||
--no-restart \
|
--no-restart \
|
||||||
--dynamic-port-range 8050-8100
|
--dynamic-port-range 8050-8100
|
||||||
--init-complete-file init-complete-node1.log \
|
--init-complete-file init-complete-node1.log \
|
||||||
@ -201,17 +200,10 @@ killNodes() {
|
|||||||
[[ ${#pids[@]} -gt 0 ]] || return
|
[[ ${#pids[@]} -gt 0 ]] || return
|
||||||
|
|
||||||
# Try to use the RPC exit API to cleanly exit the first two nodes
|
# Try to use the RPC exit API to cleanly exit the first two nodes
|
||||||
# (dynamic nodes, -x, are just killed since their RPC port is not known)
|
# (dynamic nodes, -x, are just killed)
|
||||||
echo "--- RPC exit"
|
echo "--- RPC exit"
|
||||||
for port in 8899 18899; do
|
$solana_validator --ledger "$SOLANA_CONFIG_DIR"/bootstrap-validator exit || true
|
||||||
(
|
$solana_validator --ledger "$SOLANA_CONFIG_DIR"/validator exit || true
|
||||||
set -x
|
|
||||||
curl --retry 5 --retry-delay 2 --retry-connrefused \
|
|
||||||
-X POST -H 'Content-Type: application/json' \
|
|
||||||
-d '{"jsonrpc":"2.0","id":1, "method":"validatorExit"}' \
|
|
||||||
http://localhost:$port
|
|
||||||
)
|
|
||||||
done
|
|
||||||
|
|
||||||
# Give the nodes a splash of time to cleanly exit before killing them
|
# Give the nodes a splash of time to cleanly exit before killing them
|
||||||
sleep 2
|
sleep 2
|
||||||
|
@ -25,7 +25,8 @@ snapshot_slot=1
|
|||||||
while [[ $($solana_cli --url http://localhost:8899 slot --commitment recent) -le $((snapshot_slot + 1)) ]]; do
|
while [[ $($solana_cli --url http://localhost:8899 slot --commitment recent) -le $((snapshot_slot + 1)) ]]; do
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
curl -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":1, "method":"validatorExit"}' http://localhost:8899
|
|
||||||
|
$solana_validator --ledger config/ledger exit || true
|
||||||
|
|
||||||
wait $pid
|
wait $pid
|
||||||
|
|
||||||
|
@ -1505,10 +1505,6 @@ impl RpcClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn validator_exit(&self) -> ClientResult<bool> {
|
|
||||||
self.send(RpcRequest::ValidatorExit, Value::Null)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn send<T>(&self, request: RpcRequest, params: Value) -> ClientResult<T>
|
pub fn send<T>(&self, request: RpcRequest, params: Value) -> ClientResult<T>
|
||||||
where
|
where
|
||||||
T: serde::de::DeserializeOwned,
|
T: serde::de::DeserializeOwned,
|
||||||
|
@ -7,7 +7,6 @@ use thiserror::Error;
|
|||||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
|
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
|
||||||
pub enum RpcRequest {
|
pub enum RpcRequest {
|
||||||
DeregisterNode,
|
DeregisterNode,
|
||||||
ValidatorExit,
|
|
||||||
GetAccountInfo,
|
GetAccountInfo,
|
||||||
GetBalance,
|
GetBalance,
|
||||||
GetBlockTime,
|
GetBlockTime,
|
||||||
@ -64,7 +63,6 @@ impl fmt::Display for RpcRequest {
|
|||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let method = match self {
|
let method = match self {
|
||||||
RpcRequest::DeregisterNode => "deregisterNode",
|
RpcRequest::DeregisterNode => "deregisterNode",
|
||||||
RpcRequest::ValidatorExit => "validatorExit",
|
|
||||||
RpcRequest::GetAccountInfo => "getAccountInfo",
|
RpcRequest::GetAccountInfo => "getAccountInfo",
|
||||||
RpcRequest::GetBalance => "getBalance",
|
RpcRequest::GetBalance => "getBalance",
|
||||||
RpcRequest::GetBlockTime => "getBlockTime",
|
RpcRequest::GetBlockTime => "getBlockTime",
|
||||||
|
@ -309,10 +309,6 @@ impl ThinClient {
|
|||||||
.map_err(|e| e.into())
|
.map_err(|e| e.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn validator_exit(&self) -> TransportResult<bool> {
|
|
||||||
self.rpc_client().validator_exit().map_err(|e| e.into())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_num_blocks_since_signature_confirmation(
|
pub fn get_num_blocks_since_signature_confirmation(
|
||||||
&mut self,
|
&mut self,
|
||||||
sig: &Signature,
|
sig: &Signature,
|
||||||
|
@ -29,7 +29,7 @@ flate2 = "1.0"
|
|||||||
indexmap = { version = "1.5", features = ["rayon"] }
|
indexmap = { version = "1.5", features = ["rayon"] }
|
||||||
itertools = "0.9.0"
|
itertools = "0.9.0"
|
||||||
jsonrpc-core = "17.0.0"
|
jsonrpc-core = "17.0.0"
|
||||||
jsonrpc-core-client = { version = "17.0.0", features = ["ws"] }
|
jsonrpc-core-client = { version = "17.0.0", features = ["ipc", "ws"] }
|
||||||
jsonrpc-derive = "17.0.0"
|
jsonrpc-derive = "17.0.0"
|
||||||
jsonrpc-http-server = "17.0.0"
|
jsonrpc-http-server = "17.0.0"
|
||||||
jsonrpc-pubsub = "17.0.0"
|
jsonrpc-pubsub = "17.0.0"
|
||||||
|
2432
core/src/rpc.rs
2432
core/src/rpc.rs
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,7 @@ use crate::{
|
|||||||
max_slots::MaxSlots,
|
max_slots::MaxSlots,
|
||||||
optimistically_confirmed_bank_tracker::OptimisticallyConfirmedBank,
|
optimistically_confirmed_bank_tracker::OptimisticallyConfirmedBank,
|
||||||
poh_recorder::PohRecorder,
|
poh_recorder::PohRecorder,
|
||||||
rpc::*,
|
rpc::{rpc_full::*, rpc_minimal::*, *},
|
||||||
rpc_health::*,
|
rpc_health::*,
|
||||||
send_transaction_service::{LeaderInfo, SendTransactionService},
|
send_transaction_service::{LeaderInfo, SendTransactionService},
|
||||||
validator::ValidatorExit,
|
validator::ValidatorExit,
|
||||||
@ -337,6 +337,7 @@ impl JsonRpcService {
|
|||||||
(None, None)
|
(None, None)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let minimal_api = config.minimal_api;
|
||||||
let (request_processor, receiver) = JsonRpcRequestProcessor::new(
|
let (request_processor, receiver) = JsonRpcRequestProcessor::new(
|
||||||
config,
|
config,
|
||||||
snapshot_config.clone(),
|
snapshot_config.clone(),
|
||||||
@ -392,8 +393,11 @@ impl JsonRpcService {
|
|||||||
.name("solana-jsonrpc".to_string())
|
.name("solana-jsonrpc".to_string())
|
||||||
.spawn(move || {
|
.spawn(move || {
|
||||||
let mut io = MetaIoHandler::default();
|
let mut io = MetaIoHandler::default();
|
||||||
let rpc = RpcSolImpl;
|
|
||||||
io.extend_with(rpc.to_delegate());
|
io.extend_with(rpc_minimal::MinimalImpl.to_delegate());
|
||||||
|
if !minimal_api {
|
||||||
|
io.extend_with(rpc_full::FullImpl.to_delegate());
|
||||||
|
}
|
||||||
|
|
||||||
let request_middleware = RpcRequestMiddleware::new(
|
let request_middleware = RpcRequestMiddleware::new(
|
||||||
ledger_path,
|
ledger_path,
|
||||||
|
@ -3,7 +3,7 @@ use {
|
|||||||
cluster_info::Node,
|
cluster_info::Node,
|
||||||
gossip_service::discover_cluster,
|
gossip_service::discover_cluster,
|
||||||
rpc::JsonRpcConfig,
|
rpc::JsonRpcConfig,
|
||||||
validator::{Validator, ValidatorConfig},
|
validator::{Validator, ValidatorConfig, ValidatorExit},
|
||||||
},
|
},
|
||||||
solana_client::rpc_client::RpcClient,
|
solana_client::rpc_client::RpcClient,
|
||||||
solana_ledger::{blockstore::create_new_ledger, create_new_tmp_ledger},
|
solana_ledger::{blockstore::create_new_ledger, create_new_tmp_ledger},
|
||||||
@ -28,7 +28,7 @@ use {
|
|||||||
fs::remove_dir_all,
|
fs::remove_dir_all,
|
||||||
net::{IpAddr, Ipv4Addr, SocketAddr},
|
net::{IpAddr, Ipv4Addr, SocketAddr},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::Arc,
|
sync::{Arc, RwLock},
|
||||||
thread::sleep,
|
thread::sleep,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
},
|
},
|
||||||
@ -52,6 +52,7 @@ pub struct TestValidatorGenesis {
|
|||||||
no_bpf_jit: bool,
|
no_bpf_jit: bool,
|
||||||
accounts: HashMap<Pubkey, Account>,
|
accounts: HashMap<Pubkey, Account>,
|
||||||
programs: Vec<ProgramInfo>,
|
programs: Vec<ProgramInfo>,
|
||||||
|
pub validator_exit: Arc<RwLock<ValidatorExit>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TestValidatorGenesis {
|
impl TestValidatorGenesis {
|
||||||
@ -401,6 +402,7 @@ impl TestValidator {
|
|||||||
enforce_ulimit_nofile: false,
|
enforce_ulimit_nofile: false,
|
||||||
warp_slot: config.warp_slot,
|
warp_slot: config.warp_slot,
|
||||||
bpf_jit: !config.no_bpf_jit,
|
bpf_jit: !config.no_bpf_jit,
|
||||||
|
validator_exit: config.validator_exit.clone(),
|
||||||
..ValidatorConfig::default()
|
..ValidatorConfig::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -417,7 +419,8 @@ impl TestValidator {
|
|||||||
|
|
||||||
// Needed to avoid panics in `solana-responder-gossip` in tests that create a number of
|
// Needed to avoid panics in `solana-responder-gossip` in tests that create a number of
|
||||||
// test validators concurrently...
|
// test validators concurrently...
|
||||||
discover_cluster(&gossip, 1).expect("TestValidator startup failed");
|
discover_cluster(&gossip, 1)
|
||||||
|
.map_err(|err| format!("TestValidator startup failed: {:?}", err))?;
|
||||||
|
|
||||||
// This is a hack to delay until the fees are non-zero for test consistency
|
// This is a hack to delay until the fees are non-zero for test consistency
|
||||||
// (fees from genesis are zero until the first block with a transaction in it is completed
|
// (fees from genesis are zero until the first block with a transaction in it is completed
|
||||||
@ -425,19 +428,24 @@ impl TestValidator {
|
|||||||
{
|
{
|
||||||
let rpc_client =
|
let rpc_client =
|
||||||
RpcClient::new_with_commitment(rpc_url.clone(), CommitmentConfig::processed());
|
RpcClient::new_with_commitment(rpc_url.clone(), CommitmentConfig::processed());
|
||||||
let fee_rate_governor = rpc_client
|
|
||||||
.get_fee_rate_governor()
|
if let Ok(result) = rpc_client.get_fee_rate_governor() {
|
||||||
.expect("get_fee_rate_governor")
|
let fee_rate_governor = result.value;
|
||||||
.value;
|
if fee_rate_governor.target_lamports_per_signature > 0 {
|
||||||
if fee_rate_governor.target_lamports_per_signature > 0 {
|
loop {
|
||||||
while rpc_client
|
match rpc_client.get_recent_blockhash() {
|
||||||
.get_recent_blockhash()
|
Ok((_blockhash, fee_calculator)) => {
|
||||||
.expect("get_recent_blockhash")
|
if fee_calculator.lamports_per_signature != 0 {
|
||||||
.1
|
break;
|
||||||
.lamports_per_signature
|
}
|
||||||
== 0
|
}
|
||||||
{
|
Err(err) => {
|
||||||
sleep(Duration::from_millis(DEFAULT_MS_PER_SLOT));
|
warn!("get_recent_blockhash() failed: {:?}", err);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sleep(Duration::from_millis(DEFAULT_MS_PER_SLOT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -490,6 +498,12 @@ impl TestValidator {
|
|||||||
|
|
||||||
(rpc_client, recent_blockhash, fee_calculator)
|
(rpc_client, recent_blockhash, fee_calculator)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn join(mut self) {
|
||||||
|
if let Some(validator) = self.validator.take() {
|
||||||
|
validator.join();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for TestValidator {
|
impl Drop for TestValidator {
|
||||||
|
@ -188,15 +188,21 @@ impl Default for ValidatorConfig {
|
|||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct ValidatorExit {
|
pub struct ValidatorExit {
|
||||||
|
exited: bool,
|
||||||
exits: Vec<Box<dyn FnOnce() + Send + Sync>>,
|
exits: Vec<Box<dyn FnOnce() + Send + Sync>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ValidatorExit {
|
impl ValidatorExit {
|
||||||
pub fn register_exit(&mut self, exit: Box<dyn FnOnce() + Send + Sync>) {
|
pub fn register_exit(&mut self, exit: Box<dyn FnOnce() + Send + Sync>) {
|
||||||
self.exits.push(exit);
|
if self.exited {
|
||||||
|
exit();
|
||||||
|
} else {
|
||||||
|
self.exits.push(exit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exit(&mut self) {
|
pub fn exit(&mut self) {
|
||||||
|
self.exited = true;
|
||||||
for exit in self.exits.drain(..) {
|
for exit in self.exits.drain(..) {
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
@ -219,16 +225,12 @@ struct TransactionHistoryServices {
|
|||||||
cache_block_time_service: Option<CacheBlockTimeService>,
|
cache_block_time_service: Option<CacheBlockTimeService>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RpcServices {
|
|
||||||
json_rpc_service: JsonRpcService,
|
|
||||||
pubsub_service: PubSubService,
|
|
||||||
optimistically_confirmed_bank_tracker: OptimisticallyConfirmedBankTracker,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Validator {
|
pub struct Validator {
|
||||||
pub id: Pubkey,
|
pub id: Pubkey,
|
||||||
validator_exit: Arc<RwLock<ValidatorExit>>,
|
validator_exit: Arc<RwLock<ValidatorExit>>,
|
||||||
rpc_service: Option<RpcServices>,
|
json_rpc_service: Option<JsonRpcService>,
|
||||||
|
pubsub_service: Option<PubSubService>,
|
||||||
|
optimistically_confirmed_bank_tracker: Option<OptimisticallyConfirmedBankTracker>,
|
||||||
transaction_status_service: Option<TransactionStatusService>,
|
transaction_status_service: Option<TransactionStatusService>,
|
||||||
rewards_recorder_service: Option<RewardsRecorderService>,
|
rewards_recorder_service: Option<RewardsRecorderService>,
|
||||||
cache_block_time_service: Option<CacheBlockTimeService>,
|
cache_block_time_service: Option<CacheBlockTimeService>,
|
||||||
@ -475,9 +477,12 @@ impl Validator {
|
|||||||
let poh_recorder = Arc::new(Mutex::new(poh_recorder));
|
let poh_recorder = Arc::new(Mutex::new(poh_recorder));
|
||||||
|
|
||||||
let rpc_override_health_check = Arc::new(AtomicBool::new(false));
|
let rpc_override_health_check = Arc::new(AtomicBool::new(false));
|
||||||
let (rpc_service, bank_notification_sender) = if let Some((rpc_addr, rpc_pubsub_addr)) =
|
let (
|
||||||
config.rpc_addrs
|
json_rpc_service,
|
||||||
{
|
pubsub_service,
|
||||||
|
optimistically_confirmed_bank_tracker,
|
||||||
|
bank_notification_sender,
|
||||||
|
) = if let Some((rpc_addr, rpc_pubsub_addr)) = config.rpc_addrs {
|
||||||
if ContactInfo::is_valid_address(&node.info.rpc) {
|
if ContactInfo::is_valid_address(&node.info.rpc) {
|
||||||
assert!(ContactInfo::is_valid_address(&node.info.rpc_pubsub));
|
assert!(ContactInfo::is_valid_address(&node.info.rpc_pubsub));
|
||||||
} else {
|
} else {
|
||||||
@ -485,44 +490,46 @@ impl Validator {
|
|||||||
}
|
}
|
||||||
let (bank_notification_sender, bank_notification_receiver) = unbounded();
|
let (bank_notification_sender, bank_notification_receiver) = unbounded();
|
||||||
(
|
(
|
||||||
Some(RpcServices {
|
Some(JsonRpcService::new(
|
||||||
json_rpc_service: JsonRpcService::new(
|
rpc_addr,
|
||||||
rpc_addr,
|
config.rpc_config.clone(),
|
||||||
config.rpc_config.clone(),
|
config.snapshot_config.clone(),
|
||||||
config.snapshot_config.clone(),
|
bank_forks.clone(),
|
||||||
bank_forks.clone(),
|
block_commitment_cache.clone(),
|
||||||
block_commitment_cache.clone(),
|
blockstore.clone(),
|
||||||
blockstore.clone(),
|
cluster_info.clone(),
|
||||||
cluster_info.clone(),
|
Some(poh_recorder.clone()),
|
||||||
Some(poh_recorder.clone()),
|
genesis_config.hash(),
|
||||||
genesis_config.hash(),
|
ledger_path,
|
||||||
ledger_path,
|
config.validator_exit.clone(),
|
||||||
config.validator_exit.clone(),
|
config.trusted_validators.clone(),
|
||||||
config.trusted_validators.clone(),
|
rpc_override_health_check.clone(),
|
||||||
rpc_override_health_check.clone(),
|
optimistically_confirmed_bank.clone(),
|
||||||
optimistically_confirmed_bank.clone(),
|
config.send_transaction_retry_ms,
|
||||||
config.send_transaction_retry_ms,
|
config.send_transaction_leader_forward_count,
|
||||||
config.send_transaction_leader_forward_count,
|
max_slots.clone(),
|
||||||
max_slots.clone(),
|
)),
|
||||||
),
|
if config.rpc_config.minimal_api {
|
||||||
pubsub_service: PubSubService::new(
|
None
|
||||||
|
} else {
|
||||||
|
Some(PubSubService::new(
|
||||||
config.pubsub_config.clone(),
|
config.pubsub_config.clone(),
|
||||||
&subscriptions,
|
&subscriptions,
|
||||||
rpc_pubsub_addr,
|
rpc_pubsub_addr,
|
||||||
&exit,
|
&exit,
|
||||||
),
|
))
|
||||||
optimistically_confirmed_bank_tracker: OptimisticallyConfirmedBankTracker::new(
|
},
|
||||||
bank_notification_receiver,
|
Some(OptimisticallyConfirmedBankTracker::new(
|
||||||
&exit,
|
bank_notification_receiver,
|
||||||
bank_forks.clone(),
|
&exit,
|
||||||
optimistically_confirmed_bank,
|
bank_forks.clone(),
|
||||||
subscriptions.clone(),
|
optimistically_confirmed_bank,
|
||||||
),
|
subscriptions.clone(),
|
||||||
}),
|
)),
|
||||||
Some(bank_notification_sender),
|
Some(bank_notification_sender),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
(None, None)
|
(None, None, None, None)
|
||||||
};
|
};
|
||||||
|
|
||||||
if config.dev_halt_at_slot.is_some() {
|
if config.dev_halt_at_slot.is_some() {
|
||||||
@ -704,7 +711,9 @@ impl Validator {
|
|||||||
id,
|
id,
|
||||||
gossip_service,
|
gossip_service,
|
||||||
serve_repair_service,
|
serve_repair_service,
|
||||||
rpc_service,
|
json_rpc_service,
|
||||||
|
pubsub_service,
|
||||||
|
optimistically_confirmed_bank_tracker,
|
||||||
transaction_status_service,
|
transaction_status_service,
|
||||||
rewards_recorder_service,
|
rewards_recorder_service,
|
||||||
cache_block_time_service,
|
cache_block_time_service,
|
||||||
@ -758,18 +767,23 @@ impl Validator {
|
|||||||
pub fn join(self) {
|
pub fn join(self) {
|
||||||
self.poh_service.join().expect("poh_service");
|
self.poh_service.join().expect("poh_service");
|
||||||
drop(self.poh_recorder);
|
drop(self.poh_recorder);
|
||||||
if let Some(RpcServices {
|
|
||||||
json_rpc_service,
|
if let Some(json_rpc_service) = self.json_rpc_service {
|
||||||
pubsub_service,
|
|
||||||
optimistically_confirmed_bank_tracker,
|
|
||||||
}) = self.rpc_service
|
|
||||||
{
|
|
||||||
json_rpc_service.join().expect("rpc_service");
|
json_rpc_service.join().expect("rpc_service");
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(pubsub_service) = self.pubsub_service {
|
||||||
pubsub_service.join().expect("pubsub_service");
|
pubsub_service.join().expect("pubsub_service");
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(optimistically_confirmed_bank_tracker) =
|
||||||
|
self.optimistically_confirmed_bank_tracker
|
||||||
|
{
|
||||||
optimistically_confirmed_bank_tracker
|
optimistically_confirmed_bank_tracker
|
||||||
.join()
|
.join()
|
||||||
.expect("optimistically_confirmed_bank_tracker");
|
.expect("optimistically_confirmed_bank_tracker");
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(transaction_status_service) = self.transaction_status_service {
|
if let Some(transaction_status_service) = self.transaction_status_service {
|
||||||
transaction_status_service
|
transaction_status_service
|
||||||
.join()
|
.join()
|
||||||
|
@ -61,8 +61,6 @@ gives a convenient interface for the RPC methods.
|
|||||||
- [requestAirdrop](jsonrpc-api.md#requestairdrop)
|
- [requestAirdrop](jsonrpc-api.md#requestairdrop)
|
||||||
- [sendTransaction](jsonrpc-api.md#sendtransaction)
|
- [sendTransaction](jsonrpc-api.md#sendtransaction)
|
||||||
- [simulateTransaction](jsonrpc-api.md#simulatetransaction)
|
- [simulateTransaction](jsonrpc-api.md#simulatetransaction)
|
||||||
- [setLogFilter](jsonrpc-api.md#setlogfilter)
|
|
||||||
- [validatorExit](jsonrpc-api.md#validatorexit)
|
|
||||||
- [Subscription Websocket](jsonrpc-api.md#subscription-websocket)
|
- [Subscription Websocket](jsonrpc-api.md#subscription-websocket)
|
||||||
- [accountSubscribe](jsonrpc-api.md#accountsubscribe)
|
- [accountSubscribe](jsonrpc-api.md#accountsubscribe)
|
||||||
- [accountUnsubscribe](jsonrpc-api.md#accountunsubscribe)
|
- [accountUnsubscribe](jsonrpc-api.md#accountunsubscribe)
|
||||||
@ -2986,57 +2984,6 @@ Result:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### setLogFilter
|
|
||||||
|
|
||||||
Sets the log filter on the validator
|
|
||||||
|
|
||||||
#### Parameters:
|
|
||||||
|
|
||||||
- `<string>` - the new log filter to use
|
|
||||||
|
|
||||||
#### Results:
|
|
||||||
|
|
||||||
- `<null>`
|
|
||||||
|
|
||||||
#### Example:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d '
|
|
||||||
{"jsonrpc":"2.0","id":1, "method":"setLogFilter", "params":["solana_core=debug"]}
|
|
||||||
'
|
|
||||||
```
|
|
||||||
|
|
||||||
Result:
|
|
||||||
```json
|
|
||||||
{"jsonrpc":"2.0","result":null,"id":1}
|
|
||||||
```
|
|
||||||
|
|
||||||
### validatorExit
|
|
||||||
|
|
||||||
If a validator boots with RPC exit enabled (`--enable-rpc-exit` parameter), this request causes the validator to exit.
|
|
||||||
|
|
||||||
#### Parameters:
|
|
||||||
|
|
||||||
None
|
|
||||||
|
|
||||||
#### Results:
|
|
||||||
|
|
||||||
- `<bool>` - Whether the validator exit operation was successful
|
|
||||||
|
|
||||||
#### Example:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d '
|
|
||||||
{"jsonrpc":"2.0","id":1, "method":"validatorExit"}
|
|
||||||
'
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
Result:
|
|
||||||
```json
|
|
||||||
{"jsonrpc":"2.0","result":true,"id":1}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Subscription Websocket
|
## Subscription Websocket
|
||||||
|
|
||||||
After connecting to the RPC PubSub websocket at `ws://<ADDRESS>/`:
|
After connecting to the RPC PubSub websocket at `ws://<ADDRESS>/`:
|
||||||
|
@ -51,7 +51,6 @@ For example:
|
|||||||
|
|
||||||
```text
|
```text
|
||||||
let mut validator_config = ValidatorConfig::default();
|
let mut validator_config = ValidatorConfig::default();
|
||||||
validator_config.rpc_config.enable_validator_exit = true;
|
|
||||||
let local = LocalCluster::new_with_config(
|
let local = LocalCluster::new_with_config(
|
||||||
num_nodes,
|
num_nodes,
|
||||||
10_000,
|
10_000,
|
||||||
|
@ -12,7 +12,6 @@ homepage = "https://solana.com/"
|
|||||||
clap = "2.33.1"
|
clap = "2.33.1"
|
||||||
solana-clap-utils = { path = "../clap-utils", version = "1.6.0" }
|
solana-clap-utils = { path = "../clap-utils", version = "1.6.0" }
|
||||||
solana-core = { path = "../core", version = "1.6.0" }
|
solana-core = { path = "../core", version = "1.6.0" }
|
||||||
solana-client = { path = "../client", version = "1.6.0" }
|
|
||||||
solana-logger = { path = "../logger", version = "1.6.0" }
|
solana-logger = { path = "../logger", version = "1.6.0" }
|
||||||
solana-net-utils = { path = "../net-utils", version = "1.6.0" }
|
solana-net-utils = { path = "../net-utils", version = "1.6.0" }
|
||||||
solana-sdk = { path = "../sdk", version = "1.6.0" }
|
solana-sdk = { path = "../sdk", version = "1.6.0" }
|
||||||
|
@ -8,7 +8,6 @@ use solana_clap_utils::{
|
|||||||
input_parsers::keypair_of,
|
input_parsers::keypair_of,
|
||||||
input_validators::{is_keypair_or_ask_keyword, is_port, is_pubkey},
|
input_validators::{is_keypair_or_ask_keyword, is_port, is_pubkey},
|
||||||
};
|
};
|
||||||
use solana_client::rpc_client::RpcClient;
|
|
||||||
use solana_core::{contact_info::ContactInfo, gossip_service::discover};
|
use solana_core::{contact_info::ContactInfo, gossip_service::discover};
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use std::{
|
use std::{
|
||||||
@ -141,29 +140,6 @@ fn parse_matches() -> ArgMatches<'static> {
|
|||||||
.help("Maximum time to wait in seconds [default: wait forever]"),
|
.help("Maximum time to wait in seconds [default: wait forever]"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.subcommand(
|
|
||||||
SubCommand::with_name("stop")
|
|
||||||
.about("Send stop request to a node")
|
|
||||||
.setting(AppSettings::DisableVersion)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("entrypoint")
|
|
||||||
.short("n")
|
|
||||||
.long("entrypoint")
|
|
||||||
.value_name("HOST:PORT")
|
|
||||||
.takes_value(true)
|
|
||||||
.required(true)
|
|
||||||
.validator(solana_net_utils::is_host_port)
|
|
||||||
.help("Rendezvous with the cluster at this entry point"),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("node_pubkey")
|
|
||||||
.index(1)
|
|
||||||
.required(true)
|
|
||||||
.value_name("PUBKEY")
|
|
||||||
.validator(is_pubkey)
|
|
||||||
.help("Public key of a specific node to stop"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.get_matches()
|
.get_matches()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,44 +308,6 @@ fn process_rpc_url(matches: &ArgMatches) -> std::io::Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_stop(matches: &ArgMatches) -> Result<(), Box<dyn error::Error>> {
|
|
||||||
let entrypoint_addr = parse_entrypoint(&matches);
|
|
||||||
let pubkey = matches
|
|
||||||
.value_of("node_pubkey")
|
|
||||||
.unwrap()
|
|
||||||
.parse::<Pubkey>()
|
|
||||||
.unwrap();
|
|
||||||
let (_all_peers, validators) = discover(
|
|
||||||
None,
|
|
||||||
entrypoint_addr.as_ref(),
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
Some(pubkey),
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
0,
|
|
||||||
)?;
|
|
||||||
let validator = validators.iter().find(|x| x.id == pubkey).unwrap();
|
|
||||||
|
|
||||||
if !ContactInfo::is_valid_address(&validator.rpc) {
|
|
||||||
eprintln!(
|
|
||||||
"Error: RPC service is not enabled on validator {:?}",
|
|
||||||
pubkey
|
|
||||||
);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
println!("\nSending stop request to validator {:?}", pubkey);
|
|
||||||
|
|
||||||
let result = RpcClient::new_socket(validator.rpc).validator_exit()?;
|
|
||||||
if result {
|
|
||||||
println!("Stop signal accepted");
|
|
||||||
} else {
|
|
||||||
eprintln!("Error: Stop signal ignored");
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn error::Error>> {
|
fn main() -> Result<(), Box<dyn error::Error>> {
|
||||||
solana_logger::setup_with_default("solana=info");
|
solana_logger::setup_with_default("solana=info");
|
||||||
|
|
||||||
@ -382,9 +320,6 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||||||
("rpc-url", Some(matches)) => {
|
("rpc-url", Some(matches)) => {
|
||||||
process_rpc_url(matches)?;
|
process_rpc_url(matches)?;
|
||||||
}
|
}
|
||||||
("stop", Some(matches)) => {
|
|
||||||
process_stop(matches)?;
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ use log::*;
|
|||||||
/// discover the rest of the network.
|
/// discover the rest of the network.
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use solana_client::thin_client::create_client;
|
use solana_client::thin_client::create_client;
|
||||||
|
use solana_core::validator::ValidatorExit;
|
||||||
use solana_core::{
|
use solana_core::{
|
||||||
cluster_info::VALIDATOR_PORT_RANGE, consensus::VOTE_THRESHOLD_DEPTH, contact_info::ContactInfo,
|
cluster_info::VALIDATOR_PORT_RANGE, consensus::VOTE_THRESHOLD_DEPTH, contact_info::ContactInfo,
|
||||||
gossip_service::discover_cluster,
|
gossip_service::discover_cluster,
|
||||||
@ -15,7 +16,7 @@ use solana_ledger::{
|
|||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
client::SyncClient,
|
client::SyncClient,
|
||||||
clock::{self, Slot, DEFAULT_MS_PER_SLOT, NUM_CONSECUTIVE_LEADER_SLOTS},
|
clock::{self, Slot, NUM_CONSECUTIVE_LEADER_SLOTS},
|
||||||
commitment_config::CommitmentConfig,
|
commitment_config::CommitmentConfig,
|
||||||
epoch_schedule::MINIMUM_SLOTS_PER_EPOCH,
|
epoch_schedule::MINIMUM_SLOTS_PER_EPOCH,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
@ -29,6 +30,7 @@ use solana_sdk::{
|
|||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
path::Path,
|
path::Path,
|
||||||
|
sync::{Arc, RwLock},
|
||||||
thread::sleep,
|
thread::sleep,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
@ -126,20 +128,6 @@ pub fn send_many_transactions(
|
|||||||
expected_balances
|
expected_balances
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn validator_exit(entry_point_info: &ContactInfo, nodes: usize) {
|
|
||||||
let cluster_nodes = discover_cluster(&entry_point_info.gossip, nodes).unwrap();
|
|
||||||
assert!(cluster_nodes.len() >= nodes);
|
|
||||||
for node in &cluster_nodes {
|
|
||||||
let client = create_client(node.client_facing_addr(), VALIDATOR_PORT_RANGE);
|
|
||||||
assert!(client.validator_exit().unwrap());
|
|
||||||
}
|
|
||||||
sleep(Duration::from_millis(DEFAULT_MS_PER_SLOT));
|
|
||||||
for node in &cluster_nodes {
|
|
||||||
let client = create_client(node.client_facing_addr(), VALIDATOR_PORT_RANGE);
|
|
||||||
assert!(client.validator_exit().is_err());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn verify_ledger_ticks(ledger_path: &Path, ticks_per_slot: usize) {
|
pub fn verify_ledger_ticks(ledger_path: &Path, ticks_per_slot: usize) {
|
||||||
let ledger = Blockstore::open(ledger_path).unwrap();
|
let ledger = Blockstore::open(ledger_path).unwrap();
|
||||||
let zeroth_slot = ledger.get_slot_entries(0, 0).unwrap();
|
let zeroth_slot = ledger.get_slot_entries(0, 0).unwrap();
|
||||||
@ -188,11 +176,12 @@ pub fn sleep_n_epochs(
|
|||||||
|
|
||||||
pub fn kill_entry_and_spend_and_verify_rest(
|
pub fn kill_entry_and_spend_and_verify_rest(
|
||||||
entry_point_info: &ContactInfo,
|
entry_point_info: &ContactInfo,
|
||||||
|
entry_point_validator_exit: &Arc<RwLock<ValidatorExit>>,
|
||||||
funding_keypair: &Keypair,
|
funding_keypair: &Keypair,
|
||||||
nodes: usize,
|
nodes: usize,
|
||||||
slot_millis: u64,
|
slot_millis: u64,
|
||||||
) {
|
) {
|
||||||
solana_logger::setup();
|
info!("kill_entry_and_spend_and_verify_rest...");
|
||||||
let cluster_nodes = discover_cluster(&entry_point_info.gossip, nodes).unwrap();
|
let cluster_nodes = discover_cluster(&entry_point_info.gossip, nodes).unwrap();
|
||||||
assert!(cluster_nodes.len() >= nodes);
|
assert!(cluster_nodes.len() >= nodes);
|
||||||
let client = create_client(entry_point_info.client_facing_addr(), VALIDATOR_PORT_RANGE);
|
let client = create_client(entry_point_info.client_facing_addr(), VALIDATOR_PORT_RANGE);
|
||||||
@ -211,7 +200,7 @@ pub fn kill_entry_and_spend_and_verify_rest(
|
|||||||
));
|
));
|
||||||
info!("done sleeping for first 2 warmup epochs");
|
info!("done sleeping for first 2 warmup epochs");
|
||||||
info!("killing entry point: {}", entry_point_info.id);
|
info!("killing entry point: {}", entry_point_info.id);
|
||||||
assert!(client.validator_exit().unwrap());
|
entry_point_validator_exit.write().unwrap().exit();
|
||||||
info!("sleeping for some time");
|
info!("sleeping for some time");
|
||||||
sleep(Duration::from_millis(
|
sleep(Duration::from_millis(
|
||||||
slot_millis * NUM_CONSECUTIVE_LEADER_SLOTS,
|
slot_millis * NUM_CONSECUTIVE_LEADER_SLOTS,
|
||||||
|
@ -667,7 +667,7 @@ impl Cluster for LocalCluster {
|
|||||||
entry_point_info
|
entry_point_info
|
||||||
.map(|entry_point_info| vec![entry_point_info])
|
.map(|entry_point_info| vec![entry_point_info])
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
&cluster_validator_info.config,
|
&safe_clone_config(&cluster_validator_info.config),
|
||||||
true, // should_check_duplicate_instance
|
true, // should_check_duplicate_instance
|
||||||
);
|
);
|
||||||
cluster_validator_info.validator = Some(restarted_node);
|
cluster_validator_info.validator = Some(restarted_node);
|
||||||
@ -707,8 +707,6 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_local_cluster_start_and_exit_with_config() {
|
fn test_local_cluster_start_and_exit_with_config() {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
let mut validator_config = ValidatorConfig::default();
|
|
||||||
validator_config.rpc_config.enable_validator_exit = true;
|
|
||||||
const NUM_NODES: usize = 1;
|
const NUM_NODES: usize = 1;
|
||||||
let mut config = ClusterConfig {
|
let mut config = ClusterConfig {
|
||||||
validator_configs: make_identical_validator_configs(
|
validator_configs: make_identical_validator_configs(
|
||||||
|
@ -241,37 +241,6 @@ fn test_spend_and_verify_all_nodes_env_num_nodes() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_attributes)]
|
|
||||||
#[test]
|
|
||||||
#[should_panic]
|
|
||||||
fn test_validator_exit_default_config_should_panic() {
|
|
||||||
solana_logger::setup();
|
|
||||||
error!("test_validator_exit_default_config_should_panic");
|
|
||||||
let num_nodes = 2;
|
|
||||||
let local = LocalCluster::new_with_equal_stakes(num_nodes, 10_000, 100);
|
|
||||||
cluster_tests::validator_exit(&local.entry_point_info, num_nodes);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
#[serial]
|
|
||||||
fn test_validator_exit_2() {
|
|
||||||
solana_logger::setup();
|
|
||||||
error!("test_validator_exit_2");
|
|
||||||
let num_nodes = 2;
|
|
||||||
let mut validator_config = ValidatorConfig::default();
|
|
||||||
validator_config.rpc_config.enable_validator_exit = true;
|
|
||||||
validator_config.wait_for_supermajority = Some(0);
|
|
||||||
|
|
||||||
let mut config = ClusterConfig {
|
|
||||||
cluster_lamports: 10_000,
|
|
||||||
node_stakes: vec![100; num_nodes],
|
|
||||||
validator_configs: make_identical_validator_configs(&validator_config, num_nodes),
|
|
||||||
..ClusterConfig::default()
|
|
||||||
};
|
|
||||||
let local = LocalCluster::new(&mut config);
|
|
||||||
cluster_tests::validator_exit(&local.entry_point_info, num_nodes);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cluster needs a supermajority to remain, so the minimum size for this test is 4
|
// Cluster needs a supermajority to remain, so the minimum size for this test is 4
|
||||||
#[test]
|
#[test]
|
||||||
#[serial]
|
#[serial]
|
||||||
@ -279,8 +248,7 @@ fn test_leader_failure_4() {
|
|||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
error!("test_leader_failure_4");
|
error!("test_leader_failure_4");
|
||||||
let num_nodes = 4;
|
let num_nodes = 4;
|
||||||
let mut validator_config = ValidatorConfig::default();
|
let validator_config = ValidatorConfig::default();
|
||||||
validator_config.rpc_config.enable_validator_exit = true;
|
|
||||||
let mut config = ClusterConfig {
|
let mut config = ClusterConfig {
|
||||||
cluster_lamports: 10_000,
|
cluster_lamports: 10_000,
|
||||||
node_stakes: vec![100; 4],
|
node_stakes: vec![100; 4],
|
||||||
@ -288,8 +256,15 @@ fn test_leader_failure_4() {
|
|||||||
..ClusterConfig::default()
|
..ClusterConfig::default()
|
||||||
};
|
};
|
||||||
let local = LocalCluster::new(&mut config);
|
let local = LocalCluster::new(&mut config);
|
||||||
|
|
||||||
cluster_tests::kill_entry_and_spend_and_verify_rest(
|
cluster_tests::kill_entry_and_spend_and_verify_rest(
|
||||||
&local.entry_point_info,
|
&local.entry_point_info,
|
||||||
|
&local
|
||||||
|
.validators
|
||||||
|
.get(&local.entry_point_info.id)
|
||||||
|
.unwrap()
|
||||||
|
.config
|
||||||
|
.validator_exit,
|
||||||
&local.funding_keypair,
|
&local.funding_keypair,
|
||||||
num_nodes,
|
num_nodes,
|
||||||
config.ticks_per_slot * config.poh_config.target_tick_duration.as_millis() as u64,
|
config.ticks_per_slot * config.poh_config.target_tick_duration.as_millis() as u64,
|
||||||
@ -647,12 +622,11 @@ fn test_kill_partition_switch_threshold_progress() {
|
|||||||
fn test_two_unbalanced_stakes() {
|
fn test_two_unbalanced_stakes() {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
error!("test_two_unbalanced_stakes");
|
error!("test_two_unbalanced_stakes");
|
||||||
let mut validator_config = ValidatorConfig::default();
|
let validator_config = ValidatorConfig::default();
|
||||||
let num_ticks_per_second = 100;
|
let num_ticks_per_second = 100;
|
||||||
let num_ticks_per_slot = 10;
|
let num_ticks_per_slot = 10;
|
||||||
let num_slots_per_epoch = MINIMUM_SLOTS_PER_EPOCH as u64;
|
let num_slots_per_epoch = MINIMUM_SLOTS_PER_EPOCH as u64;
|
||||||
|
|
||||||
validator_config.rpc_config.enable_validator_exit = true;
|
|
||||||
let mut cluster = LocalCluster::new(&mut ClusterConfig {
|
let mut cluster = LocalCluster::new(&mut ClusterConfig {
|
||||||
node_stakes: vec![999_990, 3],
|
node_stakes: vec![999_990, 3],
|
||||||
cluster_lamports: 1_000_000,
|
cluster_lamports: 1_000_000,
|
||||||
@ -1388,8 +1362,7 @@ fn test_faulty_node(faulty_node_type: BroadcastStageType) {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_wait_for_max_stake() {
|
fn test_wait_for_max_stake() {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
let mut validator_config = ValidatorConfig::default();
|
let validator_config = ValidatorConfig::default();
|
||||||
validator_config.rpc_config.enable_validator_exit = true;
|
|
||||||
let mut config = ClusterConfig {
|
let mut config = ClusterConfig {
|
||||||
cluster_lamports: 10_000,
|
cluster_lamports: 10_000,
|
||||||
node_stakes: vec![100; 4],
|
node_stakes: vec![100; 4],
|
||||||
@ -1410,9 +1383,10 @@ fn test_wait_for_max_stake() {
|
|||||||
// votable, then B_{i+1} still chains to B_i
|
// votable, then B_{i+1} still chains to B_i
|
||||||
fn test_no_voting() {
|
fn test_no_voting() {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
let mut validator_config = ValidatorConfig::default();
|
let validator_config = ValidatorConfig {
|
||||||
validator_config.rpc_config.enable_validator_exit = true;
|
voting_disabled: true,
|
||||||
validator_config.voting_disabled = true;
|
..ValidatorConfig::default()
|
||||||
|
};
|
||||||
let mut config = ClusterConfig {
|
let mut config = ClusterConfig {
|
||||||
cluster_lamports: 10_000,
|
cluster_lamports: 10_000,
|
||||||
node_stakes: vec![100],
|
node_stakes: vec![100],
|
||||||
@ -2498,11 +2472,12 @@ fn setup_snapshot_validator_config(
|
|||||||
let (account_storage_dirs, account_storage_paths) = generate_account_paths(num_account_paths);
|
let (account_storage_dirs, account_storage_paths) = generate_account_paths(num_account_paths);
|
||||||
|
|
||||||
// Create the validator config
|
// Create the validator config
|
||||||
let mut validator_config = ValidatorConfig::default();
|
let validator_config = ValidatorConfig {
|
||||||
validator_config.rpc_config.enable_validator_exit = true;
|
snapshot_config: Some(snapshot_config),
|
||||||
validator_config.snapshot_config = Some(snapshot_config);
|
account_paths: account_storage_paths,
|
||||||
validator_config.account_paths = account_storage_paths;
|
accounts_hash_interval_slots: snapshot_interval_slots,
|
||||||
validator_config.accounts_hash_interval_slots = snapshot_interval_slots;
|
..ValidatorConfig::default()
|
||||||
|
};
|
||||||
|
|
||||||
SnapshotValidatorConfig {
|
SnapshotValidatorConfig {
|
||||||
_snapshot_dir: snapshot_dir,
|
_snapshot_dir: snapshot_dir,
|
||||||
|
@ -97,8 +97,6 @@ ledger_dir="$SOLANA_CONFIG_DIR"/bootstrap-validator
|
|||||||
}
|
}
|
||||||
|
|
||||||
args+=(
|
args+=(
|
||||||
--enable-rpc-exit
|
|
||||||
--enable-rpc-set-log-filter
|
|
||||||
--require-tower
|
--require-tower
|
||||||
--ledger "$ledger_dir"
|
--ledger "$ledger_dir"
|
||||||
--rpc-port 8899
|
--rpc-port 8899
|
||||||
|
@ -104,9 +104,6 @@ while [[ -n $1 ]]; do
|
|||||||
elif [[ $1 = --rpc-port ]]; then
|
elif [[ $1 = --rpc-port ]]; then
|
||||||
args+=("$1" "$2")
|
args+=("$1" "$2")
|
||||||
shift 2
|
shift 2
|
||||||
elif [[ $1 = --enable-rpc-exit ]]; then
|
|
||||||
args+=("$1")
|
|
||||||
shift
|
|
||||||
elif [[ $1 = --rpc-faucet-address ]]; then
|
elif [[ $1 = --rpc-faucet-address ]]; then
|
||||||
args+=("$1" "$2")
|
args+=("$1" "$2")
|
||||||
shift 2
|
shift 2
|
||||||
@ -227,8 +224,6 @@ default_arg --identity "$identity"
|
|||||||
default_arg --vote-account "$vote_account"
|
default_arg --vote-account "$vote_account"
|
||||||
default_arg --ledger "$ledger_dir"
|
default_arg --ledger "$ledger_dir"
|
||||||
default_arg --log -
|
default_arg --log -
|
||||||
default_arg --enable-rpc-exit
|
|
||||||
default_arg --enable-rpc-set-log-filter
|
|
||||||
default_arg --require-tower
|
default_arg --require-tower
|
||||||
|
|
||||||
if [[ -n $SOLANA_CUDA ]]; then
|
if [[ -n $SOLANA_CUDA ]]; then
|
||||||
|
1
run.sh
1
run.sh
@ -100,7 +100,6 @@ args=(
|
|||||||
--rpc-port 8899
|
--rpc-port 8899
|
||||||
--rpc-faucet-address 127.0.0.1:9900
|
--rpc-faucet-address 127.0.0.1:9900
|
||||||
--log -
|
--log -
|
||||||
--enable-rpc-exit
|
|
||||||
--enable-rpc-transaction-history
|
--enable-rpc-transaction-history
|
||||||
--enable-cpi-and-log-storage
|
--enable-cpi-and-log-storage
|
||||||
--init-complete-file "$dataDir"/init-completed
|
--init-complete-file "$dataDir"/init-completed
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
#
|
|
||||||
# Reconfigures the log filter on a validator using the current RUST_LOG value
|
|
||||||
#
|
|
||||||
|
|
||||||
if [[ -n $1 ]]; then
|
|
||||||
url=$1
|
|
||||||
else
|
|
||||||
# Default to the local node
|
|
||||||
url=http://127.0.0.1:8899
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -z $RUST_LOG ]]; then
|
|
||||||
echo "RUST_LOG not defined"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
set -x
|
|
||||||
exec curl $url -X POST -H "Content-Type: application/json" \
|
|
||||||
-d "
|
|
||||||
{
|
|
||||||
\"jsonrpc\": \"2.0\",
|
|
||||||
\"id\": 1,
|
|
||||||
\"method\": \"setLogFilter\",
|
|
||||||
\"params\": [\"$RUST_LOG\"]
|
|
||||||
}
|
|
||||||
"
|
|
@ -12,18 +12,21 @@ default-run = "solana-validator"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
base64 = "0.12.3"
|
base64 = "0.12.3"
|
||||||
bincode = "1.3.1"
|
bincode = "1.3.1"
|
||||||
clap = "2.33.1"
|
|
||||||
chrono = { version = "0.4.11", features = ["serde"] }
|
chrono = { version = "0.4.11", features = ["serde"] }
|
||||||
|
clap = "2.33.1"
|
||||||
console = "0.11.3"
|
console = "0.11.3"
|
||||||
core_affinity = "0.5.10"
|
core_affinity = "0.5.10"
|
||||||
fd-lock = "1.1.1"
|
fd-lock = "1.1.1"
|
||||||
indicatif = "0.15.0"
|
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"
|
log = "0.4.11"
|
||||||
num_cpus = "1.13.0"
|
num_cpus = "1.13.0"
|
||||||
rand = "0.7.0"
|
rand = "0.7.0"
|
||||||
serde = "1.0.112"
|
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-clap-utils = { path = "../clap-utils", version = "1.6.0" }
|
||||||
solana-cli-config = { path = "../cli-config", version = "1.6.0" }
|
solana-cli-config = { path = "../cli-config", version = "1.6.0" }
|
||||||
solana-client = { path = "../client", 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-faucet = { path = "../faucet", version = "1.6.0" }
|
||||||
solana-ledger = { path = "../ledger", version = "1.6.0" }
|
solana-ledger = { path = "../ledger", version = "1.6.0" }
|
||||||
solana-logger = { path = "../logger", 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-metrics = { path = "../metrics", version = "1.6.0" }
|
||||||
solana-net-utils = { path = "../net-utils", 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-runtime = { path = "../runtime", version = "1.6.0" }
|
||||||
solana-sdk = { path = "../sdk", version = "1.6.0" }
|
solana-sdk = { path = "../sdk", version = "1.6.0" }
|
||||||
solana-version = { path = "../version", version = "1.6.0" }
|
solana-version = { path = "../version", version = "1.6.0" }
|
||||||
|
133
validator/src/admin_rpc_service.rs
Normal file
133
validator/src/admin_rpc_service.rs
Normal 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")
|
||||||
|
}
|
@ -21,7 +21,7 @@ use {
|
|||||||
system_program,
|
system_program,
|
||||||
},
|
},
|
||||||
solana_validator::{
|
solana_validator::{
|
||||||
dashboard::Dashboard, record_start, redirect_stderr_to_file, test_validator::*,
|
admin_rpc_service, dashboard::Dashboard, redirect_stderr_to_file, test_validator::*,
|
||||||
},
|
},
|
||||||
std::{
|
std::{
|
||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
@ -126,7 +126,7 @@ fn main() {
|
|||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.default_value(&default_rpc_port)
|
.default_value(&default_rpc_port)
|
||||||
.validator(solana_validator::port_validator)
|
.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(
|
||||||
Arg::with_name("bpf_program")
|
Arg::with_name("bpf_program")
|
||||||
@ -205,6 +205,7 @@ fn main() {
|
|||||||
Output::Dashboard
|
Output::Dashboard
|
||||||
};
|
};
|
||||||
let rpc_port = value_t_or_exit!(matches, "rpc_port", u16);
|
let rpc_port = value_t_or_exit!(matches, "rpc_port", u16);
|
||||||
|
|
||||||
let faucet_addr = Some(SocketAddr::new(
|
let faucet_addr = Some(SocketAddr::new(
|
||||||
IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)),
|
IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)),
|
||||||
FAUCET_PORT,
|
FAUCET_PORT,
|
||||||
@ -353,60 +354,68 @@ fn main() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
record_start(
|
let mut genesis = TestValidatorGenesis::default();
|
||||||
&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));
|
|
||||||
|
|
||||||
|
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 {
|
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 {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let test_validator = {
|
genesis
|
||||||
let mut genesis = TestValidatorGenesis::default();
|
.ledger_path(&ledger_path)
|
||||||
genesis
|
.add_account(
|
||||||
.ledger_path(&ledger_path)
|
faucet_pubkey,
|
||||||
.add_account(
|
Account::new(faucet_lamports, 0, &system_program::id()),
|
||||||
faucet_pubkey,
|
)
|
||||||
Account::new(faucet_lamports, 0, &system_program::id()),
|
.rpc_config(JsonRpcConfig {
|
||||||
)
|
enable_rpc_transaction_history: true,
|
||||||
.rpc_config(JsonRpcConfig {
|
enable_cpi_and_log_storage: true,
|
||||||
enable_validator_exit: true,
|
faucet_addr,
|
||||||
enable_rpc_transaction_history: true,
|
..JsonRpcConfig::default()
|
||||||
enable_cpi_and_log_storage: true,
|
})
|
||||||
faucet_addr,
|
.bpf_jit(bpf_jit)
|
||||||
..JsonRpcConfig::default()
|
.rpc_port(rpc_port)
|
||||||
})
|
.add_programs_with_path(&programs);
|
||||||
.bpf_jit(bpf_jit)
|
|
||||||
.rpc_port(rpc_port)
|
|
||||||
.add_programs_with_path(&programs);
|
|
||||||
|
|
||||||
if !clone_accounts.is_empty() {
|
if !clone_accounts.is_empty() {
|
||||||
genesis.clone_accounts(
|
genesis.clone_accounts(
|
||||||
clone_accounts,
|
clone_accounts,
|
||||||
cluster_rpc_client
|
cluster_rpc_client
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.expect("bug: --url argument missing?"),
|
.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) => {
|
Err(err) => {
|
||||||
drop(dashboard);
|
drop(dashboard);
|
||||||
println!("Error: failed to start validator: {}", err);
|
println!("Error: failed to start validator: {}", err);
|
||||||
@ -418,10 +427,10 @@ fn main() {
|
|||||||
fn remove_directory_contents(ledger_path: &Path) -> Result<(), io::Error> {
|
fn remove_directory_contents(ledger_path: &Path) -> Result<(), io::Error> {
|
||||||
for entry in fs::read_dir(&ledger_path)? {
|
for entry in fs::read_dir(&ledger_path)? {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
if entry.metadata()?.is_file() {
|
if entry.metadata()?.is_dir() {
|
||||||
fs::remove_file(&entry.path())?
|
|
||||||
} else {
|
|
||||||
fs::remove_dir_all(&entry.path())?
|
fs::remove_dir_all(&entry.path())?
|
||||||
|
} else {
|
||||||
|
fs::remove_file(&entry.path())?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
use {
|
use {
|
||||||
crate::{
|
crate::{admin_rpc_service, new_spinner_progress_bar, println_name_value},
|
||||||
get_validator_rpc_addr, get_validator_start_time, new_spinner_progress_bar,
|
|
||||||
println_name_value,
|
|
||||||
},
|
|
||||||
console::style,
|
console::style,
|
||||||
indicatif::ProgressBar,
|
indicatif::ProgressBar,
|
||||||
solana_client::{
|
solana_client::{
|
||||||
@ -17,6 +14,10 @@ use {
|
|||||||
std::{
|
std::{
|
||||||
io,
|
io,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
sync::{
|
||||||
|
atomic::{AtomicBool, Ordering},
|
||||||
|
Arc,
|
||||||
|
},
|
||||||
thread,
|
thread,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
},
|
},
|
||||||
@ -25,136 +26,121 @@ use {
|
|||||||
pub struct Dashboard {
|
pub struct Dashboard {
|
||||||
progress_bar: ProgressBar,
|
progress_bar: ProgressBar,
|
||||||
ledger_path: PathBuf,
|
ledger_path: PathBuf,
|
||||||
|
exit: Arc<AtomicBool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dashboard {
|
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()));
|
println_name_value("Ledger location:", &format!("{}", ledger_path.display()));
|
||||||
if let Some(log_path) = log_path {
|
if let Some(log_path) = log_path {
|
||||||
println_name_value("Log:", &format!("{}", log_path.display()));
|
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();
|
let progress_bar = new_spinner_progress_bar();
|
||||||
progress_bar.set_message("Initializing...");
|
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 {
|
Ok(Self {
|
||||||
progress_bar,
|
exit,
|
||||||
ledger_path: ledger_path.to_path_buf(),
|
ledger_path: ledger_path.to_path_buf(),
|
||||||
|
progress_bar,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(self) -> ! {
|
pub fn run(self) {
|
||||||
let Self {
|
let Self {
|
||||||
progress_bar,
|
exit,
|
||||||
ledger_path,
|
ledger_path,
|
||||||
|
progress_bar,
|
||||||
|
..
|
||||||
} = self;
|
} = 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);
|
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> {
|
let rpc_addr = admin_client
|
||||||
rpc_client
|
.rpc_addr()
|
||||||
.get_cluster_nodes()
|
.await
|
||||||
.ok()
|
.map_err(|err| format!("Unable to get validator RPC address: {}", err))?
|
||||||
.unwrap_or_default()
|
.ok_or_else(|| "RPC not available".to_string())?;
|
||||||
.into_iter()
|
|
||||||
.find(|node| node.pubkey == identity.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(contact_info) = get_contact_info(&rpc_client, &identity) {
|
let start_time = admin_client
|
||||||
println_name_value(
|
.start_time()
|
||||||
"Version:",
|
.await
|
||||||
&contact_info.version.unwrap_or_else(|| "?".to_string()),
|
.map_err(|err| format!("Unable to get validator start time: {}", err))?;
|
||||||
);
|
|
||||||
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();
|
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(
|
let rpc_client = RpcClient::new_socket(rpc_addr);
|
||||||
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() {
|
// Wait until RPC starts responding...
|
||||||
Ok(()) => "ok".to_string(),
|
match rpc_client.get_identity() {
|
||||||
Err(err) => {
|
Ok(identity) => break (start_time, rpc_client, identity),
|
||||||
if let client_error::ClientErrorKind::RpcError(
|
Err(err) => {
|
||||||
rpc_request::RpcError::RpcResponseError {
|
progress_bar.set_message(&format!("Waiting for RPC... ({})", err));
|
||||||
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((
|
drop(progress_bar);
|
||||||
processed_slot,
|
println_name_value("Identity:", &identity.to_string());
|
||||||
confirmed_slot,
|
|
||||||
finalized_slot,
|
|
||||||
transaction_count,
|
|
||||||
Sol(identity_balance),
|
|
||||||
health,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut start_time = get_validator_start_time(&ledger_path).ok();
|
if let Some(contact_info) = get_contact_info(&rpc_client, &identity) {
|
||||||
loop {
|
println_name_value(
|
||||||
let snapshot_slot = rpc_client.get_snapshot_slot().ok();
|
"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) {
|
match get_validator_stats(&rpc_client, &identity) {
|
||||||
Ok((
|
Ok((
|
||||||
processed_slot,
|
processed_slot,
|
||||||
@ -164,27 +150,23 @@ impl Dashboard {
|
|||||||
identity_balance,
|
identity_balance,
|
||||||
health,
|
health,
|
||||||
)) => {
|
)) => {
|
||||||
let uptime = match start_time {
|
let uptime = {
|
||||||
Some(start_time) => {
|
let uptime =
|
||||||
let uptime =
|
chrono::Duration::from_std(start_time.elapsed().unwrap()).unwrap();
|
||||||
chrono::Duration::from_std(start_time.elapsed().unwrap())
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
"{:02}:{:02}:{:02} ",
|
"{:02}:{:02}:{:02} ",
|
||||||
uptime.num_hours(),
|
uptime.num_hours(),
|
||||||
uptime.num_minutes() % 60,
|
uptime.num_minutes() % 60,
|
||||||
uptime.num_seconds() % 60
|
uptime.num_seconds() % 60
|
||||||
)
|
)
|
||||||
}
|
|
||||||
None => " ".to_string(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
progress_bar.set_message(&format!(
|
progress_bar.set_message(&format!(
|
||||||
"{}{}| \
|
"{}{}| \
|
||||||
Processed Slot: {} | Confirmed Slot: {} | Finalized Slot: {} | \
|
Processed Slot: {} | Confirmed Slot: {} | Finalized Slot: {} | \
|
||||||
Snapshot Slot: {} | \
|
Snapshot Slot: {} | \
|
||||||
Transactions: {} | {}",
|
Transactions: {} | {}",
|
||||||
uptime,
|
uptime,
|
||||||
if health == "ok" {
|
if health == "ok" {
|
||||||
"".to_string()
|
"".to_string()
|
||||||
@ -200,16 +182,70 @@ impl Dashboard {
|
|||||||
transaction_count,
|
transaction_count,
|
||||||
identity_balance
|
identity_balance
|
||||||
));
|
));
|
||||||
|
thread::sleep(Duration::from_millis(
|
||||||
|
MS_PER_TICK * DEFAULT_TICKS_PER_SLOT / 2,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
start_time = get_validator_start_time(&ledger_path).ok();
|
progress_bar
|
||||||
progress_bar.set_message(&format!("{}", err));
|
.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,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
@ -4,19 +4,10 @@ use {
|
|||||||
console::style,
|
console::style,
|
||||||
indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle},
|
indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle},
|
||||||
log::*,
|
log::*,
|
||||||
serde_derive::{Deserialize, Serialize},
|
std::{env, process::exit, thread::JoinHandle},
|
||||||
std::{
|
|
||||||
env,
|
|
||||||
fs::{self, File},
|
|
||||||
io::{self, Write},
|
|
||||||
net::SocketAddr,
|
|
||||||
path::Path,
|
|
||||||
process::exit,
|
|
||||||
thread::JoinHandle,
|
|
||||||
time::{Duration, SystemTime},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub mod admin_rpc_service;
|
||||||
pub mod dashboard;
|
pub mod dashboard;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
@ -91,52 +82,6 @@ pub fn port_validator(port: String) -> Result<(), String> {
|
|||||||
.map_err(|e| format!("{:?}", e))
|
.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
|
/// Creates a new process bar for processing that will take an unknown amount of time
|
||||||
pub fn new_spinner_progress_bar() -> ProgressBar {
|
pub fn new_spinner_progress_bar() -> ProgressBar {
|
||||||
let progress_bar = ProgressBar::new(42);
|
let progress_bar = ProgressBar::new(42);
|
||||||
|
@ -46,8 +46,8 @@ use solana_sdk::{
|
|||||||
signature::{Keypair, Signer},
|
signature::{Keypair, Signer},
|
||||||
};
|
};
|
||||||
use solana_validator::{
|
use solana_validator::{
|
||||||
dashboard::Dashboard, get_validator_rpc_addr, new_spinner_progress_bar, println_name_value,
|
admin_rpc_service, dashboard::Dashboard, new_spinner_progress_bar, println_name_value,
|
||||||
record_start, redirect_stderr_to_file,
|
redirect_stderr_to_file,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashSet, VecDeque},
|
collections::{HashSet, VecDeque},
|
||||||
@ -67,9 +67,11 @@ use std::{
|
|||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
enum Operation {
|
enum Operation {
|
||||||
|
Exit,
|
||||||
Initialize,
|
Initialize,
|
||||||
Monitor,
|
Monitor,
|
||||||
Run,
|
Run,
|
||||||
|
SetLogFilter { filter: String },
|
||||||
WaitForRestartWindow { min_idle_time_in_minutes: usize },
|
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 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| {
|
let admin_client = admin_rpc_service::connect(&ledger_path);
|
||||||
format!(
|
let rpc_addr = admin_rpc_service::runtime()
|
||||||
"Unable to read validator RPC address from {}: {}",
|
.block_on(async move { admin_client.await?.rpc_addr().await })
|
||||||
ledger_path.display(),
|
.map_err(|err| format!("Unable to get validator RPC address: {}", err))?;
|
||||||
err
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let rpc_client = match rpc_addr {
|
let rpc_client = match rpc_addr {
|
||||||
None => return Err("RPC not available".into()),
|
None => return Err("RPC not available".into()),
|
||||||
@ -1085,7 +1084,13 @@ pub fn main() {
|
|||||||
.value_name("PORT")
|
.value_name("PORT")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.validator(solana_validator::port_validator)
|
.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(
|
||||||
Arg::with_name("private_rpc")
|
Arg::with_name("private_rpc")
|
||||||
@ -1099,20 +1104,6 @@ pub fn main() {
|
|||||||
.takes_value(false)
|
.takes_value(false)
|
||||||
.help("Do not perform TCP/UDP reachable port checks at start-up")
|
.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(
|
||||||
Arg::with_name("enable_rpc_transaction_history")
|
Arg::with_name("enable_rpc_transaction_history")
|
||||||
.long("enable-rpc-transaction-history")
|
.long("enable-rpc-transaction-history")
|
||||||
@ -1645,17 +1636,32 @@ pub fn main() {
|
|||||||
.hidden(true),
|
.hidden(true),
|
||||||
)
|
)
|
||||||
.after_help("The default subcommand is run")
|
.after_help("The default subcommand is run")
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("exit")
|
||||||
|
.about("Send an exit request to the validator")
|
||||||
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("init")
|
SubCommand::with_name("init")
|
||||||
.about("Initialize the ledger directory then exit")
|
.about("Initialize the ledger directory then exit")
|
||||||
)
|
)
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("monitor")
|
||||||
|
.about("Monitor the validator")
|
||||||
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("run")
|
SubCommand::with_name("run")
|
||||||
.about("Run the validator")
|
.about("Run the validator")
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("monitor")
|
SubCommand::with_name("set-log-filter")
|
||||||
.about("Monitor the validator")
|
.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(
|
||||||
SubCommand::with_name("wait-for-restart-window")
|
SubCommand::with_name("wait-for-restart-window")
|
||||||
@ -1675,8 +1681,12 @@ pub fn main() {
|
|||||||
|
|
||||||
let operation = match matches.subcommand() {
|
let operation = match matches.subcommand() {
|
||||||
("", _) | ("run", _) => Operation::Run,
|
("", _) | ("run", _) => Operation::Run,
|
||||||
|
("exit", _) => Operation::Exit,
|
||||||
("init", _) => Operation::Initialize,
|
("init", _) => Operation::Initialize,
|
||||||
("monitor", _) => Operation::Monitor,
|
("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 {
|
("wait-for-restart-window", Some(subcommand_matches)) => Operation::WaitForRestartWindow {
|
||||||
min_idle_time_in_minutes: value_t_or_exit!(
|
min_idle_time_in_minutes: value_t_or_exit!(
|
||||||
subcommand_matches,
|
subcommand_matches,
|
||||||
@ -1792,8 +1802,6 @@ pub fn main() {
|
|||||||
expected_shred_version: value_t!(matches, "expected_shred_version", u16).ok(),
|
expected_shred_version: value_t!(matches, "expected_shred_version", u16).ok(),
|
||||||
new_hard_forks: hardforks_of(&matches, "hard_forks"),
|
new_hard_forks: hardforks_of(&matches, "hard_forks"),
|
||||||
rpc_config: JsonRpcConfig {
|
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_rpc_transaction_history: matches.is_present("enable_rpc_transaction_history"),
|
||||||
enable_cpi_and_log_storage: matches.is_present("enable_cpi_and_log_storage"),
|
enable_cpi_and_log_storage: matches.is_present("enable_cpi_and_log_storage"),
|
||||||
enable_bigtable_ledger_storage: matches
|
enable_bigtable_ledger_storage: matches
|
||||||
@ -1803,6 +1811,7 @@ pub fn main() {
|
|||||||
faucet_addr: matches.value_of("rpc_faucet_addr").map(|address| {
|
faucet_addr: matches.value_of("rpc_faucet_addr").map(|address| {
|
||||||
solana_net_utils::parse_host_port(address).expect("failed to parse faucet 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!(
|
max_multiple_accounts: Some(value_t_or_exit!(
|
||||||
matches,
|
matches,
|
||||||
"rpc_max_multiple_accounts",
|
"rpc_max_multiple_accounts",
|
||||||
@ -2038,8 +2047,28 @@ pub fn main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
match operation {
|
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 => {
|
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!(
|
println!(
|
||||||
"Error: Unable to connect to validator at {}: {:?}",
|
"Error: Unable to connect to validator at {}: {:?}",
|
||||||
ledger_path.display(),
|
ledger_path.display(),
|
||||||
@ -2070,15 +2099,6 @@ pub fn main() {
|
|||||||
exit(1);
|
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 = {
|
||||||
let logfile = matches
|
let logfile = matches
|
||||||
.value_of("logfile")
|
.value_of("logfile")
|
||||||
@ -2098,6 +2118,15 @@ pub fn main() {
|
|||||||
info!("{} {}", crate_name!(), solana_version::version!());
|
info!("{} {}", crate_name!(), solana_version::version!());
|
||||||
info!("Starting validator with: {:#?}", std::env::args_os());
|
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
|
let gossip_host: IpAddr = matches
|
||||||
.value_of("gossip_host")
|
.value_of("gossip_host")
|
||||||
.map(|gossip_host| {
|
.map(|gossip_host| {
|
||||||
|
Reference in New Issue
Block a user