LCOV - code coverage report
Current view: top level - disco - fd_disco_base.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 3 64 4.7 %
Date: 2025-03-20 12:08:36 Functions: 0 2898 0.0 %

          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             : 
       8             : #include "../util/wksp/fd_wksp_private.h"
       9             : 
      10           0 : #define DST_PROTO_OUTGOING (0UL)
      11           0 : #define DST_PROTO_TPU_UDP  (1UL)
      12           0 : #define DST_PROTO_TPU_QUIC (2UL)
      13           0 : #define DST_PROTO_SHRED    (3UL)
      14           0 : #define DST_PROTO_REPAIR   (4UL)
      15           0 : #define DST_PROTO_GOSSIP   (5UL)
      16             : 
      17           0 : #define POH_PKT_TYPE_MICROBLOCK    (0UL)
      18           0 : #define POH_PKT_TYPE_BECAME_LEADER (1UL)
      19           0 : #define POH_PKT_TYPE_DONE_PACKING  (2UL)
      20             : 
      21           0 : #define REPLAY_FLAG_FINISHED_BLOCK      (0x01UL)
      22           0 : #define REPLAY_FLAG_PACKED_MICROBLOCK   (0x02UL)
      23           0 : #define REPLAY_FLAG_MICROBLOCK          (0x04UL)
      24           0 : #define REPLAY_FLAG_CATCHING_UP         (0x08UL)
      25           0 : #define REPLAY_FLAG_INIT                (0x10UL)
      26             : 
      27             : 
      28             : /* FD_NET_MTU is the max full packet size, with ethernet, IP, and UDP
      29             :    headers that can go in or out of the net tile.  2048 is the maximum
      30             :    XSK entry size, so this value follows naturally. */
      31          12 : #define FD_NET_MTU (2048UL)
      32             : 
      33             : /* FD_TPU_MTU is the max serialized byte size of a txn sent over TPU.
      34             : 
      35             :    This is minimum MTU of IPv6 packet - IPv6 header - UDP header
      36             :                                  1280 -          40 -          8 */
      37           3 : #define FD_TPU_MTU (1232UL)
      38             : 
      39             : /* FD_GOSSIP_MTU is the max sz of a gossip packet which is the same as
      40             :    above. */
      41             : #define FD_GOSSIP_MTU (FD_TPU_MTU)
      42             : 
      43             : /* FD_SHRED_STORE_MTU is the size of an fd_shred34_t (statically
      44             :    asserted in fd_shred_tile.c). */
      45           3 : #define FD_SHRED_STORE_MTU (41792UL)
      46             : 
      47           0 : #define FD_NETMUX_SIG_MIN_HDR_SZ    ( 42UL) /* The default header size, which means no vlan tags and no IP options. */
      48             : #define FD_NETMUX_SIG_IGNORE_HDR_SZ (102UL) /* Outside the allowable range, but still fits in 4 bits when compressed */
      49             : 
      50             : FD_PROTOTYPES_BEGIN
      51             : 
      52             :  /* hdr_sz is the total size of network headers, including eth, ip, udp.
      53             :     Ignored for outgoing packets.
      54             :     For incoming packets, hash_{ip_addr,port} are the source IP and port,
      55             :     for outgoing packets, they are the destination IP and port. */
      56             : FD_FN_CONST static inline ulong
      57             : fd_disco_netmux_sig( uint   hash_ip_addr,
      58             :                      ushort hash_port,
      59             :                      uint   dst_ip_addr,
      60             :                      ulong  proto,
      61           0 :                      ulong  hdr_sz ) {
      62             :   /* The size of an Ethernet header is 14+4k bytes, where 0<=k<=3 (?) is
      63             :      the number of vlan tags.  The size of an IP header is 4j, where
      64             :      5<=j<=15 is the size given in the header.  The size of a UDP header
      65             :      is 8B.  Thus, the total sum of these is 42+4i, where i=k+j-5,
      66             :      0<=i<=13.  Since bits are at a premium here, we compress the header
      67             :      size by just storing i. */
      68           0 :   ulong hdr_sz_i = ((hdr_sz - 42UL)>>2)&0xFUL;
      69           0 :   ulong hash     = 0xfffffUL & fd_ulong_hash( (ulong)hash_ip_addr | ((ulong)hash_port<<32) );
      70           0 :   return (hash<<44) | ((hdr_sz_i&0xFUL)<<40UL) | ((proto&0xFFUL)<<32UL) | ((ulong)dst_ip_addr);
      71           0 : }
      72             : 
      73           0 : FD_FN_CONST static inline ulong fd_disco_netmux_sig_hash  ( ulong sig ) { return (sig>>44UL); }
      74           0 : FD_FN_CONST static inline ulong fd_disco_netmux_sig_proto ( ulong sig ) { return (sig>>32UL) & 0xFFUL; }
      75           0 : FD_FN_CONST static inline uint  fd_disco_netmux_sig_dst_ip( ulong sig ) { return (uint)(sig & 0xFFFFFFFFUL); }
      76             : 
      77             : /* fd_disco_netmux_sig_hdr_sz extracts the total size of the Ethernet,
      78             :    IP, and UDP headers from the netmux signature field.  The UDP payload
      79             :    of the packet stored in the corresponding frag begins at the returned
      80             :    offset. */
      81           0 : FD_FN_CONST static inline ulong  fd_disco_netmux_sig_hdr_sz( ulong sig ) { return 4UL*((sig>>40UL) & 0xFUL) + 42UL; }
      82             : 
      83             : FD_FN_CONST static inline ulong
      84             : fd_disco_poh_sig( ulong slot,
      85             :                   ulong pkt_type,
      86           0 :                   ulong bank_tile ) {
      87             :    /* The high 6 bits of the low byte of the signature field is the bank
      88             :       idx.  Banks will filter to only handle frags with their own idx.
      89             :       The higher 7 bytes are the slot number.  Technically, the slot
      90             :       number is a ulong, but it won't hit 256^7 for about 10^9 years at
      91             :       the current rate.  The lowest bits of the low byte is the packet
      92             :       type. */
      93           0 :   return (slot << 8) | ((bank_tile & 0x3FUL) << 2) | (pkt_type & 0x3UL);
      94           0 : }
      95             : 
      96           0 : FD_FN_CONST static inline ulong fd_disco_poh_sig_pkt_type( ulong sig ) { return (sig & 0x3UL); }
      97           0 : FD_FN_CONST static inline ulong fd_disco_poh_sig_slot( ulong sig ) { return (sig >> 8); }
      98           0 : FD_FN_CONST static inline ulong fd_disco_poh_sig_bank_tile( ulong sig ) { return (sig >> 2) & 0x3FUL; }
      99             : 
     100             : FD_FN_CONST static inline ulong
     101             : fd_disco_bank_sig( ulong slot,
     102           0 :                    ulong microblock_idx ) {
     103           0 :   return (slot << 32) | microblock_idx;
     104           0 : }
     105             : 
     106           0 : FD_FN_CONST static inline ulong fd_disco_bank_sig_slot( ulong sig ) { return (sig >> 32); }
     107           0 : FD_FN_CONST static inline ulong fd_disco_bank_sig_microblock_idx( ulong sig ) { return sig & 0xFFFFFFFFUL; }
     108             : 
     109             : /* TODO remove with store_int */
     110             : 
     111             : FD_FN_CONST static inline ulong
     112             : fd_disco_replay_old_sig( ulong slot,
     113           0 :                      ulong flags ) {
     114             :    /* The low byte of the signature field is the flags for replay message.
     115             :       The higher 7 bytes are the slot number.  These flags indicate the status
     116             :       of a microblock as it transits through the replay system.  Technically,
     117             :       the slot number is a ulong, but it won't hit 256^7 for about 10^9 years
     118             :       at the current rate.  The lowest bit of the low byte is the packet
     119             :       type. */
     120           0 :   return (slot << 8) | (flags & 0xFFUL);
     121           0 : }
     122             : 
     123           0 : FD_FN_CONST static inline ulong fd_disco_replay_old_sig_flags( ulong sig ) { return (sig & 0xFFUL); }
     124           0 : FD_FN_CONST static inline ulong fd_disco_replay_old_sig_slot( ulong sig ) { return (sig >> 8); }
     125             : 
     126             : FD_FN_CONST static inline ulong
     127             : fd_disco_shred_replay_sig( ulong slot,
     128             :                            uint  shred_idx,
     129             :                            uint  fec_set_idx,
     130             :                            int   is_code,
     131           0 :                            int   completes ) {
     132             : 
     133             :   /* | 32 LSB of slot | 15 LSB of shred_idx | 15 LSB of fec_idx | 1 bit of shred data/code type | 1 bit if shred completes the fec set |
     134             :      | slot[32,63]    | shred_idx[17,32]     | fec_idx[2,16]    | is_parity[1]                  | is_complete[0]                       | */
     135             : 
     136           0 :   ulong slot_ul        = fd_ulong_min( (ulong)slot,        (ulong)UINT_MAX              );
     137           0 :   ulong shred_idx_ul   = fd_ulong_min( (ulong)shred_idx,   (ulong)FD_SHRED_MAX_PER_SLOT );
     138           0 :   ulong fec_set_idx_ul = fd_ulong_min( (ulong)fec_set_idx, (ulong)FD_SHRED_MAX_PER_SLOT );
     139           0 :   ulong is_code_ul     = (ulong)is_code;
     140           0 :   ulong completes_ul   = (ulong)completes;
     141           0 :   return slot_ul << 32 | shred_idx_ul << 17 | fec_set_idx_ul << 2 | is_code_ul << 1 | completes_ul;
     142           0 : }
     143             : 
     144           0 : FD_FN_CONST static inline ulong fd_disco_shred_replay_sig_slot       ( ulong sig ) { return       fd_ulong_extract    ( sig, 32, 63 ); }
     145           0 : FD_FN_CONST static inline uint  fd_disco_shred_replay_sig_shred_idx  ( ulong sig ) { return (uint)fd_ulong_extract    ( sig, 17, 31 ); }
     146           0 : FD_FN_CONST static inline uint  fd_disco_shred_replay_sig_fec_set_idx( ulong sig ) { return (uint)fd_ulong_extract    ( sig, 2, 16  ); }
     147           0 : FD_FN_CONST static inline int   fd_disco_shred_replay_sig_is_code    ( ulong sig ) { return       fd_ulong_extract_bit( sig, 1      ); }
     148           0 : FD_FN_CONST static inline int   fd_disco_shred_replay_sig_completes  ( ulong sig ) { return       fd_ulong_extract_bit( sig, 0      ); }
     149             : 
     150             : FD_FN_PURE static inline ulong
     151           0 : fd_disco_compact_chunk0( void * wksp ) {
     152           0 :   return (((struct fd_wksp_private *)wksp)->gaddr_lo) >> FD_CHUNK_LG_SZ;
     153           0 : }
     154             : 
     155             : FD_FN_PURE static inline ulong
     156           0 : fd_disco_compact_wmark( void * wksp, ulong mtu ) {
     157           0 :   ulong chunk_mtu  = ((mtu + 2UL*FD_CHUNK_SZ-1UL) >> (1+FD_CHUNK_LG_SZ)) << 1;
     158           0 :   ulong wksp_hi = ((struct fd_wksp_private *)wksp)->gaddr_hi;
     159           0 :   return (wksp_hi >> FD_CHUNK_LG_SZ) - chunk_mtu;
     160           0 : }
     161             : 
     162             : FD_PROTOTYPES_END
     163             : 
     164             : #endif /* HEADER_fd_src_disco_fd_disco_base_h */

Generated by: LCOV version 1.14