Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_runtime_sysvar_fd_clock_h 2 : #define HEADER_fd_src_flamenco_runtime_sysvar_fd_clock_h 3 : 4 : /* The clock sysvar provides an approximate measure of network time. */ 5 : 6 : #include "../../fd_flamenco_base.h" 7 : #include "../context/fd_exec_instr_ctx.h" 8 : #include "fd_sysvar_cache.h" 9 : #include "fd_sysvar.h" 10 : 11 : /* https://github.com/solana-labs/solana/blob/8f2c8b8388a495d2728909e30460aa40dcc5d733/sdk/program/src/clock.rs#L10 */ 12 0 : #define FD_SYSVAR_CLOCK_DEFAULT_TICKS_PER_SECOND ( 160UL ) 13 0 : #define FD_SYSVAR_CLOCK_DEFAULT_HASHES_PER_TICK (12500UL) 14 : 15 : FD_PROTOTYPES_BEGIN 16 : 17 : /* The clock sysvar provides an approximate measure of network time. */ 18 : 19 : /* Initialize the clock sysvar account. */ 20 : 21 : void 22 : fd_sysvar_clock_init( fd_exec_slot_ctx_t * slot_ctx ); 23 : 24 : /* Update the clock sysvar account. This should be called at the start 25 : of every slot, before execution commences. */ 26 : 27 : int 28 : fd_sysvar_clock_update( fd_exec_slot_ctx_t * slot_ctx, 29 : fd_spad_t * runtime_spad ); 30 : 31 : /* Reads the current value of the clock sysvar */ 32 : 33 : fd_sol_sysvar_clock_t * 34 : fd_sysvar_clock_read( fd_sol_sysvar_clock_t * result, 35 : fd_sysvar_cache_t const * sysvar_cache, 36 : fd_acc_mgr_t * acc_mgr, 37 : fd_funk_txn_t * funk_txn ); 38 : 39 : /* fd_slot_cnt_2day returns the number of slots in two days. 40 : Used in rent collection. */ 41 : 42 : static inline ulong 43 0 : fd_slot_cnt_2day( ulong ticks_per_slot ) { 44 0 : ulong seconds = (2UL * 24UL * 60UL * 60UL); 45 0 : ulong ticks = seconds * FD_SYSVAR_CLOCK_DEFAULT_HASHES_PER_TICK; 46 0 : return ticks / ticks_per_slot; 47 0 : } 48 : 49 : FD_PROTOTYPES_END 50 : 51 : #endif /* HEADER_fd_src_flamenco_runtime_sysvar_fd_clock_h */