Skip to content

Sysvar cache v2 #5506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions src/app/fdctl/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../../disco/net/fd_net_tile.h"
#include "../../disco/quic/fd_tpu.h"
#include "../../disco/tiles.h"
#include "../../disco/fd_txn_m_t.h"
#include "../../disco/topo/fd_topob.h"
#include "../../disco/topo/fd_cpu_topo.h"
#include "../../disco/plugin/fd_plugin.h"
Expand Down
4 changes: 3 additions & 1 deletion src/app/firedancer/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
#include "../../disco/net/fd_net_tile.h"
#include "../../disco/quic/fd_tpu.h"
#include "../../disco/tiles.h"
#include "../../disco/fd_txn_m_t.h"
#include "../../disco/topo/fd_topob.h"
#include "../../disco/topo/fd_cpu_topo.h"
#include "../../disco/pack/fd_microblock.h"
#include "../../util/pod/fd_pod_format.h"
#include "../../ballet/reedsol/fd_reedsol.h"
#include "../../flamenco/runtime/fd_blockstore.h"
#include "../../flamenco/runtime/fd_txncache.h"
#include "../../flamenco/snapshot/fd_snapshot_base.h"
#include "../../util/tile/fd_tile_private.h"
#include "../../discof/restore/utils/fd_snapshot_messages.h"
Expand Down
18 changes: 12 additions & 6 deletions src/app/ledger/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@
#include "../../flamenco/fd_flamenco.h"
#include "../../flamenco/runtime/fd_hashes.h"
#include "../../flamenco/types/fd_types.h"
#include "../../flamenco/features/fd_features.h"
#include "../../flamenco/runtime/fd_runtime.h"
#include "../../flamenco/runtime/fd_runtime_init.h"
#include "../../flamenco/runtime/fd_runtime_err.h"
#include "../../flamenco/runtime/fd_runtime_public.h"
#include "../../flamenco/runtime/fd_rocksdb.h"
#include "../../flamenco/runtime/fd_txncache.h"
#include "../../flamenco/rewards/fd_rewards.h"
#include "../../ballet/base58/fd_base58.h"
#include "../../flamenco/runtime/context/fd_capture_ctx.h"
#include "../../flamenco/runtime/fd_blockstore.h"
#include "../../flamenco/shredcap/fd_shredcap.h"
#include "../../flamenco/runtime/program/fd_bpf_program_util.h"
#include "../../flamenco/snapshot/fd_snapshot.h"

#include <stdio.h>

struct fd_ledger_args {
fd_wksp_t * wksp; /* wksp for blockstore */
fd_wksp_t * funk_wksp; /* wksp for funk */
Expand Down Expand Up @@ -164,9 +167,12 @@ runtime_replay( fd_ledger_args_t * ledger_args ) {

fd_features_restore( ledger_args->slot_ctx, ledger_args->runtime_spad );

fd_runtime_update_leaders( ledger_args->slot_ctx->bank, fd_bank_slot_get( ledger_args->slot_ctx->bank ), ledger_args->runtime_spad );
fd_runtime_update_leaders(
ledger_args->slot_ctx,
fd_bank_slot_get( ledger_args->slot_ctx->bank ),
ledger_args->runtime_spad );

fd_calculate_epoch_accounts_hash_values( ledger_args->slot_ctx );
fd_calculate_epoch_accounts_hash_values( ledger_args->slot_ctx->bank );

long replay_time = -fd_log_wallclock();
ulong txn_cnt = 0;
Expand Down Expand Up @@ -519,8 +525,8 @@ fd_ledger_main_setup( fd_ledger_args_t * args ) {

/* Finish other runtime setup steps */
fd_features_restore( args->slot_ctx, args->runtime_spad );
fd_runtime_update_leaders( args->slot_ctx->bank, fd_bank_slot_get( args->slot_ctx->bank ), args->runtime_spad );
fd_calculate_epoch_accounts_hash_values( args->slot_ctx );
fd_runtime_update_leaders( args->slot_ctx, fd_bank_slot_get( args->slot_ctx->bank ), args->runtime_spad );
fd_calculate_epoch_accounts_hash_values( args->slot_ctx->bank );

/* After both snapshots have been loaded in, we can determine if we should
start distributing rewards. */
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared_dev/commands/bundle_client.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "../../shared/fd_config.h"
#include "../../shared/commands/run/run.h"
#include "../../../disco/tiles.h"
#include "../../../disco/fd_txn_m_t.h"
#include "../../../disco/topo/fd_topob.h"

#include <unistd.h> /* pause */
Expand Down
2 changes: 1 addition & 1 deletion src/disco/archiver/fd_archiver_feeder.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../tiles.h"
#include "../topo/fd_topo.h"

#include "fd_archiver.h"
#include <unistd.h>
Expand Down
2 changes: 1 addition & 1 deletion src/disco/archiver/fd_archiver_playback.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#define _GNU_SOURCE /* Enable GNU and POSIX extensions */

#include "../tiles.h"
#include "../topo/fd_topo.h"

#include "fd_archiver.h"
#include <errno.h>
Expand Down
2 changes: 1 addition & 1 deletion src/disco/archiver/fd_archiver_writer.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#define _GNU_SOURCE /* Enable GNU and POSIX extensions */

#include "../tiles.h"
#include "../topo/fd_topo.h"

#include "fd_archiver.h"
#include <errno.h>
Expand Down
3 changes: 3 additions & 0 deletions src/disco/bundle/fd_bundle_crank.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "fd_bundle_crank.h"
#include "../../flamenco/runtime/fd_pubkey_utils.h"
#if FD_HAS_AVX
#include "../../util/simd/fd_avx.h"
#endif

#if FD_HAS_AVX
#include "../../util/simd/fd_avx.h"
Expand Down
6 changes: 2 additions & 4 deletions src/disco/dedup/fd_dedup_tile.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "../tiles.h"

#include "../topo/fd_topo.h"
#include "../fd_txn_m_t.h"
#include "generated/fd_dedup_tile_seccomp.h"

#include "../verify/fd_verify_tile.h"
#include "../metrics/fd_metrics.h"

#include <linux/unistd.h>
Expand Down
2 changes: 2 additions & 0 deletions src/disco/pack/fd_pack_tile.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "../tiles.h"
#include "../fd_txn_m_t.h"
#include "../topo/fd_topo.h"

#include "generated/fd_pack_tile_seccomp.h"

Expand Down
2 changes: 1 addition & 1 deletion src/disco/plugin/fd_plugin_tile.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../tiles.h"
#include "../topo/fd_topo.h"

#include "generated/fd_plugin_tile_seccomp.h"

Expand Down
1 change: 1 addition & 0 deletions src/disco/shred/fd_shred_tile.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "../tiles.h"
#include "../topo/fd_topo.h"

#include "generated/fd_shred_tile_seccomp.h"
#include "../../util/pod/fd_pod_format.h"
Expand Down
2 changes: 1 addition & 1 deletion src/disco/sign/fd_sign_tile.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define _GNU_SOURCE
#include "../tiles.h"
#include "../topo/fd_topo.h"

#include "generated/fd_sign_tile_seccomp.h"

Expand Down
5 changes: 0 additions & 5 deletions src/disco/tiles.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#ifndef HEADER_fd_src_app_fdctl_run_tiles_h
#define HEADER_fd_src_app_fdctl_run_tiles_h

#include "stem/fd_stem.h"
#include "shred/fd_shredder.h"
#include "../ballet/shred/fd_shred.h"
#include "pack/fd_pack.h"
#include "topo/fd_topo.h"
#include "bundle/fd_bundle_crank.h"
#include "fd_txn_m_t.h"

#include <linux/filter.h>

Expand Down
10 changes: 3 additions & 7 deletions src/discof/exec/fd_exec_tile.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "../../disco/tiles.h"
#include "../../disco/topo/fd_topo.h"
#include "generated/fd_exec_tile_seccomp.h"

#include "../../util/pod/fd_pod_format.h"
#include "../../disco/pack/fd_pack.h"
#include "../../flamenco/runtime/context/fd_capture_ctx.h"
#include "../../flamenco/runtime/fd_runtime.h"
#include "../../flamenco/runtime/fd_runtime_err.h"
#include "../../flamenco/runtime/fd_runtime_public.h"
#include "../../flamenco/runtime/fd_executor.h"
#include "../../flamenco/runtime/fd_hashes.h"
Expand Down Expand Up @@ -36,7 +38,6 @@ struct fd_exec_tile_ctx {
/* Runtime public and local joins of its members. */
fd_wksp_t * runtime_public_wksp;
fd_runtime_public_t * runtime_public;
fd_spad_t const * runtime_spad;

/* Shared bank hash cmp object. */
fd_bank_hash_cmp_t * bank_hash_cmp;
Expand Down Expand Up @@ -432,11 +433,6 @@ unprivileged_init( fd_topo_t * topo,
FD_LOG_ERR(( "Failed to join runtime public" ));
}

ctx->runtime_spad = fd_runtime_public_spad( ctx->runtime_public );
if( FD_UNLIKELY( !ctx->runtime_spad ) ) {
FD_LOG_ERR(( "Failed to get and join runtime spad" ));
}

/********************************************************************/
/* banks */
/********************************************************************/
Expand Down
3 changes: 2 additions & 1 deletion src/discof/poh/fd_poh_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,16 @@
#include "../../disco/tiles.h"
#include "../../disco/bundle/fd_bundle_crank.h"
#include "../../disco/pack/fd_pack.h"
#include "../../disco/topo/fd_topo.h"
#include "../../ballet/sha256/fd_sha256.h"
#include "../../disco/metrics/fd_metrics.h"
#include "../../util/pod/fd_pod.h"
#include "../../disco/shred/fd_shredder.h"
#include "../../disco/keyguard/fd_keyload.h"
#include "../../disco/keyguard/fd_keyswitch.h"
#include "../../disco/metrics/generated/fd_metrics_poh.h"
#include "../../disco/plugin/fd_plugin.h"
#include "../../flamenco/leaders/fd_multi_epoch_leaders.h"
#include "../../util/pod/fd_pod.h"

#include <string.h>

Expand Down
1 change: 1 addition & 0 deletions src/discof/replay/fd_exec.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "fd_exec.h"
#include "../../ballet/block/fd_microblock.h"

fd_slice_exec_t *
fd_slice_exec_join( void * slmem ) {
Expand Down
11 changes: 6 additions & 5 deletions src/discof/replay/fd_exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ generate_stake_weight_msg( fd_exec_slot_ctx_t * slot_ctx,
runtime_spad );
fd_bank_epoch_stakes_end_locking_query( slot_ctx->bank );

fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank );
fd_epoch_schedule_t epoch_schedule =
fd_sysvar_epoch_schedule_read_nofail( fd_bank_sysvar_cache_query( slot_ctx->bank ) );

stake_weight_msg->epoch = epoch;
stake_weight_msg->staked_cnt = stake_weight_idx; /* staked_cnt */
stake_weight_msg->start_slot = fd_epoch_slot0( epoch_schedule, stake_weight_msg_out[0] ); /* start_slot */
stake_weight_msg->slot_cnt = epoch_schedule->slots_per_epoch; /* slot_cnt */
stake_weight_msg->excluded_stake = 0UL; /* excluded stake */
stake_weight_msg->staked_cnt = stake_weight_idx; /* staked_cnt */
stake_weight_msg->start_slot = fd_epoch_slot0( &epoch_schedule, stake_weight_msg_out[0] ); /* start_slot */
stake_weight_msg->slot_cnt = epoch_schedule.slots_per_epoch; /* slot_cnt */
stake_weight_msg->excluded_stake = 0UL; /* excluded stake */

return 5*sizeof(ulong) + (stake_weight_idx * sizeof(fd_stake_weight_t));
}
Expand Down
46 changes: 25 additions & 21 deletions src/discof/replay/fd_replay_tile.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#define _GNU_SOURCE
#include "../../disco/tiles.h"
#include "../../disco/topo/fd_topo.h"
#include "../../disco/pack/fd_pack.h"
#include "generated/fd_replay_tile_seccomp.h"

#include "fd_replay_notif.h"
Expand All @@ -9,18 +11,16 @@
#include "../../flamenco/runtime/fd_txncache.h"
#include "../../flamenco/runtime/context/fd_capture_ctx.h"
#include "../../flamenco/runtime/context/fd_exec_slot_ctx.h"
#include "../../flamenco/runtime/program/fd_bpf_program_util.h"
#include "../../flamenco/runtime/sysvar/fd_sysvar_slot_history.h"
#include "../../flamenco/runtime/fd_hashes.h"
#include "../../flamenco/runtime/fd_runtime_init.h"
#include "../../flamenco/runtime/fd_hashes.h"
#include "../../flamenco/snapshot/fd_snapshot.h"
#include "../../flamenco/stakes/fd_stakes.h"
#include "../../flamenco/runtime/fd_runtime.h"
#include "../../flamenco/runtime/fd_runtime_err.h"
#include "../../flamenco/runtime/fd_runtime_public.h"
#include "../../flamenco/rewards/fd_rewards.h"
#include "../../disco/metrics/fd_metrics.h"
#include "../../choreo/fd_choreo.h"
#include "../../disco/plugin/fd_plugin.h"
#include "../../choreo/forks/fd_forks.h"
#include "fd_exec.h"
#include "../../discof/restore/utils/fd_snapshot_messages.h"

Expand Down Expand Up @@ -307,14 +307,15 @@ static void
publish_stake_weights( fd_replay_tile_ctx_t * ctx,
fd_stem_context_t * stem,
fd_exec_slot_ctx_t * slot_ctx ) {
fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank );
fd_epoch_schedule_t epoch_schedule =
fd_sysvar_epoch_schedule_read_nofail( fd_bank_sysvar_cache_query( slot_ctx->bank ) );

fd_vote_accounts_global_t const * epoch_stakes = fd_bank_epoch_stakes_locking_query( slot_ctx->bank );
fd_vote_accounts_pair_global_t_mapnode_t * epoch_stakes_root = fd_vote_accounts_vote_accounts_root_join( epoch_stakes );

if( epoch_stakes_root!=NULL ) {
ulong * stake_weights_msg = fd_chunk_to_laddr( ctx->stake_out->mem, ctx->stake_out->chunk );
ulong epoch = fd_slot_to_leader_schedule_epoch( epoch_schedule, fd_bank_slot_get( slot_ctx->bank ) );
ulong epoch = fd_slot_to_leader_schedule_epoch( &epoch_schedule, fd_bank_slot_get( slot_ctx->bank ) );
ulong stake_weights_sz = generate_stake_weight_msg( slot_ctx, ctx->runtime_spad, epoch - 1, stake_weights_msg );
ulong stake_weights_sig = 4UL;
fd_stem_publish( stem, 0UL, stake_weights_sig, ctx->stake_out->chunk, stake_weights_sz, 0UL, 0UL, fd_frag_meta_ts_comp( fd_tickcount() ) );
Expand All @@ -329,7 +330,7 @@ publish_stake_weights( fd_replay_tile_ctx_t * ctx,

if( next_epoch_stakes_root!=NULL ) {
ulong * stake_weights_msg = fd_chunk_to_laddr( ctx->stake_out->mem, ctx->stake_out->chunk );
ulong epoch = fd_slot_to_leader_schedule_epoch( epoch_schedule, fd_bank_slot_get( slot_ctx->bank ) ); /* epoch */
ulong epoch = fd_slot_to_leader_schedule_epoch( &epoch_schedule, fd_bank_slot_get( slot_ctx->bank ) ); /* epoch */
ulong stake_weights_sz = generate_stake_weight_msg( slot_ctx, ctx->runtime_spad, epoch, stake_weights_msg );
ulong stake_weights_sig = 4UL;
fd_stem_publish( stem, 0UL, stake_weights_sig, ctx->stake_out->chunk, stake_weights_sz, 0UL, 0UL, fd_frag_meta_ts_comp( fd_tickcount() ) );
Expand Down Expand Up @@ -721,8 +722,9 @@ publish_slot_notifications( fd_replay_tile_ctx_t * ctx,

msg->slot_exec.bank_hash = fd_bank_bank_hash_get( ctx->slot_ctx->bank );

fd_block_hash_queue_global_t const * block_hash_queue = fd_bank_block_hash_queue_query( ctx->slot_ctx->bank );
fd_hash_t * last_hash = fd_block_hash_queue_last_hash_join( block_hash_queue );
fd_blockhashes_t const * block_hash_queue = fd_bank_block_hash_queue_query( ctx->slot_ctx->bank );
fd_hash_t const * last_hash = fd_blockhashes_peek_last( block_hash_queue );
FD_TEST( last_hash );
msg->slot_exec.block_hash = *last_hash;

memcpy( &msg->slot_exec.identity, ctx->validator_identity_pubkey, sizeof( fd_pubkey_t ) );
Expand Down Expand Up @@ -789,7 +791,7 @@ init_after_snapshot( fd_replay_tile_ctx_t * ctx,
/* 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( ctx->slot_ctx->bank,
fd_runtime_update_leaders( ctx->slot_ctx,
fd_bank_slot_get( ctx->slot_ctx->bank ),
ctx->runtime_spad );

Expand Down Expand Up @@ -897,7 +899,7 @@ static void
init_from_snapshot( fd_replay_tile_ctx_t * ctx,
fd_stem_context_t * stem ) {
fd_features_restore( ctx->slot_ctx, ctx->runtime_spad );
fd_calculate_epoch_accounts_hash_values( ctx->slot_ctx );
fd_calculate_epoch_accounts_hash_values( ctx->slot_ctx->bank );

fd_slot_lthash_t const * lthash = fd_bank_lthash_query( ctx->slot_ctx->bank );
if( fd_lthash_is_zero( (fd_lthash_value_t * )lthash ) ) {
Expand All @@ -921,9 +923,10 @@ init_from_snapshot( fd_replay_tile_ctx_t * ctx,
fd_memcpy( (fd_lthash_value_t *)fd_type_pun(lthash_val->lthash), &lthash_buf, sizeof(lthash_buf) );
}

fd_runtime_update_leaders( ctx->slot_ctx->bank,
fd_bank_slot_get( ctx->slot_ctx->bank ),
ctx->runtime_spad );
fd_runtime_update_leaders(
ctx->slot_ctx,
fd_bank_slot_get( ctx->slot_ctx->bank ),
ctx->runtime_spad );

fd_runtime_read_genesis( ctx->slot_ctx,
ctx->genesis,
Expand Down Expand Up @@ -1271,12 +1274,12 @@ init_poh( fd_replay_tile_ctx_t * ctx ) {
msg->ticks_per_slot = fd_bank_ticks_per_slot_get( ctx->slot_ctx->bank );
msg->tick_duration_ns = (ulong)(fd_bank_ns_per_slot_get( ctx->slot_ctx->bank )) / fd_bank_ticks_per_slot_get( ctx->slot_ctx->bank );

fd_block_hash_queue_global_t * bhq = (fd_block_hash_queue_global_t *)&ctx->slot_ctx->bank->block_hash_queue[0];
fd_hash_t * last_hash = fd_block_hash_queue_last_hash_join( bhq );
fd_blockhashes_t const * bhq = fd_bank_block_hash_queue_query( ctx->slot_ctx->bank );
fd_hash_t const * last_hash = fd_blockhashes_peek_last( bhq );
if( last_hash ) {
memcpy(msg->last_entry_hash, last_hash, sizeof(fd_hash_t));
memcpy( msg->last_entry_hash, last_hash, sizeof(fd_hash_t) );
} else {
memset(msg->last_entry_hash, 0UL, sizeof(fd_hash_t));
memset( msg->last_entry_hash, 0UL, sizeof(fd_hash_t) );
}
msg->tick_height = fd_bank_slot_get( ctx->slot_ctx->bank ) * msg->ticks_per_slot;

Expand Down Expand Up @@ -1842,8 +1845,9 @@ after_credit( fd_replay_tile_ctx_t * ctx,
if( FD_LIKELY( ctx->tower_out_idx!=ULONG_MAX && !ctx->read_only ) ) {
uchar * chunk_laddr = fd_chunk_to_laddr( ctx->tower_out_mem, ctx->tower_out_chunk );
fd_hash_t const * bank_hash = fd_bank_bank_hash_query( ctx->slot_ctx->bank );
fd_block_hash_queue_global_t * block_hash_queue = (fd_block_hash_queue_global_t *)&ctx->slot_ctx->bank->block_hash_queue[0];
fd_hash_t * last_hash = fd_block_hash_queue_last_hash_join( block_hash_queue );
fd_blockhashes_t const * block_hash_queue = fd_bank_block_hash_queue_query( ctx->slot_ctx->bank );
fd_hash_t const * last_hash = fd_blockhashes_peek_last( block_hash_queue );
FD_TEST( last_hash );

memcpy( chunk_laddr, bank_hash, sizeof(fd_hash_t) );
memcpy( chunk_laddr+sizeof(fd_hash_t), last_hash, sizeof(fd_hash_t) );
Expand Down
Loading
Loading