Line data Source code
1 : #include "fd_sysvar.h"
2 : #include "fd_sysvar_clock.h"
3 : #include "fd_sysvar_epoch_schedule.h"
4 : #include "../fd_runtime_stack.h"
5 : #include "../fd_system_ids.h"
6 : #include "../program/fd_program_util.h"
7 : #include "../program/vote/fd_vote_state_versioned.h"
8 : #include "../../accdb/fd_accdb_sync.h"
9 :
10 : /* Syvar Clock Possible Values:
11 : slot:
12 : [0, ULONG_MAX]
13 :
14 : epoch:
15 : [0, slot/432000UL]
16 :
17 : epoch_start_timestamp:
18 : [0, ULONG_MAX]
19 :
20 : unix_timestamp:
21 : This value is bounded by the slot distance from the
22 : epoch_start_timestamp.
23 : The protocol allows for a maximum drift (either fast or slow) from the
24 : start of the epoch's timestamp. The expected time is called the PoH
25 : offset. This offset is calculated by (epoch_start_timestamp + slots
26 : since epoch * slot_duration). The drift is then bounded by the
27 : max_allowable_drift_{slow,fast}. The stake weighted offset can be
28 : 150% more than the PoH offset and 25% less than the PoH offset.
29 : So, the bounds for the unix_timestamp can be calculated by:
30 : upper bound = epoch_start_timestamp + (slots since epoch * slot_duration) * 2.5
31 : lower bound = epoch_start_timestamp + (slots since epoch * slot_duration) * 0.75
32 :
33 : leader_schedule_epoch:
34 : This is the value of the epoch used for the leader schedule. It is
35 : computed based on the values of the epoch schedule (first_normal_slot,
36 : leader_schedule_slot_offset, slots_per_epoch). It is always equal to
37 : ((slot - first_normal_slot) + leader_schedule_slot_offset) / schedule->slots_per_epoch
38 : */
39 :
40 : /* https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/stake_weighted_timestamp.rs#L14 */
41 299 : #define MAX_ALLOWABLE_DRIFT_FAST_PERCENT ( 25U )
42 :
43 : /* https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/stake_weighted_timestamp.rs#L15 */
44 299 : #define MAX_ALLOWABLE_DRIFT_SLOW_PERCENT ( 150U )
45 :
46 : /* Do all intermediate calculations at nanosecond precision, to mirror
47 : Solana's behavior. */
48 624 : #define NS_IN_S ((long)1e9)
49 :
50 : /* https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/bank.rs#L2110-L2117 */
51 : static inline long
52 0 : unix_timestamp_from_genesis( fd_bank_t * bank ) {
53 : /* TODO: genesis_creation_time needs to be a long in the bank. */
54 0 : return fd_long_sat_add(
55 0 : (long)fd_bank_genesis_creation_time_get( bank ),
56 0 : (long)( fd_uint128_sat_mul( fd_bank_slot_get( bank ), fd_bank_ns_per_slot_get( bank ).ud ) / NS_IN_S ) );
57 0 : }
58 :
59 : void
60 : fd_sysvar_clock_write( fd_bank_t * bank,
61 : fd_accdb_user_t * accdb,
62 : fd_funk_txn_xid_t const * xid,
63 : fd_capture_ctx_t * capture_ctx,
64 299 : fd_sol_sysvar_clock_t * clock ) {
65 299 : uchar enc[ sizeof(fd_sol_sysvar_clock_t) ];
66 299 : fd_bincode_encode_ctx_t ctx = {
67 299 : .data = enc,
68 299 : .dataend = enc + sizeof(fd_sol_sysvar_clock_t),
69 299 : };
70 299 : if( FD_UNLIKELY( fd_sol_sysvar_clock_encode( clock, &ctx ) ) ) {
71 0 : FD_LOG_ERR(( "fd_sol_sysvar_clock_encode failed" ));
72 0 : }
73 :
74 299 : fd_sysvar_account_update( bank, accdb, xid, capture_ctx, &fd_sysvar_clock_id, enc, sizeof(fd_sol_sysvar_clock_t) );
75 299 : }
76 :
77 : fd_sol_sysvar_clock_t *
78 : fd_sysvar_clock_read( fd_accdb_user_t * accdb,
79 : fd_funk_txn_xid_t const * xid,
80 299 : fd_sol_sysvar_clock_t * clock ) {
81 299 : fd_accdb_ro_t ro[1];
82 299 : if( FD_UNLIKELY( !fd_accdb_open_ro( accdb, ro, xid, &fd_sysvar_clock_id ) ) ) {
83 0 : return NULL;
84 0 : }
85 :
86 : /* This check is needed as a quirk of the fuzzer. If a sysvar account
87 : exists in the accounts database, but doesn't have any lamports,
88 : this means that the account does not exist. This wouldn't happen
89 : in a real execution environment. */
90 299 : if( FD_UNLIKELY( fd_accdb_ref_lamports( ro )==0UL ) ) {
91 0 : fd_accdb_close_ro( accdb, ro );
92 0 : return NULL;
93 0 : }
94 :
95 299 : fd_sol_sysvar_clock_t * res = fd_bincode_decode_static(
96 299 : sol_sysvar_clock, clock,
97 299 : fd_accdb_ref_data_const( ro ),
98 299 : fd_accdb_ref_data_sz ( ro ) );
99 299 : fd_accdb_close_ro( accdb, ro );
100 299 : return res;
101 299 : }
102 :
103 : void
104 : fd_sysvar_clock_init( fd_bank_t * bank,
105 : fd_accdb_user_t * accdb,
106 : fd_funk_txn_xid_t const * xid,
107 0 : fd_capture_ctx_t * capture_ctx ) {
108 0 : long timestamp = unix_timestamp_from_genesis( bank );
109 :
110 0 : fd_sol_sysvar_clock_t clock = {
111 0 : .slot = fd_bank_slot_get( bank ),
112 0 : .epoch = 0,
113 0 : .epoch_start_timestamp = timestamp,
114 0 : .leader_schedule_epoch = 1,
115 0 : .unix_timestamp = timestamp,
116 0 : };
117 0 : fd_sysvar_clock_write( bank, accdb, xid, capture_ctx, &clock );
118 0 : }
119 :
120 : #define SORT_NAME sort_stake_ts
121 0 : #define SORT_KEY_T ts_est_ele_t
122 0 : #define SORT_BEFORE(a,b) ( (a).timestamp < (b).timestamp )
123 : #include "../../../util/tmpl/fd_sort.c"
124 :
125 : static void
126 : accum_vote_stakes_no_vat( fd_accdb_user_t * accdb,
127 : fd_funk_txn_xid_t const * xid,
128 : fd_bank_t * bank,
129 : fd_runtime_stack_t * runtime_stack,
130 : uint128 * total_stake_out,
131 299 : ulong * ts_ele_cnt_out ) {
132 :
133 299 : ts_est_ele_t * ts_eles = runtime_stack->clock_ts.staked_ts;
134 299 : ulong ts_ele_cnt = 0UL;
135 :
136 299 : uint128 total_stake = 0UL;
137 :
138 299 : fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank );
139 299 : ulong slot_duration = fd_bank_ns_per_slot_get( bank ).ul[0];
140 299 : ulong current_slot = fd_bank_slot_get( bank );
141 :
142 299 : fd_vote_stakes_t * vote_stakes = fd_bank_vote_stakes_locking_modify( bank );
143 299 : ushort fork_idx = bank->data->vote_stakes_fork_id;
144 :
145 299 : fd_top_votes_t const * top_votes = fd_bank_top_votes_query( bank );
146 299 : FD_TEST( top_votes );
147 :
148 299 : uchar __attribute__((aligned(FD_VOTE_STAKES_ITER_ALIGN))) iter_mem[ FD_VOTE_STAKES_ITER_FOOTPRINT ];
149 299 : for( fd_vote_stakes_iter_t * iter = fd_vote_stakes_fork_iter_init( vote_stakes, fork_idx, iter_mem );
150 598 : !fd_vote_stakes_fork_iter_done( vote_stakes, fork_idx, iter );
151 299 : fd_vote_stakes_fork_iter_next( vote_stakes, fork_idx, iter ) ) {
152 299 : fd_pubkey_t pubkey;
153 299 : ulong stake_t_2;
154 299 : fd_vote_stakes_fork_iter_ele( vote_stakes, fork_idx, iter, &pubkey, NULL, &stake_t_2, NULL, NULL );
155 299 : if( FD_UNLIKELY( !stake_t_2 ) ) continue;
156 :
157 299 : ulong last_vote_slot;
158 299 : long last_vote_timestamp;
159 299 : int found = fd_top_votes_query( top_votes, &pubkey, NULL, NULL, &last_vote_slot, &last_vote_timestamp );
160 299 : if( FD_UNLIKELY( !found ) ) {
161 0 : fd_accdb_ro_t ro[1];
162 0 : if( FD_UNLIKELY( !fd_accdb_open_ro( accdb, ro, xid, &pubkey ) ) ) {
163 0 : continue;
164 0 : }
165 0 : if( FD_UNLIKELY( !fd_vsv_is_correct_size_and_initialized( ro->meta ) ) ) {
166 0 : fd_accdb_close_ro( accdb, ro );
167 0 : continue;
168 0 : }
169 0 : fd_vote_block_timestamp_t last_vote = fd_vsv_get_vote_block_timestamp( fd_account_data( ro->meta ), ro->meta->dlen );
170 0 : fd_accdb_close_ro( accdb, ro );
171 0 : last_vote_slot = last_vote.slot;
172 0 : last_vote_timestamp = last_vote.timestamp;
173 0 : }
174 :
175 : /* https://github.com/anza-xyz/agave/blob/v3.0.0/runtime/src/bank.rs#L2445 */
176 299 : ulong slot_delta;
177 299 : int err = fd_ulong_checked_sub( current_slot, last_vote_slot, &slot_delta );
178 299 : if( FD_UNLIKELY( err ) ) {
179 : /* Don't count vote accounts with a last vote slot that is greater
180 : than the current slot. */
181 0 : continue;
182 0 : }
183 :
184 : /* Don't count vote accounts that haven't voted in the past 432k
185 : slots (length of an epoch).
186 : https://github.com/anza-xyz/agave/blob/v3.0.0/runtime/src/bank.rs#L2446-L2447 */
187 299 : if( FD_UNLIKELY( slot_delta>epoch_schedule->slots_per_epoch ) ) {
188 0 : continue;
189 0 : }
190 :
191 : /* Calculate the timestamp estimate by taking the last vote
192 : timestamp and adding the estimated time since the last vote
193 : (delta from last vote slot to current slot * slot duration).
194 : https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/stake_weighted_timestamp.rs#L44-L45 */
195 299 : ulong offset = fd_ulong_sat_mul( slot_duration, slot_delta );
196 299 : long estimate = last_vote_timestamp + (long)(offset / NS_IN_S);
197 :
198 : /* For each timestamp, accumulate the stake from E-2. If the entry
199 : for the timestamp doesn't exist yet, insert it. Otherwise,
200 : update the existing entry.
201 : https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/stake_weighted_timestamp.rs#L46-L53 */
202 299 : ts_eles[ ts_ele_cnt ] = (ts_est_ele_t){
203 299 : .timestamp = estimate,
204 299 : .stake = { .ud=stake_t_2 },
205 299 : };
206 299 : ts_ele_cnt++;
207 :
208 : /* https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/stake_weighted_timestamp.rs#L54 */
209 299 : total_stake += stake_t_2;
210 299 : }
211 :
212 299 : fd_bank_vote_stakes_end_locking_modify( bank );
213 :
214 299 : *total_stake_out = total_stake;
215 299 : *ts_ele_cnt_out = ts_ele_cnt;
216 299 : }
217 :
218 : static void
219 : accum_vote_stakes_vat( fd_bank_t * bank,
220 : fd_runtime_stack_t * runtime_stack,
221 : uint128 * total_stake_out,
222 0 : ulong * ts_ele_cnt_out ) {
223 :
224 0 : ts_est_ele_t * ts_eles = runtime_stack->clock_ts.staked_ts;
225 0 : ulong ts_ele_cnt = 0UL;
226 :
227 0 : uint128 total_stake = 0UL;
228 :
229 0 : fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank );
230 0 : ulong slot_duration = fd_bank_ns_per_slot_get( bank ).ul[0];
231 0 : ulong current_slot = fd_bank_slot_get( bank );
232 :
233 0 : fd_top_votes_t const * top_votes = fd_bank_top_votes_query( bank );
234 0 : FD_TEST( top_votes );
235 :
236 0 : uchar __attribute__((aligned(FD_TOP_VOTES_ITER_ALIGN))) iter_mem[ FD_TOP_VOTES_ITER_FOOTPRINT ];
237 0 : for( fd_top_votes_iter_t * iter = fd_top_votes_iter_init( top_votes, iter_mem );
238 0 : !fd_top_votes_iter_done( top_votes, iter );
239 0 : fd_top_votes_iter_next( top_votes, iter ) ) {
240 0 : fd_pubkey_t pubkey;
241 0 : ulong stake_t_2;
242 0 : ulong last_vote_slot;
243 0 : long last_vote_timestamp;
244 0 : fd_top_votes_iter_ele( top_votes, iter, &pubkey, NULL, &stake_t_2, &last_vote_slot, &last_vote_timestamp );
245 0 : if( FD_UNLIKELY( !stake_t_2 ) ) continue;
246 :
247 : /* https://github.com/anza-xyz/agave/blob/v3.0.0/runtime/src/bank.rs#L2445 */
248 0 : ulong slot_delta;
249 0 : int err = fd_ulong_checked_sub( current_slot, last_vote_slot, &slot_delta );
250 0 : if( FD_UNLIKELY( err ) ) {
251 : /* Don't count vote accounts with a last vote slot that is greater
252 : than the current slot. */
253 0 : continue;
254 0 : }
255 :
256 : /* Don't count vote accounts that haven't voted in the past 432k
257 : slots (length of an epoch).
258 : https://github.com/anza-xyz/agave/blob/v3.0.0/runtime/src/bank.rs#L2446-L2447 */
259 0 : if( FD_UNLIKELY( slot_delta>epoch_schedule->slots_per_epoch ) ) {
260 0 : continue;
261 0 : }
262 :
263 : /* Calculate the timestamp estimate by taking the last vote
264 : timestamp and adding the estimated time since the last vote
265 : (delta from last vote slot to current slot * slot duration).
266 : https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/stake_weighted_timestamp.rs#L44-L45 */
267 0 : ulong offset = fd_ulong_sat_mul( slot_duration, slot_delta );
268 0 : long estimate = last_vote_timestamp + (long)(offset / NS_IN_S);
269 :
270 : /* For each timestamp, accumulate the stake from E-2. If the entry
271 : for the timestamp doesn't exist yet, insert it. Otherwise,
272 : update the existing entry.
273 : https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/stake_weighted_timestamp.rs#L46-L53 */
274 0 : ts_eles[ ts_ele_cnt ] = (ts_est_ele_t){
275 0 : .timestamp = estimate,
276 0 : .stake = { .ud=stake_t_2 },
277 0 : };
278 0 : ts_ele_cnt++;
279 :
280 : /* https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/stake_weighted_timestamp.rs#L54 */
281 0 : total_stake += stake_t_2;
282 0 : }
283 :
284 0 : *total_stake_out = total_stake;
285 0 : *ts_ele_cnt_out = ts_ele_cnt;
286 0 : }
287 :
288 : /* get_timestamp_estimate calculates a timestamp estimate. Does not
289 : modify the slot context. Walks all cached vote accounts (from the
290 : "bank") and calculates a unix timestamp estimate. Returns the
291 : timestamp estimate. spad is used for scratch allocations (allocates
292 : a treap of size FD_SYSVAR_CLOCK_STAKE_WEIGHTS_MAX). Crashes the
293 : process with FD_LOG_ERR on failure (e.g. too many vote accounts).
294 :
295 : https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/bank.rs#L2563-L2601 */
296 : long
297 : get_timestamp_estimate( fd_accdb_user_t * accdb,
298 : fd_funk_txn_xid_t const * xid,
299 : fd_bank_t * bank,
300 : fd_sol_sysvar_clock_t * clock,
301 299 : fd_runtime_stack_t * runtime_stack ) {
302 299 : fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank );
303 299 : ulong slot_duration = fd_bank_ns_per_slot_get( bank ).ul[0];
304 299 : ulong current_slot = fd_bank_slot_get( bank );
305 :
306 299 : ts_est_ele_t * ts_eles = runtime_stack->clock_ts.staked_ts;
307 :
308 : /* https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/stake_weighted_timestamp.rs#L41 */
309 299 : ulong ts_ele_cnt = 0UL;
310 299 : uint128 total_stake = 0UL;
311 :
312 : /* A timestamp estimate is calculated at every slot using the most
313 : recent vote states of voting validators. This estimated is based on
314 : a stake weighted median using the stake as of the end of epoch E-2
315 : if we are currently in epoch E. We do not count vote accounts that
316 : have not voted in an epoch's worth of slots (432k). */
317 :
318 299 : if( FD_FEATURE_ACTIVE_BANK( bank, validator_admission_ticket ) ) {
319 0 : accum_vote_stakes_vat( bank, runtime_stack, &total_stake, &ts_ele_cnt );
320 299 : } else {
321 299 : accum_vote_stakes_no_vat( accdb, xid, bank, runtime_stack, &total_stake, &ts_ele_cnt );
322 299 : }
323 :
324 : /* https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/stake_weighted_timestamp.rs#L56-L58 */
325 299 : if( FD_UNLIKELY( total_stake==0UL ) ) {
326 0 : return 0L;
327 0 : }
328 :
329 299 : sort_stake_ts_inplace( ts_eles, ts_ele_cnt );
330 :
331 : /* Populate estimate with the stake-weighted median timestamp.
332 : https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/stake_weighted_timestamp.rs#L59-L68 */
333 299 : uint128 stake_accumulator = 0;
334 299 : long estimate = 0L;
335 299 : for( ulong i=0UL; i<ts_ele_cnt; i++ ) {
336 299 : stake_accumulator = fd_uint128_sat_add( stake_accumulator, ts_eles[i].stake.ud );
337 299 : if( stake_accumulator>(total_stake/2UL) ) {
338 299 : estimate = ts_eles[ i ].timestamp;
339 299 : break;
340 299 : }
341 299 : }
342 :
343 299 : int const fix_estimate_into_u64 = FD_FEATURE_ACTIVE_BANK( bank, warp_timestamp_again );
344 :
345 : /* Bound estimate by `max_allowable_drift` since the start of the epoch
346 : https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/stake_weighted_timestamp.rs#L69-L99 */
347 299 : ulong epoch_start_slot = fd_epoch_slot0( epoch_schedule, clock->epoch );
348 299 : long epoch_start_timestamp = clock->epoch_start_timestamp;
349 :
350 : /* https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/stake_weighted_timestamp.rs#L71-L72 */
351 299 : ulong poh_estimate_offset = fd_ulong_sat_mul( slot_duration, fd_ulong_sat_sub( current_slot, epoch_start_slot ) );
352 :
353 : /* https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/stake_weighted_timestamp.rs#L73-L77 */
354 299 : ulong estimate_offset;
355 299 : if( fix_estimate_into_u64 ) {
356 299 : estimate_offset = fd_ulong_sat_mul( NS_IN_S, fd_ulong_sat_sub( (ulong)estimate, (ulong)epoch_start_timestamp ) );
357 299 : } else {
358 0 : estimate_offset = fd_ulong_sat_mul( NS_IN_S, (ulong)fd_long_sat_sub( estimate, epoch_start_timestamp ) );
359 0 : }
360 :
361 : /* https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/stake_weighted_timestamp.rs#L78-L81 */
362 299 : ulong max_allowable_drift_fast = fd_ulong_sat_mul( poh_estimate_offset, MAX_ALLOWABLE_DRIFT_FAST_PERCENT ) / 100UL;
363 299 : ulong max_allowable_drift_slow = fd_ulong_sat_mul( poh_estimate_offset, MAX_ALLOWABLE_DRIFT_SLOW_PERCENT ) / 100UL;
364 :
365 : /* https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/stake_weighted_timestamp.rs#L82-L98 */
366 299 : if( estimate_offset>poh_estimate_offset && fd_ulong_sat_sub( estimate_offset, poh_estimate_offset )>max_allowable_drift_slow ) {
367 0 : estimate = fd_long_sat_add(
368 0 : epoch_start_timestamp,
369 0 : fd_long_sat_add( (long)poh_estimate_offset / NS_IN_S, (long)max_allowable_drift_slow / NS_IN_S ) );
370 299 : } else if( estimate_offset<poh_estimate_offset && fd_ulong_sat_sub( poh_estimate_offset, estimate_offset )>max_allowable_drift_fast ) {
371 13 : estimate = fd_long_sat_sub(
372 13 : fd_long_sat_add( epoch_start_timestamp, (long)poh_estimate_offset / NS_IN_S ),
373 13 : (long)max_allowable_drift_fast / NS_IN_S );
374 13 : }
375 :
376 299 : return estimate;
377 299 : }
378 :
379 : /* TODO: This function should be called from genesis bootup as well with
380 : parent_epoch = NULL
381 : https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/bank.rs#L2158-L2215 */
382 : void
383 : fd_sysvar_clock_update( fd_bank_t * bank,
384 : fd_accdb_user_t * accdb,
385 : fd_funk_txn_xid_t const * xid,
386 : fd_capture_ctx_t * capture_ctx,
387 : fd_runtime_stack_t * runtime_stack,
388 299 : ulong const * parent_epoch ) {
389 299 : fd_sol_sysvar_clock_t clock_[1];
390 299 : fd_sol_sysvar_clock_t * clock = fd_sysvar_clock_read( accdb, xid, clock_ );
391 299 : if( FD_UNLIKELY( !clock ) ) FD_LOG_ERR(( "fd_sysvar_clock_read failed" ));
392 :
393 299 : fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank );
394 299 : ulong current_slot = fd_bank_slot_get( bank );
395 299 : ulong current_epoch = fd_slot_to_epoch( epoch_schedule, current_slot, NULL );
396 :
397 : /* https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/bank.rs#L2159 */
398 299 : long unix_timestamp = clock->unix_timestamp;
399 :
400 : /* https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/bank.rs#L2175 */
401 299 : long ancestor_timestamp = clock->unix_timestamp;
402 :
403 : /* TODO: Are we handling slot 0 correctly?
404 : https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/bank.rs#L2176-L2183 */
405 299 : long timestamp_estimate = get_timestamp_estimate( accdb, xid, bank, clock, runtime_stack );
406 :
407 : /* If the timestamp was successfully calculated, use it. It not keep the old one. */
408 299 : if( FD_LIKELY( timestamp_estimate!=0L ) ) {
409 299 : unix_timestamp = timestamp_estimate;
410 :
411 : /* https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/bank.rs#L2180-L2182 */
412 299 : if( timestamp_estimate<ancestor_timestamp ) {
413 0 : unix_timestamp = ancestor_timestamp;
414 0 : }
415 299 : }
416 :
417 : /* https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/bank.rs#L2191-L2197 */
418 299 : long epoch_start_timestamp = (parent_epoch!=NULL && *parent_epoch!=current_epoch) ?
419 2 : unix_timestamp :
420 299 : clock->epoch_start_timestamp;
421 :
422 : /* https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/bank.rs#L2198-L2201 */
423 299 : if( FD_UNLIKELY( current_slot==0UL ) ) {
424 0 : long timestamp_from_genesis = unix_timestamp_from_genesis( bank );
425 0 : unix_timestamp = timestamp_from_genesis;
426 0 : epoch_start_timestamp = timestamp_from_genesis;
427 0 : }
428 :
429 : /* https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/bank.rs#L2202-L2208 */
430 299 : *clock = (fd_sol_sysvar_clock_t){
431 299 : .slot = current_slot,
432 299 : .epoch_start_timestamp = epoch_start_timestamp,
433 299 : .epoch = current_epoch,
434 299 : .leader_schedule_epoch = fd_slot_to_leader_schedule_epoch( epoch_schedule, current_slot ),
435 299 : .unix_timestamp = unix_timestamp,
436 299 : };
437 :
438 : /* https://github.com/anza-xyz/agave/blob/v2.3.7/runtime/src/bank.rs#L2209-L2214 */
439 299 : fd_sysvar_clock_write( bank, accdb, xid, capture_ctx, clock );
440 299 : }
|