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 55 0.0 %
Date: 2025-07-01 05:00:49 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_BANK( slot_ctx->bank, last_restart_slot_sysvar ) ) {
      11           0 :     FD_LOG_INFO(( "sysvar LastRestartSlot not supported by this ledger version!" ));
      12           0 :     return;
      13           0 :   }
      14             : 
      15             : 
      16           0 :   ulong sz = fd_sol_sysvar_last_restart_slot_size( fd_bank_last_restart_slot_query( slot_ctx->bank ) );
      17           0 :   uchar enc[ sz ];
      18           0 :   fd_memset( enc, 0, sz );
      19             : 
      20           0 :   fd_bincode_encode_ctx_t encode = {
      21           0 :     .data    = enc,
      22           0 :     .dataend = enc + sz,
      23           0 :   };
      24           0 :   int err = fd_sol_sysvar_last_restart_slot_encode( fd_bank_last_restart_slot_query( slot_ctx->bank ), &encode );
      25           0 :   FD_TEST( err==FD_BINCODE_SUCCESS );
      26             : 
      27           0 :   fd_sysvar_set( slot_ctx->bank,
      28           0 :                  slot_ctx->funk,
      29           0 :                  slot_ctx->funk_txn,
      30           0 :                  &fd_sysvar_owner_id,
      31           0 :                  &fd_sysvar_last_restart_slot_id,
      32           0 :                  enc, sz,
      33           0 :                  slot_ctx->slot );
      34           0 : }
      35             : 
      36             : fd_sol_sysvar_last_restart_slot_t *
      37             : fd_sysvar_last_restart_slot_read( fd_funk_t *     funk,
      38             :                                   fd_funk_txn_t * funk_txn,
      39           0 :                                   fd_spad_t *     spad ) {
      40             : 
      41           0 :   FD_TXN_ACCOUNT_DECL( acc );
      42           0 :   int err = fd_txn_account_init_from_funk_readonly( acc, &fd_sysvar_last_restart_slot_id, funk, funk_txn );
      43           0 :   if( FD_UNLIKELY( err!=FD_ACC_MGR_SUCCESS ) ) return NULL;
      44             : 
      45             :   /* This check is needed as a quirk of the fuzzer. If a sysvar account
      46             :      exists in the accounts database, but doesn't have any lamports,
      47             :      this means that the account does not exist. This wouldn't happen
      48             :      in a real execution environment. */
      49           0 :   if( FD_UNLIKELY( acc->vt->get_lamports( acc )==0 ) ) return NULL;
      50             : 
      51           0 :   return fd_bincode_decode_spad(
      52           0 :       sol_sysvar_last_restart_slot, spad,
      53           0 :       acc->vt->get_data( acc ),
      54           0 :       acc->vt->get_data_len( acc ),
      55           0 :       &err );
      56           0 : }
      57             : 
      58             : /* fd_sysvar_last_restart_slot_update is equivalent to
      59             :    Agave's solana_runtime::bank::Bank::update_last_restart_slot */
      60             : 
      61             : void
      62           0 : fd_sysvar_last_restart_slot_update( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) {
      63             : 
      64             :   /* https://github.com/solana-labs/solana/blob/v1.18.18/runtime/src/bank.rs#L2093-L2095 */
      65           0 :   if( !FD_FEATURE_ACTIVE_BANK( slot_ctx->bank, last_restart_slot_sysvar ) ) return;
      66             : 
      67           0 :   int   has_current_last_restart_slot = 0;
      68           0 :   ulong current_last_restart_slot     = 0UL;
      69             : 
      70             :   /* https://github.com/solana-labs/solana/blob/v1.18.18/runtime/src/bank.rs#L2098-L2106 */
      71           0 :   fd_sol_sysvar_last_restart_slot_t * old_account = fd_sysvar_last_restart_slot_read( slot_ctx->funk,
      72           0 :                                                                                       slot_ctx->funk_txn,
      73           0 :                                                                                       runtime_spad );
      74           0 :   ulong old_account_slot        = old_account ? old_account->slot : 0UL;
      75           0 :   has_current_last_restart_slot = 1;
      76           0 :   current_last_restart_slot     = old_account_slot;
      77             : 
      78             :   /* https://github.com/solana-labs/solana/blob/v1.18.18/runtime/src/bank.rs#L2108-L2120 */
      79             :   /* FIXME: Query hard forks list */
      80           0 :   ulong last_restart_slot = fd_bank_last_restart_slot_get( slot_ctx->bank ).slot;
      81             : 
      82             :   /* https://github.com/solana-labs/solana/blob/v1.18.18/runtime/src/bank.rs#L2122-L2130 */
      83           0 :   if( !has_current_last_restart_slot || current_last_restart_slot != last_restart_slot ) {
      84           0 :     fd_sysvar_set( slot_ctx->bank,
      85           0 :                    slot_ctx->funk,
      86           0 :                    slot_ctx->funk_txn,
      87           0 :                    &fd_sysvar_owner_id,
      88           0 :                    &fd_sysvar_last_restart_slot_id,
      89           0 :                    &last_restart_slot,
      90           0 :                    sizeof(ulong),
      91           0 :                    slot_ctx->slot );
      92           0 :   }
      93           0 : }

Generated by: LCOV version 1.14