LCOV - code coverage report
Current view: top level - disco - fd_disco_base.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 20 47 42.6 %
Date: 2026-09-17 04:28:31 Functions: 9 3556 0.3 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_disco_fd_disco_base_h
       2             : #define HEADER_fd_src_disco_fd_disco_base_h
       3             : 
       4             : #include "../tango/fd_tango.h"
       5             : #include "../ballet/shred/fd_shred.h"
       6             : #include "../ballet/txn/fd_txn.h"
       7             : #include "../flamenco/fd_flamenco_base.h"
       8             : #include "../util/wksp/fd_wksp_private.h"
       9             : 
      10        2226 : #define DST_PROTO_OUTGOING (0UL)
      11          48 : #define DST_PROTO_TPU_UDP  (1UL)
      12          48 : #define DST_PROTO_TPU_QUIC (2UL)
      13         102 : #define DST_PROTO_SHRED    (3UL)
      14          48 : #define DST_PROTO_REPAIR   (4UL)
      15          66 : #define DST_PROTO_GOSSIP   (5UL)
      16          48 : #define DST_PROTO_SEND     (6UL)
      17          48 : #define DST_PROTO_RSERVE   (7UL)
      18          96 : #define DST_PROTO_VOTOR    (8UL)
      19             : 
      20           0 : #define POH_PKT_TYPE_MICROBLOCK      (0UL)
      21           0 : #define POH_PKT_TYPE_BECAME_LEADER   (1UL)
      22           0 : #define POH_PKT_TYPE_SHRED_EPOCH_MSG (2UL)
      23           0 : #define POH_PKT_TYPE_LEADER_BANK     (3UL)
      24             : 
      25             : /* FD_NET_MTU is the max full packet size, with ethernet, IP, and UDP
      26             :    headers that can go in or out of the net tile.  2048 is the maximum
      27             :    XSK entry size, so this value follows naturally. */
      28             : 
      29       25173 : #define FD_NET_MTU (2048UL)
      30             : 
      31             : /* FD_TPU_MTU is the max serialized byte size of a txn sent over TPU.
      32             : 
      33             :    As per SIMD-296, this is 4096 bytes. */
      34             : 
      35       31233 : #define FD_TPU_MTU (4096UL)
      36             : 
      37             : /* FD_GOSSIP_MTU is the max sz of a gossip packet:
      38             : 
      39             :    Minimum MTU of IPv6 packet - IPv6 header - UDP header
      40             :                          1280 -          40 -          8 */
      41             : 
      42           0 : #define FD_GOSSIP_MTU (1232UL)
      43             : 
      44             : /* FD_SHRED_STORE_MTU is the size of an fd_fec_set (statically
      45             :    asserted in fd_shred_tile.c). */
      46             : 
      47           0 : #define FD_SHRED_STORE_MTU (77888UL)
      48             : 
      49           0 : #define FD_NETMUX_SIG_MIN_HDR_SZ (42UL) /* The default header size, which means no vlan tags and no IP options. */
      50             : 
      51             : /* These limits are defined here to prevent circular dependencies, and
      52             :    statically asserted they are calculated correctly in the relevant
      53             :    places.  We get one bound using transactions that consume the minimum
      54             :    number of CUs and another bound using the minimum size transactions.
      55             :    The overall bound is the lower of the two. */
      56             : #define FD_MAX_TXN_PER_SLOT_CU    98039UL
      57             : #define FD_MAX_TXN_PER_SLOT_SHRED 272635UL
      58      883011 : #define FD_MAX_TXN_PER_SLOT       98039UL
      59             : FD_STATIC_ASSERT( FD_MAX_TXN_PER_SLOT<=FD_MAX_TXN_PER_SLOT_CU&&FD_MAX_TXN_PER_SLOT<=FD_MAX_TXN_PER_SLOT_SHRED, max_txn_per_slot );
      60             : FD_STATIC_ASSERT( FD_MAX_TXN_PER_SLOT>=FD_MAX_TXN_PER_SLOT_CU||FD_MAX_TXN_PER_SLOT>=FD_MAX_TXN_PER_SLOT_SHRED, max_txn_per_slot );
      61             : 
      62             : 
      63             : FD_PROTOTYPES_BEGIN
      64             : 
      65             :  /* hdr_sz is the total size of network headers, including eth, ip, udp.
      66             :     Ignored for outgoing packets.
      67             :     For incoming packets, hash_{ip_addr,port} are the source IP and port,
      68             :     for outgoing packets, they are the destination IP and port. */
      69             : FD_FN_CONST static inline ulong
      70             : fd_disco_netmux_sig( uint   hash_ip_addr,
      71             :                      ushort hash_port,
      72             :                      uint   ip_addr,
      73             :                      ulong  proto,
      74        2379 :                      ulong  hdr_sz ) {
      75             :   /* The size of an Ethernet header is 14+4k bytes, where 0<=k<=3 (?) is
      76             :      the number of vlan tags.  The size of an IP header is 4j, where
      77             :      5<=j<=15 is the size given in the header.  The size of a UDP header
      78             :      is 8B.  Thus, the total sum of these is 42+4i, where i=k+j-5,
      79             :      0<=i<=13.  Since bits are at a premium here, we compress the header
      80             :      size by just storing i. */
      81        2379 :   ulong hdr_sz_i = ((hdr_sz - 42UL)>>2)&0xFUL;
      82        2379 :   ulong hash     = 0xfffffUL & fd_ulong_hash( (ulong)hash_ip_addr | ((ulong)hash_port<<32) );
      83        2379 :   return (hash<<44) | ((hdr_sz_i&0xFUL)<<40UL) | ((proto&0xFFUL)<<32UL) | ((ulong)ip_addr);
      84        2379 : }
      85             : 
      86         180 : FD_FN_CONST static inline ulong fd_disco_netmux_sig_hash ( ulong sig ) { return (sig>>44UL); }
      87         195 : FD_FN_CONST static inline ulong fd_disco_netmux_sig_proto( ulong sig ) { return (sig>>32UL) & 0xFFUL; }
      88         159 : FD_FN_CONST static inline uint  fd_disco_netmux_sig_ip   ( ulong sig ) { return (uint)(sig & 0xFFFFFFFFUL); }
      89             : 
      90             : /* fd_disco_netmux_sig_hdr_sz extracts the total size of the Ethernet,
      91             :    IP, and UDP headers from the netmux signature field.  The UDP payload
      92             :    of the packet stored in the corresponding frag begins at the returned
      93             :    offset. */
      94           0 : FD_FN_CONST static inline ulong  fd_disco_netmux_sig_hdr_sz( ulong sig ) { return 4UL*((sig>>40UL) & 0xFUL) + 42UL; }
      95             : 
      96             : FD_FN_CONST static inline ulong
      97             : fd_disco_poh_sig( ulong slot,
      98             :                   ulong pkt_type,
      99           0 :                   ulong execle_tile ) {
     100             :    /* The high 6 bits of the low byte of the signature field is the
     101             :       execle idx.  Execles will filter to only handle frags with their
     102             :       own idx.  The higher 7 bytes are the slot number.  Technically,
     103             :       the slot number is a ulong, but it won't hit 256^7 for about 10^9
     104             :       years at the current rate.  The lowest bits of the low byte is the
     105             :       packet type. */
     106           0 :   return (slot << 8) | ((execle_tile & 0x3FUL) << 2) | (pkt_type & 0x3UL);
     107           0 : }
     108             : 
     109           0 : FD_FN_CONST static inline ulong fd_disco_poh_sig_pkt_type( ulong sig ) { return (sig & 0x3UL); }
     110           0 : FD_FN_CONST static inline ulong fd_disco_poh_sig_slot( ulong sig ) { return (sig >> 8); }
     111           0 : FD_FN_CONST static inline ulong fd_disco_poh_sig_execle_tile( ulong sig ) { return (sig >> 2) & 0x3FUL; }
     112             : 
     113             : FD_FN_CONST static inline ulong
     114             : fd_disco_execle_sig( ulong slot,
     115           0 :                      ulong pack_idx ) {
     116           0 :   return (slot << 32) | pack_idx;
     117           0 : }
     118             : 
     119           0 : FD_FN_CONST static inline ulong fd_disco_execle_sig_slot( ulong sig ) { return (sig >> 32); }
     120           0 : FD_FN_CONST static inline ulong fd_disco_execle_sig_pack_idx( ulong sig ) { return sig & 0xFFFFFFFFUL; }
     121             : 
     122             : FD_FN_PURE static inline ulong
     123           0 : fd_disco_compact_chunk0( void * wksp ) {
     124           0 :   return (((struct fd_wksp_private *)wksp)->gaddr_lo) >> FD_CHUNK_LG_SZ;
     125           0 : }
     126             : 
     127             : FD_FN_PURE static inline ulong
     128           0 : fd_disco_compact_wmark( void * wksp, ulong mtu ) {
     129           0 :   ulong chunk_mtu  = ((mtu + 2UL*FD_CHUNK_SZ-1UL) >> (1+FD_CHUNK_LG_SZ)) << 1;
     130           0 :   ulong wksp_hi = ((struct fd_wksp_private *)wksp)->gaddr_hi;
     131           0 :   return (wksp_hi >> FD_CHUNK_LG_SZ) - chunk_mtu;
     132           0 : }
     133             : 
     134             : FD_PROTOTYPES_END
     135             : 
     136             : #endif /* HEADER_fd_src_disco_fd_disco_base_h */

Generated by: LCOV version 1.14