LCOV - code coverage report
Current view: top level - flamenco/runtime/sysvar - fd_sysvar_clock.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 3 4 75.0 %
Date: 2026-04-10 06:33:15 Functions: 1 27 3.7 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_runtime_sysvar_fd_sysvar_clock_h
       2             : #define HEADER_fd_src_flamenco_runtime_sysvar_fd_sysvar_clock_h
       3             : 
       4             : /* The clock sysvar provides an approximate measure of network time. */
       5             : 
       6             : #include "fd_sysvar.h"
       7             : #include "../fd_system_ids.h"
       8             : #include "../../types/fd_bincode.h"
       9             : 
      10             : /* https://github.com/solana-labs/solana/blob/8f2c8b8388a495d2728909e30460aa40dcc5d733/sdk/program/src/clock.rs#L10 */
      11             : #define FD_SYSVAR_CLOCK_DEFAULT_TICKS_PER_SECOND ( 160UL )
      12           0 : #define FD_SYSVAR_CLOCK_DEFAULT_HASHES_PER_TICK  (12500UL)
      13             : 
      14             : /* FD_SYSVAR_CLOCK_STAKE_WEIGHTS_MAX specifies the max number of stake
      15             :    weights processed in a clock update. */
      16             : 
      17             : #define FD_SYSVAR_CLOCK_STAKE_WEIGHTS_MAX (10240UL)
      18             : 
      19             : FD_PROTOTYPES_BEGIN
      20             : 
      21             : /* ts_est_ele_t is a temporary struct used for sorting vote accounts by
      22             :    last vote timestamp for clock sysvar calculation. */
      23             : struct ts_est_ele {
      24             :   long        timestamp;
      25             :   fd_w_u128_t stake; /* should really be fine as ulong, but we match Agave */
      26             : };
      27             : typedef struct ts_est_ele ts_est_ele_t;
      28             : 
      29             : /* The clock sysvar provides an approximate measure of network time. */
      30             : 
      31             : /* fd_sysvar_clock_init initializes the sysvar account to genesis state. */
      32             : 
      33             : void
      34             : fd_sysvar_clock_init( fd_bank_t *               bank,
      35             :                       fd_accdb_user_t *         accdb,
      36             :                       fd_funk_txn_xid_t const * xid,
      37             :                       fd_capture_ctx_t *        capture_ctx );
      38             : 
      39             : /* fd_sysvar_clock_update updates the clock sysvar account.  Runs
      40             :    fd_calculate_stake_weighted_timestamp under the hood.  Should be
      41             :    called at the start of every slot before execution commences.  Takes
      42             :    in a pointer to the parent_epoch, where *parent_epoch is the epoch of
      43             :    the parent slot.  parent_epoch = NULL is used for genesis bootup.
      44             :    Crashes the process with FD_LOG_ERR on failure. */
      45             : 
      46             : void
      47             : fd_sysvar_clock_update( fd_bank_t *               bank,
      48             :                         fd_accdb_user_t *         accdb,
      49             :                         fd_funk_txn_xid_t const * xid,
      50             :                         fd_capture_ctx_t *        capture_ctx,
      51             :                         fd_runtime_stack_t *      runtime_stack,
      52             :                         ulong const *             parent_epoch );
      53             : 
      54             : /* Writes the current value of the clock sysvar to funk. */
      55             : 
      56             : static inline void
      57             : fd_sysvar_clock_write( fd_bank_t *                   bank,
      58             :                        fd_accdb_user_t *             accdb,
      59             :                        fd_funk_txn_xid_t const *     xid,
      60             :                        fd_capture_ctx_t *            capture_ctx,
      61         303 :                        fd_sol_sysvar_clock_t const * clock ) {
      62         303 :   fd_sysvar_account_update( bank, accdb, xid, capture_ctx, &fd_sysvar_clock_id, clock, sizeof(fd_sol_sysvar_clock_t) );
      63         303 : }
      64             : 
      65             : /* fd_sysvar_clock_read reads the current value of the rent sysvar from
      66             :    funk. If the account doesn't exist in funk or if the account
      67             :    has zero lamports, this function returns NULL. */
      68             : 
      69             : fd_sol_sysvar_clock_t *
      70             : fd_sysvar_clock_read( fd_accdb_user_t *         accdb,
      71             :                       fd_funk_txn_xid_t const * xid,
      72             :                       fd_sol_sysvar_clock_t *   clock );
      73             : 
      74             : FD_PROTOTYPES_END
      75             : 
      76             : #endif /* HEADER_fd_src_flamenco_runtime_sysvar_fd_sysvar_clock_h */

Generated by: LCOV version 1.14