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

Generated by: LCOV version 1.14