LCOV - code coverage report
Current view: top level - ballet/shred - fd_shred.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 106 114 93.0 %
Date: 2026-07-30 05:22:27 Functions: 70 6696 1.0 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_ballet_shred_fd_shred_h
       2             : #define HEADER_fd_src_ballet_shred_fd_shred_h
       3             : 
       4             : #include "../bmtree/fd_bmtree.h"
       5             : 
       6             : /* Shreds form the on-wire representation of Solana block data
       7             :    optimized for transmission over unreliable links/WAN.
       8             : 
       9             :    ### Layout
      10             : 
      11             :    Each shred is 1228 bytes long.
      12             : 
      13             :       +------------------------+
      14             :       | Common Shred Header    | 83 bytes
      15             :       +------------------------+
      16             :       | Data Header            | 5 bytes
      17             :       | or Coding Header       | or 6 bytes
      18             :       +------------------------+
      19             :       |                        | variable
      20             :       | Payload                | length
      21             :       |                        |
      22             :       +------------------------+
      23             : 
      24             :        for Merkle shreds, followed by:
      25             : 
      26             :       +------------------------+
      27             :       | (Chained merkle root)  | 32 bytes
      28             :       +------------------------+
      29             :       +------------------------+
      30             :       | Merkle node #0 (root)  | 20 bytes
      31             :       +------------------------+
      32             :       | Merkle node #1         | 20 bytes
      33             :       ..........................
      34             : 
      35             :        for resigned shreds, followed by:
      36             : 
      37             :       +------------------------+
      38             :       | signature              | 64 bytes
      39             :       ..........................
      40             : 
      41             :    ### Shredding
      42             : 
      43             :    For a given input data blob (usually an entry batch),
      44             :    data shreds are derived by simply splitting up the blob into subslices.
      45             : 
      46             :    Each shred is sized such that it fits into a single UDP packet,
      47             :    i.e. currently bound by the generally accepted IPv6 MTU of 1280 bytes.
      48             : 
      49             :    ### Forward Error Correction
      50             : 
      51             :    Coding shreds implement Reed-Solomon error correction to provide tolerance against packet loss.
      52             : 
      53             :    Each data shred is first assigned an FEC set.
      54             :    For the vector of data shreds in each set, a corresponding vector of coding shreds contains parity data.
      55             : 
      56             :    FEC sets and entry batches do not necessarily align.
      57             : 
      58             :    ### Merkle Inclusion Proofs
      59             : 
      60             :    Data and coding shreds come in two variants respectively: legacy and merkle.
      61             :    Merkle shreds extend legacy shreds by adding FEC set inclusion proofs.
      62             : 
      63             :    It allows the block producer to commit to the vector of shreds that make up an FEC set.
      64             :    The inclusion proof is used to verify whether a shred is part of the FEC set commitment.
      65             : 
      66             :    The length of the inclusion proof is indicated by the variant field.
      67             : 
      68             :    ### resigned shreds
      69             : 
      70             :    Resigned shreds allow for an additional signature to be added on to lock down
      71             :    the retransmitter for turbine propagation
      72             : 
      73             :    ### Authentication
      74             : 
      75             :    Shreds are signed by the block producer.
      76             :    Consequently, only the block producer is able to create valid shreds for any given block. */
      77             : 
      78             : #include "../fd_ballet.h"
      79             : 
      80             : /* FD_SHRED_MAX_SZ: The max byte size of a shred.
      81             :    This limit derives from the IPv6 MTU of 1280 bytes, minus 48 bytes
      82             :    for the UDP/IPv6 headers and another 4 bytes for good measure.  Most
      83             :    shreds are this size, but Merkle data shreds may be smaller. */
      84    32960070 : #define FD_SHRED_MAX_SZ (1228UL)
      85             : /* FD_SHRED_MIN_SZ: The minimum byte size of a shred.
      86             :    A code shred of the max size covers a data shred of the minimum size
      87             :    with no padding. */
      88    29898111 : #define FD_SHRED_MIN_SZ (1203UL)
      89             : /* FD_SHRED_DATA_HEADER_SZ: size of all headers for data type shreds. */
      90    18331671 : #define FD_SHRED_DATA_HEADER_SZ (0x58UL)
      91             : /* FD_SHRED_CODE_HEADER_SZ: size of all headers for coding type shreds. */
      92     6219558 : #define FD_SHRED_CODE_HEADER_SZ (0x59UL)
      93             : /* This is a conservative bound.
      94             :    It's possible for a modified validator to create a data shred with
      95             :    this much payload.
      96             :    A validator that follows the default shredding policy should have
      97             :    payloads of no more than 1015 bytes.
      98             :    In general, shreds that are chained or resigned should have smaller
      99             :    payloads and a tigher bound. */
     100             : #define FD_SHRED_DATA_PAYLOAD_MAX (FD_SHRED_MIN_SZ-FD_SHRED_DATA_HEADER_SZ)
     101             : 
     102             : /* FD_SHRED_TYPE_* identifies the type of a shred.
     103             :    It is located at the four high bits of byte 0x40 (64) of the shred header
     104             :    and can be extracted using the fd_shred_type() function. */
     105             : /* FD_SHRED_TYPE_LEGACY_DATA: A shred carrying raw binary data. */
     106    20912400 : #define FD_SHRED_TYPE_LEGACY_DATA ((uchar)0xA0)
     107             : /* FD_SHRED_TYPE_LEGACY_CODE: A shred carrying Reed-Solomon ECC. */
     108             : #define FD_SHRED_TYPE_LEGACY_CODE ((uchar)0x50)
     109             : /* FD_SHRED_TYPE_MERKLE_DATA: A shred carrying raw binary data and a merkle inclusion proof. */
     110      200178 : #define FD_SHRED_TYPE_MERKLE_DATA ((uchar)0x80)
     111             : /* FD_SHRED_TYPE_MERKLE_CODE: A shred carrying Reed-Solomon ECC and a merkle inclusion proof. */
     112    30462639 : #define FD_SHRED_TYPE_MERKLE_CODE ((uchar)0x40)
     113             : /* FD_SHRED_TYPE_MERKLE_DATA_CHAINED: A shred carrying raw binary data and a chained merkle inclusion proof. */
     114      280089 : #define FD_SHRED_TYPE_MERKLE_DATA_CHAINED ((uchar)0x90)
     115             : /* FD_SHRED_TYPE_MERKLE_CODE_CHAINED: A shred carrying Reed-Solomon ECC and a chained merkle inclusion proof. */
     116      279225 : #define FD_SHRED_TYPE_MERKLE_CODE_CHAINED ((uchar)0x60)
     117             : 
     118             : /* FD_SHRED_TYPE_MERKLE_DATA_CHAINED_RESIGNED: A shred carrying raw binary data and a chained merkle inclusion proof and resigned. */
     119    24380181 : #define FD_SHRED_TYPE_MERKLE_DATA_CHAINED_RESIGNED ((uchar)0xB0)
     120             : /* FD_SHRED_TYPE_MERKLE_CODE_CHAINED_RESIGNED: A shred carrying Reed-Solomon ECC and a chained merkle inclusion proof and resigned. */
     121    24378549 : #define FD_SHRED_TYPE_MERKLE_CODE_CHAINED_RESIGNED ((uchar)0x70)
     122             : 
     123             : /* FD_SHRED_TYPEMASK_DATA: bitwise AND with type matches data shred */
     124             : #define FD_SHRED_TYPEMASK_DATA FD_SHRED_TYPE_MERKLE_DATA
     125             : /* FD_SHRED_TYPEMASK_CODE: bitwise AND with type matches code shred */
     126    29869815 : #define FD_SHRED_TYPEMASK_CODE FD_SHRED_TYPE_MERKLE_CODE
     127             : 
     128             : /* FD_SHRED_MERKLE_ROOT_SZ: the size of a merkle tree root in bytes. */
     129    24302064 : #define FD_SHRED_MERKLE_ROOT_SZ (32UL)
     130             : /* FD_SHRED_MERKLE_NODE_SZ: the size of a merkle inclusion proof node in bytes. */
     131    24281250 : #define FD_SHRED_MERKLE_NODE_SZ (20UL)
     132             : /* FD_SHRED_MERKLE_LAYER_CNT: the count of inclusion proof layers in the binary merkle tree. */
     133        6027 : #define FD_SHRED_MERKLE_LAYER_CNT (7UL)
     134             : /* FD_SHRED_SIGNATURE_SZ: the size of a signature in a shred. */
     135    27221403 : #define FD_SHRED_SIGNATURE_SZ (64UL)
     136             : /* A merkle inclusion proof node. */
     137             : typedef uchar fd_shred_merkle_t[FD_SHRED_MERKLE_NODE_SZ];
     138             : 
     139             : FD_STATIC_ASSERT( sizeof(fd_bmtree_node_t) == FD_SHRED_MERKLE_ROOT_SZ, update FD_SHRED_MERKLE_ROOT_SZ );
     140             : 
     141             : /* Constants relating to the data shred "flags" field. */
     142             : 
     143             : /* Mask of the "reference tick"    field in shred.data.flags */
     144           0 : #define FD_SHRED_DATA_REF_TICK_MASK      ((uchar)0x3f)
     145             : /* Mask of the "slot complete"       bit in shred.data.flags
     146             :    Indicates the last shred in a slot. */
     147           0 : #define FD_SHRED_DATA_FLAG_SLOT_COMPLETE ((uchar)0x80)
     148             : /* Mask of the "data batch complete" bit in shred.data.flags */
     149        6789 : #define FD_SHRED_DATA_FLAG_DATA_COMPLETE ((uchar)0x40)
     150             : 
     151             : /* Maximum number of data shreds in a slot, also maximum number of parity shreds in a slot */
     152      624150 : #define FD_SHRED_BLK_MAX (1 << 15UL) /* 32,768 shreds */
     153             : 
     154             : /* Many static bounds are specified around the assumption that this is a
     155             :    protocol limit on the max number of shreds in a slot. If this limit
     156             :    changes, all the relevant usages in other areas of the Firedancer
     157             :    codebase should be updated before modifying this assertion. */
     158             : 
     159             : FD_STATIC_ASSERT( FD_SHRED_BLK_MAX == 32768, check all usages before changing this limit! );
     160             : 
     161             : /* 36,536,320 bytes per slot */
     162             : #define FD_SHRED_DATA_PAYLOAD_MAX_PER_SLOT (FD_SHRED_DATA_PAYLOAD_MAX * FD_SHRED_BLK_MAX)
     163             : 
     164             : /* Offset of the shred variant. Used for parsing. */
     165             : #define FD_SHRED_VARIANT_OFF 0x40
     166             : 
     167             : /* Firedancer-specific internal error codes.
     168             : 
     169             :    These are not part of the Solana protocol. */
     170             : 
     171          21 : #define FD_SHRED_EBATCH  0x4000 /* End of batch reached (success)
     172             :                                    no more shreds and found FD_SHRED_DATA_FLAG_DATA_COMPLETE */
     173           9 : #define FD_SHRED_ESLOT   0x8000 /* End of slot reached (success)
     174             :                                    no more shreds and found FD_SHRED_DATA_FLAG_SLOT_COMPLETE */
     175           0 : #define FD_SHRED_ENOMEM      12 /* Error: Target buffer too small */
     176           0 : #define FD_SHRED_EINVAL      22 /* Error: Invalid shred data */
     177          27 : #define FD_SHRED_EPIPE       32 /* Error: Expected data in source buffer, got EOF */
     178             : 
     179             : /* Primary shred data structure.
     180             :    Relies heavily on packed fields and unaligned memory accesses. */
     181             : struct __attribute__((packed)) fd_shred {
     182             :   /* Ed25519 signature over the shred
     183             : 
     184             :      For legacy type shreds, signs over content of the shred structure past this signature field.
     185             :      For merkle type shreds, signs over the first node of the inclusion proof (merkle root). */
     186             :   /* 0x00 */ fd_ed25519_sig_t signature;
     187             : 
     188             :   /* Shred variant specifier
     189             :      Consists of two four bit fields. (Deliberately not using bit fields here)
     190             : 
     191             :      The high four bits indicate the shred type:
     192             :      - 0101: legacy code
     193             :      - 1010: legacy data
     194             :      - 0100: merkle code
     195             :      - 0110: merkle code (chained)
     196             :      - 0111: merkle code (chained resigned)
     197             :      - 1000: merkle data
     198             :      - 1001: merkle data (chained)
     199             :      - 1011: merkle data (chained resigned)
     200             : 
     201             :      For legacy type shreds, the low four bits are set to static patterns.
     202             :      For merkle type shreds, the low four bits are set to the number of non-root nodes in the inclusion proof.
     203             :      For merkle code type shreds, the 3rd highest bit represents if the merkle tree is chained.
     204             :      For merkle data type shreds, the 4th highest bit represents if the merkle tree is chained.
     205             :      For merkle code type shreds, the 4th highest bit represents if the shred is resigned.
     206             :      For merkle data type shreds, the 3th highest bit represents if the shred is resigned.
     207             : */
     208             :   /* 0x40 */ uchar  variant;
     209             : 
     210             :   /* Slot number that this shred is part of */
     211             :   /* 0x41 */ ulong  slot;
     212             : 
     213             :   /* Index of this shred within the slot */
     214             :   /* 0x49 */ uint   idx;
     215             : 
     216             :   /* Hash of the genesis version and historical hard forks of the current chain */
     217             :   /* 0x4d */ ushort version;
     218             : 
     219             :   /* Index into the vector of FEC sets for this slot. For data shreds, fec_set_idx<=idx. */
     220             :   /* 0x4f */ uint   fec_set_idx;
     221             : 
     222             :   union {
     223             :     /* Common data shred header */
     224             :     struct __attribute__((packed)) {
     225             :       /* Slot number difference between this block and the parent block.
     226             :          parent_off <= slot.
     227             :          Always greater than zero, except for slot 0, in which case the
     228             :          previous invariant forces this to be 0. */
     229             :       /* 0x53 */ ushort parent_off;
     230             : 
     231             :       /* Bit field (MSB first)
     232             :          See FD_SHRED_DATA_FLAG_*
     233             : 
     234             :           [XX.. ....] Block complete?       0b00=no 0b01=no 0b11=yes (implies Entry batch complete)
     235             :           [.X.. ....] Entry batch complete?  0b0=no  0b1=yes
     236             :           [..XX XXXX] Reference tick number */
     237             :       /* 0x55 */ uchar  flags;
     238             : 
     239             :       /* Shred size: size of data shred headers (88 bytes) + payload length */
     240             :       /* 0x56 */ ushort size;
     241             :     } data;
     242             : 
     243             :     /* Common coding shred header */
     244             :     struct __attribute__((packed)) {
     245             :       /* Total number of data shreds in FEC set. Must be positive <= FD_REEDSOL_DATA_SHREDS_MAX. */
     246             :       /* 0x53 */ ushort data_cnt;
     247             : 
     248             :       /* Total number of coding shreds in FEC set. Must be positive <= FD_REEDSOL_CODE_SHREDS_MAX. */
     249             :       /* 0x55 */ ushort code_cnt;
     250             : 
     251             :       /* Index within the vector of coding shreds in FEC set. In [0,
     252             :          code_cnt).  Also, shred.code.idx <= shred.idx. */
     253             :       /* 0x57 */ ushort idx;
     254             :     } code;
     255             :   };
     256             : };
     257             : typedef struct fd_shred fd_shred_t;
     258             : 
     259             : FD_PROTOTYPES_BEGIN
     260             : 
     261             : /* fd_shred_parse: Parses and validates an untrusted shred stored in
     262             :    bytes buf[i] for i in [0, sz).  sz must be at least FD_SHRED_MIN_SZ bytes.
     263             :    Allows trailing data.  max_shred_idx is the exclusive upper bound for
     264             :    data/parity shred indices within a slot, similar to max_shred_idx in
     265             :    fd_fec_resolver.
     266             : 
     267             :    The returned pointer either equals the input pointer or is NULL if
     268             :    the given shred is malformed or violates any invariants described
     269             :    above. */
     270             : FD_FN_PURE fd_shred_t const *
     271             : fd_shred_parse( uchar const * buf,
     272             :                 ulong         sz,
     273             :                 ulong         max_shred_idx );
     274             : 
     275             : /* fd_shred_type: Returns the value of the shred's type field. (FD_SHRED_TYPE_*) */
     276             : FD_FN_CONST static inline uchar
     277    67903131 : fd_shred_type( uchar variant ) {
     278    67903131 :   return variant & 0xf0;
     279    67903131 : }
     280             : 
     281             : /* fd_shred_variant: Returns the encoded variant field
     282             :    given the shred type and merkle proof length. */
     283             : FD_FN_CONST static inline uchar
     284             : fd_shred_variant( uchar type,
     285    15450897 :                   uchar merkle_cnt ) {
     286    15450897 :   if( FD_LIKELY( type==FD_SHRED_TYPE_LEGACY_DATA ) )
     287     3060702 :     merkle_cnt = 0x05;
     288    15450897 :   if( FD_LIKELY( type==FD_SHRED_TYPE_LEGACY_CODE ) )
     289           3 :     merkle_cnt = 0x0a;
     290    15450897 :   return (uchar)(type | merkle_cnt);
     291    15450897 : }
     292             : 
     293             : FD_FN_PURE static inline ulong
     294    17839026 : fd_shred_sz( fd_shred_t const * shred ) {
     295    17839026 :   uchar type = fd_shred_type( shred->variant );
     296    17839026 :   return fd_ulong_if(
     297    17839026 :     type & FD_SHRED_TYPEMASK_CODE,
     298    17839026 :     FD_SHRED_MAX_SZ,
     299    17839026 :     fd_ulong_if( type==FD_SHRED_TYPE_LEGACY_DATA, shred->data.size, FD_SHRED_MIN_SZ)
     300    17839026 :   ); /* Legacy data */
     301    17839026 : }
     302             : 
     303             : /* fd_shred_header_sz: Returns the header size of a shred.
     304             :    Returns zero if the shred has an invalid variant.
     305             : 
     306             :    Accesses offsets up to FD_SHRED_HEADER_MIN_SZ. */
     307             : FD_FN_CONST static inline ulong
     308       26223 : fd_shred_header_sz( uchar variant ) {
     309       26223 :   uchar type = fd_shred_type( variant );
     310       26223 :   if( FD_LIKELY( type & FD_SHRED_TYPEMASK_DATA ) )
     311       12822 :     return FD_SHRED_DATA_HEADER_SZ;
     312       13401 :   if( FD_LIKELY( type & FD_SHRED_TYPEMASK_CODE ) )
     313       13401 :     return FD_SHRED_CODE_HEADER_SZ;
     314           0 :   return 0;
     315       13401 : }
     316             : 
     317             : /* fd_shred_merkle_cnt: Returns number of nodes in the merkle inclusion
     318             :    proof.  Note that this excludes the root.  Returns zero if the given
     319             :    shred is not a merkle variant. */
     320             : FD_FN_CONST static inline uint
     321    24107709 : fd_shred_merkle_cnt( uchar variant ) {
     322    24107709 :   uchar type = fd_shred_type( variant );
     323    24107709 :   if( FD_UNLIKELY( ( type == FD_SHRED_TYPE_LEGACY_DATA ) | ( type == FD_SHRED_TYPE_LEGACY_CODE ) ) )
     324          69 :     return 0;
     325    24107640 :   return (variant&0xfU);
     326    24107709 : }
     327             : 
     328             : /* fd_shred_merkle_sz: Returns the size in bytes of the merkle inclusion proof.
     329             :    Returns zero if the given shred is not a merkle variant.  */
     330             : FD_FN_CONST static inline ulong
     331    24073734 : fd_shred_merkle_sz( uchar variant ) {
     332    24073734 :   return fd_shred_merkle_cnt( variant ) * FD_SHRED_MERKLE_NODE_SZ;
     333    24073734 : }
     334             : 
     335             : 
     336             : /* fd_shred_is_chained: Returns true if the shred is a chained merkle data or code shred. */
     337             : FD_FN_CONST static inline uchar
     338       88191 : fd_shred_is_chained( ulong type ) {
     339       88191 :   return (uchar)(
     340       88191 :          ( type == FD_SHRED_TYPE_MERKLE_DATA_CHAINED )
     341       88191 :        | ( type == FD_SHRED_TYPE_MERKLE_CODE_CHAINED )
     342       88191 :        | ( type == FD_SHRED_TYPE_MERKLE_DATA_CHAINED_RESIGNED )
     343       88191 :        | ( type == FD_SHRED_TYPE_MERKLE_CODE_CHAINED_RESIGNED ) );
     344       88191 : }
     345             : 
     346             : /* fd_shred_is_resigned: Returns true if the shred is resigned by the retransmitter */
     347             : FD_FN_CONST static inline uchar
     348    24101004 : fd_shred_is_resigned( ulong type ) {
     349    24101004 :   return ( type == FD_SHRED_TYPE_MERKLE_DATA_CHAINED_RESIGNED )
     350    24101004 :        | ( type == FD_SHRED_TYPE_MERKLE_CODE_CHAINED_RESIGNED );
     351    24101004 : }
     352             : 
     353             : /* fd_shred_is_{data,code} return 1 if the provided shred type is one of
     354             :    the data (or code, respectively) types, and 0 if not.  The value
     355             :    provided for type must be a valid shred type (one of the
     356             :    FD_SHRED_TYPE_* values).  For the purposes of these functions,
     357             :    properties beyond data/code are ignored; e.g. a chained resigned
     358             :    Merkle data shred is considered a data shred. */
     359     1821243 : FD_FN_CONST static inline uchar fd_shred_is_data( ulong type ) { return (type & 0xC0UL)==0x80UL; }
     360         294 : FD_FN_CONST static inline uchar fd_shred_is_code( ulong type ) { return (type & 0xC0UL)==0x40UL; }
     361             : 
     362             : /* fd_shred_swap_type: changes data into code or vice versa without
     363             :    affecting legacy, merkle, chained, or resigned status.  For example,
     364             :    fd_shred_swap_type( chained resigned data ) == chained resigned code.
     365             :    fd_shred_swap_type( merkle code ) == merkle data. */
     366             : FD_FN_CONST static inline uchar
     367        7560 : fd_shred_swap_type( ulong type ) {
     368             :   /* Swap bits 4 and 5. Swap bits 6 and 7. */
     369        7560 :   return (uchar)(((type & 0x50UL)<<1) | ((type&0xA0UL)>>1));
     370        7560 : }
     371             : 
     372             : /* fd_shred_payload_sz: Returns the payload size of a shred.
     373             :    Undefined behavior if the shred has not passed `fd_shred_parse`. */
     374             : FD_FN_PURE static inline ulong
     375         390 : fd_shred_payload_sz( fd_shred_t const * shred ) {
     376         390 :   ulong type = fd_shred_type( shred->variant );
     377         390 :   if( FD_LIKELY( type & FD_SHRED_TYPEMASK_DATA ) ) {
     378         243 :     return shred->data.size - FD_SHRED_DATA_HEADER_SZ;
     379         243 :   } else {
     380         147 :     return fd_shred_sz( shred ) - FD_SHRED_CODE_HEADER_SZ
     381         147 :       - fd_shred_merkle_sz( shred->variant )
     382         147 :       - fd_ulong_if( fd_shred_is_chained( type ), FD_SHRED_MERKLE_ROOT_SZ, 0 )
     383         147 :       - fd_ulong_if( fd_shred_is_resigned( type ), FD_SHRED_SIGNATURE_SZ, 0 );
     384         147 :   }
     385         390 : }
     386             : 
     387             : /* fd_shred_merkle_off: Returns the byte offset of the merkle inclusion proof of a shred.
     388             : 
     389             :    The provided shred must have passed validation in fd_shred_parse(). */
     390             : FD_FN_PURE static inline ulong
     391    12016575 : fd_shred_merkle_off( fd_shred_t const * shred ) {
     392    12016575 :   ulong type = fd_shred_type( shred->variant );
     393    12016575 :   return fd_shred_sz( shred )
     394    12016575 :     - fd_shred_merkle_sz( shred->variant )
     395    12016575 :     - fd_ulong_if( fd_shred_is_resigned( type ), FD_SHRED_SIGNATURE_SZ, 0 );
     396    12016575 : }
     397             : 
     398             : /* fd_shred_merkle_nodes: Returns a pointer to the shred's merkle proof data.
     399             : 
     400             :    The provided shred must have passed validation in fd_shred_parse(). */
     401             : FD_FN_PURE static inline fd_shred_merkle_t const *
     402       13599 : fd_shred_merkle_nodes( fd_shred_t const * shred ) {
     403       13599 :   uchar const * ptr = (uchar const *)shred;
     404       13599 :   ptr += fd_shred_merkle_off( shred );
     405       13599 :   return (fd_shred_merkle_t const *)ptr;
     406       13599 : }
     407             : 
     408             : /* fd_shred_merkle_root: Assuming that `shred` is a Merkle variant,
     409             :    reconstructs the merkle root from a shred and populates it in
     410             :    root_out.  Returns 1 on success, 0 on failure.  The output value must
     411             :    be ignored if a failure is returned.  U.B. if the shred is not a
     412             :    merkle variant. */
     413             : int
     414             : fd_shred_merkle_root( fd_shred_t const * shred, void * bmtree_mem, fd_bmtree_node_t * root_out );
     415             : 
     416             : /* fd_shred_data_payload: Returns a pointer to a data shred payload.
     417             : 
     418             :   The provided shred must have passed validation in fd_shred_parse(),
     419             :   and must satisfy `type&FD_SHRED_TYPEMASK_DATA`
     420             :   where `uchar type = fd_shred_type( shred->variant )`. */
     421             : FD_FN_CONST static inline uchar const *
     422          57 : fd_shred_data_payload( fd_shred_t const * shred ) {
     423          57 :   return (uchar const *)shred + FD_SHRED_DATA_HEADER_SZ;
     424          57 : }
     425             : 
     426             : /* fd_shred_code_payload: Returns a pointer to a coding shred payload.
     427             : 
     428             :   The provided shred must have passed validation in fd_shred_parse(),
     429             :   and must satisfy `type&FD_SHRED_TYPEMASK_CODE`
     430             :   where `uchar type = fd_shred_type( shred->variant )`. */
     431             : FD_FN_CONST static inline uchar const *
     432           0 : fd_shred_code_payload( fd_shred_t const * shred ) {
     433           0 :   return (uchar const *)shred + FD_SHRED_CODE_HEADER_SZ;
     434           0 : }
     435             : 
     436             : /* fd_shred_chain_offset: Assuming that `shred` is a chained Merkle
     437             :    variant, compute the offset from the start of the shred to the start
     438             :    of the chained Merkle root.  U.B. if the shred is not a chained
     439             :    variant. */
     440             : FD_FN_CONST static inline ulong
     441    12030789 : fd_shred_chain_off( uchar variant ) {
     442    12030789 :   ulong type = fd_shred_type( variant );
     443    12030789 :   return fd_ulong_if( type & FD_SHRED_TYPEMASK_CODE, FD_SHRED_MAX_SZ, FD_SHRED_MIN_SZ )
     444    12030789 :     - FD_SHRED_MERKLE_ROOT_SZ
     445    12030789 :     - fd_shred_merkle_sz( variant )
     446    12030789 :     - fd_ulong_if( fd_shred_is_resigned( type ), FD_SHRED_SIGNATURE_SZ, 0 );
     447    12030789 : }
     448             : 
     449             : /* fd_shred_retrasmitter_sig_off: Assuming that `shred` is a resigned
     450             :    variant, compute the offset from the start of the shred to the start
     451             :    of the retransmitter signature.  U.B if the shred is not a resigned
     452             :    chained type. */
     453             : FD_FN_PURE static inline ulong
     454     2745795 : fd_shred_retransmitter_sig_off( fd_shred_t const * shred ) {
     455     2745795 :   return fd_shred_sz( shred )-FD_SHRED_SIGNATURE_SZ;
     456     2745795 : }
     457             : 
     458             : FD_PROTOTYPES_END
     459             : 
     460             : #endif /* HEADER_fd_src_ballet_shred_fd_shred_h */

Generated by: LCOV version 1.14