LCOV - code coverage report
Current view: top level - flamenco/runtime/sysvar - fd_sysvar_cache_private.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 5 5 100.0 %
Date: 2026-05-25 08:51:51 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_runtime_sysvar_fd_sysvar_cache_private_h
       2             : #define HEADER_fd_src_flamenco_runtime_sysvar_fd_sysvar_cache_private_h
       3             : 
       4             : #include "fd_sysvar_base.h"
       5             : #include "fd_sysvar_cache.h"
       6             : #include "../fd_system_ids_pp.h"
       7             : 
       8        7512 : #define FD_SYSVAR_CACHE_MAGIC (0x1aa5ecb2a49b600aUL) /* random number */
       9             : 
      10             : #define FD_SYSVAR_SIMPLE_ITER( SIMPLE_SYSVAR ) \
      11             : SIMPLE_SYSVAR( clock,          CLOCK,          sol_sysvar_clock     ) \
      12             : SIMPLE_SYSVAR( epoch_rewards,  EPOCH_REWARDS,  sysvar_epoch_rewards ) \
      13             : SIMPLE_SYSVAR( epoch_schedule, EPOCH_SCHEDULE, epoch_schedule       ) \
      14             : SIMPLE_SYSVAR( rent,           RENT,           rent                 )
      15             : 
      16             : /* Declare a perfect hash table mapping sysvar IDs to sysvar cache slots
      17             :    Hashes bytes [8,12) of each sysvar address. */
      18             : 
      19             : struct sysvar_lut {
      20             :   fd_pubkey_t key;
      21             :   uchar       desc_idx;
      22             : };
      23             : typedef struct sysvar_lut sysvar_tbl_t;
      24             : 
      25             : #define MAP_PERFECT_NAME        sysvar_map
      26             : #define MAP_PERFECT_LG_TBL_SZ   4
      27             : #define MAP_PERFECT_T           sysvar_tbl_t
      28        1317 : #define MAP_PERFECT_HASH_C      212885
      29             : #define MAP_PERFECT_KEY         key.uc
      30             : #define MAP_PERFECT_KEY_T       fd_pubkey_t const *
      31             : #define MAP_PERFECT_ZERO_KEY    (0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0)
      32             : #define MAP_PERFECT_COMPLEX_KEY 1
      33        1317 : #define MAP_PERFECT_KEYS_EQUAL(k1,k2) (!memcmp( (k1), (k2), 32UL ))
      34        1317 : #define PERFECT_HASH( u ) (((MAP_PERFECT_HASH_C*(u))>>28)&0xFU)
      35             : #define MAP_PERFECT_HASH_PP( a00,a01,a02,a03,a04,a05,a06,a07,a08,a09,a10,a11,a12,a13,a14,a15,  \
      36             :                              a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31 ) \
      37             :   PERFECT_HASH( (a08 | (a09<<8) | (a10<<16) | (a11<<24)) )
      38        1317 : #define MAP_PERFECT_HASH_R( ptr ) PERFECT_HASH( fd_uint_load_4( (uchar const *)ptr + 8UL ) )
      39             : #define MAP_SYSVAR( id, desc ) ( id ), ( desc )
      40             : #define MAP_PERFECT_0  MAP_SYSVAR( SYSVAR_CLOCK_ID,          FD_SYSVAR_clock_IDX               )
      41             : #define MAP_PERFECT_1  MAP_SYSVAR( SYSVAR_SLOT_HIST_ID,      FD_SYSVAR_slot_history_IDX        )
      42             : #define MAP_PERFECT_2  MAP_SYSVAR( SYSVAR_SLOT_HASHES_ID,    FD_SYSVAR_slot_hashes_IDX         )
      43             : #define MAP_PERFECT_3  MAP_SYSVAR( SYSVAR_EPOCH_SCHED_ID,    FD_SYSVAR_epoch_schedule_IDX      )
      44             : #define MAP_PERFECT_4  MAP_SYSVAR( SYSVAR_RECENT_BLKHASH_ID, FD_SYSVAR_recent_hashes_IDX       )
      45             : #define MAP_PERFECT_5  MAP_SYSVAR( SYSVAR_RENT_ID,           FD_SYSVAR_rent_IDX                )
      46             : #define MAP_PERFECT_6  MAP_SYSVAR( SYSVAR_EPOCH_REWARDS_ID,  FD_SYSVAR_epoch_rewards_IDX       )
      47             : #define MAP_PERFECT_7  MAP_SYSVAR( SYSVAR_STAKE_HIST_ID,     FD_SYSVAR_stake_history_IDX       )
      48             : #define MAP_PERFECT_8  MAP_SYSVAR( SYSVAR_LAST_RESTART_ID,   FD_SYSVAR_last_restart_slot_IDX   )
      49             : #include "../../../util/tmpl/fd_map_perfect.c"
      50             : #undef PERFECT_HASH
      51             : 
      52             : /* Declare a table giving the buffer offsets and sizes of sysvars in the
      53             :    cache. */
      54             : 
      55             : struct fd_sysvar_pos {
      56             :   /* Offsets relative to start of sysvar cache */
      57             :   uint data_off;  /* Raw data offset */
      58             :   uint obj_off;   /* Typed object offset */
      59             :   uint data_max;
      60             :   uint obj_max;
      61             : 
      62             :   char const * name;
      63             : 
      64             :   int (* validate)( uchar const * data, ulong data_sz ); /* returns 1 if valid, 0 otherwise */
      65             : };
      66             : typedef struct fd_sysvar_pos fd_sysvar_pos_t;
      67             : 
      68             : extern fd_sysvar_pos_t const fd_sysvar_pos_tbl[ FD_SYSVAR_CACHE_ENTRY_CNT ];
      69             : 
      70             : static fd_pubkey_t const fd_sysvar_key_tbl[ FD_SYSVAR_CACHE_ENTRY_CNT ] = {
      71             :   [ FD_SYSVAR_clock_IDX             ] = {{ SYSVAR_CLOCK_ID          }},
      72             :   [ FD_SYSVAR_epoch_rewards_IDX     ] = {{ SYSVAR_EPOCH_REWARDS_ID  }},
      73             :   [ FD_SYSVAR_epoch_schedule_IDX    ] = {{ SYSVAR_EPOCH_SCHED_ID    }},
      74             :   [ FD_SYSVAR_last_restart_slot_IDX ] = {{ SYSVAR_LAST_RESTART_ID   }},
      75             :   [ FD_SYSVAR_recent_hashes_IDX     ] = {{ SYSVAR_RECENT_BLKHASH_ID }},
      76             :   [ FD_SYSVAR_rent_IDX              ] = {{ SYSVAR_RENT_ID           }},
      77             :   [ FD_SYSVAR_slot_hashes_IDX       ] = {{ SYSVAR_SLOT_HASHES_ID    }},
      78             :   [ FD_SYSVAR_slot_history_IDX      ] = {{ SYSVAR_SLOT_HIST_ID      }},
      79             :   [ FD_SYSVAR_stake_history_IDX     ] = {{ SYSVAR_STAKE_HIST_ID     }},
      80             : };
      81             : 
      82             : /* fd_sysvar_obj_restore restores a typed representation of a sysvar
      83             :    from serialized data.  This is called internally whenever sysvar
      84             :    serialized data is updated directly.  DO NOT USE DIRECTLY. */
      85             : 
      86             : int
      87             : fd_sysvar_obj_restore( fd_sysvar_cache_t *     cache,
      88             :                        fd_sysvar_desc_t *      desc,
      89             :                        fd_sysvar_pos_t const * pos );
      90             : 
      91             : #endif /* HEADER_fd_src_flamenco_runtime_sysvar_fd_sysvar_cache_private_h */

Generated by: LCOV version 1.14