Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tpu client next in validator with receiver #3893

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 117 additions & 29 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ use {
solana_rayon_threadlimit::{get_max_thread_count, get_thread_count},
solana_rpc::{
cache_block_meta_service::{CacheBlockMetaSender, CacheBlockMetaService},
cluster_tpu_info::ClusterTpuInfo,
max_slots::MaxSlots,
optimistically_confirmed_bank_tracker::{
BankNotificationSenderConfig, OptimisticallyConfirmedBank,
Expand Down Expand Up @@ -120,11 +121,15 @@ use {
hard_forks::HardForks,
hash::Hash,
pubkey::Pubkey,
quic::NotifyKeyUpdate,
shred_version::compute_shred_version,
signature::{Keypair, Signer},
timing::timestamp,
},
solana_send_transaction_service::send_transaction_service,
solana_send_transaction_service::{
send_transaction_service,
transaction_client::{ConnectionCacheClient, TpuClientNextClient},
},
solana_streamer::{socket::SocketAddrSpace, streamer::StakedNodes},
solana_turbine::{self, broadcast_stage::BroadcastStageType},
solana_unified_scheduler_pool::DefaultSchedulerPool,
Expand All @@ -146,7 +151,7 @@ use {
strum::VariantNames,
strum_macros::{Display, EnumCount, EnumIter, EnumString, EnumVariantNames, IntoStaticStr},
thiserror::Error,
tokio::runtime::Runtime as TokioRuntime,
tokio::runtime::{self, Runtime as TokioRuntime},
};

const MAX_COMPLETED_DATA_SETS_IN_CHANNEL: usize = 100_000;
Expand Down Expand Up @@ -286,6 +291,7 @@ pub struct ValidatorConfig {
pub replay_transactions_threads: NonZeroUsize,
pub tvu_shred_sigverify_threads: NonZeroUsize,
pub delay_leader_block_for_pending_fork: bool,
pub use_tpu_client_next: bool,
}

impl Default for ValidatorConfig {
Expand Down Expand Up @@ -358,6 +364,7 @@ impl Default for ValidatorConfig {
replay_transactions_threads: NonZeroUsize::new(1).expect("1 is non-zero"),
tvu_shred_sigverify_threads: NonZeroUsize::new(1).expect("1 is non-zero"),
delay_leader_block_for_pending_fork: false,
use_tpu_client_next: false,
}
}
}
Expand Down Expand Up @@ -1009,6 +1016,9 @@ impl Validator {

let staked_nodes = Arc::new(RwLock::new(StakedNodes::default()));

// ConnectionCache might be used for JsonRpc and for Forwarding. Since
// the latter is not migrated yet to the tpu-client-next, create
// ConnectionCache regardless of config.use_tpu_client_next for now.
let connection_cache = if use_quic {
let connection_cache = ConnectionCache::new_with_client_options(
"connection_cache_tpu_quic",
Expand Down Expand Up @@ -1067,6 +1077,7 @@ impl Validator {
rpc_completed_slots_service,
optimistically_confirmed_bank_tracker,
bank_notification_sender,
client_updater,
) = if let Some((rpc_addr, rpc_pubsub_addr)) = config.rpc_addrs {
assert_eq!(
node.info
Expand All @@ -1085,31 +1096,98 @@ impl Validator {
None
};

let json_rpc_service = JsonRpcService::new(
rpc_addr,
config.rpc_config.clone(),
Some(config.snapshot_config.clone()),
bank_forks.clone(),
block_commitment_cache.clone(),
blockstore.clone(),
cluster_info.clone(),
Some(poh_recorder.clone()),
genesis_config.hash(),
ledger_path,
config.validator_exit.clone(),
exit.clone(),
rpc_override_health_check.clone(),
startup_verification_complete,
optimistically_confirmed_bank.clone(),
config.send_transaction_service_config.clone(),
max_slots.clone(),
leader_schedule_cache.clone(),
connection_cache.clone(),
max_complete_transaction_status_slot,
max_complete_rewards_slot,
prioritization_fee_cache.clone(),
)
.map_err(ValidatorError::Other)?;
let leader_info = ClusterTpuInfo::new(cluster_info.clone(), poh_recorder.clone());
let (json_rpc_service, client_updater) = if config.use_tpu_client_next {
let tpu_client_next_runtime = runtime::Builder::new_multi_thread()
.enable_all()
.thread_name("solSTSQuic")
.build()
.expect(
"Should be possible to create tokio runtime for SendTransactionService.",
);
let my_tpu_address = cluster_info
.my_contact_info()
.tpu(Protocol::QUIC)
.map_err(|err| ValidatorError::Other(format!("{err}")))?;

let client = TpuClientNextClient::new(
tpu_client_next_runtime.handle().clone(),
my_tpu_address,
config.send_transaction_service_config.tpu_peers.clone(),
Some(leader_info),
config.send_transaction_service_config.leader_forward_count,
Some(identity_keypair.insecure_clone()),
);

let json_rpc_service = JsonRpcService::new(
rpc_addr,
config.rpc_config.clone(),
Some(config.snapshot_config.clone()),
bank_forks.clone(),
block_commitment_cache.clone(),
blockstore.clone(),
cluster_info.clone(),
genesis_config.hash(),
ledger_path,
config.validator_exit.clone(),
exit.clone(),
rpc_override_health_check.clone(),
startup_verification_complete,
optimistically_confirmed_bank.clone(),
config.send_transaction_service_config.clone(),
max_slots.clone(),
leader_schedule_cache.clone(),
client.clone(),
max_complete_transaction_status_slot,
max_complete_rewards_slot,
prioritization_fee_cache.clone(),
)
.map_err(ValidatorError::Other)?;
(
json_rpc_service,
Arc::new(client) as Arc<dyn NotifyKeyUpdate + Send + Sync>,
)
} else {
let my_tpu_address = cluster_info
.my_contact_info()
.tpu(connection_cache.protocol())
.map_err(|err| ValidatorError::Other(format!("{err}")))?;
let client = ConnectionCacheClient::new(
connection_cache.clone(),
my_tpu_address,
config.send_transaction_service_config.tpu_peers.clone(),
Some(leader_info),
config.send_transaction_service_config.leader_forward_count,
);
let json_rpc_service = JsonRpcService::new(
rpc_addr,
config.rpc_config.clone(),
Some(config.snapshot_config.clone()),
bank_forks.clone(),
block_commitment_cache.clone(),
blockstore.clone(),
cluster_info.clone(),
genesis_config.hash(),
ledger_path,
config.validator_exit.clone(),
exit.clone(),
rpc_override_health_check.clone(),
startup_verification_complete,
optimistically_confirmed_bank.clone(),
config.send_transaction_service_config.clone(),
max_slots.clone(),
leader_schedule_cache.clone(),
client.clone(),
max_complete_transaction_status_slot,
max_complete_rewards_slot,
prioritization_fee_cache.clone(),
)
.map_err(ValidatorError::Other)?;
(
json_rpc_service,
Arc::new(client) as Arc<dyn NotifyKeyUpdate + Send + Sync>,
)
};

let pubsub_service = if !config.rpc_config.full_api {
None
Expand Down Expand Up @@ -1185,9 +1263,10 @@ impl Validator {
rpc_completed_slots_service,
optimistically_confirmed_bank_tracker,
bank_notification_sender_config,
Some(client_updater),
)
} else {
(None, None, None, None, None, None, None)
(None, None, None, None, None, None, None, None)
};

if config.halt_at_slot.is_some() {
Expand Down Expand Up @@ -1409,6 +1488,11 @@ impl Validator {
let cluster_slots =
Arc::new(crate::cluster_slots_service::cluster_slots::ClusterSlots::default());

// If RPC is supported and ConnectionCache is used, pass ConnectionCache for being warmup inside Tvu.
let connection_cache_for_warmup = (json_rpc_service.is_some()
&& !config.use_tpu_client_next)
.then_some(&connection_cache);

let tvu = Tvu::new(
vote_account,
authorized_voter_keypairs,
Expand Down Expand Up @@ -1457,7 +1541,7 @@ impl Validator {
config.wait_to_vote_slot,
accounts_background_request_sender.clone(),
config.runtime_config.log_messages_bytes_limit,
json_rpc_service.is_some().then_some(&connection_cache), // for the cache warmer only used for STS for RPC service
connection_cache_for_warmup,
&prioritization_fee_cache,
banking_tracer.clone(),
turbine_quic_endpoint_sender.clone(),
Expand Down Expand Up @@ -1551,6 +1635,10 @@ impl Validator {
);

*start_progress.write().unwrap() = ValidatorStartProgress::Running;
if let Some(client_updater) = client_updater {
key_notifies.push(client_updater);
}
// add connection_cache because it is still used in Forwarder.
key_notifies.push(connection_cache);

*admin_rpc_service_post_init.write().unwrap() = Some(AdminRpcRequestMetadataPostInit {
Expand Down
1 change: 1 addition & 0 deletions local-cluster/src/validator_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub fn safe_clone_config(config: &ValidatorConfig) -> ValidatorConfig {
replay_transactions_threads: config.replay_transactions_threads,
tvu_shred_sigverify_threads: config.tvu_shred_sigverify_threads,
delay_leader_block_for_pending_fork: config.delay_leader_block_for_pending_fork,
use_tpu_client_next: config.use_tpu_client_next,
}
}

Expand Down
1 change: 1 addition & 0 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
solana-runtime-transaction = { workspace = true, features = [
"dev-context-only-utils",
] }
solana-send-transaction-service = { workspace = true, features = ["dev-context-only-utils"] }
solana-stake-program = { workspace = true }
spl-pod = { workspace = true }
symlink = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(clippy::arithmetic_side_effects)]
pub mod cache_block_meta_service;
mod cluster_tpu_info;
pub mod cluster_tpu_info;
pub mod filter;
pub mod max_slots;
pub mod optimistically_confirmed_bank_tracker;
Expand Down
Loading
Loading