Line data Source code
1 : #include "fd_send_tile.h"
2 : #include "../../disco/topo/fd_topo.h"
3 : #include "../../disco/keyguard/fd_keyload.h"
4 : #include "../../disco/fd_txn_m.h"
5 : #include "../../disco/keyguard/fd_keyguard.h"
6 : #include "../../discof/tower/fd_tower_tile.h"
7 : #include "generated/fd_send_tile_seccomp.h"
8 : #include "../../flamenco/gossip/fd_gossip_types.h"
9 :
10 : #include <sys/random.h>
11 :
12 : /* map leader pubkey to contact/conn info
13 : A map entry is created only for staked peers. On receiving contact info, we update
14 : the map entry with the following 4 sockets from the contact info:
15 : - QUIC_VOTE
16 : - QUIC_TPU
17 : - UDP_VOTE
18 : - UDP_TPU
19 :
20 : For the UDP ports, we simply send to that sockaddr when the leader is selected.
21 : For QUIC ports, we establish a quic connection just in time for the leader slot.
22 : We allow that connection to time out if it's going to be dormant for a while.
23 : This reduces the bandwidth consumed and the amount of work the fd_quic needs to do.
24 : */
25 :
26 : #define MAP_NAME fd_send_conn_map
27 0 : #define MAP_T fd_send_conn_entry_t
28 0 : #define MAP_LG_SLOT_CNT 17
29 0 : #define MAP_KEY pubkey
30 0 : #define MAP_KEY_T fd_pubkey_t
31 0 : #define MAP_KEY_NULL (fd_pubkey_t){0}
32 0 : #define MAP_KEY_EQUAL(k0,k1) (!(memcmp((k0).key,(k1).key,sizeof(fd_pubkey_t))))
33 0 : #define MAP_KEY_INVAL(k) (MAP_KEY_EQUAL((k),MAP_KEY_NULL))
34 : #define MAP_KEY_EQUAL_IS_SLOW 1
35 0 : #define MAP_KEY_HASH(key) ((key).ui[3])
36 : #include "../../util/tmpl/fd_map.c"
37 :
38 : fd_quic_limits_t quic_limits = {
39 : .conn_cnt = MAX_STAKED_LEADERS,
40 : .handshake_cnt = MAX_STAKED_LEADERS,
41 : .conn_id_cnt = FD_QUIC_MIN_CONN_ID_CNT,
42 : .inflight_frame_cnt = 16UL * MAX_STAKED_LEADERS,
43 : .min_inflight_frame_cnt_conn = 4UL,
44 : .stream_id_cnt = 64UL,
45 : .tx_buf_sz = FD_TXN_MTU,
46 : .stream_pool_cnt = 1UL<<13
47 : };
48 :
49 : FD_FN_CONST static inline ulong
50 0 : scratch_align( void ) {
51 0 : return fd_ulong_max( fd_ulong_max( 128UL, fd_quic_align() ), fd_send_conn_map_align() );
52 0 : }
53 :
54 : FD_FN_PURE static inline ulong
55 0 : scratch_footprint( fd_topo_tile_t const * tile FD_PARAM_UNUSED) {
56 0 : ulong l = FD_LAYOUT_INIT;
57 0 : l = FD_LAYOUT_APPEND( l, alignof(fd_send_tile_ctx_t), sizeof(fd_send_tile_ctx_t) );
58 0 : l = FD_LAYOUT_APPEND( l, fd_quic_align(), fd_quic_footprint( &quic_limits ) );
59 0 : l = FD_LAYOUT_APPEND( l, fd_send_conn_map_align(), fd_send_conn_map_footprint() );
60 0 : return FD_LAYOUT_FINI( l, scratch_align() );
61 0 : }
62 :
63 : /* QUIC callbacks */
64 :
65 : static void
66 : quic_tls_cv_sign( void * signer_ctx,
67 : uchar signature[ static 64 ],
68 0 : uchar const payload[ static 130 ] ) {
69 0 : fd_send_tile_ctx_t * ctx = signer_ctx;
70 0 : long dt = -fd_clock_now( ctx->clock );
71 0 : fd_keyguard_client_sign( ctx->keyguard_client, signature, payload, 130UL, FD_KEYGUARD_SIGN_TYPE_ED25519 );
72 0 : dt += ( ctx->now = fd_clock_now( ctx->clock ) );
73 0 : fd_histf_sample( ctx->metrics.sign_duration, (ulong)dt );
74 0 : }
75 :
76 : /* quic_hs_complete is called when the QUIC handshake is complete
77 : It is currently used only for debug logging */
78 : static void
79 : quic_hs_complete( fd_quic_conn_t * conn,
80 0 : void * quic_ctx FD_PARAM_UNUSED ) {
81 0 : fd_send_tile_ctx_t * ctx = fd_type_pun( quic_ctx );
82 0 : fd_send_conn_entry_t * entry = fd_type_pun( fd_quic_conn_get_context( conn ) );
83 0 : if( FD_UNLIKELY( !entry ) ) return;
84 :
85 0 : for( ulong i=0; i<FD_SEND_PORT_QUIC_CNT; i++ ) {
86 0 : if( entry->conn[i] == conn ) { ctx->metrics.quic_hs_complete[i]++; break; }
87 0 : }
88 0 : FD_DEBUG(
89 0 : FD_BASE58_ENCODE_32_BYTES( entry->pubkey.key, pubkey_b58 );
90 0 : FD_LOG_DEBUG(( "QUIC handshake complete for leader %s", pubkey_b58 ));
91 0 : )
92 0 : }
93 :
94 : inline static int
95 0 : port_idx_is_quic( ulong port_idx ) {
96 0 : return (port_idx==FD_SEND_PORT_QUIC_VOTE_IDX) | (port_idx==FD_SEND_PORT_QUIC_TPU_IDX);
97 0 : }
98 :
99 : /* quic_conn_final is called when the QUIC connection dies. */
100 : static void
101 : quic_conn_final( fd_quic_conn_t * conn,
102 0 : void * quic_ctx ) {
103 0 : fd_send_conn_entry_t * entry = fd_type_pun( fd_quic_conn_get_context( conn ) );
104 0 : if( FD_UNLIKELY( !entry ) ) {
105 0 : FD_LOG_CRIT(( "Conn map entry not found in conn_final" ));
106 0 : }
107 :
108 0 : fd_send_tile_ctx_t * ctx = fd_type_pun( quic_ctx );
109 :
110 0 : for( ulong i=0UL; i<FD_SEND_PORT_QUIC_CNT; i++ ) {
111 0 : if( entry->conn[i] == conn ) {
112 0 : entry->conn[i] = NULL;
113 0 : FD_DEBUG(
114 0 : FD_BASE58_ENCODE_32_BYTES( entry->pubkey.key, pubkey_b58 );
115 0 : FD_LOG_DEBUG(("Quic final for conn: %p to peer " FD_IP4_ADDR_FMT ":%u in entry %p to pubkey %s",
116 0 : (void*)conn, FD_IP4_ADDR_FMT_ARGS(entry->ip4s[i]), entry->ports[i], (void*)entry,
117 0 : pubkey_b58));
118 0 : )
119 0 : ctx->metrics.quic_conn_final[i]++;
120 0 : if( i==FD_SEND_PORT_QUIC_VOTE_IDX ) entry->last_quic_vote_close = ctx->now;
121 0 : return;
122 0 : }
123 0 : }
124 :
125 0 : FD_BASE58_ENCODE_32_BYTES( entry->pubkey.key, pubkey_b58 );
126 0 : FD_LOG_CRIT(( "conn not found in entry for peer %s", pubkey_b58 ));
127 0 : }
128 :
129 : /* send_to_net sends a packet to the net tile.
130 : It takes pointers to the ip4 hdr, udp hdr, and the payload.
131 : Always uses the eth hdr from ctx->packet_hdr. */
132 : static void
133 : send_to_net( fd_send_tile_ctx_t * ctx,
134 : fd_ip4_hdr_t const * ip4_hdr,
135 : fd_udp_hdr_t const * udp_hdr,
136 : uchar const * payload,
137 0 : ulong payload_sz ) {
138 :
139 0 : uint const ip_dst = FD_LOAD( uint, ip4_hdr->daddr_c );
140 0 : ulong const ip_sz = FD_IP4_GET_LEN( *ip4_hdr );
141 :
142 0 : fd_send_link_out_t * net_out_link = ctx->net_out;
143 0 : uchar * packet_l2 = fd_chunk_to_laddr( net_out_link->mem, net_out_link->chunk );
144 0 : uchar * packet_l3 = packet_l2 + sizeof(fd_eth_hdr_t);
145 0 : uchar * packet_l4 = packet_l3 + ip_sz;
146 0 : uchar * packet_l5 = packet_l4 + sizeof(fd_udp_hdr_t);
147 :
148 0 : fd_memcpy( packet_l2, ctx->packet_hdr->eth, sizeof(fd_eth_hdr_t) );
149 0 : fd_memcpy( packet_l3, ip4_hdr, ip_sz );
150 0 : fd_memcpy( packet_l4, udp_hdr, sizeof(fd_udp_hdr_t) );
151 0 : fd_memcpy( packet_l5, payload, payload_sz );
152 :
153 0 : ulong sig = fd_disco_netmux_sig( ip_dst, 0U, ip_dst, DST_PROTO_OUTGOING, FD_NETMUX_SIG_MIN_HDR_SZ );
154 0 : ulong tspub = (ulong)ctx->now;
155 0 : ulong sz_l2 = sizeof(fd_eth_hdr_t) + ip_sz + sizeof(fd_udp_hdr_t) + payload_sz;
156 :
157 0 : fd_stem_publish( ctx->stem, net_out_link->idx, sig, net_out_link->chunk, sz_l2, 0UL, 0, tspub );
158 0 : net_out_link->chunk = fd_dcache_compact_next( net_out_link->chunk, sz_l2, net_out_link->chunk0, net_out_link->wmark );
159 0 : }
160 :
161 : static int
162 : quic_tx_aio_send( void * _ctx,
163 : fd_aio_pkt_info_t const * batch,
164 : ulong batch_cnt,
165 : ulong * opt_batch_idx,
166 0 : int flush FD_PARAM_UNUSED ) {
167 0 : fd_send_tile_ctx_t * ctx = _ctx;
168 :
169 0 : for( ulong i=0; i<batch_cnt; i++ ) {
170 0 : if( FD_UNLIKELY( batch[ i ].buf_sz<FD_NETMUX_SIG_MIN_HDR_SZ ) ) continue;
171 0 : uchar * buf = batch[ i ].buf;
172 0 : fd_ip4_hdr_t * ip4_hdr = fd_type_pun( buf );
173 0 : ulong const ip4_len = FD_IP4_GET_LEN( *ip4_hdr );
174 0 : fd_udp_hdr_t * udp_hdr = fd_type_pun( buf + ip4_len );
175 0 : uchar * payload = buf + ip4_len + sizeof(fd_udp_hdr_t);
176 0 : FD_TEST( batch[ i ].buf_sz >= ip4_len + sizeof(fd_udp_hdr_t) );
177 0 : ulong payload_sz = batch[ i ].buf_sz - ip4_len - sizeof(fd_udp_hdr_t);
178 0 : send_to_net( ctx, ip4_hdr, udp_hdr, payload, payload_sz );
179 0 : }
180 :
181 0 : if( FD_LIKELY( opt_batch_idx ) ) {
182 0 : *opt_batch_idx = batch_cnt;
183 0 : }
184 :
185 0 : return FD_AIO_SUCCESS;
186 0 : }
187 :
188 : static void
189 0 : during_housekeeping( fd_send_tile_ctx_t * ctx ) {
190 0 : if( FD_UNLIKELY( ctx->recal_next <= ctx->now ) ) {
191 0 : ctx->recal_next = fd_clock_default_recal( ctx->clock );
192 0 : }
193 0 : }
194 :
195 : /* quic_connect initiates quic connections for a given entry and port. It uses the
196 : contact info stored in entry, and points the conn and entry to each other.
197 : Returns a handle to the new connection, and NULL if creating it failed */
198 :
199 : static fd_quic_conn_t *
200 : quic_connect( fd_send_tile_ctx_t * ctx,
201 : fd_send_conn_entry_t * entry,
202 0 : ulong port_idx ) {
203 :
204 0 : ulong conn_idx = port_idx;
205 0 : uint dst_ip = entry->ip4s[port_idx];
206 0 : ushort dst_port = entry->ports[port_idx];
207 :
208 0 : FD_TEST( entry->conn[conn_idx] == NULL );
209 :
210 0 : fd_quic_conn_t * conn = fd_quic_connect( ctx->quic, dst_ip, dst_port, ctx->src_ip_addr, ctx->src_port, ctx->now );
211 0 : if( FD_UNLIKELY( !conn ) ) {
212 0 : FD_LOG_WARNING(( "Failed to create QUIC connection to " FD_IP4_ADDR_FMT ":%u", FD_IP4_ADDR_FMT_ARGS(dst_ip), dst_port ));
213 0 : return NULL;
214 0 : }
215 :
216 0 : FD_DEBUG(
217 0 : FD_BASE58_ENCODE_32_BYTES(entry->pubkey.key, pubkey_b58);
218 0 : FD_LOG_DEBUG(("Quic created conn: %p to peer " FD_IP4_ADDR_FMT ":%u in entry %p to pubkey %s",
219 0 : (void*)conn, FD_IP4_ADDR_FMT_ARGS(dst_ip), dst_port, (void*)entry,
220 0 : pubkey_b58));
221 0 : )
222 :
223 0 : entry->conn[conn_idx] = conn;
224 0 : fd_quic_conn_set_context( conn, entry );
225 :
226 0 : return conn;
227 0 : }
228 :
229 : /* ensure_conn_for_slot ensures a connection exists for the given pubkey if it's
230 : a leader for the target slot. Creates connection if needed. */
231 : static void
232 : ensure_conn_for_slot( fd_send_tile_ctx_t * ctx,
233 : ulong target_slot,
234 0 : long lifespan ) {
235 0 : fd_pubkey_t const * leader = fd_multi_epoch_leaders_get_leader_for_slot( ctx->mleaders, target_slot );
236 0 : if( FD_UNLIKELY( !leader ) ) {
237 : /* Track NoLeader outcome for both QUIC ports */
238 0 : for( ulong i=0UL; i<FD_SEND_PORT_QUIC_CNT; i++ ) {
239 0 : ctx->metrics.ensure_conn_result[i][FD_METRICS_ENUM_SEND_ENSURE_CONN_RESULT_V_NO_LEADER_IDX]++;
240 0 : }
241 0 : return;
242 0 : }
243 :
244 0 : fd_send_conn_entry_t * entry = fd_send_conn_map_query( ctx->conn_map, *leader, NULL );
245 0 : if( FD_UNLIKELY( !entry ) ) FD_LOG_CRIT(( "Tried ensuring conn for unstaked pubkey"));
246 :
247 0 : for( ulong i=0UL; i<FD_SEND_PORT_QUIC_CNT; i++ ) {
248 0 : if( FD_UNLIKELY( !entry->ip4s[i] | !entry->ports[i] ) ) {
249 0 : ctx->metrics.ensure_conn_result[i][FD_METRICS_ENUM_SEND_ENSURE_CONN_RESULT_V_NO_CI_IDX]++;
250 0 : continue;
251 0 : }
252 :
253 0 : if( !entry->conn[i] ) {
254 : /* Attempting to create new connection */
255 0 : if( (i==FD_SEND_PORT_QUIC_VOTE_IDX) & (ctx->now<entry->last_quic_vote_close+1e9L*FD_SEND_QUIC_VOTE_MIN_CONN_COOLDOWN_SECONDS) ) {
256 0 : FD_LOG_DEBUG(("Skipping QUIC connection to " FD_IP4_ADDR_FMT ":%u bc of cooldown", FD_IP4_ADDR_FMT_ARGS(entry->ip4s[i]), entry->ports[i] ));
257 0 : ctx->metrics.ensure_conn_result[i][FD_METRICS_ENUM_SEND_ENSURE_CONN_RESULT_V_COOLDOWN_IDX]++;
258 0 : continue;
259 0 : }
260 0 : fd_quic_conn_t * conn = quic_connect( ctx, entry, i );
261 0 : if( FD_UNLIKELY( !conn ) ) {
262 0 : ctx->metrics.ensure_conn_result[i][FD_METRICS_ENUM_SEND_ENSURE_CONN_RESULT_V_CONN_FAILED_IDX]++;
263 0 : continue;
264 0 : }
265 0 : ctx->metrics.ensure_conn_result[i][FD_METRICS_ENUM_SEND_ENSURE_CONN_RESULT_V_NEW_CONNECTION_IDX]++;
266 0 : fd_quic_service( ctx->quic, ctx->now );
267 0 : } else {
268 : /* Connection already exists */
269 0 : ctx->metrics.ensure_conn_result[i][FD_METRICS_ENUM_SEND_ENSURE_CONN_RESULT_V_CONNECTED_IDX]++;
270 0 : fd_quic_conn_let_die( entry->conn[i], lifespan, ctx->now );
271 0 : fd_quic_service( ctx->quic, ctx->now );
272 0 : }
273 0 : }
274 0 : }
275 :
276 : /* leader_send sends a payload to 'pubkey' in all possible ways. For quic targets,
277 : it relies on quic connections that are already established. */
278 : static void
279 : leader_send( fd_send_tile_ctx_t * ctx,
280 : fd_pubkey_t const * pubkey,
281 : uchar const * payload,
282 0 : ulong payload_sz ) {
283 :
284 0 : fd_send_conn_entry_t * entry = fd_send_conn_map_query( ctx->conn_map, *pubkey, NULL );
285 0 : if( FD_UNLIKELY( !entry ) ) {
286 0 : FD_LOG_CRIT(( "Tried looking up connection for an unstaked pubkey"));
287 0 : }
288 :
289 0 : for( ulong i=0UL; i<FD_SEND_PORT_CNT; i++ ) {
290 : /* skip unroutable */
291 0 : if( !entry->ip4s[i] | !entry->ports[i] ) {
292 0 : ctx->metrics.send_result_cnt[i][FD_METRICS_ENUM_TXN_SEND_RESULT_V_NO_CI_IDX]++;
293 0 : continue;
294 0 : }
295 :
296 0 : if( port_idx_is_quic( i ) ) {
297 0 : fd_quic_conn_t * conn = entry->conn[i];
298 0 : if( FD_UNLIKELY( !conn ) ) {
299 0 : FD_BASE58_ENCODE_32_BYTES( pubkey->key, pubkey_b58 );
300 0 : FD_LOG_DEBUG(("no conn for %s at " FD_IP4_ADDR_FMT ":%u", pubkey_b58, FD_IP4_ADDR_FMT_ARGS(entry->ip4s[i]), entry->ports[i] ));
301 0 : ctx->metrics.send_result_cnt[i][FD_METRICS_ENUM_TXN_SEND_RESULT_V_NO_CONN_IDX]++;
302 0 : continue;
303 0 : }
304 :
305 0 : fd_quic_stream_t * stream = fd_quic_conn_new_stream( conn );
306 0 : if( FD_UNLIKELY( !stream ) ) {
307 0 : FD_BASE58_ENCODE_32_BYTES( pubkey->key, pubkey_b58 );
308 0 : FD_LOG_DEBUG(("new_stream failed for %s at " FD_IP4_ADDR_FMT ":%u bc conn state was %u", pubkey_b58, FD_IP4_ADDR_FMT_ARGS(entry->ip4s[i]), entry->ports[i], conn->state ));
309 0 : ctx->metrics.send_result_cnt[i][FD_METRICS_ENUM_TXN_SEND_RESULT_V_NO_STREAM_IDX]++;
310 0 : continue;
311 0 : }
312 :
313 0 : ctx->metrics.send_result_cnt[i][FD_METRICS_ENUM_TXN_SEND_RESULT_V_SUCCESS_IDX]++;
314 :
315 0 : fd_quic_stream_send( stream, payload, payload_sz, 1 );
316 0 : fd_quic_service( ctx->quic, ctx->now ); /* trigger send ASAP */
317 0 : } else {
318 :
319 0 : fd_ip4_hdr_t * ip4_hdr = ctx->packet_hdr->ip4;
320 0 : fd_udp_hdr_t * udp_hdr = ctx->packet_hdr->udp;
321 :
322 0 : ctx->metrics.send_result_cnt[i][FD_METRICS_ENUM_TXN_SEND_RESULT_V_SUCCESS_IDX]++;
323 :
324 0 : ip4_hdr->daddr = entry->ip4s[i];
325 0 : ip4_hdr->net_tot_len = fd_ushort_bswap( (ushort)(payload_sz + sizeof(fd_ip4_hdr_t)+sizeof(fd_udp_hdr_t)) );
326 0 : ip4_hdr->net_id = fd_ushort_bswap( ctx->net_id++ );
327 0 : ip4_hdr->check = 0;
328 0 : ip4_hdr->check = fd_ip4_hdr_check_fast( ip4_hdr );
329 :
330 0 : udp_hdr->net_dport = fd_ushort_bswap( entry->ports[i] ); /* to net order */
331 0 : udp_hdr->net_len = fd_ushort_bswap( (ushort)( payload_sz + sizeof(fd_udp_hdr_t) ) );
332 0 : send_to_net( ctx, ip4_hdr, udp_hdr, payload, payload_sz );
333 0 : }
334 0 : }
335 0 : }
336 :
337 : /* handle_contact_info_update handles a new contact. Validates contact info
338 : and starts/restarts a connection if necessary. */
339 : static inline void
340 : handle_contact_info_update( fd_send_tile_ctx_t * ctx,
341 0 : fd_gossip_update_message_t const * msg ) {
342 0 : static uint const socket_idx[FD_SEND_PORT_CNT] = {
343 0 : FD_CONTACT_INFO_SOCKET_TPU_VOTE_QUIC,
344 0 : FD_CONTACT_INFO_SOCKET_TPU_QUIC,
345 0 : FD_CONTACT_INFO_SOCKET_TPU_VOTE,
346 0 : FD_CONTACT_INFO_SOCKET_TPU
347 0 : };
348 :
349 0 : fd_send_conn_entry_t * entry = fd_send_conn_map_query( ctx->conn_map, *(fd_pubkey_t *)(msg->origin_pubkey), NULL );
350 0 : if( FD_UNLIKELY( !entry ) ) {
351 : /* Skip if UNSTAKED */
352 0 : ctx->metrics.unstaked_ci_rcvd++;
353 0 : return;
354 0 : }
355 :
356 0 : for( ulong i=0UL; i<FD_SEND_PORT_CNT; i++ ) {
357 :
358 0 : fd_ip4_port_t const * socket = &msg->contact_info.contact_info->sockets[ socket_idx[i] ];
359 0 : uint new_ip = socket->addr;
360 0 : ushort new_port = fd_ushort_bswap( socket->port ); /* convert port to host order */
361 0 : uint old_ip = entry->ip4s[i];
362 0 : ushort old_port = entry->ports[i];
363 :
364 0 : if( FD_UNLIKELY( !new_ip || !new_port ) ) {
365 0 : FD_BASE58_ENCODE_32_BYTES( msg->origin_pubkey, origin_pubkey_b58 );
366 0 : FD_LOG_DEBUG(( "Unroutable contact info for pubkey %s", origin_pubkey_b58 ));
367 0 : ctx->metrics.new_contact_info[i][FD_METRICS_ENUM_NEW_CONTACT_OUTCOME_V_UNROUTABLE_IDX]++;
368 0 : continue;
369 0 : }
370 :
371 0 : int info_changed = (old_ip != new_ip) | (old_port != new_port);
372 0 : entry->ip4s [i] = new_ip;
373 0 : entry->ports[i] = new_port;
374 :
375 0 : ulong quic_conn_idx = i;
376 0 : if( port_idx_is_quic( i ) && info_changed && entry->conn[quic_conn_idx]!=NULL ) {
377 : /* Track connection finalization before closing */
378 0 : fd_quic_conn_close( entry->conn[i], 0 );
379 0 : }
380 :
381 : /* bc taking branches for just metrics would be sad */
382 : /* !info_changed -> NoChange, info_changed && old_port==0 -> Initialized, info_changed && old_port!=0 -> Changed */
383 0 : static ulong metric_idx_map[] = {
384 0 : FD_METRICS_ENUM_NEW_CONTACT_OUTCOME_V_NO_CHANGE_IDX,
385 0 : FD_METRICS_ENUM_NEW_CONTACT_OUTCOME_V_INITIALIZED_IDX,
386 0 : FD_METRICS_ENUM_NEW_CONTACT_OUTCOME_V_CHANGED_IDX
387 0 : };
388 0 : ulong metric_idx = metric_idx_map[ !!info_changed<<(!!old_port) ];
389 0 : ctx->metrics.new_contact_info[i][metric_idx]++;
390 0 : }
391 0 : }
392 :
393 : static inline void
394 : handle_contact_info_removal( fd_send_tile_ctx_t * ctx FD_PARAM_UNUSED,
395 0 : fd_gossip_update_message_t const * msg FD_PARAM_UNUSED ) {
396 0 : fd_send_conn_entry_t * entry = fd_send_conn_map_query( ctx->conn_map, *(fd_pubkey_t *)(msg->origin_pubkey), NULL );
397 0 : if( FD_LIKELY( entry ) ) {
398 0 : for( ulong i=0UL; i<FD_SEND_PORT_QUIC_CNT; i++ ) {
399 0 : if( FD_UNLIKELY( entry->conn[i] ) ) fd_quic_conn_close( entry->conn[i], 0 );
400 0 : entry->ip4s[i] = 0;
401 0 : entry->ports[i] = 0;
402 0 : }
403 0 : ctx->metrics.ci_removed++;
404 0 : }
405 0 : }
406 :
407 : /* Called during after_frag for stake messages. */
408 : static void
409 0 : finalize_stake_msg( fd_send_tile_ctx_t * ctx ) {
410 :
411 0 : fd_multi_epoch_leaders_stake_msg_fini( ctx->mleaders );
412 :
413 : /* Get the current stake destinations */
414 0 : fd_vote_stake_weight_t const * stakes = fd_multi_epoch_leaders_get_stake_weights( ctx->mleaders );
415 0 : ulong stake_cnt = fd_multi_epoch_leaders_get_stake_cnt( ctx->mleaders );
416 0 : if( FD_UNLIKELY( !stakes ) ) {
417 0 : FD_LOG_WARNING(( "No stake destinations available for current slot" ));
418 0 : return;
419 0 : }
420 :
421 : /* populate staked validators in connection map */
422 0 : for( ulong i=0UL; i<stake_cnt; i++ ) {
423 0 : fd_vote_stake_weight_t const * stake_info = &stakes[i];
424 0 : fd_pubkey_t const pubkey = stake_info->id_key;
425 :
426 0 : fd_send_conn_entry_t * entry = fd_send_conn_map_query( ctx->conn_map, pubkey, NULL );
427 : /* UNSTAKED -> NO_CONN: create new entry in NO_CONN state */
428 0 : if( FD_UNLIKELY( !entry ) ) {
429 : /* insert and initialize entry */
430 0 : entry = fd_send_conn_map_insert( ctx->conn_map, pubkey );
431 0 : *entry = (fd_send_conn_entry_t){.pubkey = entry->pubkey, .hash = entry->hash };
432 0 : }
433 0 : }
434 0 : }
435 :
436 : static void
437 : handle_vote_msg( fd_send_tile_ctx_t * ctx,
438 : ulong vote_slot,
439 : uchar * signed_vote_txn,
440 0 : ulong vote_txn_sz ) {
441 :
442 0 : uchar txn_mem[ FD_TXN_MAX_SZ ] __attribute__((aligned(alignof(fd_txn_t))));
443 0 : fd_txn_t * txn = (fd_txn_t *)txn_mem;
444 0 : FD_TEST( fd_txn_parse( signed_vote_txn, vote_txn_sz, txn_mem, NULL ) );
445 :
446 : /* sign the txn */
447 0 : uchar * signature = signed_vote_txn + txn->signature_off;
448 0 : uchar const * message = signed_vote_txn + txn->message_off;
449 0 : ulong message_sz = vote_txn_sz - txn->message_off;
450 0 : fd_keyguard_client_sign( ctx->keyguard_client, signature, message, message_sz, FD_KEYGUARD_SIGN_TYPE_ED25519 );
451 :
452 0 : ulong poh_slot = vote_slot+1;
453 0 : FD_LOG_INFO(("got vote for slot %lu", vote_slot));
454 :
455 : /* send to leader for next few slots */
456 0 : for( ulong i=0UL; i<FD_SEND_TARGET_LEADER_CNT; i++ ) {
457 0 : ulong target_slot = poh_slot + i*FD_EPOCH_SLOTS_PER_ROTATION;
458 0 : fd_pubkey_t const * leader = fd_multi_epoch_leaders_get_leader_for_slot( ctx->mleaders, target_slot );
459 0 : FD_CRIT( !leader, "leader not found for slot %lu" );
460 0 : leader_send( ctx, leader, signed_vote_txn, vote_txn_sz );
461 0 : }
462 :
463 0 : for( ulong i=0; i<FD_SEND_CONNECT_AHEAD_LEADER_CNT; i++ ) {
464 0 : ulong connect_slot = poh_slot + i*FD_EPOCH_SLOTS_PER_ROTATION;
465 : /* keep alive for at least as long as needed */
466 0 : ensure_conn_for_slot( ctx, connect_slot, FD_SEND_QUIC_MIN_CONN_LIFETIME_SECONDS * (long)1e9 );
467 0 : }
468 :
469 : /* send to gossip and dedup */
470 0 : fd_send_link_out_t * gossip_verify_out = ctx->gossip_verify_out;
471 0 : uchar * msg_to_gossip = fd_chunk_to_laddr( gossip_verify_out->mem, gossip_verify_out->chunk );
472 0 : fd_txn_m_t * txnm = (fd_txn_m_t *)msg_to_gossip;
473 0 : *txnm = (fd_txn_m_t) { 0UL };
474 0 : txnm->payload_sz = (ushort)vote_txn_sz;
475 0 : txnm->source_ipv4 = ctx->src_ip_addr;
476 0 : txnm->source_tpu = FD_TXN_M_TPU_SOURCE_SEND;
477 0 : fd_memcpy( msg_to_gossip+sizeof(fd_txn_m_t), signed_vote_txn, vote_txn_sz );
478 0 : ulong msg_sz = fd_txn_m_realized_footprint( txnm, 0, 0 );
479 0 : fd_stem_publish( ctx->stem, gossip_verify_out->idx, 1UL, gossip_verify_out->chunk, msg_sz, 0UL, 0, 0 );
480 0 : gossip_verify_out->chunk = fd_dcache_compact_next(
481 0 : gossip_verify_out->chunk,
482 0 : msg_sz,
483 0 : gossip_verify_out->chunk0,
484 0 : gossip_verify_out->wmark );
485 0 : }
486 :
487 : /* Stem callbacks */
488 :
489 : static inline void
490 : before_credit( fd_send_tile_ctx_t * ctx,
491 : fd_stem_context_t * stem,
492 0 : int * charge_busy ) {
493 0 : ctx->stem = stem;
494 :
495 0 : ctx->now = fd_clock_now( ctx->clock );
496 : /* Publishes to mcache via callbacks */
497 0 : *charge_busy = fd_quic_service( ctx->quic, ctx->now );
498 0 : }
499 :
500 : static inline int
501 : before_frag( fd_send_tile_ctx_t * ctx,
502 : ulong in_idx,
503 : ulong seq FD_PARAM_UNUSED,
504 0 : ulong sig ) {
505 0 : if( FD_UNLIKELY( ctx->in_links[in_idx].kind==IN_KIND_GOSSIP ) ) {
506 0 : return sig!=FD_GOSSIP_UPDATE_TAG_CONTACT_INFO &&
507 0 : sig!=FD_GOSSIP_UPDATE_TAG_CONTACT_INFO_REMOVE;
508 0 : }
509 0 : return 0;
510 0 : }
511 :
512 : static void
513 : during_frag( fd_send_tile_ctx_t * ctx,
514 : ulong in_idx,
515 : ulong seq FD_PARAM_UNUSED,
516 : ulong sig FD_PARAM_UNUSED,
517 : ulong chunk,
518 : ulong sz,
519 0 : ulong ctl ) {
520 :
521 0 : fd_send_link_in_t * in_link = &ctx->in_links[ in_idx ];
522 0 : if( FD_UNLIKELY( chunk<in_link->chunk0 || chunk>in_link->wmark ) ) {
523 0 : FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu] on link %lu", chunk, sz, in_link->chunk0, in_link->wmark, in_idx ));
524 0 : }
525 :
526 0 : uchar const * dcache_entry = fd_chunk_to_laddr_const( in_link->mem, chunk );
527 0 : ulong kind = in_link->kind;
528 :
529 0 : if( FD_UNLIKELY( kind==IN_KIND_NET ) ) {
530 0 : void const * src = fd_net_rx_translate_frag( &ctx->net_in_bounds[ in_idx ], chunk, ctl, sz );
531 0 : fd_memcpy( ctx->quic_buf, src, sz );
532 0 : }
533 :
534 0 : if( FD_UNLIKELY( kind==IN_KIND_EPOCH ) ) {
535 0 : if( sz>FD_EPOCH_INFO_MAX_MSG_SZ ) {
536 0 : FD_LOG_ERR(( "sz %lu >= max expected epoch update size %lu", sz, FD_EPOCH_INFO_MAX_MSG_SZ ));
537 0 : }
538 0 : fd_multi_epoch_leaders_epoch_msg_init( ctx->mleaders, fd_type_pun_const( dcache_entry ) );
539 0 : }
540 :
541 0 : if( FD_LIKELY( kind==IN_KIND_GOSSIP ) ) {
542 0 : fd_memcpy( ctx->contact_buf, dcache_entry, sz );
543 0 : }
544 :
545 0 : if( FD_UNLIKELY( kind==IN_KIND_TOWER ) ) {
546 0 : if( FD_LIKELY( sig==FD_TOWER_SIG_SLOT_DONE ) ) {
547 0 : FD_TEST( sz==sizeof(fd_tower_slot_done_t) );
548 :
549 0 : fd_tower_slot_done_t const * slot_done = fd_type_pun_const( dcache_entry );
550 :
551 0 : ulong const vote_slot = slot_done->vote_slot;
552 0 : ulong const vote_txn_sz = slot_done->vote_txn_sz;
553 0 : if( FD_UNLIKELY( vote_slot==ULONG_MAX ) ) return; /* no new vote to send */
554 :
555 0 : uchar vote_txn[ FD_TPU_MTU ];
556 0 : fd_memcpy( vote_txn, slot_done->vote_txn, vote_txn_sz );
557 :
558 0 : handle_vote_msg( ctx, vote_slot, vote_txn, vote_txn_sz );
559 0 : }
560 0 : }
561 0 : }
562 :
563 : static void
564 : after_frag( fd_send_tile_ctx_t * ctx,
565 : ulong in_idx,
566 : ulong seq FD_PARAM_UNUSED,
567 : ulong sig FD_PARAM_UNUSED,
568 : ulong sz,
569 : ulong tsorig FD_PARAM_UNUSED,
570 : ulong tspub FD_PARAM_UNUSED,
571 0 : fd_stem_context_t * stem ) {
572 :
573 0 : ctx->stem = stem;
574 :
575 0 : fd_send_link_in_t * in_link = &ctx->in_links[ in_idx ];
576 0 : ulong kind = in_link->kind;
577 :
578 0 : if( FD_UNLIKELY( kind==IN_KIND_NET ) ) {
579 0 : uchar * ip_pkt = ctx->quic_buf + sizeof(fd_eth_hdr_t);
580 0 : ulong ip_sz = sz - sizeof(fd_eth_hdr_t);
581 0 : fd_quic_t * quic = ctx->quic;
582 :
583 0 : fd_quic_process_packet( quic, ip_pkt, ip_sz, ctx->now );
584 0 : }
585 :
586 0 : if( FD_UNLIKELY( kind==IN_KIND_GOSSIP ) ) {
587 0 : fd_gossip_update_message_t const * msg = fd_type_pun_const( ctx->contact_buf );
588 0 : if( FD_LIKELY( msg->tag==FD_GOSSIP_UPDATE_TAG_CONTACT_INFO ) ) {
589 0 : handle_contact_info_update( ctx, msg );
590 0 : } else if ( FD_UNLIKELY( msg->tag==FD_GOSSIP_UPDATE_TAG_CONTACT_INFO_REMOVE ) ) {
591 0 : handle_contact_info_removal( ctx, msg );
592 0 : }
593 0 : }
594 :
595 0 : if( FD_UNLIKELY( kind==IN_KIND_EPOCH ) ) {
596 0 : finalize_stake_msg( ctx );
597 0 : }
598 0 : }
599 :
600 : static void
601 : privileged_init( fd_topo_t * topo,
602 0 : fd_topo_tile_t * tile ) {
603 0 : void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
604 :
605 0 : FD_SCRATCH_ALLOC_INIT( l, scratch );
606 0 : fd_send_tile_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_send_tile_ctx_t), sizeof(fd_send_tile_ctx_t) );
607 0 : fd_memset( ctx, 0, sizeof(fd_send_tile_ctx_t) );
608 :
609 0 : if( FD_UNLIKELY( !strcmp( tile->send.identity_key_path, "" ) ) )
610 0 : FD_LOG_ERR(( "identity_key_path not set" ));
611 :
612 0 : ctx->identity_key[ 0 ] = *(fd_pubkey_t const *)(fd_keyload_load( tile->send.identity_key_path, /* pubkey only: */ 1 ) );
613 0 : }
614 :
615 : static fd_send_link_in_t *
616 : setup_input_link( fd_send_tile_ctx_t * ctx,
617 : fd_topo_t * topo,
618 : fd_topo_tile_t * tile,
619 : ulong kind,
620 0 : ulong in_idx) {
621 0 : fd_topo_link_t * in_link = &topo->links[ tile->in_link_id[ in_idx ] ];
622 0 : fd_send_link_in_t * in_link_desc = &ctx->in_links[ in_idx ];
623 :
624 0 : in_link_desc->mem = topo->workspaces[ topo->objs[ in_link->dcache_obj_id ].wksp_id ].wksp;
625 0 : in_link_desc->chunk0 = fd_dcache_compact_chunk0( in_link_desc->mem, in_link->dcache );
626 0 : in_link_desc->wmark = fd_dcache_compact_wmark( in_link_desc->mem, in_link->dcache, in_link->mtu );
627 0 : in_link_desc->dcache = in_link->dcache;
628 0 : in_link_desc->kind = kind;
629 :
630 0 : return in_link_desc;
631 0 : }
632 :
633 : static void
634 : setup_output_link( fd_send_link_out_t * desc,
635 : fd_topo_t * topo,
636 : fd_topo_tile_t * tile,
637 0 : const char * name ) {
638 0 : ulong out_idx = fd_topo_find_tile_out_link( topo, tile, name, 0 );
639 0 : FD_TEST( out_idx!=ULONG_MAX );
640 0 : fd_topo_link_t * out_link = &topo->links[ tile->out_link_id[ out_idx ] ];
641 :
642 0 : desc->idx = out_idx;
643 0 : desc->mcache = out_link->mcache;
644 0 : desc->sync = fd_mcache_seq_laddr( desc->mcache );
645 0 : desc->depth = fd_mcache_depth( desc->mcache );
646 0 : desc->mem = topo->workspaces[ topo->objs[ out_link->dcache_obj_id ].wksp_id ].wksp;
647 0 : desc->chunk0 = fd_dcache_compact_chunk0( desc->mem, out_link->dcache );
648 0 : desc->wmark = fd_dcache_compact_wmark( desc->mem, out_link->dcache, out_link->mtu );
649 0 : desc->chunk = desc->chunk0;
650 0 : }
651 :
652 : static void
653 : unprivileged_init( fd_topo_t * topo,
654 0 : fd_topo_tile_t * tile ) {
655 0 : void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
656 :
657 0 : if( FD_UNLIKELY( !tile->out_cnt ) ) FD_LOG_ERR(( "send has no output link" ));
658 :
659 : /* Scratch mem setup */
660 0 : FD_SCRATCH_ALLOC_INIT( l, scratch );
661 0 : fd_send_tile_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_send_tile_ctx_t), sizeof(fd_send_tile_ctx_t) );
662 :
663 0 : ctx->mleaders = fd_multi_epoch_leaders_join( fd_multi_epoch_leaders_new( ctx->mleaders_mem ) );
664 0 : FD_TEST( ctx->mleaders );
665 :
666 0 : fd_aio_t * quic_tx_aio = fd_aio_join( fd_aio_new( ctx->quic_tx_aio, ctx, quic_tx_aio_send ) );
667 0 : if( FD_UNLIKELY( !quic_tx_aio ) ) FD_LOG_ERR(( "fd_aio_join failed" ));
668 :
669 0 : fd_quic_t * quic = fd_quic_join( fd_quic_new( FD_SCRATCH_ALLOC_APPEND( l, fd_quic_align(), fd_quic_footprint( &quic_limits ) ), &quic_limits ) );
670 0 : if( FD_UNLIKELY( !quic ) ) FD_LOG_ERR(( "fd_quic_new failed" ));
671 :
672 0 : quic->config.role = FD_QUIC_ROLE_CLIENT;
673 0 : quic->config.idle_timeout = FD_SEND_QUIC_IDLE_TIMEOUT_NS;
674 0 : quic->config.ack_delay = FD_SEND_QUIC_ACK_DELAY_NS;
675 0 : quic->config.keep_alive = 1;
676 0 : quic->config.sign = quic_tls_cv_sign;
677 0 : quic->config.sign_ctx = ctx;
678 0 : fd_memcpy( quic->config.identity_public_key, ctx->identity_key, sizeof(ctx->identity_key) );
679 :
680 0 : quic->cb.conn_hs_complete = quic_hs_complete;
681 0 : quic->cb.conn_final = quic_conn_final;
682 0 : quic->cb.quic_ctx = ctx;
683 :
684 0 : fd_quic_set_aio_net_tx( quic, quic_tx_aio );
685 0 : FD_TEST_CUSTOM( fd_quic_init( quic ), "fd_quic_init failed" );
686 :
687 0 : ctx->quic = quic;
688 :
689 : /* Initialize connection map */
690 0 : void * conn_map_mem = FD_SCRATCH_ALLOC_APPEND( l, fd_send_conn_map_align(), fd_send_conn_map_footprint() );
691 0 : ctx->conn_map = fd_send_conn_map_join( fd_send_conn_map_new( conn_map_mem ) );
692 0 : if( FD_UNLIKELY( !ctx->conn_map ) ) FD_LOG_ERR(( "fd_send_conn_map_join failed" ));
693 :
694 0 : ctx->src_ip_addr = tile->send.ip_addr;
695 0 : ctx->src_port = tile->send.send_src_port;
696 0 : fd_ip4_udp_hdr_init( ctx->packet_hdr, FD_TXN_MTU, ctx->src_ip_addr, ctx->src_port );
697 :
698 : /* Initialize input links */
699 0 : for( ulong i=0; i<tile->in_cnt; i++ ) {
700 0 : fd_topo_link_t * link = &topo->links[ tile->in_link_id[ i ] ];
701 0 : if( 0==strcmp( link->name, "net_send" ) ) {
702 0 : setup_input_link( ctx, topo, tile, IN_KIND_NET, i );
703 0 : fd_net_rx_bounds_init( &ctx->net_in_bounds[ i ], link->dcache );
704 0 : } else if( 0==strcmp( link->name, "gossip_out" ) ) {
705 0 : setup_input_link( ctx, topo, tile, IN_KIND_GOSSIP, i );
706 0 : } else if( 0==strcmp( link->name, "replay_epoch" ) ) {
707 0 : setup_input_link( ctx, topo, tile, IN_KIND_EPOCH, i );
708 0 : } else if( 0==strcmp( link->name, "tower_out" ) ) {
709 0 : setup_input_link( ctx, topo, tile, IN_KIND_TOWER, i );
710 0 : }
711 0 : }
712 :
713 0 : setup_output_link( ctx->gossip_verify_out, topo, tile, "send_out" );
714 0 : setup_output_link( ctx->net_out, topo, tile, "send_net" );
715 :
716 : /* Set up keyguard(s) */
717 0 : ulong sign_in_idx = fd_topo_find_tile_in_link( topo, tile, "sign_send", 0 );
718 0 : ulong sign_out_idx = fd_topo_find_tile_out_link( topo, tile, "send_sign", 0 );
719 0 : fd_topo_link_t * sign_in = &topo->links[ tile->in_link_id[ sign_in_idx ] ];
720 0 : fd_topo_link_t * sign_out = &topo->links[ tile->out_link_id[ sign_out_idx ] ];
721 :
722 0 : if ( fd_keyguard_client_join( fd_keyguard_client_new( ctx->keyguard_client,
723 0 : sign_out->mcache,
724 0 : sign_out->dcache,
725 0 : sign_in->mcache,
726 0 : sign_in->dcache,
727 0 : sign_out->mtu ) )==NULL ) {
728 0 : FD_LOG_ERR(( "Keyguard join failed" ));
729 0 : }
730 :
731 : /* init metrics */
732 0 : fd_memset( &ctx->metrics, 0, sizeof(ctx->metrics) );
733 0 : fd_histf_join( fd_histf_new( ctx->metrics.sign_duration,
734 0 : FD_MHIST_MIN( SEND, SIGN_DURATION_NANOS ),
735 0 : FD_MHIST_MAX( SEND, SIGN_DURATION_NANOS ) ) );
736 :
737 : /* Call new/join here rather than in fd_quic so min/max can differ across uses */
738 0 : fd_histf_join( fd_histf_new( quic->metrics.service_duration,
739 0 : FD_MHIST_SECONDS_MIN( SEND, SERVICE_DURATION_SECONDS ),
740 0 : FD_MHIST_SECONDS_MAX( SEND, SERVICE_DURATION_SECONDS ) ) );
741 0 : fd_histf_join( fd_histf_new( quic->metrics.receive_duration,
742 0 : FD_MHIST_SECONDS_MIN( SEND, RECEIVE_DURATION_SECONDS ),
743 0 : FD_MHIST_SECONDS_MAX( SEND, RECEIVE_DURATION_SECONDS ) ) );
744 :
745 0 : ulong scratch_top = FD_SCRATCH_ALLOC_FINI( l, scratch_align() );
746 0 : if( FD_UNLIKELY( scratch_top != (ulong)scratch + scratch_footprint( tile ) ) ) {
747 0 : FD_LOG_ERR(( "scratch overflow %lu %lu %lu", scratch_top - (ulong)scratch - scratch_footprint( tile ), scratch_top, (ulong)scratch + scratch_footprint( tile ) ));
748 0 : }
749 :
750 0 : fd_clock_t * clock = ctx->clock;
751 0 : fd_clock_default_init( clock, ctx->clock_mem );
752 0 : ctx->recal_next = fd_clock_recal_next( clock );
753 0 : ctx->now = fd_clock_now( clock );
754 0 : }
755 :
756 : static ulong
757 : populate_allowed_seccomp( fd_topo_t const * topo FD_PARAM_UNUSED,
758 : fd_topo_tile_t const * tile FD_PARAM_UNUSED,
759 : ulong out_cnt,
760 0 : struct sock_filter * out ) {
761 :
762 0 : populate_sock_filter_policy_fd_send_tile( out_cnt, out, (uint)fd_log_private_logfile_fd() );
763 0 : return sock_filter_policy_fd_send_tile_instr_cnt;
764 0 : }
765 :
766 : static ulong
767 : populate_allowed_fds( fd_topo_t const * topo FD_PARAM_UNUSED,
768 : fd_topo_tile_t const * tile FD_PARAM_UNUSED,
769 : ulong out_fds_cnt,
770 0 : int * out_fds ) {
771 0 : if( FD_UNLIKELY( out_fds_cnt<2UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));
772 :
773 0 : ulong out_cnt = 0;
774 0 : out_fds[ out_cnt++ ] = 2UL; /* stderr */
775 0 : if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) )
776 0 : out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
777 0 : return out_cnt;
778 0 : }
779 :
780 : static void
781 0 : metrics_write( fd_send_tile_ctx_t * ctx ) {
782 :
783 : /* Basic counters */
784 0 : FD_MCNT_SET( SEND, UNSTAKED_CI, ctx->metrics.unstaked_ci_rcvd );
785 0 : FD_MCNT_SET( SEND, CI_REMOVED, ctx->metrics.ci_removed );
786 :
787 : /* Port-separated contact info metrics */
788 0 : FD_MCNT_ENUM_COPY( SEND, NEW_CONTACT_INFO_QUIC_VOTE, ctx->metrics.new_contact_info[FD_SEND_PORT_QUIC_VOTE_IDX] );
789 0 : FD_MCNT_ENUM_COPY( SEND, NEW_CONTACT_INFO_QUIC_TPU, ctx->metrics.new_contact_info[FD_SEND_PORT_QUIC_TPU_IDX] );
790 0 : FD_MCNT_ENUM_COPY( SEND, NEW_CONTACT_INFO_UDP_VOTE, ctx->metrics.new_contact_info[FD_SEND_PORT_UDP_VOTE_IDX] );
791 0 : FD_MCNT_ENUM_COPY( SEND, NEW_CONTACT_INFO_UDP_TPU, ctx->metrics.new_contact_info[FD_SEND_PORT_UDP_TPU_IDX] );
792 :
793 : /* Port-separated send result metrics */
794 0 : FD_MCNT_ENUM_COPY( SEND, SEND_RESULT_QUIC_VOTE, ctx->metrics.send_result_cnt[FD_SEND_PORT_QUIC_VOTE_IDX] );
795 0 : FD_MCNT_ENUM_COPY( SEND, SEND_RESULT_QUIC_TPU, ctx->metrics.send_result_cnt[FD_SEND_PORT_QUIC_TPU_IDX] );
796 0 : FD_MCNT_ENUM_COPY( SEND, SEND_RESULT_UDP_VOTE, ctx->metrics.send_result_cnt[FD_SEND_PORT_UDP_VOTE_IDX] );
797 0 : FD_MCNT_ENUM_COPY( SEND, SEND_RESULT_UDP_TPU, ctx->metrics.send_result_cnt[FD_SEND_PORT_UDP_TPU_IDX] );
798 :
799 : /* Port-separated QUIC metrics */
800 0 : FD_MCNT_ENUM_COPY( SEND, HANDSHAKE_COMPLETE, ctx->metrics.quic_hs_complete );
801 0 : FD_MCNT_ENUM_COPY( SEND, QUIC_CONN_FINAL, ctx->metrics.quic_conn_final );
802 0 : FD_MCNT_ENUM_COPY( SEND, ENSURE_CONN_RESULT_QUIC_VOTE, ctx->metrics.ensure_conn_result[FD_METRICS_ENUM_SEND_QUIC_PORTS_V_QUIC_VOTE_IDX] );
803 0 : FD_MCNT_ENUM_COPY( SEND, ENSURE_CONN_RESULT_QUIC_TPU, ctx->metrics.ensure_conn_result[FD_METRICS_ENUM_SEND_QUIC_PORTS_V_QUIC_TPU_IDX] );
804 :
805 0 : FD_MHIST_COPY( SEND, SIGN_DURATION_NANOS, ctx->metrics.sign_duration );
806 :
807 : /* General QUIC metrics */
808 0 : FD_MCNT_SET( SEND, RECEIVED_BYTES, ctx->quic->metrics.net_rx_byte_cnt );
809 0 : FD_MCNT_ENUM_COPY( SEND, RECEIVED_FRAMES, ctx->quic->metrics.frame_rx_cnt );
810 0 : FD_MCNT_SET( SEND, RECEIVED_PACKETS, ctx->quic->metrics.net_rx_pkt_cnt );
811 0 : FD_MCNT_SET( SEND, STREAM_RECEIVED_BYTES, ctx->quic->metrics.stream_rx_byte_cnt );
812 0 : FD_MCNT_SET( SEND, STREAM_RECEIVED_EVENTS, ctx->quic->metrics.stream_rx_event_cnt );
813 :
814 0 : FD_MCNT_SET( SEND, SENT_PACKETS, ctx->quic->metrics.net_tx_pkt_cnt );
815 0 : FD_MCNT_SET( SEND, SENT_BYTES, ctx->quic->metrics.net_tx_byte_cnt );
816 0 : FD_MCNT_SET( SEND, RETRY_SENT, ctx->quic->metrics.retry_tx_cnt );
817 0 : FD_MCNT_ENUM_COPY( SEND, ACK_TX, ctx->quic->metrics.ack_tx );
818 :
819 0 : FD_MGAUGE_ENUM_COPY( SEND, CONNECTIONS_STATE, ctx->quic->metrics.conn_state_cnt );
820 0 : FD_MGAUGE_SET( SEND, CONNECTIONS_ALLOC, ctx->quic->metrics.conn_alloc_cnt );
821 0 : FD_MCNT_SET( SEND, CONNECTIONS_CREATED, ctx->quic->metrics.conn_created_cnt );
822 0 : FD_MCNT_SET( SEND, CONNECTIONS_CLOSED, ctx->quic->metrics.conn_closed_cnt );
823 0 : FD_MCNT_SET( SEND, CONNECTIONS_ABORTED, ctx->quic->metrics.conn_aborted_cnt );
824 0 : FD_MCNT_SET( SEND, CONNECTIONS_TIMED_OUT, ctx->quic->metrics.conn_timeout_cnt );
825 0 : FD_MCNT_SET( SEND, CONNECTIONS_RETRIED, ctx->quic->metrics.conn_retry_cnt );
826 0 : FD_MCNT_SET( SEND, CONNECTION_ERROR_NO_SLOTS, ctx->quic->metrics.conn_err_no_slots_cnt );
827 0 : FD_MCNT_SET( SEND, CONNECTION_ERROR_RETRY_FAIL, ctx->quic->metrics.conn_err_retry_fail_cnt );
828 :
829 0 : FD_MCNT_ENUM_COPY( SEND, PKT_CRYPTO_FAILED, ctx->quic->metrics.pkt_decrypt_fail_cnt );
830 0 : FD_MCNT_ENUM_COPY( SEND, PKT_NO_KEY, ctx->quic->metrics.pkt_no_key_cnt );
831 0 : FD_MCNT_ENUM_COPY( SEND, PKT_NO_CONN, ctx->quic->metrics.pkt_no_conn_cnt );
832 0 : FD_MCNT_ENUM_COPY( SEND, FRAME_TX_ALLOC, ctx->quic->metrics.frame_tx_alloc_cnt );
833 0 : FD_MCNT_SET( SEND, PKT_NET_HEADER_INVALID, ctx->quic->metrics.pkt_net_hdr_err_cnt );
834 0 : FD_MCNT_SET( SEND, PKT_QUIC_HEADER_INVALID, ctx->quic->metrics.pkt_quic_hdr_err_cnt );
835 0 : FD_MCNT_SET( SEND, PKT_UNDERSZ, ctx->quic->metrics.pkt_undersz_cnt );
836 0 : FD_MCNT_SET( SEND, PKT_OVERSZ, ctx->quic->metrics.pkt_oversz_cnt );
837 0 : FD_MCNT_SET( SEND, PKT_VERNEG, ctx->quic->metrics.pkt_verneg_cnt );
838 0 : FD_MCNT_ENUM_COPY( SEND, PKT_RETRANSMISSIONS, ctx->quic->metrics.pkt_retransmissions_cnt );
839 :
840 0 : FD_MCNT_SET( SEND, HANDSHAKES_CREATED, ctx->quic->metrics.hs_created_cnt );
841 0 : FD_MCNT_SET( SEND, HANDSHAKE_ERROR_ALLOC_FAIL, ctx->quic->metrics.hs_err_alloc_fail_cnt );
842 0 : FD_MCNT_SET( SEND, HANDSHAKE_EVICTED, ctx->quic->metrics.hs_evicted_cnt );
843 :
844 0 : FD_MCNT_SET( SEND, FRAME_FAIL_PARSE, ctx->quic->metrics.frame_rx_err_cnt );
845 :
846 0 : FD_MHIST_COPY( SEND, SERVICE_DURATION_SECONDS, ctx->quic->metrics.service_duration );
847 0 : FD_MHIST_COPY( SEND, RECEIVE_DURATION_SECONDS, ctx->quic->metrics.receive_duration );
848 0 : }
849 :
850 :
851 0 : #define STEM_BURST 1UL
852 0 : #define STEM_LAZY (10e3L) /* 10us */
853 :
854 0 : #define STEM_CALLBACK_CONTEXT_TYPE fd_send_tile_ctx_t
855 0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_send_tile_ctx_t)
856 :
857 0 : #define STEM_CALLBACK_BEFORE_FRAG before_frag
858 0 : #define STEM_CALLBACK_DURING_FRAG during_frag
859 0 : #define STEM_CALLBACK_AFTER_FRAG after_frag
860 0 : #define STEM_CALLBACK_METRICS_WRITE metrics_write
861 0 : #define STEM_CALLBACK_BEFORE_CREDIT before_credit
862 0 : #define STEM_CALLBACK_DURING_HOUSEKEEPING during_housekeeping
863 : #include "../../disco/stem/fd_stem.c"
864 :
865 : fd_topo_run_tile_t fd_tile_send = {
866 : .name = "send",
867 : .populate_allowed_seccomp = populate_allowed_seccomp,
868 : .populate_allowed_fds = populate_allowed_fds,
869 : .scratch_align = scratch_align,
870 : .scratch_footprint = scratch_footprint,
871 : .privileged_init = privileged_init,
872 : .unprivileged_init = unprivileged_init,
873 : .run = stem_run,
874 : };
|