removes redundant NewConnectionConfig trait (#31979)

Working towards removing hard-coded TPU specific configurations from
QUIC code; NewConnectionConfig is redundant and gets in the way.
This commit is contained in:
behzad nouri 2023-06-06 21:28:29 +00:00 committed by GitHub
parent 0db4f3f263
commit 5760390d3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 12 additions and 37 deletions

View File

@ -1,9 +1,7 @@
use { use {
crate::bench_tps_client::{BenchTpsClient, BenchTpsError, Result}, crate::bench_tps_client::{BenchTpsClient, BenchTpsError, Result},
solana_client::tpu_client::TpuClient, solana_client::tpu_client::TpuClient,
solana_connection_cache::connection_cache::{ solana_connection_cache::connection_cache::{ConnectionManager, ConnectionPool},
ConnectionManager, ConnectionPool, NewConnectionConfig,
},
solana_sdk::{ solana_sdk::{
account::Account, commitment_config::CommitmentConfig, epoch_info::EpochInfo, hash::Hash, account::Account, commitment_config::CommitmentConfig, epoch_info::EpochInfo, hash::Hash,
message::Message, pubkey::Pubkey, signature::Signature, transaction::Transaction, message::Message, pubkey::Pubkey, signature::Signature, transaction::Transaction,
@ -14,7 +12,6 @@ impl<P, M, C> BenchTpsClient for TpuClient<P, M, C>
where where
P: ConnectionPool<NewConnectionConfig = C>, P: ConnectionPool<NewConnectionConfig = C>,
M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>, M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>,
C: NewConnectionConfig,
{ {
fn send_transaction(&self, transaction: Transaction) -> Result<Signature> { fn send_transaction(&self, transaction: Transaction) -> Result<Signature> {
let signature = transaction.signatures[0]; let signature = transaction.signatures[0];

View File

@ -5,7 +5,6 @@ use {
client_connection::ClientConnection, client_connection::ClientConnection,
connection_cache::{ connection_cache::{
BaseClientConnection, ConnectionCache as BackendConnectionCache, ConnectionPool, BaseClientConnection, ConnectionCache as BackendConnectionCache, ConnectionPool,
NewConnectionConfig,
}, },
}, },
solana_quic_client::{QuicConfig, QuicConnectionManager, QuicPool}, solana_quic_client::{QuicConfig, QuicConnectionManager, QuicPool},

View File

@ -3,7 +3,6 @@ use {
crate::{connection_cache::ConnectionCache, tpu_client::TpuClientConfig}, crate::{connection_cache::ConnectionCache, tpu_client::TpuClientConfig},
solana_connection_cache::connection_cache::{ solana_connection_cache::connection_cache::{
ConnectionCache as BackendConnectionCache, ConnectionManager, ConnectionPool, ConnectionCache as BackendConnectionCache, ConnectionManager, ConnectionPool,
NewConnectionConfig,
}, },
solana_quic_client::{QuicConfig, QuicConnectionManager, QuicPool}, solana_quic_client::{QuicConfig, QuicConnectionManager, QuicPool},
solana_rpc_client::nonblocking::rpc_client::RpcClient, solana_rpc_client::nonblocking::rpc_client::RpcClient,
@ -31,7 +30,6 @@ impl<P, M, C> TpuClient<P, M, C>
where where
P: ConnectionPool<NewConnectionConfig = C>, P: ConnectionPool<NewConnectionConfig = C>,
M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>, M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>,
C: NewConnectionConfig,
{ {
/// Serialize and send transaction to the current and upcoming leader TPUs according to fanout /// Serialize and send transaction to the current and upcoming leader TPUs according to fanout
/// size /// size
@ -101,7 +99,6 @@ impl<P, M, C> TpuClient<P, M, C>
where where
P: ConnectionPool<NewConnectionConfig = C>, P: ConnectionPool<NewConnectionConfig = C>,
M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>, M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>,
C: NewConnectionConfig,
{ {
/// Create a new client that disconnects when dropped /// Create a new client that disconnects when dropped
pub async fn new_with_connection_cache( pub async fn new_with_connection_cache(

View File

@ -2,7 +2,6 @@ use {
crate::connection_cache::ConnectionCache, crate::connection_cache::ConnectionCache,
solana_connection_cache::connection_cache::{ solana_connection_cache::connection_cache::{
ConnectionCache as BackendConnectionCache, ConnectionManager, ConnectionPool, ConnectionCache as BackendConnectionCache, ConnectionManager, ConnectionPool,
NewConnectionConfig,
}, },
solana_quic_client::{QuicConfig, QuicConnectionManager, QuicPool}, solana_quic_client::{QuicConfig, QuicConnectionManager, QuicPool},
solana_rpc_client::rpc_client::RpcClient, solana_rpc_client::rpc_client::RpcClient,
@ -35,7 +34,6 @@ impl<P, M, C> TpuClient<P, M, C>
where where
P: ConnectionPool<NewConnectionConfig = C>, P: ConnectionPool<NewConnectionConfig = C>,
M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>, M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>,
C: NewConnectionConfig,
{ {
/// Serialize and send transaction to the current and upcoming leader TPUs according to fanout /// Serialize and send transaction to the current and upcoming leader TPUs according to fanout
/// size /// size
@ -92,7 +90,6 @@ impl<P, M, C> TpuClient<P, M, C>
where where
P: ConnectionPool<NewConnectionConfig = C>, P: ConnectionPool<NewConnectionConfig = C>,
M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>, M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>,
C: NewConnectionConfig,
{ {
/// Create a new client that disconnects when dropped /// Create a new client that disconnects when dropped
pub fn new_with_connection_cache( pub fn new_with_connection_cache(

View File

@ -29,7 +29,7 @@ pub enum Protocol {
pub trait ConnectionManager { pub trait ConnectionManager {
type ConnectionPool: ConnectionPool; type ConnectionPool: ConnectionPool;
type NewConnectionConfig: NewConnectionConfig; type NewConnectionConfig;
const PROTOCOL: Protocol; const PROTOCOL: Protocol;
@ -55,7 +55,6 @@ impl<P, M, C> ConnectionCache<P, M, C>
where where
P: ConnectionPool<NewConnectionConfig = C>, P: ConnectionPool<NewConnectionConfig = C>,
M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>, M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>,
C: NewConnectionConfig,
{ {
pub fn new( pub fn new(
name: &'static str, name: &'static str,
@ -300,12 +299,8 @@ pub enum ClientError {
IoError(#[from] std::io::Error), IoError(#[from] std::io::Error),
} }
pub trait NewConnectionConfig: Sized {
fn new() -> Result<Self, ClientError>;
}
pub trait ConnectionPool { pub trait ConnectionPool {
type NewConnectionConfig: NewConnectionConfig; type NewConnectionConfig;
type BaseClientConnection: BaseClientConnection; type BaseClientConnection: BaseClientConnection;
/// Add a connection to the pool /// Add a connection to the pool
@ -441,7 +436,7 @@ mod tests {
} }
} }
impl NewConnectionConfig for MockUdpConfig { impl MockUdpConfig {
fn new() -> Result<Self, ClientError> { fn new() -> Result<Self, ClientError> {
Ok(Self { Ok(Self {
udp_socket: Arc::new( udp_socket: Arc::new(

View File

@ -19,7 +19,7 @@ use {
solana_connection_cache::{ solana_connection_cache::{
connection_cache::{ connection_cache::{
BaseClientConnection, ClientError, ConnectionManager, ConnectionPool, BaseClientConnection, ClientError, ConnectionManager, ConnectionPool,
ConnectionPoolError, NewConnectionConfig, Protocol, ConnectionPoolError, Protocol,
}, },
connection_cache_stats::ConnectionCacheStats, connection_cache_stats::ConnectionCacheStats,
}, },
@ -89,8 +89,8 @@ pub struct QuicConfig {
client_endpoint: Option<Endpoint>, client_endpoint: Option<Endpoint>,
} }
impl NewConnectionConfig for QuicConfig { impl QuicConfig {
fn new() -> Result<Self, ClientError> { pub fn new() -> Result<Self, ClientError> {
let (cert, priv_key) = let (cert, priv_key) =
new_self_signed_tls_certificate(&Keypair::new(), IpAddr::V4(Ipv4Addr::UNSPECIFIED))?; new_self_signed_tls_certificate(&Keypair::new(), IpAddr::V4(Ipv4Addr::UNSPECIFIED))?;
Ok(Self { Ok(Self {

View File

@ -8,9 +8,7 @@ use {
rayon::iter::{IntoParallelIterator, ParallelIterator}, rayon::iter::{IntoParallelIterator, ParallelIterator},
solana_connection_cache::{ solana_connection_cache::{
client_connection::ClientConnection, client_connection::ClientConnection,
connection_cache::{ connection_cache::{ConnectionCache, ConnectionManager, ConnectionPool},
ConnectionCache, ConnectionManager, ConnectionPool, NewConnectionConfig,
},
}, },
solana_rpc_client::rpc_client::RpcClient, solana_rpc_client::rpc_client::RpcClient,
solana_rpc_client_api::{config::RpcProgramAccountsConfig, response::Response}, solana_rpc_client_api::{config::RpcProgramAccountsConfig, response::Response},
@ -126,7 +124,6 @@ impl<P, M, C> ThinClient<P, M, C>
where where
P: ConnectionPool<NewConnectionConfig = C>, P: ConnectionPool<NewConnectionConfig = C>,
M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>, M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>,
C: NewConnectionConfig,
{ {
/// Create a new ThinClient that will interface with the Rpc at `rpc_addr` using TCP /// Create a new ThinClient that will interface with the Rpc at `rpc_addr` using TCP
/// and the Tpu at `tpu_addr` over `transactions_socket` using Quic or UDP /// and the Tpu at `tpu_addr` over `transactions_socket` using Quic or UDP
@ -327,7 +324,6 @@ impl<P, M, C> Client for ThinClient<P, M, C>
where where
P: ConnectionPool<NewConnectionConfig = C>, P: ConnectionPool<NewConnectionConfig = C>,
M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>, M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>,
C: NewConnectionConfig,
{ {
fn tpu_addr(&self) -> String { fn tpu_addr(&self) -> String {
self.tpu_addr().to_string() self.tpu_addr().to_string()
@ -338,7 +334,6 @@ impl<P, M, C> SyncClient for ThinClient<P, M, C>
where where
P: ConnectionPool<NewConnectionConfig = C>, P: ConnectionPool<NewConnectionConfig = C>,
M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>, M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>,
C: NewConnectionConfig,
{ {
fn send_and_confirm_message<T: Signers + ?Sized>( fn send_and_confirm_message<T: Signers + ?Sized>(
&self, &self,
@ -623,7 +618,6 @@ impl<P, M, C> AsyncClient for ThinClient<P, M, C>
where where
P: ConnectionPool<NewConnectionConfig = C>, P: ConnectionPool<NewConnectionConfig = C>,
M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>, M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>,
C: NewConnectionConfig,
{ {
fn async_send_versioned_transaction( fn async_send_versioned_transaction(
&self, &self,

View File

@ -6,7 +6,7 @@ use {
log::*, log::*,
solana_connection_cache::{ solana_connection_cache::{
connection_cache::{ connection_cache::{
ConnectionCache, ConnectionManager, ConnectionPool, NewConnectionConfig, Protocol, ConnectionCache, ConnectionManager, ConnectionPool, Protocol,
DEFAULT_CONNECTION_POOL_SIZE, DEFAULT_CONNECTION_POOL_SIZE,
}, },
nonblocking::client_connection::ClientConnection, nonblocking::client_connection::ClientConnection,
@ -280,7 +280,6 @@ async fn send_wire_transaction_to_addr<P, M, C>(
where where
P: ConnectionPool<NewConnectionConfig = C>, P: ConnectionPool<NewConnectionConfig = C>,
M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>, M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>,
C: NewConnectionConfig,
{ {
let conn = connection_cache.get_nonblocking_connection(addr); let conn = connection_cache.get_nonblocking_connection(addr);
conn.send_data(&wire_transaction).await conn.send_data(&wire_transaction).await
@ -294,7 +293,6 @@ async fn send_wire_transaction_batch_to_addr<P, M, C>(
where where
P: ConnectionPool<NewConnectionConfig = C>, P: ConnectionPool<NewConnectionConfig = C>,
M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>, M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>,
C: NewConnectionConfig,
{ {
let conn = connection_cache.get_nonblocking_connection(addr); let conn = connection_cache.get_nonblocking_connection(addr);
conn.send_data_batch(wire_transactions).await conn.send_data_batch(wire_transactions).await
@ -304,7 +302,6 @@ impl<P, M, C> TpuClient<P, M, C>
where where
P: ConnectionPool<NewConnectionConfig = C>, P: ConnectionPool<NewConnectionConfig = C>,
M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>, M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>,
C: NewConnectionConfig,
{ {
/// Serialize and send transaction to the current and upcoming leader TPUs according to fanout /// Serialize and send transaction to the current and upcoming leader TPUs according to fanout
/// size /// size

View File

@ -3,7 +3,7 @@ use {
crate::nonblocking::tpu_client::TpuClient as NonblockingTpuClient, crate::nonblocking::tpu_client::TpuClient as NonblockingTpuClient,
rayon::iter::{IntoParallelIterator, ParallelIterator}, rayon::iter::{IntoParallelIterator, ParallelIterator},
solana_connection_cache::connection_cache::{ solana_connection_cache::connection_cache::{
ConnectionCache, ConnectionManager, ConnectionPool, NewConnectionConfig, ConnectionCache, ConnectionManager, ConnectionPool,
}, },
solana_rpc_client::rpc_client::RpcClient, solana_rpc_client::rpc_client::RpcClient,
solana_sdk::{clock::Slot, transaction::Transaction, transport::Result as TransportResult}, solana_sdk::{clock::Slot, transaction::Transaction, transport::Result as TransportResult},
@ -71,7 +71,6 @@ impl<P, M, C> TpuClient<P, M, C>
where where
P: ConnectionPool<NewConnectionConfig = C>, P: ConnectionPool<NewConnectionConfig = C>,
M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>, M: ConnectionManager<ConnectionPool = P, NewConnectionConfig = C>,
C: NewConnectionConfig,
{ {
/// Serialize and send transaction to the current and upcoming leader TPUs according to fanout /// Serialize and send transaction to the current and upcoming leader TPUs according to fanout
/// size /// size

View File

@ -11,7 +11,7 @@ use {
solana_connection_cache::{ solana_connection_cache::{
connection_cache::{ connection_cache::{
BaseClientConnection, ClientError, ConnectionManager, ConnectionPool, BaseClientConnection, ClientError, ConnectionManager, ConnectionPool,
ConnectionPoolError, NewConnectionConfig, Protocol, ConnectionPoolError, Protocol,
}, },
connection_cache_stats::ConnectionCacheStats, connection_cache_stats::ConnectionCacheStats,
}, },
@ -57,7 +57,7 @@ pub struct UdpConfig {
udp_socket: Arc<UdpSocket>, udp_socket: Arc<UdpSocket>,
} }
impl NewConnectionConfig for UdpConfig { impl UdpConfig {
fn new() -> Result<Self, ClientError> { fn new() -> Result<Self, ClientError> {
let socket = solana_net_utils::bind_with_any_port(IpAddr::V4(Ipv4Addr::UNSPECIFIED)) let socket = solana_net_utils::bind_with_any_port(IpAddr::V4(Ipv4Addr::UNSPECIFIED))
.map_err(Into::<ClientError>::into)?; .map_err(Into::<ClientError>::into)?;