LCOV - code coverage report
Current view: top level - choreo/eqvoc - fd_eqvoc_private.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 19 0.0 %
Date: 2026-03-13 05:38:29 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef HEADER_fd_src_choreo_eqvoc_fd_eqvoc_private_h
       2             : #define HEADER_fd_src_choreo_eqvoc_fd_eqvoc_private_h
       3             : 
       4             : #include "fd_eqvoc.h"
       5             : #include "../fd_choreo_base.h"
       6             : 
       7             : typedef struct {
       8             :   ulong key;  /* 32 bits = slot | 32 lsb = fec_set_idx  */
       9             :   ulong prev; /* reserved for map_chain */
      10             :   ulong next; /* reserved for map_chain */
      11             :   union {
      12             :     fd_shred_t shred;
      13             :     uchar      bytes[FD_SHRED_MAX_SZ]; /* entire shred, both header and payload */
      14             :   };
      15             : } shred_t;
      16             : 
      17             : #define POOL_NAME shred_pool
      18           0 : #define POOL_T    shred_t
      19             : #include "../../util/tmpl/fd_pool.c"
      20             : 
      21             : #define MAP_NAME                           shred_map
      22           0 : #define MAP_ELE_T                          shred_t
      23             : #define MAP_OPTIMIZE_RANDOM_ACCESS_REMOVAL 1
      24             : #include "../../util/tmpl/fd_map_chain.c"
      25             : 
      26             : #define DEQUE_NAME shred_deque
      27           0 : #define DEQUE_T    ulong
      28             : #include "../../util/tmpl/fd_deque_dynamic.c"
      29             : 
      30             : typedef struct {
      31             :   ulong      slot;
      32             :   ulong      prev;
      33             :   ulong      next;
      34             :   int        err; /* positive error code (FD_EQVOC_VERIFIED_{...}) if inserted */
      35             : } verified_t;
      36             : 
      37             : #define POOL_NAME verified_pool
      38           0 : #define POOL_T    verified_t
      39             : #include "../../util/tmpl/fd_pool.c"
      40             : 
      41             : #define MAP_NAME                           verified_map
      42           0 : #define MAP_ELE_T                          verified_t
      43           0 : #define MAP_KEY                            slot
      44             : #define MAP_OPTIMIZE_RANDOM_ACCESS_REMOVAL 1
      45             : #include "../../util/tmpl/fd_map_chain.c"
      46             : 
      47             : #define DEQUE_NAME verified_deque
      48           0 : #define DEQUE_T    ulong
      49             : #include "../../util/tmpl/fd_deque_dynamic.c"
      50             : 
      51             : typedef struct {
      52             :   ulong       slot;
      53             :   fd_pubkey_t from;
      54             : } xid_t;
      55             : 
      56             : /* fd_eqvoc_proof describes an equivocation proof.  Its structure is two
      57             :    shreds that demonstrate the leader must have produced two versions of
      58             :    a given block, because the shreds conflict in some way.
      59             : 
      60             :    Proofs are encoded into Gossip "DuplicateShred" messages, laid out as
      61             :    follows:
      62             : 
      63             :    ---------
      64             :    shred1_sz
      65             :    ---------
      66             :    shred1
      67             :    ---------
      68             :    shred2_sz
      69             :    ---------
      70             :    shred2
      71             :    ---------
      72             : 
      73             :    Note each shred is prepended with its size in bytes. */
      74             : 
      75             : struct fd_eqvoc_proof {
      76             :   xid_t key;
      77             :   ulong prev; /* reserved for map_chain */
      78             :   ulong next; /* reserved for map_chain */
      79             :   uchar idxs; /* [0, 7]. bit vec encoding which of the chunk idxs have been received (at most FD_EQVOC_CHUNK_CNT = 3). */
      80             :   uchar buf[2 * FD_SHRED_MAX_SZ + 2 * sizeof(ulong)];
      81             :   ulong buf_sz;
      82             : };
      83             : typedef struct fd_eqvoc_proof fd_eqvoc_proof_t;
      84             : 
      85             : #define POOL_NAME proof_pool
      86           0 : #define POOL_T    fd_eqvoc_proof_t
      87             : #include "../../util/tmpl/fd_pool.c"
      88             : 
      89             : #define MAP_NAME                           proof_map
      90           0 : #define MAP_ELE_T                          fd_eqvoc_proof_t
      91             : #define MAP_KEY_T                          xid_t
      92           0 : #define MAP_KEY_EQ(k0,k1)                  ((((k0)->slot)==((k1)->slot)) & !(memcmp(((k0)->from.uc),((k1)->from.uc),sizeof(fd_pubkey_t))))
      93           0 : #define MAP_KEY_HASH(key,seed)             fd_ulong_hash( ((key)->slot) ^ ((key)->from.ul[0]) ^ (seed) )
      94             : #define MAP_OPTIMIZE_RANDOM_ACCESS_REMOVAL 1
      95             : #include "../../util/tmpl/fd_map_chain.c"
      96             : 
      97             : #define DEQUE_NAME proof_deque
      98           0 : #define DEQUE_T    ulong
      99             : #include "../../util/tmpl/fd_deque_dynamic.c"
     100             : 
     101             : struct from {
     102             :   fd_pubkey_t from;
     103             :   uint        hash;
     104             :   ulong *     proofs; /* deque of proofs, FIFO order. this is the slot number, can lookup proof via proof_map key (slot, from) */
     105             : };
     106             : typedef struct from from_t;
     107             : 
     108             : #define MAP_NAME               from_map
     109           0 : #define MAP_T                  from_t
     110           0 : #define MAP_KEY                from
     111           0 : #define MAP_KEY_T              fd_pubkey_t
     112           0 : #define MAP_KEY_NULL           pubkey_null
     113             : #define MAP_KEY_EQUAL_IS_SLOW  1
     114           0 : #define MAP_KEY_INVAL(k)       MAP_KEY_EQUAL((k),MAP_KEY_NULL)
     115           0 : #define MAP_KEY_EQUAL(k0,k1)   (!memcmp( (k0).key, (k1).key, 32UL ))
     116           0 : #define MAP_KEY_HASH(key,seed) ((MAP_HASH_T)( (key).ul[1] )) /* FIXME: use seed? */
     117             : #include "../../util/tmpl/fd_map_dynamic.c"
     118             : 
     119             : struct fd_eqvoc {
     120             : 
     121             :   /* copy */
     122             : 
     123             :   ulong  shred_max;
     124             :   ulong  hist_max;
     125             :   ulong  from_max;
     126             :   ushort shred_version; /* eqvoc will ignore shreds or chunks with different shred versions */
     127             : 
     128             :   /* owned */
     129             : 
     130             :   fd_sha512_t *      sha512;
     131             :   void *             bmtree_mem;
     132             :   shred_t *          shred_pool;
     133             :   shred_map_t *      shred_map;
     134             :   ulong *            shred_deque;
     135             :   verified_t *       verified_pool;
     136             :   verified_map_t *   verified_map;
     137             :   ulong *            verified_deque;
     138             :   fd_eqvoc_proof_t * proof_pool;
     139             :   proof_map_t *      proof_map;
     140             :   from_t *           from_map;
     141             : 
     142             :   /* borrowed */
     143             : 
     144             :   fd_epoch_leaders_t const * lsched;
     145             : };
     146             : typedef struct fd_eqvoc fd_eqvoc_t;
     147             : 
     148             : /* The below APIs are exposed for tests. */
     149             : 
     150             : void
     151             : construct_proof( fd_shred_t const *          shred1,
     152             :                  fd_shred_t const *          shred2,
     153             :                  fd_gossip_duplicate_shred_t chunks_out[static FD_EQVOC_CHUNK_CNT] );
     154             : 
     155             : int
     156             : verify_proof( fd_eqvoc_t const * eqvoc,
     157             :               fd_shred_t const * shred1,
     158             :               fd_shred_t const * shred2 );
     159             : 
     160             : #endif /* HEADER_fd_src_choreo_eqvoc_fd_eqvoc_private_h */

Generated by: LCOV version 1.14