LCOV - code coverage report
Current view: top level - flamenco/runtime/sysvar - fd_sysvar_last_restart_slot.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 63 0.0 %
Date: 2025-03-20 12:08:36 Functions: 0 3 0.0 %

          Line data    Source code
       1             : #include "fd_sysvar_last_restart_slot.h"
       2             : #include "../../types/fd_types.h"
       3             : #include "fd_sysvar.h"
       4             : #include "../fd_system_ids.h"
       5             : #include "../fd_runtime.h"
       6             : 
       7             : void
       8           0 : fd_sysvar_last_restart_slot_init( fd_exec_slot_ctx_t * slot_ctx ) {
       9             : 
      10           0 :   if( !FD_FEATURE_ACTIVE( slot_ctx->slot_bank.slot, slot_ctx->epoch_ctx->features, last_restart_slot_sysvar ) ) {
      11           0 :     FD_LOG_INFO(( "sysvar LastRestartSlot not supported by this ledger version!" ));
      12           0 :     return;
      13           0 :   }
      14             : 
      15           0 :   fd_sol_sysvar_last_restart_slot_t const * sysvar = &slot_ctx->slot_bank.last_restart_slot;
      16             : 
      17           0 :   ulong sz = fd_sol_sysvar_last_restart_slot_size( sysvar );
      18           0 :   uchar enc[ sz ];
      19           0 :   fd_memset( enc, 0, sz );
      20             : 
      21           0 :   fd_bincode_encode_ctx_t encode = {
      22           0 :     .data    = enc,
      23           0 :     .dataend = enc + sz,
      24           0 :   };
      25           0 :   int err = fd_sol_sysvar_last_restart_slot_encode( sysvar, &encode );
      26           0 :   FD_TEST( err==FD_BINCODE_SUCCESS );
      27             : 
      28           0 :   fd_sysvar_set( slot_ctx,
      29           0 :                  fd_sysvar_owner_id.key,
      30           0 :                  &fd_sysvar_last_restart_slot_id,
      31           0 :                  enc, sz,
      32           0 :                  slot_ctx->slot_bank.slot );
      33           0 : }
      34             : 
      35             : fd_sol_sysvar_last_restart_slot_t *
      36             : fd_sysvar_last_restart_slot_read( fd_sol_sysvar_last_restart_slot_t * result,
      37             :                                   fd_sysvar_cache_t const *           sysvar_cache,
      38             :                                   fd_acc_mgr_t *                      acc_mgr,
      39           0 :                                   fd_funk_txn_t *                     funk_txn ) {
      40             : 
      41           0 :   fd_sol_sysvar_last_restart_slot_t const * ret = (fd_sol_sysvar_last_restart_slot_t const *)fd_sysvar_cache_last_restart_slot( sysvar_cache );
      42           0 :   if( FD_UNLIKELY( NULL != ret ) ) {
      43           0 :     fd_memcpy(result, ret, sizeof(fd_sol_sysvar_last_restart_slot_t));
      44           0 :     return result;
      45           0 :   }
      46             : 
      47           0 :   FD_TXN_ACCOUNT_DECL( acc );
      48           0 :   int err = fd_acc_mgr_view(acc_mgr, funk_txn, &fd_sysvar_last_restart_slot_id, acc);
      49           0 :   if( FD_UNLIKELY( err!=FD_ACC_MGR_SUCCESS ) ) return NULL;
      50             : 
      51           0 :   fd_bincode_decode_ctx_t decode = {
      52           0 :     .data    = acc->const_data,
      53           0 :     .dataend = acc->const_data + acc->const_meta->dlen
      54           0 :   };
      55             : 
      56           0 :   ulong total_sz = 0UL;
      57           0 :   err = fd_sol_sysvar_last_restart_slot_decode_footprint( &decode, &total_sz );
      58           0 :   if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) {
      59           0 :     return NULL;
      60           0 :   }
      61             : 
      62             :   /* This assumes that the result has been setup already with the correct
      63             :      memory layout (pointers point to valid sized buffers, etc) */
      64             : 
      65           0 :   fd_sol_sysvar_last_restart_slot_decode( result, &decode );
      66           0 :   return result;
      67           0 : }
      68             : 
      69             : /* fd_sysvar_last_restart_slot_update is equivalent to
      70             :    Agave's solana_runtime::bank::Bank::update_last_restart_slot */
      71             : 
      72             : void
      73           0 : fd_sysvar_last_restart_slot_update( fd_exec_slot_ctx_t * slot_ctx ) {
      74             : 
      75             :   /* https://github.com/solana-labs/solana/blob/v1.18.18/runtime/src/bank.rs#L2093-L2095 */
      76           0 :   if( !FD_FEATURE_ACTIVE( slot_ctx->slot_bank.slot, slot_ctx->epoch_ctx->features, last_restart_slot_sysvar ) ) return;
      77             : 
      78           0 :   int   has_current_last_restart_slot = 0;
      79           0 :   ulong     current_last_restart_slot = 0UL;
      80             : 
      81             :   /* https://github.com/solana-labs/solana/blob/v1.18.18/runtime/src/bank.rs#L2098-L2106 */
      82           0 :   fd_sol_sysvar_last_restart_slot_t old_account;
      83           0 :   if( fd_sysvar_last_restart_slot_read( &old_account,
      84           0 :                                         slot_ctx->sysvar_cache,
      85           0 :                                         slot_ctx->acc_mgr,
      86           0 :                                         slot_ctx->funk_txn ) ) {
      87           0 :     has_current_last_restart_slot = 1;
      88           0 :         current_last_restart_slot = old_account.slot;
      89           0 :   }
      90             : 
      91             :   /* https://github.com/solana-labs/solana/blob/v1.18.18/runtime/src/bank.rs#L2108-L2120 */
      92             :   /* FIXME: Query hard forks list */
      93           0 :   ulong last_restart_slot = slot_ctx->slot_bank.last_restart_slot.slot;
      94             : 
      95             :   /* https://github.com/solana-labs/solana/blob/v1.18.18/runtime/src/bank.rs#L2122-L2130 */
      96           0 :   if( !has_current_last_restart_slot || current_last_restart_slot != last_restart_slot ) {
      97           0 :     fd_sysvar_set(
      98           0 :         slot_ctx, fd_sysvar_owner_id.key,
      99           0 :         &fd_sysvar_last_restart_slot_id,
     100           0 :         &last_restart_slot, sizeof(ulong),
     101           0 :         slot_ctx->slot_bank.slot );
     102           0 :   }
     103           0 : }

Generated by: LCOV version 1.14