LCOV - code coverage report
Current view: top level - flamenco/runtime - fd_runtime_stack_tmpl.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 64 73 87.7 %
Date: 2026-10-16 04:29:28 Functions: 8 44 18.2 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_runtime_fd_runtime_stack_tmpl_h
       2             : #define HEADER_fd_src_flamenco_runtime_fd_runtime_stack_tmpl_h
       3             : 
       4             : /* The fd_runtime_stack_t container instantiations and constructors.
       5             :    fd_runtime_stack.h only declares the map types; include this header
       6             :    to use the maps or to size/create a runtime stack. */
       7             : 
       8             : #include "fd_runtime_stack.h"
       9             : 
      10             : #define MAP_NAME               fd_vote_rewards_map
      11             : #define MAP_KEY_T              fd_pubkey_t
      12             : #define MAP_ELE_T              fd_vote_rewards_t
      13         399 : #define MAP_KEY                pubkey
      14         501 : #define MAP_KEY_EQ(k0,k1)      (!memcmp( k0, k1, sizeof(fd_pubkey_t) ))
      15         876 : #define MAP_KEY_HASH(key,seed) (fd_ulong_hash( (seed)^FD_LOAD( ulong, ((uchar const *)(key))+24UL ) ))
      16         939 : #define MAP_NEXT               next
      17        2376 : #define MAP_IDX_T              uint
      18             : #include "../../util/tmpl/fd_map_chain.c"
      19             : 
      20             : #define MAP_NAME               fd_stake_accum_map
      21             : #define MAP_KEY_T              fd_pubkey_t
      22             : #define MAP_ELE_T              fd_stake_accum_t
      23         453 : #define MAP_KEY                pubkey
      24         225 : #define MAP_KEY_EQ(k0,k1)      (!memcmp( k0, k1, sizeof(fd_pubkey_t) ))
      25        1053 : #define MAP_KEY_HASH(key,seed) (fd_ulong_hash( (seed)^FD_LOAD( ulong, ((uchar const *)(key))+24UL ) ))
      26         969 : #define MAP_NEXT               next
      27        2727 : #define MAP_IDX_T              uint
      28             : #include "../../util/tmpl/fd_map_chain.c"
      29             : 
      30             : FD_FN_CONST static inline ulong
      31         663 : fd_runtime_stack_align( void ) {
      32         663 :   return 128UL;
      33         663 : }
      34             : 
      35             : FD_FN_PURE static inline ulong
      36             : fd_runtime_stack_footprint( ulong max_vote_accounts,
      37             :                             ulong max_staked_vote_accounts,
      38         198 :                             ulong max_stake_accounts ) {
      39         198 :   ulong vote_chain_cnt  = fd_vote_rewards_map_chain_cnt_est( max_vote_accounts );
      40         198 :   ulong stake_chain_cnt = fd_stake_accum_map_chain_cnt_est( max_staked_vote_accounts );
      41         198 :   ulong l = FD_LAYOUT_INIT;
      42         198 :   l = FD_LAYOUT_APPEND( l, alignof(fd_runtime_stack_t),           sizeof(fd_runtime_stack_t) );
      43         198 :   l = FD_LAYOUT_APPEND( l, alignof(ts_est_ele_t),                 sizeof(ts_est_ele_t) * max_vote_accounts );
      44         198 :   l = FD_LAYOUT_APPEND( l, alignof(fd_vote_stake_weight_t),       sizeof(fd_vote_stake_weight_t) * max_vote_accounts );
      45         198 :   l = FD_LAYOUT_APPEND( l, alignof(fd_stake_weight_t),            sizeof(fd_stake_weight_t) * max_vote_accounts );
      46         198 :   l = FD_LAYOUT_APPEND( l, 128UL,                                 sizeof(fd_vote_rewards_t) * max_vote_accounts );
      47         198 :   l = FD_LAYOUT_APPEND( l, fd_vote_rewards_map_align(),           fd_vote_rewards_map_footprint( vote_chain_cnt ) );
      48         198 :   l = FD_LAYOUT_APPEND( l, 128UL,                                 sizeof(fd_stake_accum_t) * max_staked_vote_accounts );
      49         198 :   l = FD_LAYOUT_APPEND( l, fd_stake_accum_map_align(),            fd_stake_accum_map_footprint( stake_chain_cnt ) );
      50         198 :   l = FD_LAYOUT_APPEND( l, alignof(fd_calculated_stake_points_t), sizeof(fd_calculated_stake_points_t) * max_stake_accounts );
      51         198 :   l = FD_LAYOUT_APPEND( l, alignof(fd_calculated_stake_rewards_t),sizeof(fd_calculated_stake_rewards_t) * max_stake_accounts );
      52         198 :   return FD_LAYOUT_FINI( l, fd_runtime_stack_align() );
      53         198 : }
      54             : 
      55             : static inline void *
      56             : fd_runtime_stack_new( void * shmem,
      57             :                       ulong  max_vote_accounts,
      58             :                       ulong  max_staked_vote_accounts,
      59             :                       ulong  max_stake_accounts,
      60          69 :                       ulong  seed ) {
      61          69 :   if( FD_UNLIKELY( !shmem ) ) return NULL;
      62          69 :   ulong vote_chain_cnt  = fd_vote_rewards_map_chain_cnt_est( max_vote_accounts );
      63          69 :   ulong stake_chain_cnt = fd_stake_accum_map_chain_cnt_est( max_staked_vote_accounts );
      64          69 :   FD_SCRATCH_ALLOC_INIT( l, shmem );
      65          69 :   fd_runtime_stack_t *            runtime_stack        = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_runtime_stack_t),            sizeof(fd_runtime_stack_t) );
      66          69 :   ts_est_ele_t *                  staked_ts            = FD_SCRATCH_ALLOC_APPEND( l, alignof(ts_est_ele_t),                  sizeof(ts_est_ele_t) * max_vote_accounts );
      67          69 :   fd_vote_stake_weight_t *        stake_weights        = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_vote_stake_weight_t),        sizeof(fd_vote_stake_weight_t) * max_vote_accounts );
      68          69 :   fd_stake_weight_t *             id_weights           = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_stake_weight_t),             sizeof(fd_stake_weight_t) * max_vote_accounts );
      69          69 :   fd_vote_rewards_t *             vote_ele             = FD_SCRATCH_ALLOC_APPEND( l, 128UL,                                  sizeof(fd_vote_rewards_t) * max_vote_accounts );
      70          69 :   void *                          vote_map_mem         = FD_SCRATCH_ALLOC_APPEND( l, fd_vote_rewards_map_align(),            fd_vote_rewards_map_footprint( vote_chain_cnt ) );
      71          69 :   fd_stake_accum_t *              stake_accum          = FD_SCRATCH_ALLOC_APPEND( l, 128UL,                                  sizeof(fd_stake_accum_t) * max_staked_vote_accounts );
      72          69 :   void *                          stake_accum_map_mem  = FD_SCRATCH_ALLOC_APPEND( l, fd_stake_accum_map_align(),             fd_stake_accum_map_footprint( stake_chain_cnt ) );
      73          69 :   fd_calculated_stake_points_t *  stake_points_result  = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_calculated_stake_points_t),  sizeof(fd_calculated_stake_points_t) * max_stake_accounts );
      74          69 :   fd_calculated_stake_rewards_t * stake_rewards_result = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_calculated_stake_rewards_t), sizeof(fd_calculated_stake_rewards_t) * max_stake_accounts );
      75          69 :   if( FD_UNLIKELY( FD_SCRATCH_ALLOC_FINI( l, fd_runtime_stack_align() )!=(ulong)shmem + fd_runtime_stack_footprint( max_vote_accounts, max_staked_vote_accounts, max_stake_accounts ) ) ) {
      76           0 :     FD_LOG_WARNING(( "fd_runtime_stack_new: bad layout" ));
      77           0 :     return NULL;
      78           0 :   }
      79             : 
      80          69 :   runtime_stack->max_vote_accounts           = max_vote_accounts;
      81          69 :   runtime_stack->max_staked_vote_accounts    = max_staked_vote_accounts;
      82          69 :   runtime_stack->max_stake_accounts          = max_stake_accounts;
      83          69 :   runtime_stack->clock_ts.staked_ts          = staked_ts;
      84          69 :   runtime_stack->stakes.stake_weights        = stake_weights;
      85          69 :   runtime_stack->stakes.id_weights           = id_weights;
      86          69 :   runtime_stack->stakes.vote_ele             = vote_ele;
      87          69 :   runtime_stack->stakes.stake_points_result  = stake_points_result;
      88          69 :   runtime_stack->stakes.stake_rewards_result = stake_rewards_result;
      89          69 :   runtime_stack->stakes.stake_accum          = stake_accum;
      90             : 
      91          69 :   runtime_stack->stakes.stake_accum_map = fd_stake_accum_map_join( fd_stake_accum_map_new( stake_accum_map_mem, stake_chain_cnt, seed ) );
      92          69 :   if( FD_UNLIKELY( !runtime_stack->stakes.stake_accum_map ) ) {
      93           0 :     FD_LOG_WARNING(( "fd_runtime_stack_new: bad map" ));
      94           0 :     return NULL;
      95           0 :   }
      96             : 
      97          69 :   runtime_stack->stakes.vote_map = fd_vote_rewards_map_join( fd_vote_rewards_map_new( vote_map_mem, vote_chain_cnt, seed ) );
      98          69 :   if( FD_UNLIKELY( !runtime_stack->stakes.vote_map ) ) {
      99           0 :     FD_LOG_WARNING(( "fd_runtime_stack_new: bad map" ));
     100           0 :     return NULL;
     101           0 :   }
     102             : 
     103          69 :   return shmem;
     104          69 : }
     105             : 
     106             : FD_FN_CONST static inline fd_runtime_stack_t *
     107          69 : fd_runtime_stack_join( void * shruntime_stack ) {
     108          69 :   return (fd_runtime_stack_t *)shruntime_stack;
     109          69 : }
     110             : 
     111             : #endif /* HEADER_fd_src_flamenco_runtime_fd_runtime_stack_tmpl_h */

Generated by: LCOV version 1.14