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: 27 57 47.4 %
Date: 2024-11-13 11:58:15 Functions: 2 3 66.7 %

          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 "../context/fd_exec_epoch_ctx.h"
       6             : #include "../context/fd_exec_slot_ctx.h"
       7             : 
       8             : void
       9       11361 : fd_sysvar_last_restart_slot_init( fd_exec_slot_ctx_t * slot_ctx ) {
      10             : 
      11       11361 :   if( !FD_FEATURE_ACTIVE( slot_ctx, last_restart_slot_sysvar ) ) {
      12        9492 :     FD_LOG_INFO(( "sysvar LastRestartSlot not supported by this ledger version!" ));
      13        9492 :     return;
      14        9492 :   }
      15             : 
      16        1869 :   fd_sol_sysvar_last_restart_slot_t const * sysvar = &slot_ctx->slot_bank.last_restart_slot;
      17             : 
      18        1869 :   ulong sz = fd_sol_sysvar_last_restart_slot_size( sysvar );
      19        1869 :   uchar enc[ sz ];
      20        1869 :   fd_memset( enc, 0, sz );
      21             : 
      22        1869 :   fd_bincode_encode_ctx_t encode = {
      23        1869 :     .data    = enc,
      24        1869 :     .dataend = enc + sz,
      25        1869 :   };
      26        1869 :   int err = fd_sol_sysvar_last_restart_slot_encode( sysvar, &encode );
      27        1869 :   FD_TEST( err==FD_BINCODE_SUCCESS );
      28             : 
      29        1869 :   fd_sysvar_set( slot_ctx,
      30        1869 :                  fd_sysvar_owner_id.key,
      31        1869 :                  &fd_sysvar_last_restart_slot_id,
      32        1869 :                  enc, sz,
      33        1869 :                  slot_ctx->slot_bank.slot );
      34        1869 : }
      35             : 
      36             : fd_sol_sysvar_last_restart_slot_t *
      37             : fd_sysvar_last_restart_slot_read( fd_sol_sysvar_last_restart_slot_t * result,
      38           3 :                                   fd_exec_slot_ctx_t const *          slot_ctx ) {
      39           3 :   fd_sol_sysvar_last_restart_slot_t const * ret = fd_sysvar_cache_last_restart_slot( slot_ctx->sysvar_cache );
      40           3 :   if( FD_UNLIKELY( NULL != ret ) ) {
      41           3 :     fd_memcpy(result, ret, sizeof(fd_sol_sysvar_last_restart_slot_t));
      42           3 :     return result;
      43           3 :   }
      44             : 
      45           0 :   FD_BORROWED_ACCOUNT_DECL(acc);
      46           0 :   int err = fd_acc_mgr_view(slot_ctx->acc_mgr, slot_ctx->funk_txn, &fd_sysvar_last_restart_slot_id, acc);
      47           0 :   if( FD_UNLIKELY( err!=FD_ACC_MGR_SUCCESS ) ) return NULL;
      48             : 
      49           0 :   fd_bincode_decode_ctx_t decode =
      50           0 :     { .data    = acc->const_data,
      51           0 :       .dataend = acc->const_data + acc->const_meta->dlen,
      52           0 :       .valloc  = {0}  /* valloc not required */ };
      53             : 
      54           0 :   if( FD_UNLIKELY( fd_sol_sysvar_last_restart_slot_decode( result, &decode )!=FD_BINCODE_SUCCESS ) ) {
      55           0 :     return NULL;
      56           0 :   }
      57           0 :   return result;
      58           0 : }
      59             : 
      60             : /* fd_sysvar_last_restart_slot_update is equivalent to
      61             :    Agave's solana_runtime::bank::Bank::update_last_restart_slot */
      62             : 
      63             : void
      64           0 : fd_sysvar_last_restart_slot_update( fd_exec_slot_ctx_t * slot_ctx ) {
      65             : 
      66             :   /* https://github.com/solana-labs/solana/blob/v1.18.18/runtime/src/bank.rs#L2093-L2095 */
      67           0 :   if( !FD_FEATURE_ACTIVE( slot_ctx, last_restart_slot_sysvar ) ) return;
      68             : 
      69           0 :   int   has_current_last_restart_slot = 0;
      70           0 :   ulong     current_last_restart_slot = 0UL;
      71             : 
      72             :   /* https://github.com/solana-labs/solana/blob/v1.18.18/runtime/src/bank.rs#L2098-L2106 */
      73           0 :   fd_sol_sysvar_last_restart_slot_t old_account;
      74           0 :   if( fd_sysvar_last_restart_slot_read( &old_account, slot_ctx ) ) {
      75           0 :     has_current_last_restart_slot = 1;
      76           0 :         current_last_restart_slot = old_account.slot;
      77           0 :   }
      78             : 
      79             :   /* https://github.com/solana-labs/solana/blob/v1.18.18/runtime/src/bank.rs#L2108-L2120 */
      80             :   /* FIXME: Query hard forks list */
      81           0 :   ulong last_restart_slot = slot_ctx->slot_bank.last_restart_slot.slot;
      82             : 
      83             :   /* https://github.com/solana-labs/solana/blob/v1.18.18/runtime/src/bank.rs#L2122-L2130 */
      84           0 :   if( !has_current_last_restart_slot || current_last_restart_slot != last_restart_slot ) {
      85           0 :     fd_sysvar_set(
      86           0 :         slot_ctx, fd_sysvar_owner_id.key,
      87           0 :         &fd_sysvar_last_restart_slot_id,
      88           0 :         &last_restart_slot, sizeof(ulong),
      89           0 :         slot_ctx->slot_bank.slot );
      90           0 :   }
      91           0 : }

Generated by: LCOV version 1.14