LCOV - code coverage report
Current view: top level - flamenco/runtime/sysvar - fd_sysvar_cache_db.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 34 43 79.1 %
Date: 2025-08-05 05:04:49 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /* fd_sysvar_cache_db.c contains database interactions between the
       2             :    sysvar cache and the account database. */
       3             : 
       4             : #include "fd_sysvar.h"
       5             : #include "fd_sysvar_cache.h"
       6             : #include "fd_sysvar_cache_private.h"
       7             : #include "../context/fd_exec_slot_ctx.h"
       8             : #include "../fd_txn_account.h"
       9             : #include "../fd_acc_mgr.h"
      10             : #include <errno.h>
      11             : 
      12             : static int
      13             : sysvar_data_fill( fd_sysvar_cache_t *  cache,
      14             :                   fd_exec_slot_ctx_t * slot_ctx,
      15             :                   ulong                idx,
      16        4131 :                   int                  log_fails ) {
      17        4131 :   fd_sysvar_pos_t const * pos  = &fd_sysvar_pos_tbl[ idx ];
      18        4131 :   fd_pubkey_t const *     key  = &fd_sysvar_key_tbl[ idx ];
      19        4131 :   fd_sysvar_desc_t *      desc = &cache->desc      [ idx ];
      20             : 
      21             :   /* Read account from database */
      22        4131 :   fd_funk_t *     funk     = slot_ctx->funk;
      23        4131 :   fd_funk_txn_t * funk_txn = slot_ctx->funk_txn;
      24        4131 :   FD_TXN_ACCOUNT_DECL( rec );
      25        4131 :   int err = fd_txn_account_init_from_funk_readonly( rec, key, funk, funk_txn );
      26        4131 :   if( err==FD_ACC_MGR_ERR_UNKNOWN_ACCOUNT ) {
      27        3672 :     if( log_fails ) FD_LOG_DEBUG(( "Sysvar %s not found", pos->name ));
      28        3672 :     return 0;
      29        3672 :   } else if( err!=FD_ACC_MGR_SUCCESS ) {
      30           0 :     FD_LOG_ERR(( "fd_txn_account_init_from_funk_readonly failed: %i", err ));
      31           0 :     return EIO;
      32           0 :   }
      33             : 
      34             :   /* Work around instruction fuzzer quirk */
      35         459 :   if( FD_UNLIKELY( rec->vt->get_lamports( rec )==0 ) ) {
      36           0 :     if( log_fails ) FD_LOG_WARNING(( "Skipping sysvar %s: zero balance", pos->name ));
      37           0 :     return 0;
      38           0 :   }
      39             : 
      40             :   /* Fill data cache entry */
      41         459 :   ulong data_sz = rec->vt->get_data_len( rec );
      42         459 :   data_sz = fd_ulong_min( data_sz, pos->data_max );
      43         459 :   uchar * data = (uchar *)cache+pos->data_off;
      44         459 :   fd_memcpy( data, rec->vt->get_data( rec ), data_sz );
      45         459 :   desc->data_sz = (uint)data_sz;
      46             : 
      47             :   /* Recover object cache entry from data cache entry */
      48         459 :   return fd_sysvar_obj_restore( cache, desc, pos, log_fails );
      49         459 : }
      50             : 
      51             : static int
      52             : fd_sysvar_cache_restore1( fd_exec_slot_ctx_t * slot_ctx,
      53         459 :                           int                  log_fails ) {
      54         459 :   fd_sysvar_cache_t * cache = fd_sysvar_cache_join( fd_sysvar_cache_new(
      55         459 :       fd_bank_sysvar_cache_modify( slot_ctx->bank ) ) );
      56             : 
      57         459 :   int saw_err = 0;
      58        4590 :   for( ulong i=0UL; i<FD_SYSVAR_CACHE_ENTRY_CNT; i++ ) {
      59        4131 :     int err = sysvar_data_fill( cache, slot_ctx, i, log_fails );
      60        4131 :     if( err ) saw_err = 1;
      61        4131 :   }
      62             : 
      63         459 :   fd_sysvar_cache_leave( cache );
      64             : 
      65         459 :   return !saw_err;
      66         459 : }
      67             : 
      68             : int
      69         459 : fd_sysvar_cache_restore( fd_exec_slot_ctx_t * slot_ctx ) {
      70         459 :   return fd_sysvar_cache_restore1( slot_ctx, 1 );
      71         459 : }
      72             : 
      73             : void
      74           0 : fd_sysvar_cache_restore_fuzz( fd_exec_slot_ctx_t * slot_ctx ) {
      75           0 :   (void)fd_sysvar_cache_restore1( slot_ctx, 0 );
      76           0 : }

Generated by: LCOV version 1.14