LCOV - code coverage report
Current view: top level - flamenco/runtime - fd_slot_params.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 68 68 100.0 %
Date: 2026-08-28 06:53:58 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_runtime_fd_slot_params_h
       2             : #define HEADER_fd_src_flamenco_runtime_fd_slot_params_h
       3             : 
       4             : #include "../fd_flamenco_base.h"
       5             : 
       6             : /* fd_slot_params groups the runtime parameters that move together when
       7             :    the slot time changes due to the reduce_slot_time feature gates as
       8             :    described in SIMD-525.
       9             : 
      10             :    Slot time reductions happen in 50ms increments, each with a separate
      11             :    feature gate:
      12             :      reduce_slot_time_to_350ms
      13             :      reduce_slot_time_to_300ms
      14             :      reduce_slot_time_to_250ms
      15             :      reduce_slot_time_to_200ms
      16             : 
      17             :    Note that these feature gates take effect an epoch after they
      18             :    have been activated, because they affect the turbine shred filtering
      19             :    rules. */
      20             : 
      21             : /* https://github.com/anza-xyz/agave/blob/v4.2/runtime/src/slot_params.rs#L13 */
      22        4056 : #define FD_DEFAULT_MAX_ENTRY_BYTES_PER_SLOT (20UL*1024UL*1024UL) /* 20 MiB */
      23             : 
      24             : /* https://github.com/anza-xyz/agave/blob/v4.2/runtime/src/slot_params.rs#L122 */
      25        4056 : #define FD_LEGACY_HASHES_PER_TICK (62500UL)
      26             : 
      27             : /* In order to hit the target slot time, when producing blocks we
      28             :    subtract a fixed overhead amount to compensate for time spent
      29             :    outside of block production itself, such as network propagation.
      30             : 
      31             :    50ms is used to match Agave's behaviour:
      32             :    https://github.com/anza-xyz/agave/blob/v4.2/poh/src/poh_service.rs#L47 */
      33        4152 : #define FD_TARGET_SLOT_ADJUSTMENT_NS (50000000UL)
      34             : 
      35             : /* Runtime parameters that need to change when the slot time changes
      36             :    due to one of the reduce_slot_time feature gates.
      37             : 
      38             :    https://github.com/anza-xyz/agave/blob/v4.2/runtime/src/slot_params.rs#L20-L30 */
      39             : 
      40             : struct fd_slot_params {
      41             :   ulong  ns_per_slot;
      42             :   ulong  ns_per_slot_adjusted;
      43             :   double slots_per_year;
      44             :   ulong  hashes_per_tick;
      45             :   ulong  max_block_units;
      46             :   ulong  max_writable_account_units;
      47             :   ulong  max_block_accounts_data_size_delta;
      48             :   ulong  max_shred_idx;
      49             :   ulong  max_entry_bytes_per_slot;
      50             :   ulong  stake_account_stores_per_block;
      51             :   ulong  vat_to_burn_per_epoch;
      52             : };
      53             : typedef struct fd_slot_params fd_slot_params_t;
      54             : 
      55             : /* https://github.com/anza-xyz/agave/blob/v4.2/runtime/src/slot_params.rs#L123-L133 */
      56        4056 : #define FD_SLOT_PARAMS_400MS ((fd_slot_params_t){                                 \
      57        4056 :   .ns_per_slot                        = 400000000UL,                              \
      58        4056 :   .ns_per_slot_adjusted               = 400000000UL-FD_TARGET_SLOT_ADJUSTMENT_NS, \
      59        4056 :   .slots_per_year                     = 78892314.984,                             \
      60        4056 :   .hashes_per_tick                    = FD_LEGACY_HASHES_PER_TICK,                \
      61        4056 :   .max_block_units                    = 60000000UL,                               \
      62        4056 :   .max_writable_account_units         = 24000000UL,                               \
      63        4056 :   .max_block_accounts_data_size_delta = 100000000UL,                              \
      64        4056 :   .max_shred_idx                      = 32768UL,                                  \
      65        4056 :   .max_entry_bytes_per_slot           = FD_DEFAULT_MAX_ENTRY_BYTES_PER_SLOT,      \
      66        4056 :   .stake_account_stores_per_block     = 4096UL,                                   \
      67        4056 :   .vat_to_burn_per_epoch              = 1600000000UL,                             \
      68        4056 : })
      69             : 
      70             : /* https://github.com/anza-xyz/agave/blob/v4.2/runtime/src/slot_params.rs#L135-L145 */
      71          18 : #define FD_SLOT_PARAMS_350MS ((fd_slot_params_t){                                 \
      72          18 :   .ns_per_slot                        = 350000000UL,                              \
      73          18 :   .ns_per_slot_adjusted               = 350000000UL-FD_TARGET_SLOT_ADJUSTMENT_NS, \
      74          18 :   .slots_per_year                     = 90162645.696,                             \
      75          18 :   .hashes_per_tick                    = 54687UL,                                  \
      76          18 :   .max_block_units                    = 52500000UL,                               \
      77          18 :   .max_writable_account_units         = 21000000UL,                               \
      78          18 :   .max_block_accounts_data_size_delta = 87500000UL,                               \
      79          18 :   .max_shred_idx                      = 28672UL,                                  \
      80          18 :   .max_entry_bytes_per_slot           = 18350080UL,                               \
      81          18 :   .stake_account_stores_per_block     = 3584UL,                                   \
      82          18 :   .vat_to_burn_per_epoch              = 1400000000UL,                             \
      83          18 : })
      84             : 
      85             : /* https://github.com/anza-xyz/agave/blob/v4.2/runtime/src/slot_params.rs#L147-L157 */
      86          24 : #define FD_SLOT_PARAMS_300MS ((fd_slot_params_t){                                 \
      87          24 :   .ns_per_slot                        = 300000000UL,                              \
      88          24 :   .ns_per_slot_adjusted               = 300000000UL-FD_TARGET_SLOT_ADJUSTMENT_NS, \
      89          24 :   .slots_per_year                     = 105189753.312,                            \
      90          24 :   .hashes_per_tick                    = 46875UL,                                  \
      91          24 :   .max_block_units                    = 45000000UL,                               \
      92          24 :   .max_writable_account_units         = 18000000UL,                               \
      93          24 :   .max_block_accounts_data_size_delta = 75000000UL,                               \
      94          24 :   .max_shred_idx                      = 24576UL,                                  \
      95          24 :   .max_entry_bytes_per_slot           = 15728640UL,                               \
      96          24 :   .stake_account_stores_per_block     = 3072UL,                                   \
      97          24 :   .vat_to_burn_per_epoch              = 1200000000UL,                             \
      98          24 : })
      99             : 
     100             : /* https://github.com/anza-xyz/agave/blob/v4.2/runtime/src/slot_params.rs#L159-L169 */
     101          12 : #define FD_SLOT_PARAMS_250MS ((fd_slot_params_t){                                 \
     102          12 :   .ns_per_slot                        = 250000000UL,                              \
     103          12 :   .ns_per_slot_adjusted               = 250000000UL-FD_TARGET_SLOT_ADJUSTMENT_NS, \
     104          12 :   .slots_per_year                     = 126227703.974,                            \
     105          12 :   .hashes_per_tick                    = 39062UL,                                  \
     106          12 :   .max_block_units                    = 37500000UL,                               \
     107          12 :   .max_writable_account_units         = 15000000UL,                               \
     108          12 :   .max_block_accounts_data_size_delta = 62500000UL,                               \
     109          12 :   .max_shred_idx                      = 20480UL,                                  \
     110          12 :   .max_entry_bytes_per_slot           = 13107200UL,                               \
     111          12 :   .stake_account_stores_per_block     = 2560UL,                                   \
     112          12 :   .vat_to_burn_per_epoch              = 1000000000UL,                             \
     113          12 : })
     114             : 
     115             : /* https://github.com/anza-xyz/agave/blob/v4.2/runtime/src/slot_params.rs#L171-L181 */
     116          33 : #define FD_SLOT_PARAMS_200MS ((fd_slot_params_t){                                 \
     117          33 :   .ns_per_slot                        = 200000000UL,                              \
     118          33 :   .ns_per_slot_adjusted               = 200000000UL-FD_TARGET_SLOT_ADJUSTMENT_NS, \
     119          33 :   .slots_per_year                     = 157784629.968,                            \
     120          33 :   .hashes_per_tick                    = 31250UL,                                  \
     121          33 :   .max_block_units                    = 30000000UL,                               \
     122          33 :   .max_writable_account_units         = 12000000UL,                               \
     123          33 :   .max_block_accounts_data_size_delta = 50000000UL,                               \
     124          33 :   .max_shred_idx                      = 16384UL,                                  \
     125          33 :   .max_entry_bytes_per_slot           = 10485760UL,                               \
     126          33 :   .stake_account_stores_per_block     = 2048UL,                                   \
     127          33 :   .vat_to_burn_per_epoch              = 800000000UL,                              \
     128          33 : })
     129             : 
     130             : FD_PROTOTYPES_BEGIN
     131             : 
     132             : /* fd_slot_params_at_slot returns the effective slot params at the given
     133             :    slot, using the bank's default params, features, and epoch schedule.
     134             : 
     135             :    This takes into account the fact that the reduce_slot_time feature
     136             :    gates take effect an epoch after they have been activated.
     137             : 
     138             :    https://github.com/anza-xyz/agave/blob/v4.2/runtime/src/slot_params.rs#L241-L286 */
     139             : 
     140             : fd_slot_params_t
     141             : fd_slot_params_at_slot( fd_bank_t const * bank,
     142             :                         ulong             slot );
     143             : 
     144             : /* fd_slot_params_lookup returns the effective slot params at the given
     145             :    slot, using the given default params, features, and epoch schedule.
     146             : 
     147             :    This takes into account the fact that the reduce_slot_time feature
     148             :    gates take effect an epoch after they have been activated. */
     149             : 
     150             : fd_slot_params_t
     151             : fd_slot_params_lookup( fd_slot_params_t const *    default_params,
     152             :                        fd_features_t const *       features,
     153             :                        fd_epoch_schedule_t const * epoch_schedule,
     154             :                        ulong                       slot );
     155             : 
     156             : /* fd_slot_params_effective_slot returns the slot at which the given
     157             :    slot params regime takes effect. */
     158             : 
     159             : ulong
     160             : fd_slot_params_effective_slot( fd_slot_params_t const *    params,
     161             :                                fd_features_t const *       features,
     162             :                                fd_epoch_schedule_t const * epoch_schedule );
     163             : 
     164             : /* fd_slot_params_next_effective_slot returns the slot at which the next
     165             :    slot params regime after the given one takes effect. */
     166             : 
     167             : ulong
     168             : fd_slot_params_next_effective_slot( fd_slot_params_t const *    params,
     169             :                                     fd_features_t const *       features,
     170             :                                     fd_epoch_schedule_t const * epoch_schedule );
     171             : 
     172             : /* fd_slot_params_slot_range_duration_ns returns the duration in
     173             :    nanoseconds for the slot range [start_slot, end_slot),
     174             :    taking into account any reduce_slot_time feature gate activations
     175             :    between the two slots.
     176             : 
     177             :    This is equivalent to Agave's slot_range_duration_nanos
     178             :    https://github.com/anza-xyz/agave/blob/v4.2/runtime/src/slot_params.rs#L295-L320 */
     179             : 
     180             : FD_FN_PURE ulong
     181             : fd_slot_params_slot_range_duration_ns( fd_bank_t const * bank,
     182             :                                        ulong             start_slot,
     183             :                                        ulong             end_slot );
     184             : 
     185             : /* fd_slot_params_slot_range_duration_years returns the duration in
     186             :    years for the slot range [start_slot, end_slot), taking into
     187             :    account any reduce_slot_time feature gate activations between the
     188             :    two slots.
     189             : 
     190             :    This is equivalent to Agave's slot_range_duration_in_years:
     191             :    https://github.com/anza-xyz/agave/blob/v4.2/runtime/src/bank.rs#L2850-L2874 */
     192             : 
     193             : FD_FN_PURE double
     194             : fd_slot_params_slot_range_duration_years( fd_bank_t const * bank,
     195             :                                           ulong             start_slot,
     196             :                                           ulong             end_slot );
     197             : 
     198             : FD_PROTOTYPES_END
     199             : 
     200             : #endif /* HEADER_fd_src_flamenco_runtime_fd_slot_params_h */

Generated by: LCOV version 1.14