Skip to content

Commit a869533

Browse files
jvarela-jump0x0ece
authored andcommitted
firedancer-dev: repair profiler light - update
1 parent e35d048 commit a869533

File tree

2 files changed

+70
-58
lines changed

2 files changed

+70
-58
lines changed

src/discof/shredcap/fd_shredcap_tile.c

Lines changed: 65 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "../../util/pod/fd_pod_format.h"
77
#include "../../disco/fd_disco.h"
88
#include "../../discof/fd_discof.h"
9+
#include "../../discof/restore/utils/fd_ssmsg.h"
10+
#include "../../discof/restore/utils/fd_ssmanifest_parser.h"
911
#include "../../flamenco/stakes/fd_stakes.h"
1012
#include "../../flamenco/runtime/sysvar/fd_sysvar_epoch_schedule.h"
1113
#include "../../disco/fd_disco.h"
@@ -225,69 +227,72 @@ scratch_footprint( fd_topo_tile_t const * tile ) {
225227
return FD_LAYOUT_FINI( l, scratch_align() );
226228
}
227229

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;
249241
}
250242

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+
}
251262
static void
252263
publish_stake_weights( fd_capture_tile_ctx_t * ctx,
253264
fd_stem_context_t * stem,
254-
fd_solana_manifest_global_t const * manifest ) {
265+
fd_snapshot_manifest_t const * manifest ) {
255266
FD_SPAD_FRAME_BEGIN( ctx->shared_spad ) {
256267

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 ) {
268279
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 );
270281
ulong stake_weights_sig = 4UL;
271282
fd_stem_publish( stem, 0UL, stake_weights_sig, ctx->stake_out->chunk, stake_weights_sz, 0UL, 0UL, fd_frag_meta_ts_comp( fd_tickcount() ) );
272283
ctx->stake_out->chunk = fd_dcache_compact_next( ctx->stake_out->chunk, stake_weights_sz, ctx->stake_out->chunk0, ctx->stake_out->wmark );
273284
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]));
274285
}
275286

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 ) {
283289
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 );
285291
ulong stake_weights_sig = 4UL;
286292
fd_stem_publish( stem, 0UL, stake_weights_sig, ctx->stake_out->chunk, stake_weights_sz, 0UL, 0UL, fd_frag_meta_ts_comp( fd_tickcount() ) );
287293
ctx->stake_out->chunk = fd_dcache_compact_next( ctx->stake_out->chunk, stake_weights_sz, ctx->stake_out->chunk0, ctx->stake_out->wmark );
288294
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]));
289295
}
290-
fd_bank_next_epoch_stakes_end_locking_query( slot_ctx->bank );
291296

292297
} FD_SPAD_FRAME_END;
293298
}
@@ -446,7 +451,6 @@ after_credit( fd_capture_tile_ctx_t * ctx,
446451
if( FD_LIKELY( !!strcmp( ctx->manifest_path, "") ) ) {
447452
/* ctx->manifest_spad will hold the processed manifest. */
448453
fd_spad_reset( ctx->manifest_spad );
449-
fd_spad_push( ctx->manifest_spad );
450454
/* do not pop from ctx->manifest_spad, the manifest needs
451455
to remain available until a new manifest is processed. */
452456

@@ -457,26 +461,29 @@ after_credit( fd_capture_tile_ctx_t * ctx,
457461
}
458462
FD_LOG_NOTICE(( "manifest %s.", ctx->manifest_path ));
459463

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+
462470
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;
466473
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;
469474

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 ));
475483

476-
fd_fseq_update( ctx->manifest_wmark, manifest->bank.slot /*root_slot*/ );
484+
fd_fseq_update( ctx->manifest_wmark, manifest->slot );
477485

478486
publish_stake_weights( ctx, stem, manifest );
479-
480487
//*charge_busy = 0;
481488
}
482489
/* No need to strcmp every time after_credit is called. */

src/flamenco/types/fd_types_custom.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ struct fd_vote_stake_weight {
222222
};
223223
typedef struct fd_vote_stake_weight fd_vote_stake_weight_t;
224224

225+
#define SORT_NAME sort_vote_weights_by_stake_vote
226+
#define SORT_KEY_T fd_vote_stake_weight_t
227+
#define SORT_BEFORE(a,b) ((a).stake > (b).stake ? 1 : ((a).stake < (b).stake ? 0 : memcmp( (a).vote_key.uc, (b).vote_key.uc, 32UL )>0))
228+
#include "../../util/tmpl/fd_sort.c"
229+
225230
struct fd_stake_weight {
226231
fd_pubkey_t key; /* validator identity pubkey */
227232
ulong stake; /* total stake by identity */

0 commit comments

Comments
 (0)