safecoin_client/nonblocking/
tpu_connection.rs

1//! Trait defining async send functions, to be used for UDP or QUIC sending
2
3use {
4    crate::nonblocking::{quic_client::QuicTpuConnection, udp_client::UdpTpuConnection},
5    async_trait::async_trait,
6    enum_dispatch::enum_dispatch,
7    solana_sdk::{transaction::VersionedTransaction, transport::Result as TransportResult},
8    std::net::SocketAddr,
9};
10
11// Due to the existence of `crate::connection_cache::Connection`, if this is named
12// `Connection`, enum_dispatch gets confused between the two and throws errors when
13// trying to convert later.
14#[enum_dispatch]
15pub enum NonblockingConnection {
16    QuicTpuConnection,
17    UdpTpuConnection,
18}
19
20#[async_trait]
21#[enum_dispatch(NonblockingConnection)]
22pub trait TpuConnection {
23    fn tpu_addr(&self) -> &SocketAddr;
24
25    async fn serialize_and_send_transaction(
26        &self,
27        transaction: &VersionedTransaction,
28    ) -> TransportResult<()> {
29        let wire_transaction =
30            bincode::serialize(transaction).expect("serialize Transaction in send_batch");
31        self.send_wire_transaction(&wire_transaction).await
32    }
33
34    async fn send_wire_transaction<T>(&self, wire_transaction: T) -> TransportResult<()>
35    where
36        T: AsRef<[u8]> + Send + Sync;
37
38    async fn send_wire_transaction_batch<T>(&self, buffers: &[T]) -> TransportResult<()>
39    where
40        T: AsRef<[u8]> + Send + Sync;
41}