LCOV - code coverage report
Current view: top level - flamenco/stakes - fd_vote_stakes_private.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 43 43 100.0 %
Date: 2026-03-31 06:22:16 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 "../../util/fd_util_base.h"
       5             : #include "../types/fd_types_custom.h"
       6             : #include "../fd_rwlock.h"
       7             : 
       8             : struct index_key {
       9             :   fd_pubkey_t pubkey;
      10             :   fd_pubkey_t node_account_t_1;
      11             :   ulong       stake_t_1 : 63;
      12             :   ulong       epoch : 1;
      13             :   ulong       commission_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             :       ulong       commission_t_1;
      25             :     };
      26             :     index_key_t index_key;
      27             :   };
      28             :   ulong       stake_t_2;
      29             :   fd_pubkey_t node_account_t_2;
      30             :   uint        next;
      31             :   uint        prev_multi;
      32             :   uint        next_multi;
      33             :   ushort      refcnt;
      34             :   uchar       commission_t_2;
      35             :   uchar       exists_t_1; /* scratch memory for accumulating stake */
      36             : };
      37             : typedef struct index_ele index_ele_t;
      38             : 
      39             : #define POOL_NAME  index_pool
      40         798 : #define POOL_T     index_ele_t
      41     1635210 : #define POOL_NEXT  next
      42             : #define POOL_IDX_T uint
      43             : #include "../../util/tmpl/fd_pool.c"
      44             : 
      45             : #define MAP_NAME               index_map
      46             : #define MAP_KEY_T              index_key_t
      47             : #define MAP_ELE_T              index_ele_t
      48          81 : #define MAP_KEY                index_key
      49          81 : #define MAP_KEY_EQ(k0,k1)      (!memcmp( k0, k1, sizeof(index_key_t) ))
      50         201 : #define MAP_KEY_HASH(key,seed) (fd_hash( seed, key, sizeof(index_key_t) ))
      51         159 : #define MAP_NEXT               next
      52         669 : #define MAP_IDX_T              uint
      53             : #include "../../util/tmpl/fd_map_chain.c"
      54             : 
      55             : #define MAP_NAME                           index_map_multi
      56             : #define MAP_MULTI                          1
      57             : #define MAP_OPTIMIZE_RANDOM_ACCESS_REMOVAL 1
      58             : #define MAP_KEY_T                          fd_pubkey_t
      59          57 : #define MAP_ELE_T                          index_ele_t
      60          99 : #define MAP_KEY                            pubkey
      61          93 : #define MAP_KEY_EQ(k0,k1)                  (!memcmp( k0, k1, sizeof(fd_pubkey_t) ))
      62         192 : #define MAP_KEY_HASH(key,seed)             (fd_hash( seed, key, sizeof(fd_pubkey_t) ))
      63         234 : #define MAP_PREV                           prev_multi
      64         207 : #define MAP_NEXT                           next_multi
      65         600 : #define MAP_IDX_T                          uint
      66             : #include "../../util/tmpl/fd_map_chain.c"
      67             : 
      68             : /* Each pool index is just an array of uint indices into the pool. */
      69             : struct stake {
      70             :   uint idx;
      71             :   uint next;
      72             : };
      73             : typedef struct stake stake_t;
      74             : 
      75             : #define POOL_NAME  stakes_pool
      76        1248 : #define POOL_T     stake_t
      77     1229460 : #define POOL_NEXT  next
      78             : #define POOL_IDX_T uint
      79             : #include "../../util/tmpl/fd_pool.c"
      80             : 
      81             : #define MAP_NAME               stakes_map
      82             : #define MAP_KEY_T              uint
      83             : #define MAP_ELE_T              stake_t
      84          84 : #define MAP_KEY                idx
      85         204 : #define MAP_NEXT               next
      86        1053 : #define MAP_IDX_T              uint
      87             : #include "../../util/tmpl/fd_map_chain.c"
      88             : 
      89             : struct fork {
      90             :   ushort prev;
      91             :   ushort next;
      92             : };
      93             : typedef struct fork fork_t;
      94             : 
      95             : #define POOL_NAME  fork_pool
      96         798 : #define POOL_T     fork_t
      97        1131 : #define POOL_NEXT  next
      98             : #define POOL_IDX_T ushort
      99             : #include "../../util/tmpl/fd_pool.c"
     100             : 
     101             : #define DLIST_NAME  fork_dlist
     102             : #define DLIST_ELE_T fork_t
     103             : #define DLIST_IDX_T ushort
     104             : #include "../../util/tmpl/fd_dlist.c"
     105             : 
     106         399 : #define FD_VOTE_STAKES_MAGIC (0xF17EDA2CE7601E71UL) /* FIREDANCER VOTER V1 */
     107             : 
     108             : #define MAX_FORK_WIDTH (128UL)
     109             : 
     110             : struct fd_vote_stakes {
     111             :   ulong magic;
     112             :   ulong index_pool_off;
     113             :   ulong index_map_off;
     114             :   ulong index_map_multi_off;
     115             : 
     116             :   ulong fork_pool_off;
     117             :   ulong fork_dlist_off;
     118             : 
     119             :   ulong  stakes_pool_off[ MAX_FORK_WIDTH ];
     120             :   ulong  stakes_map_off[ MAX_FORK_WIDTH ];
     121             : 
     122             :   stakes_map_iter_t fork_iter;
     123             : 
     124             :   ushort max_fork_width;
     125             :   ushort root_idx;
     126             : 
     127             :   fd_rwlock_t lock;
     128             : };
     129             : typedef struct fd_vote_stakes fd_vote_stakes_t;
     130             : 
     131             : static inline index_ele_t *
     132         258 : get_index_pool( fd_vote_stakes_t const * vote_stakes ) {
     133         258 :   return fd_type_pun( (uchar *)vote_stakes + vote_stakes->index_pool_off );
     134         258 : }
     135             : 
     136             : static inline index_map_t *
     137         123 : get_index_map( fd_vote_stakes_t const * vote_stakes ) {
     138         123 :   return fd_type_pun( (uchar *)vote_stakes + vote_stakes->index_map_off );
     139         123 : }
     140             : 
     141             : static inline index_map_multi_t *
     142         195 : get_index_map_multi( fd_vote_stakes_t const * vote_stakes ) {
     143         195 :   return fd_type_pun( (uchar *)vote_stakes + vote_stakes->index_map_multi_off );
     144         195 : }
     145             : 
     146             : static inline stake_t *
     147             : get_stakes_pool( fd_vote_stakes_t const * vote_stakes,
     148         567 :                  ushort                   fork_idx ) {
     149         567 :   return fd_type_pun( (uchar *)vote_stakes + vote_stakes->stakes_pool_off[ fork_idx ] );
     150         567 : }
     151             : 
     152             : static inline stakes_map_t *
     153             : get_stakes_map( fd_vote_stakes_t const * vote_stakes,
     154         546 :                 ushort                   fork_idx ) {
     155         546 :   return fd_type_pun( (uchar *)vote_stakes + vote_stakes->stakes_map_off[ fork_idx ] );
     156         546 : }
     157             : 
     158             : static inline fork_t *
     159          42 : get_fork_pool( fd_vote_stakes_t const * vote_stakes ) {
     160          42 :   return fd_type_pun( (uchar *)vote_stakes + vote_stakes->fork_pool_off );
     161          42 : }
     162             : 
     163             : static inline fork_dlist_t *
     164          42 : get_fork_dlist( fd_vote_stakes_t const * vote_stakes ) {
     165          42 :   return fd_type_pun( (uchar *)vote_stakes + vote_stakes->fork_dlist_off );
     166          42 : }
     167             : 
     168             : #endif /* HEADER_fd_src_flamenco_stakes_fd_vote_stakes_private_h */

Generated by: LCOV version 1.14