Skip to content

Commit

Permalink
Merge branch 'main' into ll/testnet-multiple-entrypoints
Browse files Browse the repository at this point in the history
  • Loading branch information
llamb-jump authored May 16, 2024
2 parents b9d947c + 718e74f commit 9d89124
Show file tree
Hide file tree
Showing 19 changed files with 285 additions and 203 deletions.
16 changes: 14 additions & 2 deletions src/app/fdctl/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ static int parse_key_value( config_t * config,
ENTRY_UINT ( ., layout, bank_tile_count );
ENTRY_UINT ( ., layout, shred_tile_count );

ENTRY_STR ( ., hugetlbfs, gigantic_page_mount_path );
ENTRY_STR ( ., hugetlbfs, huge_page_mount_path );
ENTRY_STR ( ., hugetlbfs, mount_path );

ENTRY_STR ( ., tiles.net, interface );
ENTRY_STR ( ., tiles.net, xdp_mode );
Expand Down Expand Up @@ -921,6 +920,19 @@ config_parse( int * pargc,
if( FD_UNLIKELY( getgid() != 0 && config->gid != getgid() ) )
FD_LOG_ERR(( "running as gid %i, but config specifies gid %i", getgid(), config->gid ));

ulong len = strlen( config->hugetlbfs.mount_path );
if( FD_UNLIKELY( !len ) ) FD_LOG_ERR(( "[hugetlbfs.mount_path] must be non-empty in your configuration file" ));
FD_TEST( fd_cstr_printf_check( config->hugetlbfs.gigantic_page_mount_path,
sizeof(config->hugetlbfs.gigantic_page_mount_path),
NULL,
"%s/.gigantic",
config->hugetlbfs.mount_path ) );
FD_TEST( fd_cstr_printf_check( config->hugetlbfs.huge_page_mount_path,
sizeof(config->hugetlbfs.huge_page_mount_path),
NULL,
"%s/.huge",
config->hugetlbfs.mount_path ) );

replace( config->log.path, "{user}", config->user );
replace( config->log.path, "{name}", config->name );
if( FD_LIKELY( !strcmp( "auto", config->log.colorize ) ) ) config->log.colorize1 = 2;
Expand Down
1 change: 1 addition & 0 deletions src/app/fdctl/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ typedef struct {
struct {
char gigantic_page_mount_path[ PATH_MAX ];
char huge_page_mount_path[ PATH_MAX ];
char mount_path[ PATH_MAX ];
} hugetlbfs;

struct {
Expand Down
18 changes: 8 additions & 10 deletions src/app/fdctl/config/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -578,16 +578,14 @@ dynamic_port_range = "8900-9000"
# +-- scratch2.wksp
[hugetlbfs]
# The absolute path to a directory in the filesystem. Firedancer
# will mount the hugetlbfs filesystem for gigantic pages at this
# path, or if the path already exists, will use it as-is. If the
# mount already exists it should be writable by the Firedancer user.
gigantic_page_mount_path = "/mnt/.fd/.gigantic"

# The absolute path to a directory in the filesystem. Firedancer
# will mount the hugetlbfs filesystem for huge pages at this path,
# or if the path already exists, will use it as-is. If the mount
# already exists it should be writable by the Firedancer user.
huge_page_mount_path = "/mnt/.fd/.huge"
# will mount the hugetlbfs filesystem for gigantic pages at a
# subdirectory named .gigantic under this path, or if the entire
# path already exists, will use it as-is. Firedancer will also
# mount the hugetlbfs filesystem for huge pages at a subdirectory
# named .huge under this path, or if the entire path already exists,
# will use it as-is. If the mount already exists it should be
# writable by the Firedancer user.
mount_path = "/mnt/.fd"

# Tiles are described in detail in the layout section above. While the
# layout configuration determines how many of each tile to place on
Expand Down
10 changes: 9 additions & 1 deletion src/app/fdctl/main1.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ fdctl_boot( int * pargc,
strncpy( config->log.path, log_path, sizeof( config->log.path ) - 1 );
}

char * shmem_args[ 3 ];
/* pass in --shmem-path value from the config */
shmem_args[ 0 ] = "--shmem-path";
shmem_args[ 1 ] = config->hugetlbfs.mount_path;
shmem_args[ 2 ] = NULL;
char ** argv = shmem_args;
int argc = 2;

int * log_lock = map_log_memfd( config->log.lock_fd );
ulong pid = fd_sandbox_getpid(); /* Need to read /proc since we might be in a PID namespace now */;

Expand Down Expand Up @@ -199,7 +207,7 @@ fdctl_boot( int * pargc,
config->log.log_fd,
log_path );
config->log.log_fd = fd_log_private_logfile_fd();
fd_shmem_private_boot( pargc, pargv );;
fd_shmem_private_boot( &argc, &argv );
fd_tile_private_boot( 0, NULL );

/* Kind of a hack but initializing NUMA config depends on shmem, which
Expand Down
57 changes: 38 additions & 19 deletions src/app/fdctl/run/tiles/fd_replay.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define _GNU_SOURCE
#define _GNU_SOURCE

#include "tiles.h"

Expand Down Expand Up @@ -110,7 +110,7 @@ struct fd_replay_tile_ctx {
ulong parent_slot;
ulong flags;
fd_hash_t blockhash;

uchar tpool_mem[FD_TPOOL_FOOTPRINT( FD_TILE_MAX )] __attribute__( ( aligned( FD_TPOOL_ALIGN ) ) );
fd_tpool_t * tpool;
ulong max_workers;
Expand Down Expand Up @@ -156,14 +156,14 @@ during_frag( void * _ctx,
ulong sz,
int * opt_filter FD_PARAM_UNUSED ) {
fd_replay_tile_ctx_t * ctx = (fd_replay_tile_ctx_t *)_ctx;

if( FD_UNLIKELY( chunk<ctx->store_in_chunk0 || chunk>ctx->store_in_wmark || sz>MAX_TXNS_PER_REPLAY ) ) {
FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu]", chunk, sz, ctx->store_in_chunk0, ctx->store_in_wmark ));
}

void * dst_poh = fd_chunk_to_laddr( ctx->poh_out_mem, ctx->poh_out_chunk );
uchar * src = (uchar *)fd_chunk_to_laddr( ctx->store_in_mem, chunk );

/* Incoming packet from store tile. Format:
* Parent slot (ulong - 8 bytes)
* Updated block hash/PoH hash (fd_hash_t - 32 bytes)
Expand Down Expand Up @@ -226,7 +226,7 @@ after_frag( void * _ctx,

fork->slot_ctx.slot_bank.prev_slot = fork->slot_ctx.slot_bank.slot;
fork->slot_ctx.slot_bank.slot = ctx->curr_slot;

fd_funk_txn_xid_t xid;

fd_memcpy(xid.uc, ctx->blockhash.uc, sizeof(fd_funk_txn_xid_t));
Expand Down Expand Up @@ -270,7 +270,7 @@ after_frag( void * _ctx,
*opt_filter = 1;
return;
}

fd_blockstore_start_write( ctx->replay->blockstore );

fd_block_t * block_ = fd_blockstore_block_query( ctx->replay->blockstore, ctx->curr_slot );
Expand Down Expand Up @@ -365,7 +365,31 @@ read_snapshot( void * _ctx, char const * snapshotfile, char const * incremental
}

static void
after_credit( void * _ctx,
init_after_snapshot( fd_replay_tile_ctx_t * ctx ) {
ulong snapshot_slot = ctx->slot_ctx->slot_bank.slot;
if( snapshot_slot != ctx->curr_slot ) {
/* The initial snapshot_slot was wrong or unspecified. Fix everything. */
FD_LOG_NOTICE(( "detected snapshot slot %lu, prev_slot %lu", snapshot_slot, ctx->slot_ctx->slot_bank.prev_slot ));
fd_fork_t * ele = fd_fork_frontier_ele_remove( ctx->replay->forks->frontier, &ctx->curr_slot, NULL, ctx->replay->forks->pool );
ele->slot = snapshot_slot;
fd_fork_frontier_ele_insert( ctx->replay->forks->frontier, ele, ctx->replay->forks->pool );
ctx->replay->smr = snapshot_slot;
fd_bank_hash_cmp_t * bank_hash_cmp = fd_exec_epoch_ctx_bank_hash_cmp( ctx->epoch_ctx );
bank_hash_cmp->slot = snapshot_slot;
ctx->curr_slot = snapshot_slot;
ctx->parent_slot = ctx->slot_ctx->slot_bank.prev_slot;
}

fd_features_restore( ctx->slot_ctx );
fd_runtime_update_leaders( ctx->slot_ctx, ctx->slot_ctx->slot_bank.slot );
fd_calculate_epoch_accounts_hash_values( ctx->slot_ctx );
fd_funk_start_write( ctx->slot_ctx->acc_mgr->funk );
fd_bpf_scan_and_create_bpf_program_cache_entry( ctx->slot_ctx, ctx->slot_ctx->funk_txn );
fd_funk_end_write( ctx->slot_ctx->acc_mgr->funk );
}

static void
after_credit( void * _ctx,
fd_mux_context_t * mux_ctx ) {
fd_replay_tile_ctx_t * ctx = (fd_replay_tile_ctx_t *)_ctx;

Expand All @@ -392,12 +416,7 @@ after_credit( void * _ctx,

fd_runtime_read_genesis( ctx->slot_ctx, ctx->genesis, is_snapshot );

fd_features_restore( ctx->slot_ctx );
fd_runtime_update_leaders( ctx->slot_ctx, ctx->slot_ctx->slot_bank.slot );
fd_calculate_epoch_accounts_hash_values( ctx->slot_ctx );
fd_funk_start_write( ctx->slot_ctx->acc_mgr->funk );
fd_bpf_scan_and_create_bpf_program_cache_entry( ctx->slot_ctx, ctx->slot_ctx->funk_txn );
fd_funk_end_write( ctx->slot_ctx->acc_mgr->funk );
init_after_snapshot( ctx );
} FD_SCRATCH_SCOPE_END;
}
}
Expand Down Expand Up @@ -525,17 +544,17 @@ unprivileged_init( fd_topo_t * topo,

/* Valloc setup */
void * alloc_shalloc = fd_alloc_new( alloc_shmem, 3UL );
if( FD_UNLIKELY( !alloc_shalloc ) ) {
if( FD_UNLIKELY( !alloc_shalloc ) ) {
FD_LOG_ERR( ( "fd_allow_new failed" ) ); }
fd_alloc_t * alloc = fd_alloc_join( alloc_shalloc, 3UL );
if( FD_UNLIKELY( !alloc ) ) {
FD_LOG_ERR( ( "fd_alloc_join failed" ) );
FD_LOG_ERR( ( "fd_alloc_join failed" ) );
}

fd_valloc_t valloc = fd_alloc_virtual( alloc );

ctx->epoch_ctx = fd_exec_epoch_ctx_join( fd_exec_epoch_ctx_new( ctx->epoch_ctx_mem , VOTE_ACC_MAX ) );

ctx->snapshot = tile->replay.snapshot;
ctx->incremental = tile->replay.incremental;
ctx->genesis = tile->replay.genesis;
Expand Down Expand Up @@ -590,7 +609,7 @@ unprivileged_init( fd_topo_t * topo,
}
}
}

ctx->replay->tpool = ctx->tpool;
ctx->replay->max_workers = ctx->max_workers;

Expand All @@ -612,7 +631,7 @@ unprivileged_init( fd_topo_t * topo,
ctx->store_out_chunk0 = fd_dcache_compact_chunk0( ctx->store_out_mem, store_out_link->dcache );
ctx->store_out_wmark = fd_dcache_compact_wmark( ctx->store_out_mem, store_out_link->dcache, store_out_link->mtu );
ctx->store_out_chunk = ctx->store_out_chunk0;

fd_topo_link_t * poh_out_link = &topo->links[ tile->out_link_id[ POH_OUT_IDX ] ];
ctx->poh_out_mem = topo->workspaces[ topo->objs[ poh_out_link->dcache_obj_id ].wksp_id ].wksp;
ctx->poh_out_chunk0 = fd_dcache_compact_chunk0( ctx->poh_out_mem, poh_out_link->dcache );
Expand Down
47 changes: 17 additions & 30 deletions src/app/fdctl/run/tiles/fd_store_int.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Store tile manages a blockstore and serves requests to repair and replay. */

#define _GNU_SOURCE
#define _GNU_SOURCE

#include "tiles.h"

Expand Down Expand Up @@ -66,7 +66,7 @@ struct fd_store_tile_ctx {
fd_wksp_t * replay_in_mem;
ulong replay_in_chunk0;
ulong replay_in_wmark;

fd_wksp_t * pack_in_mem;
ulong pack_in_chunk0;
ulong pack_in_wmark;
Expand Down Expand Up @@ -182,7 +182,7 @@ after_frag( void * _ctx,
fd_mux_context_t * mux FD_PARAM_UNUSED ) {

fd_store_tile_ctx_t * ctx = (fd_store_tile_ctx_t *)_ctx;

ctx->store->now = fd_log_wallclock();

if( FD_UNLIKELY( in_idx==STAKE_IN_IDX ) ) {
Expand Down Expand Up @@ -220,7 +220,7 @@ privileged_init( fd_topo_t * topo FD_PARAM_UNUSED,
FD_LOG_ERR(( "identity_key_path not set" ));

ctx->identity_key[ 0 ] = *(fd_pubkey_t *)fd_keyload_load( tile->store_int.identity_key_path, /* pubkey only: */ 1 );

FD_TEST( sizeof(ulong) == getrandom( &ctx->blockstore_seed, sizeof(ulong), 0 ) );
}

Expand All @@ -243,11 +243,11 @@ fd_store_tile_slot_prepare( fd_store_tile_ctx_t * ctx,
}

/* We are leader at this slot and the slot is newer than turbine! */
// FIXME: I dont think that this `ctx->store->curr_turbine_slot >= slot`
// FIXME: I dont think that this `ctx->store->curr_turbine_slot >= slot`
// check works on fork switches to lower slot numbers. Use a given fork height
// instead

if( ctx->store->curr_turbine_slot >= slot
if( ctx->store->curr_turbine_slot >= slot
&& memcmp( ctx->identity_key, slot_leader, sizeof(fd_pubkey_t) ) == 0 ) {
if( store_slot_prepare_mode == FD_STORE_SLOT_PREPARE_CONTINUE ) {
fd_block_t * block = fd_blockstore_block_query( ctx->blockstore, slot );
Expand All @@ -258,13 +258,13 @@ fd_store_tile_slot_prepare( fd_store_tile_ctx_t * ctx,
return;
}
}

ulong repair_req_cnt = 0;
switch( store_slot_prepare_mode ) {
case FD_STORE_SLOT_PREPARE_CONTINUE: {
if( slot > 64UL ) {
ctx->store->smr = fd_ulong_max( ctx->store->smr, slot - 64UL );
fd_pending_slots_set_lo_wmark( ctx->store->pending_slots, ctx->store->smr );
ctx->blockstore->smr = fd_ulong_max( ctx->blockstore->smr, slot - 64UL );
fd_pending_slots_set_lo_wmark( ctx->store->pending_slots, ctx->blockstore->smr );
}
ctx->store->now = fd_log_wallclock();
break;
Expand Down Expand Up @@ -292,7 +292,7 @@ fd_store_tile_slot_prepare( fd_store_tile_ctx_t * ctx,
return;
}
}

if( store_slot_prepare_mode == FD_STORE_SLOT_PREPARE_CONTINUE ) {

ulong tspub = fd_frag_meta_ts_comp( fd_tickcount() );
Expand All @@ -318,14 +318,14 @@ fd_store_tile_slot_prepare( fd_store_tile_ctx_t * ctx,
out_buf += sizeof(ulong);

memcpy( out_buf, block_hash->uc, sizeof(fd_hash_t) );
out_buf += sizeof(fd_hash_t);
out_buf += sizeof(fd_hash_t);

uchar * block_data = fd_blockstore_block_data_laddr( ctx->blockstore, block );

FD_SCRATCH_SCOPE_BEGIN {
fd_block_info_t block_info;
fd_runtime_block_prepare( block_data, block->data_sz, fd_scratch_virtual(), &block_info );

FD_LOG_DEBUG(( "block prepared - slot: %lu", slot ));
FD_LOG_NOTICE(( "first turbine: %lu, current received turbine: %lu, behind: %lu current "
"executed: %lu, caught up: %d",
Expand Down Expand Up @@ -395,7 +395,7 @@ unprivileged_init( fd_topo_t * topo,
strcmp( topo->links[ tile->out_link_id[ REPLAY_OUT_IDX ] ].name, "store_replay" ) ) )
FD_LOG_ERR(( "store tile has none or unexpected output links %lu %s %s",
tile->out_cnt, topo->links[ tile->out_link_id[ 0 ] ].name, topo->links[ tile->out_link_id[ 1 ] ].name ));

if( FD_UNLIKELY( tile->out_link_id_primary != ULONG_MAX ) )
FD_LOG_ERR(( "store tile has a primary output link" ));

Expand All @@ -414,9 +414,9 @@ unprivileged_init( fd_topo_t * topo,
FD_TEST( (!!smem) & (!!fmem) );
fd_scratch_attach( smem, fmem, SCRATCH_SMAX, SCRATCH_SDEPTH );


ctx->wksp = topo->workspaces[ topo->objs[ tile->tile_obj_id ].wksp_id ].wksp;

ulong blockstore_obj_id = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "blockstore" );
FD_TEST( blockstore_obj_id!=ULONG_MAX );
ctx->blockstore_wksp = topo->workspaces[ topo->objs[ blockstore_obj_id ].wksp_id ].wksp;
Expand Down Expand Up @@ -445,25 +445,12 @@ unprivileged_init( fd_topo_t * topo,
FD_LOG_ERR( ( "failed to allocate a blockstore" ) );
}

FD_LOG_WARNING(("snapshot slot %lu", tile->store_int.snapshot_slot ));
/* fake the snapshot slot's block and mark it as executed */
// fd_blockstore_slot_map_t * slot_entry =
// fd_blockstore_slot_map_insert( fd_blockstore_slot_map( blockstore ), tile->store_int.snapshot_slot );
// slot_entry->block.data_gaddr = ULONG_MAX;
// slot_entry->block.flags = fd_uchar_set_bit( slot_entry->block.flags, FD_BLOCK_FLAG_SNAPSHOT );
// slot_entry->block.flags = fd_uchar_set_bit( slot_entry->block.flags, FD_BLOCK_FLAG_PROCESSED );

// if( FD_LIKELY( tile->store_int.snapshot_slot != 0 ) ) {
// blockstore->root = tile->store_int.snapshot_slot;
// blockstore->min = tile->store_int.snapshot_slot;
// }

ctx->blockstore = blockstore;
ctx->store->blockstore = blockstore;

void * alloc_shmem = fd_wksp_alloc_laddr( ctx->wksp, fd_alloc_align(), fd_alloc_footprint(), 3UL );
if( FD_UNLIKELY( !alloc_shmem ) ) {
FD_LOG_ERR( ( "fd_alloc too large for workspace" ) );
if( FD_UNLIKELY( !alloc_shmem ) ) {
FD_LOG_ERR( ( "fd_alloc too large for workspace" ) );
}

/* Set up shred tile input */
Expand Down
Loading

0 comments on commit 9d89124

Please sign in to comment.