Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/discof/replay/fd_replay_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ struct fd_replay_tile {
TODO: Should be replaced by tile-level allocations. */
fd_spad_t * runtime_spad;

fd_runtime_mem_t runtime_mem;

/* Buffer to store vote towers that need to be published to the Tower
tile. */
ulong vote_tower_out_idx; /* index of vote tower to publish next */
Expand Down Expand Up @@ -648,10 +650,11 @@ replay_block_start( fd_replay_tile_t * ctx,
&xid,
ctx->capture_ctx,
ctx->runtime_spad,
&ctx->runtime_mem,
&is_epoch_boundary );
if( FD_UNLIKELY( is_epoch_boundary ) ) publish_stake_weights( ctx, stem, bank, 1 );

int res = fd_runtime_block_execute_prepare( bank, ctx->funk, &xid, ctx->capture_ctx, ctx->runtime_spad );
int res = fd_runtime_block_execute_prepare( bank, ctx->funk, &xid, ctx->capture_ctx, &ctx->runtime_mem );
if( FD_UNLIKELY( res!=FD_RUNTIME_EXECUTE_SUCCESS ) ) {
FD_LOG_CRIT(( "block prep execute failed" ));
}
Expand Down Expand Up @@ -762,10 +765,10 @@ replay_block_finalize( fd_replay_tile_t * ctx,
break;
}
int rc = fd_bank_hash_cmp_check( bank_hash_cmp, cmp_slot );
switch ( rc ) {
switch( rc ) {
case -1:
/* Mismatch */
FD_LOG_WARNING(( "Bank hash mismatch on slot: %lu. Halting.", cmp_slot ));
FD_LOG_WARNING(( "Bank hash mismatch on slot: %lu.", cmp_slot ));
break;
case 0:
/* Not ready */
Expand Down Expand Up @@ -849,10 +852,11 @@ prepare_leader_bank( fd_replay_tile_t * ctx,
&xid,
ctx->capture_ctx,
ctx->runtime_spad,
&ctx->runtime_mem,
&is_epoch_boundary );
if( FD_UNLIKELY( is_epoch_boundary ) ) publish_stake_weights( ctx, stem, ctx->leader_bank, 1 );

int res = fd_runtime_block_execute_prepare( ctx->leader_bank, ctx->funk, &xid, ctx->capture_ctx, ctx->runtime_spad );
int res = fd_runtime_block_execute_prepare( ctx->leader_bank, ctx->funk, &xid, ctx->capture_ctx, &ctx->runtime_mem );
if( FD_UNLIKELY( res!=FD_RUNTIME_EXECUTE_SUCCESS ) ) {
FD_LOG_CRIT(( "block prep execute failed" ));
}
Expand Down Expand Up @@ -947,23 +951,23 @@ init_after_snapshot( fd_replay_tile_t * ctx ) {
/* After both snapshots have been loaded in, we can determine if we should
start distributing rewards. */

fd_rewards_recalculate_partitioned_rewards( ctx->banks, bank, ctx->funk, &xid, ctx->capture_ctx, ctx->runtime_spad );
fd_rewards_recalculate_partitioned_rewards( ctx->banks, bank, ctx->funk, &xid, ctx->capture_ctx, ctx->runtime_spad, &ctx->runtime_mem );

ulong snapshot_slot = fd_bank_slot_get( bank );
if( FD_UNLIKELY( !snapshot_slot ) ) {
/* Genesis-specific setup. */
/* FIXME: This branch does not set up a new block exec ctx
properly. Needs to do whatever prepare_new_block_execution
does, but just hacking that in breaks stuff. */
fd_runtime_update_leaders( bank, ctx->runtime_spad );
fd_runtime_update_leaders( bank, ctx->runtime_mem.epoch_weights_mem );

ulong hashcnt_per_slot = fd_bank_hashes_per_tick_get( bank ) * fd_bank_ticks_per_slot_get( bank );
fd_hash_t * poh = fd_bank_poh_modify( bank );
while( hashcnt_per_slot-- ) {
fd_sha256_hash( poh->hash, 32UL, poh->hash );
}

FD_TEST( fd_runtime_block_execute_prepare( bank, ctx->funk, &xid, ctx->capture_ctx, ctx->runtime_spad ) == 0 );
FD_TEST( fd_runtime_block_execute_prepare( bank, ctx->funk, &xid, ctx->capture_ctx, &ctx->runtime_mem ) == 0 );
fd_runtime_block_execute_finalize( bank, ctx->funk, &xid, ctx->capture_ctx, 1 );

snapshot_slot = 0UL;
Expand Down Expand Up @@ -1166,7 +1170,7 @@ boot_genesis( fd_replay_tile_t * ctx,
}
fd_funk_txn_xid_t xid = { .ul = { 0UL, 0UL } };

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

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

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

fd_runtime_update_leaders( bank, ctx->runtime_spad );
fd_runtime_update_leaders( bank, ctx->runtime_mem.epoch_weights_mem );

fd_block_id_ele_t * block_id_ele = &ctx->block_id_arr[ 0 ];
FD_TEST( block_id_ele );
Expand Down Expand Up @@ -1390,7 +1394,7 @@ replay( fd_replay_tile_t * ctx,

fd_funk_txn_xid_t xid = { .ul = { ready_txn->slot, ready_txn->slot } };

fd_runtime_update_program_cache( bank, ctx->funk, &xid, txn_p, ctx->runtime_spad );
fd_runtime_update_program_cache( bank, ctx->funk, &xid, txn_p, &ctx->runtime_mem );

/* At this point, we are going to send the txn down the execution
pipeline. Increment the refcnt so we don't prematurely prune a
Expand Down Expand Up @@ -1526,7 +1530,6 @@ process_fec_set( fd_replay_tile_t * ctx,
fd_funk_txn_xid_copy( sched_fec->alut_ctx->xid, fd_funk_last_publish( ctx->funk ) );
sched_fec->alut_ctx->funk = ctx->funk;
sched_fec->alut_ctx->els = ctx->published_root_slot;
sched_fec->alut_ctx->runtime_spad = ctx->runtime_spad;

if( FD_UNLIKELY( !fd_sched_fec_ingest( ctx->sched, sched_fec ) ) ) {
fd_banks_mark_bank_dead( ctx->banks, fd_banks_bank_query( ctx->banks, sched_fec->bank_idx ) );
Expand Down
5 changes: 1 addition & 4 deletions src/discof/replay/fd_sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,17 +1114,14 @@ fd_sched_parse_txn( fd_sched_t * sched, fd_sched_block_t * block, fd_sched_alut_
int has_aluts = txn->transaction_version==FD_TXN_V0 && txn->addr_table_adtl_cnt>0;
int serializing = 0;
if( has_aluts ) {
/* FIXME: statically size out slot hashes decode footprint. */
FD_SPAD_FRAME_BEGIN( alut_ctx->runtime_spad ) {
fd_slot_hashes_global_t const * slot_hashes_global = fd_sysvar_slot_hashes_read( alut_ctx->funk, alut_ctx->xid, alut_ctx->runtime_spad );
fd_slot_hashes_global_t const * slot_hashes_global = fd_sysvar_slot_hashes_read( alut_ctx->funk, alut_ctx->xid, alut_ctx->slot_hashes_mem );
if( FD_LIKELY( slot_hashes_global ) ) {
fd_slot_hash_t * slot_hash = deq_fd_slot_hash_t_join( (uchar *)slot_hashes_global + slot_hashes_global->hashes_offset );
serializing = !!fd_runtime_load_txn_address_lookup_tables( txn, block->fec_buf+block->fec_buf_soff, alut_ctx->funk, alut_ctx->xid, alut_ctx->els, slot_hash, block->aluts );
sched->metrics->alut_success_cnt += (uint)!serializing;
} else {
serializing = 1;
}
} FD_SPAD_FRAME_END;
}

ulong bank_idx = (ulong)(block-sched->block_pool);
Expand Down
9 changes: 5 additions & 4 deletions src/discof/replay/fd_sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#define HEADER_fd_src_discof_replay_fd_sched_h

#include "fd_rdisp.h"
#include "../../disco/store/fd_store.h" /* for fd_store_fec_t */
#include "../../disco/store/fd_store.h" /* for fd_store_fec_t */
#include "../../disco/pack/fd_microblock.h" /* for fd_txn_p_t */

#include "../../funk/fd_funk_base.h" /* for ALUTs */
#include "../../util/spad/fd_spad.h" /* for ALUTs */
#include "../../funk/fd_funk_base.h" /* for ALUTs */
#include "../../util/spad/fd_spad.h" /* for ALUTs */
#include "../../flamenco/runtime/sysvar/fd_sysvar_slot_hashes.h" /* for ALUTs*/

/* fd_sched wraps all the smarts and mechanical chores around scheduling
transactions for replay execution. It is built on top of the
Expand Down Expand Up @@ -58,7 +59,7 @@ struct fd_sched_alut_ctx {
fd_funk_t * funk;
fd_funk_txn_xid_t xid[1];
ulong els; /* Effective lookup slot. */
fd_spad_t * runtime_spad;
uchar slot_hashes_mem[ FD_SYSVAR_SLOT_HASHES_DECODE_FOOTPRINT ];
};
typedef struct fd_sched_alut_ctx fd_sched_alut_ctx_t;

Expand Down
3 changes: 3 additions & 0 deletions src/flamenco/fd_flamenco_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ typedef struct fd_borrowed_account fd_borrowed_account_t;
struct fd_txn_account;
typedef struct fd_txn_account fd_txn_account_t;

struct fd_runtime_mem;
typedef struct fd_runtime_mem fd_runtime_mem_t;

struct fd_account_meta {
uchar owner[32];
ulong lamports;
Expand Down
28 changes: 18 additions & 10 deletions src/flamenco/rewards/fd_rewards.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,10 @@ calculate_validator_rewards( fd_bank_t * bank,
ulong rewarded_epoch,
ulong rewards,
fd_calculate_validator_rewards_result_t * result,
fd_spad_t * runtime_spad ) {
fd_spad_t * runtime_spad,
fd_runtime_mem_t * runtime_mem ) {
/* https://github.com/firedancer-io/solana/blob/dab3da8e7b667d7527565bddbdbecf7ec1fb868e/runtime/src/bank.rs#L2759-L2786 */
fd_stake_history_t const * stake_history = fd_sysvar_stake_history_read( funk, xid, runtime_spad );
fd_stake_history_t const * stake_history = fd_sysvar_stake_history_read( funk, xid, runtime_mem->stake_history_mem );
if( FD_UNLIKELY( !stake_history ) ) {
FD_LOG_ERR(( "Unable to read and decode stake history sysvar" ));
}
Expand Down Expand Up @@ -774,7 +775,8 @@ calculate_rewards_for_partitioning( fd_bank_t * bank,
ulong prev_epoch,
const fd_hash_t * parent_blockhash,
fd_partitioned_rewards_calculation_t * result,
fd_spad_t * runtime_spad ) {
fd_spad_t * runtime_spad,
fd_runtime_mem_t * runtime_mem ) {
/* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L227 */
fd_prev_epoch_inflation_rewards_t rewards;

Expand All @@ -792,7 +794,8 @@ calculate_rewards_for_partitioning( fd_bank_t * bank,
prev_epoch,
rewards.validator_rewards,
validator_result,
runtime_spad );
runtime_spad,
runtime_mem );

fd_stake_reward_calculation_t * stake_reward_calculation = &validator_result->calculate_stake_vote_rewards_result.stake_reward_calculation;
fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( bank );
Expand Down Expand Up @@ -831,7 +834,8 @@ calculate_rewards_and_distribute_vote_rewards( fd_bank_t * ba
fd_capture_ctx_t * capture_ctx,
ulong prev_epoch,
fd_hash_t const * parent_blockhash,
fd_spad_t * runtime_spad ) {
fd_spad_t * runtime_spad,
fd_runtime_mem_t * runtime_mem ) {

/* https://github.com/firedancer-io/solana/blob/dab3da8e7b667d7527565bddbdbecf7ec1fb868e/runtime/src/bank.rs#L2406-L2492 */
fd_partitioned_rewards_calculation_t rewards_calc_result[1] = {0};
Expand All @@ -843,7 +847,8 @@ calculate_rewards_and_distribute_vote_rewards( fd_bank_t * ba
prev_epoch,
parent_blockhash,
rewards_calc_result,
runtime_spad );
runtime_spad,
runtime_mem );

/* Iterate over all the vote reward nodes */
ulong distributed_rewards = 0UL;
Expand Down Expand Up @@ -1137,7 +1142,8 @@ fd_begin_partitioned_rewards( fd_bank_t * bank,
fd_stake_delegations_t const * stake_delegations,
fd_hash_t const * parent_blockhash,
ulong parent_epoch,
fd_spad_t * runtime_spad ) {
fd_spad_t * runtime_spad,
fd_runtime_mem_t * runtime_mem ) {

/* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L55 */
calculate_rewards_and_distribute_vote_rewards(
Expand All @@ -1148,7 +1154,8 @@ fd_begin_partitioned_rewards( fd_bank_t * bank,
capture_ctx,
parent_epoch,
parent_blockhash,
runtime_spad );
runtime_spad,
runtime_mem );

/* https://github.com/anza-xyz/agave/blob/9a7bf72940f4b3cd7fc94f54e005868ce707d53d/runtime/src/bank/partitioned_epoch_rewards/calculation.rs#L62 */
ulong distribution_starting_block_height = fd_bank_block_height_get( bank ) + REWARD_CALCULATION_NUM_BLOCKS;
Expand Down Expand Up @@ -1184,7 +1191,8 @@ fd_rewards_recalculate_partitioned_rewards( fd_banks_t * banks,
fd_funk_t * funk,
fd_funk_txn_xid_t const * xid,
fd_capture_ctx_t * capture_ctx,
fd_spad_t * runtime_spad ) {
fd_spad_t * runtime_spad,
fd_runtime_mem_t * runtime_mem ) {
FD_SPAD_FRAME_BEGIN( runtime_spad ) {

fd_sysvar_epoch_rewards_t epoch_rewards[1];
Expand Down Expand Up @@ -1221,7 +1229,7 @@ fd_rewards_recalculate_partitioned_rewards( fd_banks_t * banks,
new_warmup_cooldown_rate_epoch = NULL;
}

fd_stake_history_t const * stake_history = fd_sysvar_stake_history_read( funk, xid, runtime_spad );
fd_stake_history_t const * stake_history = fd_sysvar_stake_history_read( funk, xid, runtime_mem->stake_history_mem );
if( FD_UNLIKELY( !stake_history ) ) {
FD_LOG_ERR(( "Unable to read and decode stake history sysvar" ));
}
Expand Down
6 changes: 4 additions & 2 deletions src/flamenco/rewards/fd_rewards.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ fd_begin_partitioned_rewards( fd_bank_t * bank,
fd_stake_delegations_t const * stake_delegations,
fd_hash_t const * parent_blockhash,
ulong parent_epoch,
fd_spad_t * runtime_spad );
fd_spad_t * runtime_spad,
fd_runtime_mem_t * runtime_mem );

/* fd_rewards_recalculate_partitioned_rewards restores epoch bank stake
and account reward calculations. Does not update accounts. Called
Expand All @@ -54,7 +55,8 @@ fd_rewards_recalculate_partitioned_rewards( fd_banks_t * banks,
fd_funk_t * funk,
fd_funk_txn_xid_t const * xid,
fd_capture_ctx_t * capture_ctx,
fd_spad_t * runtime_spad );
fd_spad_t * runtime_spad,
fd_runtime_mem_t * runtime_mem );

/* fd_distribute_partitioned_epoch_rewards pays out rewards to stake
accounts. Called at the beginning of a few slots per epoch.
Expand Down
Loading
Loading