LCOV - code coverage report
Current view: top level - flamenco/stakes - fd_vote_stakes_private.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 42 43 97.7 %
Date: 2026-05-16 06:43:53 Functions: 10 14 71.4 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_stakes_fd_vote_stakes_private_h
       2             : #define HEADER_fd_src_flamenco_stakes_fd_vote_stakes_private_h
       3             : 
       4             : #include "fd_vote_stakes.h"
       5             : #include "../fd_rwlock.h"
       6             : 
       7             : struct index_key {
       8             :   fd_pubkey_t pubkey;
       9             :   fd_pubkey_t node_account_t_1;
      10             :   ulong       stake_t_1 : 63;
      11             :   ulong       epoch : 1;
      12             :   uint        commission_t_1;
      13             :   uint        exists_t_1;
      14             : };
      15             : typedef struct index_key index_key_t;
      16             : 
      17             : struct index_ele {
      18             :   union {
      19             :     struct {
      20             :       fd_pubkey_t pubkey;
      21             :       fd_pubkey_t node_account_t_1;
      22             :       ulong       stake_t_1 : 63;
      23             :       ulong       epoch : 1;
      24             :       uint        commission_t_1;
      25             :       uint        exists_t_1;
      26             :     };
      27             :     index_key_t index_key;
      28             :   };
      29             :   ulong       stake_t_2;
      30             :   fd_pubkey_t node_account_t_2;
      31             :   uint        next;
      32             :   uint        prev_multi;
      33             :   uint        next_multi;
      34             :   ushort      refcnt;
      35             :   uchar       commission_t_2;
      36             :   uchar       exists_t_2;
      37             : };
      38             : typedef struct index_ele index_ele_t;
      39             : 
      40             : #define POOL_NAME  index_pool
      41        1194 : #define POOL_T     index_ele_t
      42     5906157 : #define POOL_NEXT  next
      43             : #define POOL_IDX_T uint
      44             : #include "../../util/tmpl/fd_pool.c"
      45             : 
      46             : #define MAP_NAME               index_map
      47             : #define MAP_KEY_T              index_key_t
      48             : #define MAP_ELE_T              index_ele_t
      49        3636 : #define MAP_KEY                index_key
      50          90 : #define MAP_KEY_EQ(k0,k1)      (!memcmp( k0, k1, sizeof(index_key_t) ))
      51        3882 : #define MAP_KEY_HASH(key,seed) (fd_hash( seed, key, sizeof(index_key_t) ))
      52        3723 : #define MAP_NEXT               next
      53       11532 : #define MAP_IDX_T              uint
      54             : #include "../../util/tmpl/fd_map_chain.c"
      55             : 
      56             : #define MAP_NAME                           index_map_multi
      57             : #define MAP_MULTI                          1
      58             : #define MAP_OPTIMIZE_RANDOM_ACCESS_REMOVAL 1
      59             : #define MAP_KEY_T                          fd_pubkey_t
      60          57 : #define MAP_ELE_T                          index_ele_t
      61        3654 : #define MAP_KEY                            pubkey
      62        3798 : #define MAP_KEY_EQ(k0,k1)                  (!memcmp( k0, k1, sizeof(fd_pubkey_t) ))
      63        7455 : #define MAP_KEY_HASH(key,seed)             (fd_hash( seed, key, sizeof(fd_pubkey_t) ))
      64        3915 : #define MAP_PREV                           prev_multi
      65        7185 : #define MAP_NEXT                           next_multi
      66       25188 : #define MAP_IDX_T                          uint
      67             : #include "../../util/tmpl/fd_map_chain.c"
      68             : 
      69             : /* Each pool index is just an array of uint indices into the pool. */
      70             : struct stake {
      71             :   uint idx;
      72             :   uint next;
      73             : };
      74             : typedef struct stake stake_t;
      75             : 
      76             : #define POOL_NAME  stakes_pool
      77        1698 : #define POOL_T     stake_t
      78           0 : #define POOL_NEXT  next
      79             : #define POOL_IDX_T uint
      80             : #define POOL_LAZY  1
      81             : #include "../../util/tmpl/fd_pool.c"
      82             : 
      83             : #define MAP_NAME               stakes_map
      84             : #define MAP_KEY_T              uint
      85             : #define MAP_ELE_T              stake_t
      86        3639 : #define MAP_KEY                idx
      87        7503 : #define MAP_NEXT               next
      88       40047 : #define MAP_IDX_T              uint
      89             : #include "../../util/tmpl/fd_map_chain.c"
      90             : 
      91             : struct fork {
      92             :   ushort prev;
      93             :   ushort next;
      94             : };
      95             : typedef struct fork fork_t;
      96             : 
      97             : #define POOL_NAME  fork_pool
      98        1194 : #define POOL_T     fork_t
      99       36000 : #define POOL_NEXT  next
     100             : #define POOL_IDX_T ushort
     101             : #include "../../util/tmpl/fd_pool.c"
     102             : 
     103             : #define DLIST_NAME  fork_dlist
     104             : #define DLIST_ELE_T fork_t
     105             : #define DLIST_IDX_T ushort
     106             : #include "../../util/tmpl/fd_dlist.c"
     107             : 
     108         597 : #define FD_VOTE_STAKES_MAGIC (0xF17EDA2CE7601E71UL) /* FIREDANCER VOTER V1 */
     109             : 
     110             : #define MAX_FORK_WIDTH (128UL)
     111             : 
     112             : struct fd_vote_stakes {
     113             :   ulong magic;
     114             :   ulong index_pool_off;
     115             :   ulong index_map_off;
     116             :   ulong index_map_multi_off;
     117             : 
     118             :   ulong fork_pool_off;
     119             :   ulong fork_dlist_off;
     120             : 
     121             :   ulong  stakes_pool_off[ MAX_FORK_WIDTH ];
     122             :   ulong  stakes_map_off[ MAX_FORK_WIDTH ];
     123             : 
     124             :   stakes_map_iter_t fork_iter;
     125             : 
     126             :   ushort max_fork_width;
     127             :   ushort root_idx;
     128             : 
     129             :   fd_rwlock_t lock;
     130             : };
     131             : typedef struct fd_vote_stakes fd_vote_stakes_t;
     132             : 
     133             : static inline index_ele_t *
     134       21537 : get_index_pool( fd_vote_stakes_t const * vote_stakes ) {
     135       21537 :   return fd_type_pun( (uchar *)vote_stakes + vote_stakes->index_pool_off );
     136       21537 : }
     137             : 
     138             : static inline index_map_t *
     139       13962 : get_index_map( fd_vote_stakes_t const * vote_stakes ) {
     140       13962 :   return fd_type_pun( (uchar *)vote_stakes + vote_stakes->index_map_off );
     141       13962 : }
     142             : 
     143             : static inline index_map_multi_t *
     144       17730 : get_index_map_multi( fd_vote_stakes_t const * vote_stakes ) {
     145       17730 :   return fd_type_pun( (uchar *)vote_stakes + vote_stakes->index_map_multi_off );
     146       17730 : }
     147             : 
     148             : static inline stake_t *
     149             : get_stakes_pool( fd_vote_stakes_t const * vote_stakes,
     150       50547 :                  ushort                   fork_idx ) {
     151       50547 :   return fd_type_pun( (uchar *)vote_stakes + vote_stakes->stakes_pool_off[ fork_idx ] );
     152       50547 : }
     153             : 
     154             : static inline stakes_map_t *
     155             : get_stakes_map( fd_vote_stakes_t const * vote_stakes,
     156       50526 :                 ushort                   fork_idx ) {
     157       50526 :   return fd_type_pun( (uchar *)vote_stakes + vote_stakes->stakes_map_off[ fork_idx ] );
     158       50526 : }
     159             : 
     160             : static inline fork_t *
     161        7020 : get_fork_pool( fd_vote_stakes_t const * vote_stakes ) {
     162        7020 :   return fd_type_pun( (uchar *)vote_stakes + vote_stakes->fork_pool_off );
     163        7020 : }
     164             : 
     165             : static inline fork_dlist_t *
     166        7020 : get_fork_dlist( fd_vote_stakes_t const * vote_stakes ) {
     167        7020 :   return fd_type_pun( (uchar *)vote_stakes + vote_stakes->fork_dlist_off );
     168        7020 : }
     169             : 
     170             : #endif /* HEADER_fd_src_flamenco_stakes_fd_vote_stakes_private_h */

Generated by: LCOV version 1.14