Line data Source code
1 : #ifndef HEADER_fd_src_discof_send_fd_send_tile_h 2 : #define HEADER_fd_src_discof_send_fd_send_tile_h 3 : 4 : /* Sender tile signs and sends transactions to the current leader. 5 : Currently only supports transactions which require one signature. 6 : Designed with voting as primary use case. Signing those votes will 7 : eventually move to a separate consensus tile.*/ 8 : #define _GNU_SOURCE 9 : 10 : #include "../../util/net/fd_net_headers.h" 11 : #include "../../disco/stem/fd_stem.h" 12 : #include "../../disco/fd_disco.h" 13 : #include "../../disco/net/fd_net_tile.h" 14 : #include "../../disco/keyguard/fd_keyguard_client.h" 15 : #include "../../flamenco/leaders/fd_multi_epoch_leaders.h" 16 : #include "../../waltz/quic/fd_quic.h" 17 : 18 : #define IN_KIND_SIGN (0UL) 19 0 : #define IN_KIND_GOSSIP (1UL) 20 0 : #define IN_KIND_STAKE (2UL) 21 0 : #define IN_KIND_TOWER (3UL) 22 0 : #define IN_KIND_NET (4UL) 23 : 24 : /* Send votes to next FD_SEND_TARGET_LEADER_CNT leaders (slot x, x+4, x+8, ...) */ 25 0 : #define FD_SEND_TARGET_LEADER_CNT (3UL) 26 : 27 : /* Connect FD_CONNECT_AHEAD_LEADER_CNT leaders ahead (slot x, x+4, x+8, ...) */ 28 0 : #define FD_SEND_CONNECT_AHEAD_LEADER_CNT (6UL) 29 : 30 : /* Agave currently rate limits connections per minute per IP */ 31 : #define FD_AGAVE_MAX_CONNS_PER_MINUTE (8UL) 32 : /* so each of our connections must survive at least 60/8 = 7.5 seconds 33 : Let's conservatively go to 10 */ 34 0 : #define FD_SEND_QUIC_MIN_CONN_LIFETIME_SECONDS (10UL) 35 : 36 : /* the 1M lets this be integer math */ 37 : FD_STATIC_ASSERT((60*1000000)/FD_SEND_QUIC_MIN_CONN_LIFETIME_SECONDS <= 1000000*FD_AGAVE_MAX_CONNS_PER_MINUTE, "QUIC conn lifetime too low for rate limit"); 38 : 39 0 : #define FD_SEND_QUIC_IDLE_TIMEOUT_NS (2e9) /* 2 s */ 40 0 : #define FD_SEND_QUIC_ACK_DELAY_NS (25e6) /* 25 ms */ 41 : 42 : /* quic ports first, so we can re-use idx to select conn ptr 43 : Don't rearrange, lots of stuff depends on this order. */ 44 0 : #define FD_SEND_PORT_QUIC_VOTE_IDX (0UL) 45 0 : #define FD_SEND_PORT_QUIC_TPU_IDX (1UL) 46 : #define FD_SEND_PORT_UDP_VOTE_IDX (2UL) 47 : #define FD_SEND_PORT_UDP_TPU_IDX (3UL) 48 0 : #define FD_SEND_PORT_QUIC_CNT (2UL) 49 0 : #define FD_SEND_PORT_CNT (4UL) 50 : 51 : struct fd_send_link_in { 52 : fd_wksp_t * mem; 53 : ulong chunk0; 54 : ulong wmark; 55 : ulong kind; 56 : void * dcache; 57 : }; 58 : typedef struct fd_send_link_in fd_send_link_in_t; 59 : 60 : struct fd_send_link_out { 61 : ulong idx; 62 : fd_frag_meta_t * mcache; 63 : ulong * sync; 64 : ulong depth; 65 : 66 : fd_wksp_t * mem; 67 : ulong chunk0; 68 : ulong wmark; 69 : ulong chunk; 70 : }; 71 : typedef struct fd_send_link_out fd_send_link_out_t; 72 : 73 : struct fd_send_conn_entry { 74 : fd_pubkey_t pubkey; 75 : uint hash; 76 : 77 : fd_quic_conn_t * conn[ FD_SEND_PORT_UDP_VOTE_IDX ]; /* first non-quic port */ 78 : long last_ci_ticks; 79 : uint ip4s [ FD_SEND_PORT_CNT ]; /* net order */ 80 : ushort ports[ FD_SEND_PORT_CNT ]; /* host order */ 81 : int got_ci_msg; 82 : }; 83 : typedef struct fd_send_conn_entry fd_send_conn_entry_t; 84 : 85 : 86 : struct fd_send_tile_ctx { 87 : 88 : /* link things */ 89 : #define FD_SEND_MAX_IN_LINK_CNT 32UL 90 : fd_stem_context_t * stem; 91 : fd_send_link_in_t in_links[ FD_SEND_MAX_IN_LINK_CNT ]; 92 : fd_net_rx_bounds_t net_in_bounds; 93 : fd_send_link_out_t gossip_verify_out[ 1 ]; 94 : fd_send_link_out_t net_out [ 1 ]; 95 : 96 : fd_keyguard_client_t keyguard_client [ 1 ]; 97 : 98 : /* buffers btwn during_frag and after_frag :( */ 99 : union { 100 : /* IN_KIND_GOSSIP */ 101 : struct { 102 : fd_shred_dest_wire_t contact_buf[ MAX_STAKED_LEADERS ]; 103 : ulong contact_cnt; 104 : }; 105 : 106 : /* IN_KIND_NET */ 107 : uchar quic_buf[ FD_NET_MTU ]; 108 : }; 109 : 110 : /* networking things */ 111 : uint src_ip_addr; 112 : ushort src_port; 113 : fd_ip4_udp_hdrs_t packet_hdr[1]; /* template, but will be modified directly */ 114 : ushort net_id; 115 : 116 : /* tls pubkey */ 117 : fd_pubkey_t identity_key [ 1 ]; /* also tls pubkey - only really used by quic */ 118 : 119 : /* Leader schedule tracking */ 120 : fd_multi_epoch_leaders_t * mleaders; 121 : 122 : /* QUIC handles */ 123 : fd_quic_t * quic; 124 : fd_aio_t quic_tx_aio[1]; 125 : 126 : /* Connection map for outgoing QUIC connections and contact info */ 127 : fd_send_conn_entry_t * conn_map; 128 : 129 : /* timekeeping */ 130 : long now; 131 : ulong ticks_per_sec; 132 : ulong housekeeping_ctr; 133 : 134 : struct { 135 : ulong leader_not_found; 136 : ulong staked_no_ci; 137 : ulong stale_ci; 138 : 139 : /* Contact info */ 140 : ulong unstaked_ci_rcvd; 141 : ulong new_contact_info[FD_SEND_PORT_CNT][FD_METRICS_ENUM_NEW_CONTACT_OUTCOME_CNT]; 142 : ulong ci_removed; 143 : 144 : /* Outcome of trying to send data */ 145 : ulong send_result_cnt[FD_SEND_PORT_CNT][FD_METRICS_ENUM_TXN_SEND_RESULT_CNT]; 146 : 147 : /* QUIC-specific metrics */ 148 : ulong quic_hs_complete [FD_METRICS_ENUM_SEND_QUIC_PORTS_CNT]; 149 : ulong quic_conn_final [FD_METRICS_ENUM_SEND_QUIC_PORTS_CNT]; 150 : ulong ensure_conn_result [FD_METRICS_ENUM_SEND_QUIC_PORTS_CNT] 151 : [FD_METRICS_ENUM_SEND_ENSURE_CONN_RESULT_CNT]; 152 : 153 : /* Time spent waiting for tls_cv signatures */ 154 : fd_histf_t sign_duration[ 1 ]; 155 : } metrics; 156 : 157 : uchar __attribute__((aligned(FD_MULTI_EPOCH_LEADERS_ALIGN))) mleaders_mem[ FD_MULTI_EPOCH_LEADERS_FOOTPRINT ]; 158 : }; 159 : 160 : typedef struct fd_send_tile_ctx fd_send_tile_ctx_t; 161 : 162 : #endif /* HEADER_fd_src_discof_send_fd_send_tile_h */ 163 :