Rename ValidatorExit and move to sdk (#17728)

This commit is contained in:
Tyera Eulberg
2021-06-03 21:06:13 -06:00
committed by GitHub
parent 3dcc8e0046
commit 3a647c4bea
11 changed files with 62 additions and 55 deletions

View File

@ -3,7 +3,6 @@
use crate::{
rpc_health::*,
send_transaction_service::{SendTransactionService, TransactionInfo},
validator::ValidatorExit,
};
use bincode::{config::Options, serialize};
use jsonrpc_core::{types::error, Error, Metadata, Result};
@ -58,6 +57,7 @@ use solana_sdk::{
commitment_config::{CommitmentConfig, CommitmentLevel},
epoch_info::EpochInfo,
epoch_schedule::EpochSchedule,
exit::Exit,
hash::Hash,
pubkey::Pubkey,
sanitize::Sanitize,
@ -148,7 +148,7 @@ pub struct JsonRpcRequestProcessor {
blockstore: Arc<Blockstore>,
config: JsonRpcConfig,
snapshot_config: Option<SnapshotConfig>,
validator_exit: Arc<RwLock<ValidatorExit>>,
validator_exit: Arc<RwLock<Exit>>,
health: Arc<RpcHealth>,
cluster_info: Arc<ClusterInfo>,
genesis_hash: Hash,
@ -235,7 +235,7 @@ impl JsonRpcRequestProcessor {
bank_forks: Arc<RwLock<BankForks>>,
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
blockstore: Arc<Blockstore>,
validator_exit: Arc<RwLock<ValidatorExit>>,
validator_exit: Arc<RwLock<Exit>>,
health: Arc<RpcHealth>,
cluster_info: Arc<ClusterInfo>,
genesis_hash: Hash,
@ -3772,8 +3772,8 @@ fn deserialize_transaction(
.map(|transaction| (wire_transaction, transaction))
}
pub(crate) fn create_validator_exit(exit: &Arc<AtomicBool>) -> Arc<RwLock<ValidatorExit>> {
let mut validator_exit = ValidatorExit::default();
pub(crate) fn create_validator_exit(exit: &Arc<AtomicBool>) -> Arc<RwLock<Exit>> {
let mut validator_exit = Exit::default();
let exit_ = exit.clone();
validator_exit.register_exit(Box::new(move || exit_.store(true, Ordering::Relaxed)));
Arc::new(RwLock::new(validator_exit))

View File

@ -6,7 +6,6 @@ use crate::{
rpc::{rpc_deprecated_v1_7::*, rpc_full::*, rpc_minimal::*, rpc_obsolete_v1_7::*, *},
rpc_health::*,
send_transaction_service::{LeaderInfo, SendTransactionService},
validator::ValidatorExit,
};
use jsonrpc_core::{futures::prelude::*, MetaIoHandler};
use jsonrpc_http_server::{
@ -27,8 +26,8 @@ use solana_runtime::{
snapshot_utils,
};
use solana_sdk::{
genesis_config::DEFAULT_GENESIS_DOWNLOAD_PATH, hash::Hash, native_token::lamports_to_sol,
pubkey::Pubkey,
exit::Exit, genesis_config::DEFAULT_GENESIS_DOWNLOAD_PATH, hash::Hash,
native_token::lamports_to_sol, pubkey::Pubkey,
};
use std::{
collections::HashSet,
@ -273,7 +272,7 @@ impl JsonRpcService {
poh_recorder: Option<Arc<Mutex<PohRecorder>>>,
genesis_hash: Hash,
ledger_path: &Path,
validator_exit: Arc<RwLock<ValidatorExit>>,
validator_exit: Arc<RwLock<Exit>>,
trusted_validators: Option<HashSet<Pubkey>>,
override_health_check: Arc<AtomicBool>,
optimistically_confirmed_bank: Arc<RwLock<OptimisticallyConfirmedBank>>,

View File

@ -1,7 +1,7 @@
use {
crate::{
rpc::JsonRpcConfig,
validator::{Validator, ValidatorConfig, ValidatorExit, ValidatorStartProgress},
validator::{Validator, ValidatorConfig, ValidatorStartProgress},
},
solana_client::rpc_client::RpcClient,
solana_gossip::{cluster_info::Node, gossip_service::discover_cluster, socketaddr},
@ -18,6 +18,7 @@ use {
clock::{Slot, DEFAULT_MS_PER_SLOT},
commitment_config::CommitmentConfig,
epoch_schedule::EpochSchedule,
exit::Exit,
fee_calculator::{FeeCalculator, FeeRateGovernor},
hash::Hash,
native_token::sol_to_lamports,
@ -79,7 +80,7 @@ pub struct TestValidatorGenesis {
programs: Vec<ProgramInfo>,
epoch_schedule: Option<EpochSchedule>,
node_config: TestValidatorNodeConfig,
pub validator_exit: Arc<RwLock<ValidatorExit>>,
pub validator_exit: Arc<RwLock<Exit>>,
pub start_progress: Arc<RwLock<ValidatorStartProgress>>,
pub authorized_voter_keypairs: Arc<RwLock<Vec<Arc<Keypair>>>>,
pub max_ledger_shreds: Option<u64>,

View File

@ -59,6 +59,7 @@ use solana_runtime::{
use solana_sdk::{
clock::Slot,
epoch_schedule::MAX_LEADER_SCHEDULE_EPOCH_OFFSET,
exit::Exit,
genesis_config::GenesisConfig,
hash::Hash,
pubkey::Pubkey,
@ -70,7 +71,6 @@ use solana_vote_program::vote_state::VoteState;
use std::time::Instant;
use std::{
collections::HashSet,
fmt,
net::SocketAddr,
ops::Deref,
path::{Path, PathBuf},
@ -135,7 +135,7 @@ pub struct ValidatorConfig {
pub accounts_db_test_hash_calculation: bool,
pub accounts_db_use_index_hash_calculation: bool,
pub tpu_coalesce_ms: u64,
pub validator_exit: Arc<RwLock<ValidatorExit>>,
pub validator_exit: Arc<RwLock<Exit>>,
pub no_wait_for_vote_to_start_leader: bool,
}
@ -191,7 +191,7 @@ impl Default for ValidatorConfig {
accounts_db_test_hash_calculation: false,
accounts_db_use_index_hash_calculation: true,
tpu_coalesce_ms: DEFAULT_TPU_COALESCE_MS,
validator_exit: Arc::new(RwLock::new(ValidatorExit::default())),
validator_exit: Arc::new(RwLock::new(Exit::default())),
no_wait_for_vote_to_start_leader: true,
}
}
@ -223,35 +223,6 @@ impl Default for ValidatorStartProgress {
}
}
#[derive(Default)]
pub struct ValidatorExit {
exited: bool,
exits: Vec<Box<dyn FnOnce() + Send + Sync>>,
}
impl ValidatorExit {
pub fn register_exit(&mut self, exit: Box<dyn FnOnce() + Send + Sync>) {
if self.exited {
exit();
} else {
self.exits.push(exit);
}
}
pub fn exit(&mut self) {
self.exited = true;
for exit in self.exits.drain(..) {
exit();
}
}
}
impl fmt::Debug for ValidatorExit {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} exits", self.exits.len())
}
}
#[derive(Default)]
struct TransactionHistoryServices {
transaction_status_sender: Option<TransactionStatusSender>,
@ -264,7 +235,7 @@ struct TransactionHistoryServices {
}
pub struct Validator {
validator_exit: Arc<RwLock<ValidatorExit>>,
validator_exit: Arc<RwLock<Exit>>,
json_rpc_service: Option<JsonRpcService>,
pubsub_service: Option<PubSubService>,
optimistically_confirmed_bank_tracker: Option<OptimisticallyConfirmedBankTracker>,