LCOV - code coverage report
Current view: top level - disco - fd_disco_base.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 51 0.0 %
Date: 2026-10-22 18:10:43 Functions: 0 3660 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             : #include "../flamenco/fd_flamenco_base.h"
       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           0 : #define DST_PROTO_RSERVE   (7UL)
      17           0 : #define DST_PROTO_VOTOR    (8UL)
      18             : 
      19           0 : #define POH_PKT_TYPE_MICROBLOCK      (0UL)
      20             : 
      21             : /* FD_NET_MTU is the max full packet size, with ethernet, IP, and UDP
      22             :    headers that can go in or out of the net tile.  2048 is the maximum
      23             :    XSK entry size, so this value follows naturally. */
      24             : 
      25           0 : #define FD_NET_MTU (2048UL)
      26             : 
      27             : /* FD_TPU_MTU is the max serialized byte size of a txn sent over TPU.
      28             : 
      29             :    As per SIMD-296, this is 4096 bytes. */
      30             : 
      31           0 : #define FD_TPU_MTU (4096UL)
      32             : 
      33             : /* FD_GOSSIP_MTU is the max sz of a gossip packet:
      34             : 
      35             :    Minimum MTU of IPv6 packet - IPv6 header - UDP header
      36             :                          1280 -          40 -          8 */
      37             : 
      38           0 : #define FD_GOSSIP_MTU (1232UL)
      39             : 
      40           0 : #define FD_NETMUX_SIG_MIN_HDR_SZ (42UL) /* The default header size, which means no vlan tags and no IP options. */
      41             : 
      42             : /* These limits are defined here to prevent circular dependencies, and
      43             :    statically asserted they are calculated correctly in the relevant
      44             :    places.  We get one bound using transactions that consume the minimum
      45             :    number of CUs and another bound using the minimum size transactions.
      46             :    The overall bound is the lower of the two.  Both use the 200ms slot
      47             :    params with raise_block_limits_to_100m (50M CUs, 16384 shreds). */
      48             : #define FD_MAX_TXN_PER_SLOT_CU    49019UL
      49             : #define FD_MAX_TXN_PER_SLOT_SHRED 136306UL
      50           0 : #define FD_MAX_TXN_PER_SLOT       49019UL
      51             : 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 );
      52             : 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 );
      53             : 
      54             : 
      55             : FD_PROTOTYPES_BEGIN
      56             : 
      57             :  /* hdr_sz is the total size of network headers, including eth, ip, udp.
      58             :     Ignored for outgoing packets.
      59             :     For incoming packets, hash_{ip_addr,port} are the source IP and port,
      60             :     for outgoing packets, they are the destination IP and port. */
      61             : FD_FN_CONST static inline ulong
      62             : fd_disco_netmux_sig( uint   hash_ip_addr,
      63             :                      ushort hash_port,
      64             :                      uint   ip_addr,
      65             :                      ulong  proto,
      66           0 :                      ulong  hdr_sz ) {
      67             :   /* The size of an Ethernet header is 14+4k bytes, where 0<=k<=3 (?) is
      68             :      the number of vlan tags.  The size of an IP header is 4j, where
      69             :      5<=j<=15 is the size given in the header.  The size of a UDP header
      70             :      is 8B.  Thus, the total sum of these is 42+4i, where i=k+j-5,
      71             :      0<=i<=13.  Since bits are at a premium here, we compress the header
      72             :      size by just storing i. */
      73           0 :   ulong hdr_sz_i = ((hdr_sz - 42UL)>>2)&0xFUL;
      74           0 :   ulong hash     = 0xfffffUL & fd_ulong_hash( (ulong)hash_ip_addr | ((ulong)hash_port<<32) );
      75           0 :   return (hash<<44) | ((hdr_sz_i&0xFUL)<<40UL) | ((proto&0xFFUL)<<32UL) | ((ulong)ip_addr);
      76           0 : }
      77             : 
      78           0 : FD_FN_CONST static inline ulong fd_disco_netmux_sig_hash ( ulong sig ) { return (sig>>44UL); }
      79           0 : FD_FN_CONST static inline ulong fd_disco_netmux_sig_proto( ulong sig ) { return (sig>>32UL) & 0xFFUL; }
      80           0 : FD_FN_CONST static inline uint  fd_disco_netmux_sig_ip   ( ulong sig ) { return (uint)(sig & 0xFFFFFFFFUL); }
      81             : 
      82             : /* fd_disco_netmux_sig_hdr_sz extracts the total size of the Ethernet,
      83             :    IP, and UDP headers from the netmux signature field.  The UDP payload
      84             :    of the packet stored in the corresponding frag begins at the returned
      85             :    offset. */
      86           0 : FD_FN_CONST static inline ulong  fd_disco_netmux_sig_hdr_sz( ulong sig ) { return 4UL*((sig>>40UL) & 0xFUL) + 42UL; }
      87             : 
      88             : FD_FN_CONST static inline ulong
      89             : fd_disco_poh_sig( ulong slot,
      90             :                   ulong pkt_type,
      91           0 :                   ulong execle_tile ) {
      92             :    /* The high 6 bits of the low byte of the signature field is the
      93             :       execle idx.  Execles will filter to only handle frags with their
      94             :       own idx.  The higher 7 bytes are the slot number.  Technically,
      95             :       the slot number is a ulong, but it won't hit 256^7 for about 10^9
      96             :       years at the current rate.  The lowest bits of the low byte is the
      97             :       packet type. */
      98           0 :   return (slot << 8) | ((execle_tile & 0x3FUL) << 2) | (pkt_type & 0x3UL);
      99           0 : }
     100             : 
     101           0 : FD_FN_CONST static inline ulong fd_disco_poh_sig_pkt_type( ulong sig ) { return (sig & 0x3UL); }
     102           0 : FD_FN_CONST static inline ulong fd_disco_poh_sig_slot( ulong sig ) { return (sig >> 8); }
     103           0 : FD_FN_CONST static inline ulong fd_disco_poh_sig_execle_tile( ulong sig ) { return (sig >> 2) & 0x3FUL; }
     104             : 
     105             : FD_FN_CONST static inline ulong
     106             : fd_disco_execle_sig( ulong slot,
     107           0 :                      ulong pack_idx ) {
     108           0 :   return (slot << 32) | (pack_idx & 0xFFFFFFFFUL);
     109           0 : }
     110             : 
     111           0 : FD_FN_CONST static inline ulong fd_disco_execle_sig_slot( ulong sig ) { return (sig >> 32); }
     112           0 : FD_FN_CONST static inline ulong fd_disco_execle_sig_pack_idx( ulong sig ) { return sig & 0xFFFFFFFFUL; }
     113             : 
     114             : FD_FN_PURE static inline ulong
     115           0 : fd_disco_compact_chunk0( void * wksp ) {
     116           0 :   return (((struct fd_wksp_private *)wksp)->gaddr_lo) >> FD_CHUNK_LG_SZ;
     117           0 : }
     118             : 
     119             : FD_FN_PURE static inline ulong
     120           0 : fd_disco_compact_wmark( void * wksp, ulong mtu ) {
     121           0 :   ulong chunk_mtu  = ((mtu + 2UL*FD_CHUNK_SZ-1UL) >> (1+FD_CHUNK_LG_SZ)) << 1;
     122           0 :   ulong wksp_hi = ((struct fd_wksp_private *)wksp)->gaddr_hi;
     123           0 :   return (wksp_hi >> FD_CHUNK_LG_SZ) - chunk_mtu;
     124           0 : }
     125             : 
     126             : /* Returns 0 if not a durable nonce transaction and 1 if it may be a
     127             :    durable nonce transaction.  This is suitable for TPU purposes, but
     128             :    not for replay purposes, where it needs to be exact in all edge
     129             :    cases. */
     130             : FD_FN_PURE static inline int
     131             : fd_disco_tpu_is_durable_nonce( fd_txn_t const * txn,
     132           0 :                                uchar    const * payload ) {
     133           0 :   if( FD_UNLIKELY( txn->instr_cnt==0 ) ) return 0;
     134             : 
     135           0 :   fd_txn_instr_t const * ix0 = &txn->instr[ 0 ];
     136           0 :   fd_acct_addr_t const * prog0 = fd_txn_get_acct_addrs( txn, payload ) + ix0->program_id;
     137             :   /* First instruction must be SystemProgram nonceAdvance instruction */
     138           0 :   fd_acct_addr_t const system_program[1] = { { { 0 } } };
     139           0 :   if( FD_LIKELY( memcmp( prog0, system_program, sizeof(fd_acct_addr_t) ) ) )        return 0;
     140             : 
     141             :   /* instruction with three accounts and a four byte instruction data, a
     142             :      little-endian uint value 4 */
     143           0 :   if( FD_UNLIKELY( (ix0->data_sz!=4) | (ix0->acct_cnt!=3) ) ) return 0;
     144             : 
     145           0 :   return fd_uint_load_4( payload + ix0->data_off )==4U;
     146           0 : }
     147             : 
     148             : FD_PROTOTYPES_END
     149             : 
     150             : #endif /* HEADER_fd_src_disco_fd_disco_base_h */

Generated by: LCOV version 1.14