Skip to content

Commit d51a133

Browse files
initial commit
1 parent a4589f3 commit d51a133

File tree

5 files changed

+39
-24
lines changed

5 files changed

+39
-24
lines changed

src/discof/replay/fd_replay_tile.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ struct fd_replay_tile {
315315
TODO: Should be replaced by tile-level allocations. */
316316
fd_spad_t * runtime_spad;
317317

318+
fd_runtime_mem_t runtime_mem;
319+
318320
/* Buffer to store vote towers that need to be published to the Tower
319321
tile. */
320322
ulong vote_tower_out_idx; /* index of vote tower to publish next */
@@ -648,6 +650,7 @@ replay_block_start( fd_replay_tile_t * ctx,
648650
&xid,
649651
ctx->capture_ctx,
650652
ctx->runtime_spad,
653+
&ctx->runtime_mem,
651654
&is_epoch_boundary );
652655
if( FD_UNLIKELY( is_epoch_boundary ) ) publish_stake_weights( ctx, stem, bank, 1 );
653656

@@ -849,6 +852,7 @@ prepare_leader_bank( fd_replay_tile_t * ctx,
849852
&xid,
850853
ctx->capture_ctx,
851854
ctx->runtime_spad,
855+
&ctx->runtime_mem,
852856
&is_epoch_boundary );
853857
if( FD_UNLIKELY( is_epoch_boundary ) ) publish_stake_weights( ctx, stem, ctx->leader_bank, 1 );
854858

@@ -955,7 +959,7 @@ init_after_snapshot( fd_replay_tile_t * ctx ) {
955959
/* FIXME: This branch does not set up a new block exec ctx
956960
properly. Needs to do whatever prepare_new_block_execution
957961
does, but just hacking that in breaks stuff. */
958-
fd_runtime_update_leaders( bank, ctx->runtime_spad );
962+
fd_runtime_update_leaders( bank, ctx->runtime_mem.epoch_weights_mem );
959963

960964
ulong hashcnt_per_slot = fd_bank_hashes_per_tick_get( bank ) * fd_bank_ticks_per_slot_get( bank );
961965
fd_hash_t * poh = fd_bank_poh_modify( bank );
@@ -1166,7 +1170,7 @@ boot_genesis( fd_replay_tile_t * ctx,
11661170
}
11671171
fd_funk_txn_xid_t xid = { .ul = { 0UL, 0UL } };
11681172

1169-
fd_runtime_read_genesis( ctx->banks, bank, ctx->funk, &xid, NULL, fd_type_pun_const( genesis_hash ), fd_type_pun_const( lthash ), genesis, ctx->runtime_spad );
1173+
fd_runtime_read_genesis( ctx->banks, bank, ctx->funk, &xid, NULL, fd_type_pun_const( genesis_hash ), fd_type_pun_const( lthash ), genesis, ctx->runtime_spad, &ctx->runtime_mem );
11701174

11711175
static const fd_txncache_fork_id_t txncache_root = { .val = USHORT_MAX };
11721176
bank->txncache_fork_id = fd_txncache_attach_child( ctx->txncache, txncache_root );
@@ -1285,7 +1289,7 @@ on_snapshot_message( fd_replay_tile_t * ctx,
12851289

12861290
fd_features_restore( bank, ctx->funk, &xid );
12871291

1288-
fd_runtime_update_leaders( bank, ctx->runtime_spad );
1292+
fd_runtime_update_leaders( bank, ctx->runtime_mem.epoch_weights_mem );
12891293

12901294
fd_block_id_ele_t * block_id_ele = &ctx->block_id_arr[ 0 ];
12911295
FD_TEST( block_id_ele );

src/flamenco/runtime/fd_runtime.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ fd_runtime_update_slots_per_epoch( fd_bank_t * bank,
116116

117117
void
118118
fd_runtime_update_leaders( fd_bank_t * bank,
119-
fd_spad_t * runtime_spad ) {
120-
121-
FD_SPAD_FRAME_BEGIN( runtime_spad ) {
119+
uchar * epoch_weights_mem ) {
122120

123121
fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank );
124122

@@ -127,8 +125,7 @@ fd_runtime_update_leaders( fd_bank_t * bank,
127125
ulong slot_cnt = fd_epoch_slot_cnt( epoch_schedule, epoch );
128126

129127
fd_vote_states_t const * vote_states_prev_prev = fd_bank_vote_states_prev_prev_locking_query( bank );
130-
ulong vote_acc_cnt = fd_vote_states_cnt( vote_states_prev_prev ) ;
131-
fd_vote_stake_weight_t * epoch_weights = fd_spad_alloc_check( runtime_spad, alignof(fd_vote_stake_weight_t), vote_acc_cnt * sizeof(fd_vote_stake_weight_t) );
128+
fd_vote_stake_weight_t * epoch_weights = fd_type_pun( epoch_weights_mem );
132129
ulong stake_weight_cnt = fd_stake_weights_by_node( vote_states_prev_prev, epoch_weights );
133130
fd_bank_vote_states_prev_prev_end_locking_query( bank );
134131

@@ -146,9 +143,8 @@ fd_runtime_update_leaders( fd_bank_t * bank,
146143
}
147144

148145
ulong vote_keyed_lsched = (ulong)fd_runtime_should_use_vote_keyed_leader_schedule( bank );
149-
void * epoch_leaders_mem = fd_bank_epoch_leaders_locking_modify( bank );
150146
fd_epoch_leaders_t * leaders = fd_epoch_leaders_join( fd_epoch_leaders_new(
151-
epoch_leaders_mem,
147+
fd_bank_epoch_leaders_locking_modify( bank ),
152148
epoch,
153149
slot0,
154150
slot_cnt,
@@ -161,7 +157,6 @@ fd_runtime_update_leaders( fd_bank_t * bank,
161157
}
162158
fd_bank_epoch_leaders_end_locking_modify( bank );
163159
}
164-
} FD_SPAD_FRAME_END;
165160
}
166161

167162
/******************************************************************************/
@@ -1488,7 +1483,8 @@ fd_runtime_process_new_epoch( fd_banks_t * banks,
14881483
fd_funk_txn_xid_t const * xid,
14891484
fd_capture_ctx_t * capture_ctx,
14901485
ulong parent_epoch,
1491-
fd_spad_t * runtime_spad ) {
1486+
fd_spad_t * runtime_spad,
1487+
fd_runtime_mem_t * runtime_mem ) {
14921488
FD_LOG_NOTICE(( "fd_process_new_epoch start, epoch: %lu, slot: %lu", fd_bank_epoch_get( bank ), fd_bank_slot_get( bank ) ));
14931489

14941490
FD_SPAD_FRAME_BEGIN( runtime_spad ) {
@@ -1574,7 +1570,7 @@ fd_runtime_process_new_epoch( fd_banks_t * banks,
15741570

15751571
/* Update current leaders using epoch_stakes (new T-2 stakes) */
15761572

1577-
fd_runtime_update_leaders( bank, runtime_spad );
1573+
fd_runtime_update_leaders( bank, runtime_mem->epoch_weights_mem );
15781574

15791575
FD_LOG_NOTICE(( "fd_process_new_epoch end" ));
15801576

@@ -1878,7 +1874,8 @@ fd_runtime_process_genesis_block( fd_bank_t * bank,
18781874
fd_funk_t * funk,
18791875
fd_funk_txn_xid_t const * xid,
18801876
fd_capture_ctx_t * capture_ctx,
1881-
fd_spad_t * runtime_spad ) {
1877+
fd_spad_t * runtime_spad,
1878+
fd_runtime_mem_t * runtime_mem ) {
18821879

18831880
fd_hash_t * poh = fd_bank_poh_modify( bank );
18841881
ulong hashcnt_per_slot = fd_bank_hashes_per_tick_get( bank ) * fd_bank_ticks_per_slot_get( bank );
@@ -1904,7 +1901,7 @@ fd_runtime_process_genesis_block( fd_bank_t * bank,
19041901

19051902
fd_sysvar_slot_history_update( bank, funk, xid, capture_ctx );
19061903

1907-
fd_runtime_update_leaders( bank, runtime_spad );
1904+
fd_runtime_update_leaders( bank, runtime_mem->epoch_weights_mem );
19081905

19091906
fd_runtime_freeze( bank, funk, xid, capture_ctx );
19101907

@@ -1934,7 +1931,8 @@ fd_runtime_read_genesis( fd_banks_t * banks,
19341931
fd_hash_t const * genesis_hash,
19351932
fd_lthash_value_t const * genesis_lthash,
19361933
fd_genesis_solana_global_t const * genesis_block,
1937-
fd_spad_t * runtime_spad ) {
1934+
fd_spad_t * runtime_spad,
1935+
fd_runtime_mem_t * runtime_mem ) {
19381936
FD_SPAD_FRAME_BEGIN( runtime_spad ) {
19391937

19401938
fd_lthash_value_t * lthash = fd_bank_lthash_locking_modify( bank );
@@ -1966,7 +1964,7 @@ fd_runtime_read_genesis( fd_banks_t * banks,
19661964
block. In practice, this updates some bank fields (notably the
19671965
poh and bank hash). */
19681966

1969-
int err = fd_runtime_process_genesis_block( bank, funk, xid, capture_ctx, runtime_spad );
1967+
int err = fd_runtime_process_genesis_block( bank, funk, xid, capture_ctx, runtime_spad, runtime_mem );
19701968
if( FD_UNLIKELY( err ) ) FD_LOG_CRIT(( "genesis slot 0 execute failed with error %d", err ));
19711969

19721970
} FD_SPAD_FRAME_END;
@@ -1987,6 +1985,7 @@ fd_runtime_block_pre_execute_process_new_epoch( fd_banks_t * banks,
19871985
fd_funk_txn_xid_t const * xid,
19881986
fd_capture_ctx_t * capture_ctx,
19891987
fd_spad_t * runtime_spad,
1988+
fd_runtime_mem_t * runtime_mem,
19901989
int * is_epoch_boundary ) {
19911990

19921991
ulong const slot = fd_bank_slot_get( bank );
@@ -2003,7 +2002,7 @@ fd_runtime_block_pre_execute_process_new_epoch( fd_banks_t * banks,
20032002

20042003
if( FD_UNLIKELY( prev_epoch<new_epoch || !slot_idx ) ) {
20052004
FD_LOG_DEBUG(( "Epoch boundary starting" ));
2006-
fd_runtime_process_new_epoch( banks, bank, funk, xid, capture_ctx, prev_epoch, runtime_spad );
2005+
fd_runtime_process_new_epoch( banks, bank, funk, xid, capture_ctx, prev_epoch, runtime_spad, runtime_mem );
20072006
*is_epoch_boundary = 1;
20082007
}
20092008
} else {

src/flamenco/runtime/fd_runtime.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ fd_runtime_compute_max_tick_height( ulong ticks_per_slot,
259259

260260
void
261261
fd_runtime_update_leaders( fd_bank_t * bank,
262-
fd_spad_t * runtime_spad );
262+
uchar * epoch_weights_mem );
263263

264264
/* TODO: Invoked by fd_executor: layering violation. Rent logic is deprecated
265265
and will be torn out entirely very soon. */
@@ -490,6 +490,7 @@ fd_runtime_block_pre_execute_process_new_epoch( fd_banks_t * banks,
490490
fd_funk_txn_xid_t const * xid,
491491
fd_capture_ctx_t * capture_ctx,
492492
fd_spad_t * runtime_spad,
493+
fd_runtime_mem_t * runtime_mem,
493494
int * is_epoch_boundary );
494495

495496
/* `fd_runtime_update_program_cache()` is responsible for updating the
@@ -519,7 +520,8 @@ fd_runtime_read_genesis( fd_banks_t * banks,
519520
fd_hash_t const * genesis_hash,
520521
fd_lthash_value_t const * genesis_lthash,
521522
fd_genesis_solana_global_t const * genesis_block,
522-
fd_spad_t * runtime_spad );
523+
fd_spad_t * runtime_spad,
524+
fd_runtime_mem_t * runtime_mem );
523525

524526

525527
/* Returns whether the specified epoch should use the new vote account

src/flamenco/runtime/fd_runtime_const.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ FD_PROTOTYPES_BEGIN
4545

4646
#define FD_RUNTIME_ACC_SZ_MAX (10UL<<20) /* 10MiB */
4747

48+
struct fd_runtime_mem {
49+
uchar __attribute__((aligned(alignof(fd_vote_stake_weight_t)))) epoch_weights_mem[ FD_RUNTIME_MAX_VOTE_ACCOUNTS * sizeof(fd_vote_stake_weight_t) ];
50+
uchar __attribute__((aligned(128UL))) stake_pool_mem [ FD_RUNTIME_MAX_VOTE_ACCOUNTS * 64UL ]; /* TODO: Don't use magic number */
51+
};
52+
typedef struct fd_runtime_mem fd_runtime_mem_t;
53+
4854
FD_PROTOTYPES_END
4955

5056
#endif /* HEADER_fd_src_flamenco_runtime_fd_runtime_const_h */

src/flamenco/runtime/tests/fd_block_harness.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ fd_runtime_fuzz_block_ctx_destroy( fd_solfuzz_runner_t * runner ) {
168168
Returns block_info on success and NULL on failure. */
169169
static fd_runtime_block_info_t *
170170
fd_runtime_fuzz_block_ctx_create( fd_solfuzz_runner_t * runner,
171+
fd_runtime_mem_t * runtime_mem,
171172
fd_exec_test_block_context_t const * test_ctx ) {
172173
fd_funk_t * funk = runner->funk;
173174
fd_bank_t * bank = runner->bank;
@@ -320,7 +321,7 @@ fd_runtime_fuzz_block_ctx_create( fd_solfuzz_runner_t * runner,
320321
fd_bank_vote_states_prev_prev_end_locking_modify( bank );
321322

322323
/* Update leader schedule */
323-
fd_runtime_update_leaders( bank, runner->spad );
324+
fd_runtime_update_leaders( bank, runtime_mem->epoch_weights_mem );
324325

325326
/* Initialize the blockhash queue and recent blockhashes sysvar from the input blockhash queue */
326327
ulong blockhash_seed; FD_TEST( fd_rng_secure( &blockhash_seed, sizeof(ulong) ) );
@@ -438,6 +439,7 @@ fd_runtime_fuzz_block_ctx_create( fd_solfuzz_runner_t * runner,
438439
and executes it against the runtime. Returns the execution result. */
439440
static int
440441
fd_runtime_fuzz_block_ctx_exec( fd_solfuzz_runner_t * runner,
442+
fd_runtime_mem_t * runtime_mem,
441443
fd_funk_txn_xid_t const * xid,
442444
fd_runtime_block_info_t * block_info ) {
443445
int res = 0;
@@ -461,7 +463,7 @@ fd_runtime_fuzz_block_ctx_exec( fd_solfuzz_runner_t * runner,
461463
/* Process new epoch may push a new spad frame onto the runtime spad. We should make sure this frame gets
462464
cleared (if it was allocated) before executing the block. */
463465
int is_epoch_boundary = 0;
464-
fd_runtime_block_pre_execute_process_new_epoch( runner->banks, runner->bank, runner->funk, xid, capture_ctx, runner->spad, &is_epoch_boundary );
466+
fd_runtime_block_pre_execute_process_new_epoch( runner->banks, runner->bank, runner->funk, xid, capture_ctx, runner->spad, runtime_mem, &is_epoch_boundary );
465467

466468
res = fd_runtime_block_execute_prepare( runner->bank, runner->funk, xid, capture_ctx, runner->spad );
467469
if( FD_UNLIKELY( res ) ) {
@@ -520,8 +522,10 @@ fd_solfuzz_block_run( fd_solfuzz_runner_t * runner,
520522
fd_exec_test_block_effects_t ** output = fd_type_pun( output_ );
521523

522524
FD_SPAD_FRAME_BEGIN( runner->spad ) {
525+
fd_runtime_mem_t * runtime_mem = fd_spad_alloc( runner->spad, alignof(fd_runtime_mem_t), sizeof(fd_runtime_mem_t) );
526+
523527
/* Set up the block execution context */
524-
fd_runtime_block_info_t * block_info = fd_runtime_fuzz_block_ctx_create( runner, input );
528+
fd_runtime_block_info_t * block_info = fd_runtime_fuzz_block_ctx_create( runner, runtime_mem, input );
525529
if( block_info==NULL ) {
526530
fd_runtime_fuzz_block_ctx_destroy( runner );
527531
return 0;
@@ -530,7 +534,7 @@ fd_solfuzz_block_run( fd_solfuzz_runner_t * runner,
530534
fd_funk_txn_xid_t xid = { .ul = { fd_bank_slot_get( runner->bank ), fd_bank_slot_get( runner->bank ) } };
531535

532536
/* Execute the constructed block against the runtime. */
533-
int res = fd_runtime_fuzz_block_ctx_exec( runner, &xid, block_info );
537+
int res = fd_runtime_fuzz_block_ctx_exec( runner, runtime_mem, &xid, block_info );
534538

535539
/* Start saving block exec results */
536540
FD_SCRATCH_ALLOC_INIT( l, output_buf );

0 commit comments

Comments
 (0)