LCOV - code coverage report
Current view: top level - flamenco/runtime - fd_slot_params.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 69 69 100.0 %
Date: 2026-10-16 04:29:28 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        4929 : #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        4929 : #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        5040 : #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        4929 : #define FD_SLOT_PARAMS_400MS ((fd_slot_params_t){                                 \
      57        4929 :   .ns_per_slot                        = 400000000UL,                              \
      58        4929 :   .ns_per_slot_adjusted               = 400000000UL-FD_TARGET_SLOT_ADJUSTMENT_NS, \
      59        4929 :   .slots_per_year                     = 78892314.984,                             \
      60        4929 :   .hashes_per_tick                    = FD_LEGACY_HASHES_PER_TICK,                \
      61        4929 :   .max_block_units                    = 60000000UL,                               \
      62        4929 :   .max_writable_account_units         = 24000000UL,                               \
      63        4929 :   .max_block_accounts_data_size_delta = 100000000UL,                              \
      64        4929 :   .max_shred_idx                      = 32768UL,                                  \
      65        4929 :   .max_entry_bytes_per_slot           = FD_DEFAULT_MAX_ENTRY_BYTES_PER_SLOT,      \
      66        4929 :   .stake_account_stores_per_block     = 4096UL,                                   \
      67        4929 :   .vat_to_burn_per_epoch              = 1600000000UL,                             \
      68        4929 : })
      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          30 : #define FD_SLOT_PARAMS_200MS_MAX_BLOCK_UNITS (30000000UL)
     116             : 
     117             : /* https://github.com/anza-xyz/agave/blob/v4.2/runtime/src/slot_params.rs#L171-L181 */
     118          30 : #define FD_SLOT_PARAMS_200MS ((fd_slot_params_t){                                 \
     119          30 :   .ns_per_slot                        = 200000000UL,                              \
     120          30 :   .ns_per_slot_adjusted               = 200000000UL-FD_TARGET_SLOT_ADJUSTMENT_NS, \
     121          30 :   .slots_per_year                     = 157784629.968,                            \
     122          30 :   .hashes_per_tick                    = 31250UL,                                  \
     123          30 :   .max_block_units                    = FD_SLOT_PARAMS_200MS_MAX_BLOCK_UNITS,     \
     124          30 :   .max_writable_account_units         = 12000000UL,                               \
     125          30 :   .max_block_accounts_data_size_delta = 50000000UL,                               \
     126          30 :   .max_shred_idx                      = 16384UL,                                  \
     127          30 :   .max_entry_bytes_per_slot           = 10485760UL,                               \
     128          30 :   .stake_account_stores_per_block     = 2048UL,                                   \
     129          30 :   .vat_to_burn_per_epoch              = 800000000UL,                              \
     130          30 : })
     131             : 
     132             : FD_PROTOTYPES_BEGIN
     133             : 
     134             : /* fd_slot_params_at_slot returns the effective slot params at the given
     135             :    slot, using the bank's default params, features, and epoch schedule.
     136             : 
     137             :    This takes into account the fact that the reduce_slot_time feature
     138             :    gates take effect an epoch after they have been activated.
     139             : 
     140             :    https://github.com/anza-xyz/agave/blob/v4.2/runtime/src/slot_params.rs#L241-L286 */
     141             : 
     142             : fd_slot_params_t
     143             : fd_slot_params_at_slot( fd_bank_t const * bank,
     144             :                         ulong             slot );
     145             : 
     146             : /* fd_slot_params_lookup returns the effective slot params at the given
     147             :    slot, using the given default params, features, and epoch schedule.
     148             : 
     149             :    This takes into account the fact that the reduce_slot_time feature
     150             :    gates take effect an epoch after they have been activated. */
     151             : 
     152             : fd_slot_params_t
     153             : fd_slot_params_lookup( fd_slot_params_t const *    default_params,
     154             :                        fd_features_t const *       features,
     155             :                        fd_epoch_schedule_t const * epoch_schedule,
     156             :                        ulong                       slot );
     157             : 
     158             : /* fd_slot_params_effective_slot returns the slot at which the given
     159             :    slot params regime takes effect. */
     160             : 
     161             : ulong
     162             : fd_slot_params_effective_slot( fd_slot_params_t const *    params,
     163             :                                fd_features_t const *       features,
     164             :                                fd_epoch_schedule_t const * epoch_schedule );
     165             : 
     166             : /* fd_slot_params_next_effective_slot returns the slot at which the next
     167             :    slot params regime after the given one takes effect. */
     168             : 
     169             : ulong
     170             : fd_slot_params_next_effective_slot( fd_slot_params_t const *    params,
     171             :                                     fd_features_t const *       features,
     172             :                                     fd_epoch_schedule_t const * epoch_schedule );
     173             : 
     174             : /* fd_slot_params_slot_range_duration_ns returns the duration in
     175             :    nanoseconds for the slot range [start_slot, end_slot),
     176             :    taking into account any reduce_slot_time feature gate activations
     177             :    between the two slots.
     178             : 
     179             :    This is equivalent to Agave's slot_range_duration_nanos
     180             :    https://github.com/anza-xyz/agave/blob/v4.2/runtime/src/slot_params.rs#L295-L320 */
     181             : 
     182             : FD_FN_PURE ulong
     183             : fd_slot_params_slot_range_duration_ns( fd_bank_t const * bank,
     184             :                                        ulong             start_slot,
     185             :                                        ulong             end_slot );
     186             : 
     187             : /* fd_slot_params_slot_range_duration_years returns the duration in
     188             :    years for the slot range [start_slot, end_slot), taking into
     189             :    account any reduce_slot_time feature gate activations between the
     190             :    two slots.
     191             : 
     192             :    This is equivalent to Agave's slot_range_duration_in_years:
     193             :    https://github.com/anza-xyz/agave/blob/v4.2/runtime/src/bank.rs#L2850-L2874 */
     194             : 
     195             : FD_FN_PURE double
     196             : fd_slot_params_slot_range_duration_years( fd_bank_t const * bank,
     197             :                                           ulong             start_slot,
     198             :                                           ulong             end_slot );
     199             : 
     200             : FD_PROTOTYPES_END
     201             : 
     202             : #endif /* HEADER_fd_src_flamenco_runtime_fd_slot_params_h */

Generated by: LCOV version 1.14