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: 32 41 78.0 %
Date: 2025-10-13 04:42:14 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 "../fd_txn_account.h"
       8             : #include "../fd_acc_mgr.h"
       9             : #include <errno.h>
      10             : 
      11             : static int
      12             : sysvar_data_fill( fd_sysvar_cache_t *       cache,
      13             :                   fd_funk_t *               funk,
      14             :                   fd_funk_txn_xid_t const * xid,
      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_TXN_ACCOUNT_DECL( rec );
      23        4131 :   int err = fd_txn_account_init_from_funk_readonly( rec, key, funk, xid );
      24        4131 :   if( err==FD_ACC_MGR_ERR_UNKNOWN_ACCOUNT ) {
      25        3672 :     if( log_fails ) FD_LOG_DEBUG(( "Sysvar %s not found", pos->name ));
      26        3672 :     return 0;
      27        3672 :   } else if( err!=FD_ACC_MGR_SUCCESS ) {
      28           0 :     FD_LOG_ERR(( "fd_txn_account_init_from_funk_readonly failed: %i", err ));
      29           0 :     return EIO;
      30           0 :   }
      31             : 
      32             :   /* Work around instruction fuzzer quirk */
      33         459 :   if( FD_UNLIKELY( fd_txn_account_get_lamports( rec )==0 ) ) {
      34           0 :     if( log_fails ) FD_LOG_WARNING(( "Skipping sysvar %s: zero balance", pos->name ));
      35           0 :     return 0;
      36           0 :   }
      37             : 
      38             :   /* Fill data cache entry */
      39         459 :   ulong data_sz = fd_txn_account_get_data_len( rec );
      40         459 :   data_sz = fd_ulong_min( data_sz, pos->data_max );
      41         459 :   uchar * data = (uchar *)cache+pos->data_off;
      42         459 :   fd_memcpy( data, fd_txn_account_get_data( rec ), data_sz );
      43         459 :   desc->data_sz = (uint)data_sz;
      44             : 
      45             :   /* Recover object cache entry from data cache entry */
      46         459 :   return fd_sysvar_obj_restore( cache, desc, pos );
      47         459 : }
      48             : 
      49             : static int
      50             : fd_sysvar_cache_restore1( fd_bank_t *               bank,
      51             :                           fd_funk_t *               funk,
      52             :                           fd_funk_txn_xid_t const * xid,
      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( 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, funk, xid, 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             : fd_sysvar_cache_restore( fd_bank_t *               bank,
      70             :                          fd_funk_t *               funk,
      71         459 :                          fd_funk_txn_xid_t const * xid ) {
      72         459 :   return fd_sysvar_cache_restore1( bank, funk, xid, 1 );
      73         459 : }
      74             : 
      75             : void
      76             : fd_sysvar_cache_restore_fuzz( fd_bank_t *               bank,
      77             :                               fd_funk_t *               funk,
      78           0 :                               fd_funk_txn_xid_t const * xid ) {
      79           0 :   (void)fd_sysvar_cache_restore1( bank, funk, xid, 0 );
      80           0 : }

Generated by: LCOV version 1.14