LCOV - code coverage report
Current view: top level - discof/send - fd_send_tile.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 13 0.0 %
Date: 2025-09-20 04:42:25 Functions: 0 0 -

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

Generated by: LCOV version 1.14