6
6
#include "../../util/pod/fd_pod_format.h"
7
7
#include "../../disco/fd_disco.h"
8
8
#include "../../discof/fd_discof.h"
9
+ #include "../../discof/restore/utils/fd_ssmsg.h"
10
+ #include "../../discof/restore/utils/fd_ssmanifest_parser.h"
9
11
#include "../../flamenco/stakes/fd_stakes.h"
10
12
#include "../../flamenco/runtime/sysvar/fd_sysvar_epoch_schedule.h"
11
13
#include "../../disco/fd_disco.h"
@@ -225,69 +227,72 @@ scratch_footprint( fd_topo_tile_t const * tile ) {
225
227
return FD_LAYOUT_FINI ( l , scratch_align () );
226
228
}
227
229
228
- static inline ulong
229
- generate_stake_weight_msg ( fd_exec_slot_ctx_t * slot_ctx ,
230
- fd_spad_t * runtime_spad ,
231
- ulong epoch ,
232
- fd_vote_accounts_global_t const * vote_accounts ,
233
- ulong * stake_weight_msg_out ) {
234
-
235
- fd_stake_weight_msg_t * stake_weight_msg = (fd_stake_weight_msg_t * )fd_type_pun ( stake_weight_msg_out );
236
- fd_vote_stake_weight_t * stake_weights = stake_weight_msg -> weights ;
237
- ulong stake_weight_idx = fd_stake_weights_by_node ( vote_accounts ,
238
- stake_weights ,
239
- runtime_spad );
240
- fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query ( slot_ctx -> bank );
241
-
242
- stake_weight_msg -> epoch = epoch ;
243
- stake_weight_msg -> staked_cnt = stake_weight_idx ;
244
- stake_weight_msg -> start_slot = fd_epoch_slot0 ( epoch_schedule , stake_weight_msg_out [0 ] );
245
- stake_weight_msg -> slot_cnt = epoch_schedule -> slots_per_epoch ;
246
- stake_weight_msg -> excluded_stake = 0UL ;
247
-
248
- return 5 * sizeof (ulong ) + (stake_weight_idx * sizeof (fd_stake_weight_t ));
230
+ ulong
231
+ fd_stake_weights_by_node_custom ( fd_snapshot_manifest_epoch_stakes_t const * epoch_stakes ,
232
+ fd_vote_stake_weight_t * weights ) {
233
+
234
+ for ( ulong i = 0UL ; i < epoch_stakes -> vote_stakes_len ; i ++ ) {
235
+ weights [ i ].stake = epoch_stakes -> vote_stakes [ i ].stake ;
236
+ memcpy ( weights [ i ].id_key .uc , epoch_stakes -> vote_stakes [ i ].identity , sizeof (fd_pubkey_t ) );
237
+ memcpy ( weights [ i ].vote_key .uc , epoch_stakes -> vote_stakes [ i ].vote , sizeof (fd_pubkey_t ) );
238
+ }
239
+ sort_vote_weights_by_stake_vote_inplace ( weights , epoch_stakes -> vote_stakes_len );
240
+ return epoch_stakes -> vote_stakes_len ;
249
241
}
250
242
243
+ static inline ulong
244
+ generate_stake_weight_msg ( ulong epoch ,
245
+ fd_epoch_schedule_t const * epoch_schedule ,
246
+ fd_snapshot_manifest_epoch_stakes_t const * epoch_stakes ,
247
+ ulong * stake_weight_msg_out ) {
248
+
249
+ fd_stake_weight_msg_t * stake_weight_msg = (fd_stake_weight_msg_t * )fd_type_pun ( stake_weight_msg_out );
250
+ fd_vote_stake_weight_t * stake_weights = stake_weight_msg -> weights ;
251
+ ulong stake_weight_idx = fd_stake_weights_by_node_custom ( epoch_stakes , stake_weights );
252
+
253
+ stake_weight_msg -> epoch = epoch ;
254
+ stake_weight_msg -> staked_cnt = stake_weight_idx ;
255
+ stake_weight_msg -> start_slot = fd_epoch_slot0 ( epoch_schedule , epoch );
256
+ stake_weight_msg -> slot_cnt = epoch_schedule -> slots_per_epoch ;
257
+ stake_weight_msg -> excluded_stake = 0UL ;
258
+ stake_weight_msg -> vote_keyed_lsched = 0UL ;
259
+
260
+ return fd_stake_weight_msg_sz ( epoch_stakes -> vote_stakes_len );
261
+ }
251
262
static void
252
263
publish_stake_weights ( fd_capture_tile_ctx_t * ctx ,
253
264
fd_stem_context_t * stem ,
254
- fd_solana_manifest_global_t const * manifest ) {
265
+ fd_snapshot_manifest_t const * manifest ) {
255
266
FD_SPAD_FRAME_BEGIN ( ctx -> shared_spad ) {
256
267
257
- /* Process the manifest. */
258
- ulong epoch = manifest -> bank . stakes . epoch ;
259
- fd_exec_slot_ctx_t * slot_ctx = ctx -> manifest_exec_slot_ctx ;
260
- fd_exec_slot_ctx_t * ret = fd_exec_slot_ctx_recover ( slot_ctx , manifest ) ;
261
- FD_TEST ( ret == slot_ctx ) ;
262
-
263
- /* Publish current epoch. */
264
- fd_vote_accounts_global_t const * vote_accounts = fd_bank_epoch_stakes_locking_query ( slot_ctx -> bank );
265
- fd_vote_accounts_pair_global_t_mapnode_t * epoch_stakes_root = fd_vote_accounts_vote_accounts_root_join ( vote_accounts );
266
-
267
- if ( epoch_stakes_root != NULL ) {
268
+ /* Process the schedule from manifest. */
269
+ fd_epoch_schedule_t schedule [ 1 ] ;
270
+ schedule [ 0 ]. slots_per_epoch = manifest -> epoch_schedule_params . slots_per_epoch ;
271
+ schedule [ 0 ]. leader_schedule_slot_offset = manifest -> epoch_schedule_params . leader_schedule_slot_offset ;
272
+ schedule [ 0 ]. warmup = manifest -> epoch_schedule_params . warmup ;
273
+ schedule [ 0 ]. first_normal_epoch = manifest -> epoch_schedule_params . first_normal_epoch ;
274
+ schedule [ 0 ]. first_normal_slot = manifest -> epoch_schedule_params . first_normal_slot ;
275
+ ulong epoch = fd_slot_to_epoch ( schedule , manifest -> slot , NULL );
276
+
277
+ /* current epoch */
278
+ if ( 1 ) {
268
279
ulong * stake_weights_msg = fd_chunk_to_laddr ( ctx -> stake_out -> mem , ctx -> stake_out -> chunk );
269
- ulong stake_weights_sz = generate_stake_weight_msg ( slot_ctx , ctx -> shared_spad , epoch , vote_accounts , stake_weights_msg );
280
+ ulong stake_weights_sz = generate_stake_weight_msg ( epoch , schedule , & manifest -> epoch_stakes [ 0 ] , stake_weights_msg );
270
281
ulong stake_weights_sig = 4UL ;
271
282
fd_stem_publish ( stem , 0UL , stake_weights_sig , ctx -> stake_out -> chunk , stake_weights_sz , 0UL , 0UL , fd_frag_meta_ts_comp ( fd_tickcount () ) );
272
283
ctx -> stake_out -> chunk = fd_dcache_compact_next ( ctx -> stake_out -> chunk , stake_weights_sz , ctx -> stake_out -> chunk0 , ctx -> stake_out -> wmark );
273
284
FD_LOG_NOTICE (("sending current epoch stake weights - epoch: %lu, stake_weight_cnt: %lu, start_slot: %lu, slot_cnt: %lu" , stake_weights_msg [0 ], stake_weights_msg [1 ], stake_weights_msg [2 ], stake_weights_msg [3 ]));
274
285
}
275
286
276
- fd_bank_epoch_stakes_end_locking_query ( slot_ctx -> bank );
277
-
278
- /* Publish next epoch. */
279
- fd_vote_accounts_global_t const * next_vote_accounts = fd_bank_next_epoch_stakes_locking_query ( slot_ctx -> bank );
280
- fd_vote_accounts_pair_global_t_mapnode_t * next_epoch_stakes_root = fd_vote_accounts_vote_accounts_root_join ( next_vote_accounts );
281
-
282
- if ( next_epoch_stakes_root != NULL ) {
287
+ /* next current epoch */
288
+ if ( 1 ) {
283
289
ulong * stake_weights_msg = fd_chunk_to_laddr ( ctx -> stake_out -> mem , ctx -> stake_out -> chunk );
284
- ulong stake_weights_sz = generate_stake_weight_msg ( slot_ctx , ctx -> shared_spad , epoch + 1 , next_vote_accounts , stake_weights_msg );
290
+ ulong stake_weights_sz = generate_stake_weight_msg ( epoch + 1 , schedule , & manifest -> epoch_stakes [ 1 ] , stake_weights_msg );
285
291
ulong stake_weights_sig = 4UL ;
286
292
fd_stem_publish ( stem , 0UL , stake_weights_sig , ctx -> stake_out -> chunk , stake_weights_sz , 0UL , 0UL , fd_frag_meta_ts_comp ( fd_tickcount () ) );
287
293
ctx -> stake_out -> chunk = fd_dcache_compact_next ( ctx -> stake_out -> chunk , stake_weights_sz , ctx -> stake_out -> chunk0 , ctx -> stake_out -> wmark );
288
294
FD_LOG_NOTICE (("sending next epoch stake weights - epoch: %lu, stake_weight_cnt: %lu, start_slot: %lu, slot_cnt: %lu" , stake_weights_msg [0 ], stake_weights_msg [1 ], stake_weights_msg [2 ], stake_weights_msg [3 ]));
289
295
}
290
- fd_bank_next_epoch_stakes_end_locking_query ( slot_ctx -> bank );
291
296
292
297
} FD_SPAD_FRAME_END ;
293
298
}
@@ -446,7 +451,6 @@ after_credit( fd_capture_tile_ctx_t * ctx,
446
451
if ( FD_LIKELY ( !!strcmp ( ctx -> manifest_path , "" ) ) ) {
447
452
/* ctx->manifest_spad will hold the processed manifest. */
448
453
fd_spad_reset ( ctx -> manifest_spad );
449
- fd_spad_push ( ctx -> manifest_spad );
450
454
/* do not pop from ctx->manifest_spad, the manifest needs
451
455
to remain available until a new manifest is processed. */
452
456
@@ -457,26 +461,29 @@ after_credit( fd_capture_tile_ctx_t * ctx,
457
461
}
458
462
FD_LOG_NOTICE (( "manifest %s." , ctx -> manifest_path ));
459
463
460
- fd_solana_manifest_global_t * manifest = NULL ;
461
- int err = 0 ;
464
+ fd_snapshot_manifest_t * manifest = NULL ;
465
+ FD_SPAD_FRAME_BEGIN ( ctx -> manifest_spad ) {
466
+ manifest = fd_spad_alloc ( ctx -> manifest_spad , alignof(fd_snapshot_manifest_t ), sizeof (fd_snapshot_manifest_t ) );
467
+ } FD_SPAD_FRAME_END ;
468
+ FD_TEST ( manifest );
469
+
462
470
FD_SPAD_FRAME_BEGIN ( ctx -> shared_spad ) {
463
- /* alloc_max is slightly less than manifest_load_footprint(). */
464
- uchar * buf = fd_spad_alloc ( ctx -> shared_spad , manifest_load_align (), manifest_load_footprint () );
465
- ulong buf_sz = 0 ;
471
+ uchar * buf = fd_spad_alloc ( ctx -> shared_spad , manifest_load_align (), manifest_load_footprint () );
472
+ ulong buf_sz = 0 ;
466
473
FD_TEST ( !fd_io_read ( fd , buf /*dst*/ , 0 /*dst_min*/ , manifest_load_footprint ()- 1UL /*dst_max*/ , & buf_sz ) );
467
- manifest = fd_bincode_decode_spad_global ( solana_manifest , ctx -> manifest_spad , buf , buf_sz , & err );
468
- } FD_SPAD_FRAME_END ;
469
474
470
- if ( FD_UNLIKELY ( err ) ) {
471
- FD_LOG_WARNING (( "fd_solana_manifest_decode failed (%d)" , err ));
472
- return ;
473
- }
474
- FD_LOG_NOTICE (( "manifest bank slot %lu" , manifest -> bank .slot ));
475
+ fd_ssmanifest_parser_t * parser = fd_ssmanifest_parser_join ( fd_ssmanifest_parser_new ( aligned_alloc (
476
+ fd_ssmanifest_parser_align (), fd_ssmanifest_parser_footprint ( 1UL <<24UL ) ), 1UL <<24UL , 42UL ) );
477
+ FD_TEST ( parser );
478
+ fd_ssmanifest_parser_init ( parser , manifest );
479
+ int parser_err = fd_ssmanifest_parser_consume ( parser , buf , buf_sz );
480
+ if ( FD_UNLIKELY ( parser_err ) ) FD_LOG_ERR (( "fd_ssmanifest_parser_consume failed (%d)" , parser_err ));
481
+ } FD_SPAD_FRAME_END ;
482
+ FD_LOG_NOTICE (( "manifest bank slot %lu" , manifest -> slot ));
475
483
476
- fd_fseq_update ( ctx -> manifest_wmark , manifest -> bank . slot /*root_slot*/ );
484
+ fd_fseq_update ( ctx -> manifest_wmark , manifest -> slot );
477
485
478
486
publish_stake_weights ( ctx , stem , manifest );
479
-
480
487
//*charge_busy = 0;
481
488
}
482
489
/* No need to strcmp every time after_credit is called. */
0 commit comments