Move ValidatorExit into ValidatorConfig, making it accessible from the solana-validator crate
This commit is contained in:
@ -130,7 +130,7 @@ pub struct JsonRpcRequestProcessor {
|
|||||||
blockstore: Arc<Blockstore>,
|
blockstore: Arc<Blockstore>,
|
||||||
config: JsonRpcConfig,
|
config: JsonRpcConfig,
|
||||||
snapshot_config: Option<SnapshotConfig>,
|
snapshot_config: Option<SnapshotConfig>,
|
||||||
validator_exit: Arc<RwLock<Option<ValidatorExit>>>,
|
validator_exit: Arc<RwLock<ValidatorExit>>,
|
||||||
health: Arc<RpcHealth>,
|
health: Arc<RpcHealth>,
|
||||||
cluster_info: Arc<ClusterInfo>,
|
cluster_info: Arc<ClusterInfo>,
|
||||||
genesis_hash: Hash,
|
genesis_hash: Hash,
|
||||||
@ -215,7 +215,7 @@ impl JsonRpcRequestProcessor {
|
|||||||
bank_forks: Arc<RwLock<BankForks>>,
|
bank_forks: Arc<RwLock<BankForks>>,
|
||||||
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
|
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
|
||||||
blockstore: Arc<Blockstore>,
|
blockstore: Arc<Blockstore>,
|
||||||
validator_exit: Arc<RwLock<Option<ValidatorExit>>>,
|
validator_exit: Arc<RwLock<ValidatorExit>>,
|
||||||
health: Arc<RpcHealth>,
|
health: Arc<RpcHealth>,
|
||||||
cluster_info: Arc<ClusterInfo>,
|
cluster_info: Arc<ClusterInfo>,
|
||||||
genesis_hash: Hash,
|
genesis_hash: Hash,
|
||||||
@ -661,9 +661,7 @@ impl JsonRpcRequestProcessor {
|
|||||||
pub fn validator_exit(&self) -> bool {
|
pub fn validator_exit(&self) -> bool {
|
||||||
if self.config.enable_validator_exit {
|
if self.config.enable_validator_exit {
|
||||||
warn!("validator_exit request...");
|
warn!("validator_exit request...");
|
||||||
if let Some(x) = self.validator_exit.write().unwrap().take() {
|
self.validator_exit.write().unwrap().exit();
|
||||||
x.exit()
|
|
||||||
}
|
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
debug!("validator_exit ignored");
|
debug!("validator_exit ignored");
|
||||||
@ -3049,11 +3047,11 @@ fn deserialize_transaction(
|
|||||||
.map(|transaction| (wire_transaction, transaction))
|
.map(|transaction| (wire_transaction, transaction))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn create_validator_exit(exit: &Arc<AtomicBool>) -> Arc<RwLock<Option<ValidatorExit>>> {
|
pub(crate) fn create_validator_exit(exit: &Arc<AtomicBool>) -> Arc<RwLock<ValidatorExit>> {
|
||||||
let mut validator_exit = ValidatorExit::default();
|
let mut validator_exit = ValidatorExit::default();
|
||||||
let exit_ = exit.clone();
|
let exit_ = exit.clone();
|
||||||
validator_exit.register_exit(Box::new(move || exit_.store(true, Ordering::Relaxed)));
|
validator_exit.register_exit(Box::new(move || exit_.store(true, Ordering::Relaxed)));
|
||||||
Arc::new(RwLock::new(Some(validator_exit)))
|
Arc::new(RwLock::new(validator_exit))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -267,7 +267,7 @@ impl JsonRpcService {
|
|||||||
poh_recorder: Option<Arc<Mutex<PohRecorder>>>,
|
poh_recorder: Option<Arc<Mutex<PohRecorder>>>,
|
||||||
genesis_hash: Hash,
|
genesis_hash: Hash,
|
||||||
ledger_path: &Path,
|
ledger_path: &Path,
|
||||||
validator_exit: Arc<RwLock<Option<ValidatorExit>>>,
|
validator_exit: Arc<RwLock<ValidatorExit>>,
|
||||||
trusted_validators: Option<HashSet<Pubkey>>,
|
trusted_validators: Option<HashSet<Pubkey>>,
|
||||||
override_health_check: Arc<AtomicBool>,
|
override_health_check: Arc<AtomicBool>,
|
||||||
optimistically_confirmed_bank: Arc<RwLock<OptimisticallyConfirmedBank>>,
|
optimistically_confirmed_bank: Arc<RwLock<OptimisticallyConfirmedBank>>,
|
||||||
@ -434,9 +434,8 @@ impl JsonRpcService {
|
|||||||
|
|
||||||
let close_handle = close_handle_receiver.recv().unwrap();
|
let close_handle = close_handle_receiver.recv().unwrap();
|
||||||
let close_handle_ = close_handle.clone();
|
let close_handle_ = close_handle.clone();
|
||||||
let mut validator_exit_write = validator_exit.write().unwrap();
|
validator_exit
|
||||||
validator_exit_write
|
.write()
|
||||||
.as_mut()
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.register_exit(Box::new(move || close_handle_.close()));
|
.register_exit(Box::new(move || close_handle_.close()));
|
||||||
Self {
|
Self {
|
||||||
|
@ -66,6 +66,7 @@ use solana_vote_program::vote_state::VoteState;
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
|
fmt,
|
||||||
net::SocketAddr,
|
net::SocketAddr,
|
||||||
ops::Deref,
|
ops::Deref,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
@ -127,6 +128,7 @@ pub struct ValidatorConfig {
|
|||||||
pub accounts_db_test_hash_calculation: bool,
|
pub accounts_db_test_hash_calculation: bool,
|
||||||
pub accounts_db_use_index_hash_calculation: bool,
|
pub accounts_db_use_index_hash_calculation: bool,
|
||||||
pub tpu_coalesce_ms: u64,
|
pub tpu_coalesce_ms: u64,
|
||||||
|
pub validator_exit: Arc<RwLock<ValidatorExit>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ValidatorConfig {
|
impl Default for ValidatorConfig {
|
||||||
@ -179,6 +181,7 @@ impl Default for ValidatorConfig {
|
|||||||
accounts_db_test_hash_calculation: false,
|
accounts_db_test_hash_calculation: false,
|
||||||
accounts_db_use_index_hash_calculation: true,
|
accounts_db_use_index_hash_calculation: true,
|
||||||
tpu_coalesce_ms: DEFAULT_TPU_COALESCE_MS,
|
tpu_coalesce_ms: DEFAULT_TPU_COALESCE_MS,
|
||||||
|
validator_exit: Arc::new(RwLock::new(ValidatorExit::default())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,13 +196,19 @@ impl ValidatorExit {
|
|||||||
self.exits.push(exit);
|
self.exits.push(exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exit(self) {
|
pub fn exit(&mut self) {
|
||||||
for exit in self.exits {
|
for exit in self.exits.drain(..) {
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for ValidatorExit {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "{} exits", self.exits.len())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct TransactionHistoryServices {
|
struct TransactionHistoryServices {
|
||||||
transaction_status_sender: Option<TransactionStatusSender>,
|
transaction_status_sender: Option<TransactionStatusSender>,
|
||||||
@ -218,7 +227,7 @@ struct RpcServices {
|
|||||||
|
|
||||||
pub struct Validator {
|
pub struct Validator {
|
||||||
pub id: Pubkey,
|
pub id: Pubkey,
|
||||||
validator_exit: Arc<RwLock<Option<ValidatorExit>>>,
|
validator_exit: Arc<RwLock<ValidatorExit>>,
|
||||||
rpc_service: Option<RpcServices>,
|
rpc_service: Option<RpcServices>,
|
||||||
transaction_status_service: Option<TransactionStatusService>,
|
transaction_status_service: Option<TransactionStatusService>,
|
||||||
rewards_recorder_service: Option<RewardsRecorderService>,
|
rewards_recorder_service: Option<RewardsRecorderService>,
|
||||||
@ -319,11 +328,15 @@ impl Validator {
|
|||||||
start.stop();
|
start.stop();
|
||||||
info!("done. {}", start);
|
info!("done. {}", start);
|
||||||
|
|
||||||
let mut validator_exit = ValidatorExit::default();
|
|
||||||
let exit = Arc::new(AtomicBool::new(false));
|
let exit = Arc::new(AtomicBool::new(false));
|
||||||
let exit_ = exit.clone();
|
{
|
||||||
validator_exit.register_exit(Box::new(move || exit_.store(true, Ordering::Relaxed)));
|
let exit = exit.clone();
|
||||||
let validator_exit = Arc::new(RwLock::new(Some(validator_exit)));
|
config
|
||||||
|
.validator_exit
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.register_exit(Box::new(move || exit.store(true, Ordering::Relaxed)));
|
||||||
|
}
|
||||||
|
|
||||||
let (replay_vote_sender, replay_vote_receiver) = unbounded();
|
let (replay_vote_sender, replay_vote_receiver) = unbounded();
|
||||||
let (
|
let (
|
||||||
@ -484,7 +497,7 @@ impl Validator {
|
|||||||
Some(poh_recorder.clone()),
|
Some(poh_recorder.clone()),
|
||||||
genesis_config.hash(),
|
genesis_config.hash(),
|
||||||
ledger_path,
|
ledger_path,
|
||||||
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(),
|
||||||
@ -703,15 +716,13 @@ impl Validator {
|
|||||||
poh_service,
|
poh_service,
|
||||||
poh_recorder,
|
poh_recorder,
|
||||||
ip_echo_server,
|
ip_echo_server,
|
||||||
validator_exit,
|
validator_exit: config.validator_exit.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used for notifying many nodes in parallel to exit
|
// Used for notifying many nodes in parallel to exit
|
||||||
pub fn exit(&mut self) {
|
pub fn exit(&mut self) {
|
||||||
if let Some(x) = self.validator_exit.write().unwrap().take() {
|
self.validator_exit.write().unwrap().exit();
|
||||||
x.exit()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn close(mut self) {
|
pub fn close(mut self) {
|
||||||
|
Reference in New Issue
Block a user