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 8333 : #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 8333 : #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 8333 : #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 8333 : #define FD_SLOT_PARAMS_400MS ((fd_slot_params_t){ \
57 8333 : .ns_per_slot = 400000000UL, \
58 8333 : .ns_per_slot_adjusted = 400000000UL-FD_TARGET_SLOT_ADJUSTMENT_NS, \
59 8333 : .slots_per_year = 78892314.984, \
60 8333 : .hashes_per_tick = FD_LEGACY_HASHES_PER_TICK, \
61 8333 : .max_block_units = 60000000UL, \
62 8333 : .max_writable_account_units = 24000000UL, \
63 8333 : .max_block_accounts_data_size_delta = 100000000UL, \
64 8333 : .max_shred_idx = 32768UL, \
65 8333 : .max_entry_bytes_per_slot = FD_DEFAULT_MAX_ENTRY_BYTES_PER_SLOT, \
66 8333 : .stake_account_stores_per_block = 4096UL, \
67 8333 : .vat_to_burn_per_epoch = 1600000000UL, \
68 8333 : })
69 :
70 : /* https://github.com/anza-xyz/agave/blob/v4.2/runtime/src/slot_params.rs#L135-L145 */
71 0 : #define FD_SLOT_PARAMS_350MS ((fd_slot_params_t){ \
72 0 : .ns_per_slot = 350000000UL, \
73 0 : .ns_per_slot_adjusted = 350000000UL-FD_TARGET_SLOT_ADJUSTMENT_NS, \
74 0 : .slots_per_year = 90162645.696, \
75 0 : .hashes_per_tick = 54687UL, \
76 0 : .max_block_units = 52500000UL, \
77 0 : .max_writable_account_units = 21000000UL, \
78 0 : .max_block_accounts_data_size_delta = 87500000UL, \
79 0 : .max_shred_idx = 28672UL, \
80 0 : .max_entry_bytes_per_slot = 18350080UL, \
81 0 : .stake_account_stores_per_block = 3584UL, \
82 0 : .vat_to_burn_per_epoch = 1400000000UL, \
83 0 : })
84 :
85 : /* https://github.com/anza-xyz/agave/blob/v4.2/runtime/src/slot_params.rs#L147-L157 */
86 0 : #define FD_SLOT_PARAMS_300MS ((fd_slot_params_t){ \
87 0 : .ns_per_slot = 300000000UL, \
88 0 : .ns_per_slot_adjusted = 300000000UL-FD_TARGET_SLOT_ADJUSTMENT_NS, \
89 0 : .slots_per_year = 105189753.312, \
90 0 : .hashes_per_tick = 46875UL, \
91 0 : .max_block_units = 45000000UL, \
92 0 : .max_writable_account_units = 18000000UL, \
93 0 : .max_block_accounts_data_size_delta = 75000000UL, \
94 0 : .max_shred_idx = 24576UL, \
95 0 : .max_entry_bytes_per_slot = 15728640UL, \
96 0 : .stake_account_stores_per_block = 3072UL, \
97 0 : .vat_to_burn_per_epoch = 1200000000UL, \
98 0 : })
99 :
100 : /* https://github.com/anza-xyz/agave/blob/v4.2/runtime/src/slot_params.rs#L159-L169 */
101 0 : #define FD_SLOT_PARAMS_250MS ((fd_slot_params_t){ \
102 0 : .ns_per_slot = 250000000UL, \
103 0 : .ns_per_slot_adjusted = 250000000UL-FD_TARGET_SLOT_ADJUSTMENT_NS, \
104 0 : .slots_per_year = 126227703.974, \
105 0 : .hashes_per_tick = 39062UL, \
106 0 : .max_block_units = 37500000UL, \
107 0 : .max_writable_account_units = 15000000UL, \
108 0 : .max_block_accounts_data_size_delta = 62500000UL, \
109 0 : .max_shred_idx = 20480UL, \
110 0 : .max_entry_bytes_per_slot = 13107200UL, \
111 0 : .stake_account_stores_per_block = 2560UL, \
112 0 : .vat_to_burn_per_epoch = 1000000000UL, \
113 0 : })
114 :
115 0 : #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 0 : #define FD_SLOT_PARAMS_200MS ((fd_slot_params_t){ \
119 0 : .ns_per_slot = 200000000UL, \
120 0 : .ns_per_slot_adjusted = 200000000UL-FD_TARGET_SLOT_ADJUSTMENT_NS, \
121 0 : .slots_per_year = 157784629.968, \
122 0 : .hashes_per_tick = 31250UL, \
123 0 : .max_block_units = FD_SLOT_PARAMS_200MS_MAX_BLOCK_UNITS, \
124 0 : .max_writable_account_units = 12000000UL, \
125 0 : .max_block_accounts_data_size_delta = 50000000UL, \
126 0 : .max_shred_idx = 16384UL, \
127 0 : .max_entry_bytes_per_slot = 10485760UL, \
128 0 : .stake_account_stores_per_block = 2048UL, \
129 0 : .vat_to_burn_per_epoch = 800000000UL, \
130 0 : })
131 :
132 : FD_PROTOTYPES_BEGIN
133 :
134 : /* fd_slot_params_from_genesis returns the slot params implied by the
135 : genesis PoH config: ns_per_slot, ns_per_slot_adjusted,
136 : slots_per_year and hashes_per_tick are derived from genesis, all
137 : other fields are the 400ms values.
138 :
139 : https://github.com/anza-xyz/agave/blob/4f8937b9568f7672ce0edcf67501666a95df015b/runtime/src/bank.rs#L2876-L2886 */
140 :
141 : fd_slot_params_t
142 : fd_slot_params_from_genesis( fd_genesis_t const * genesis );
143 :
144 : /* fd_slot_params_any_reduction_effective returns 1 if any
145 : reduce_slot_time gate with a slot time <= ns_per_slot is effective
146 : at the given slot, 0 otherwise.
147 :
148 : https://github.com/anza-xyz/agave/blob/4f8937b9568f7672ce0edcf67501666a95df015b/runtime/src/slot_params.rs#L332-L349 */
149 :
150 : int
151 : fd_slot_params_any_reduction_effective( fd_features_t const * features,
152 : fd_epoch_schedule_t const * epoch_schedule,
153 : ulong slot,
154 : ulong ns_per_slot );
155 :
156 : /* fd_slot_params_at_slot returns the effective slot params at the given
157 : slot, using the bank's default params, features, and epoch schedule.
158 :
159 : This takes into account the fact that the reduce_slot_time feature
160 : gates take effect an epoch after they have been activated.
161 :
162 : https://github.com/anza-xyz/agave/blob/v4.2/runtime/src/slot_params.rs#L241-L286 */
163 :
164 : fd_slot_params_t
165 : fd_slot_params_at_slot( fd_bank_t const * bank,
166 : ulong slot );
167 :
168 : /* fd_slot_params_lookup returns the effective slot params at the given
169 : slot, using the given default params, features, and epoch schedule.
170 :
171 : This takes into account the fact that the reduce_slot_time feature
172 : gates take effect an epoch after they have been activated. */
173 :
174 : fd_slot_params_t
175 : fd_slot_params_lookup( fd_slot_params_t const * default_params,
176 : fd_features_t const * features,
177 : fd_epoch_schedule_t const * epoch_schedule,
178 : ulong slot );
179 :
180 : /* fd_slot_params_effective_slot returns the slot at which the given
181 : slot params regime takes effect. */
182 :
183 : ulong
184 : fd_slot_params_effective_slot( fd_slot_params_t const * params,
185 : fd_features_t const * features,
186 : fd_epoch_schedule_t const * epoch_schedule );
187 :
188 : /* fd_slot_params_next_effective_slot returns the slot at which the next
189 : slot params regime after the given one takes effect. */
190 :
191 : ulong
192 : fd_slot_params_next_effective_slot( fd_slot_params_t const * params,
193 : fd_features_t const * features,
194 : fd_epoch_schedule_t const * epoch_schedule );
195 :
196 : /* https://github.com/anza-xyz/agave/blob/9bcf93e368b5fb52c21677ed8c7f0360eb93b5b7/runtime/src/slot_params.rs#L243-L269 */
197 :
198 : ulong
199 : fd_slot_params_next_transition( fd_features_t const * features,
200 : fd_epoch_schedule_t const * epoch_schedule,
201 : ulong slot,
202 : ulong current_ns_per_slot );
203 :
204 : /* fd_slot_params_slot_range_duration_ns returns the duration in
205 : nanoseconds for the slot range [start_slot, end_slot),
206 : taking into account any reduce_slot_time feature gate activations
207 : between the two slots.
208 :
209 : This is equivalent to Agave's slot_range_duration_nanos
210 : https://github.com/anza-xyz/agave/blob/v4.2/runtime/src/slot_params.rs#L295-L320 */
211 :
212 : FD_FN_PURE ulong
213 : fd_slot_params_slot_range_duration_ns( fd_bank_t const * bank,
214 : ulong start_slot,
215 : ulong end_slot );
216 :
217 : /* fd_slot_params_slot_range_duration_years returns the duration in
218 : years for the slot range [start_slot, end_slot), taking into
219 : account any reduce_slot_time feature gate activations between the
220 : two slots.
221 :
222 : This is equivalent to Agave's slot_range_duration_in_years:
223 : https://github.com/anza-xyz/agave/blob/v4.2/runtime/src/bank.rs#L2850-L2874 */
224 :
225 : FD_FN_PURE double
226 : fd_slot_params_slot_range_duration_years( fd_bank_t const * bank,
227 : ulong start_slot,
228 : ulong end_slot );
229 :
230 : FD_PROTOTYPES_END
231 :
232 : #endif /* HEADER_fd_src_flamenco_runtime_fd_slot_params_h */
|