Skip to content

Commit

Permalink
fdctl: remove concrete objects (#3094)
Browse files Browse the repository at this point in the history
* fdctl: remove concrete objects

* contrib: fix configuration of firedancer localnet script

---------

Co-authored-by: Liam Heeger <[email protected]>
  • Loading branch information
lheeger-jump and CantelopePeel authored Oct 11, 2024
1 parent 0128ca3 commit 08e48e2
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 146 deletions.
5 changes: 1 addition & 4 deletions contrib/test/test_firedancer_leader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ FULL_SNAPSHOT=$(wget -c -nc -S --trust-server-names http://$PRIMARY_IP:8899/snap
echo "
name = \"fd1\"
[layout]
affinity = \"1-37\"
affinity = \"auto\"
bank_tile_count = 1
verify_tile_count = 16
shred_tile_count = 1
Expand Down Expand Up @@ -65,9 +65,6 @@ name = \"fd1\"
path = \"fddev.log\"
level_stderr = \"INFO\"
level_flush = \"ERR\"
[development]
topology = \"firedancer\"
[consensus]
vote = true
identity_path = \"fd-identity-keypair.json\"
Expand Down
25 changes: 15 additions & 10 deletions src/app/fdctl/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include "../../ballet/toml/fd_toml.h"
#include "../../disco/topo/fd_topob.h"
#include "../../disco/topo/fd_pod_format.h"
#include "../../flamenco/runtime/fd_blockstore.h"
#include "../../flamenco/runtime/fd_txncache.h"
#include "../../funk/fd_funk.h"
#include "../../util/net/fd_eth.h"
#include "../../util/net/fd_ip4.h"
#include "../../util/tile/fd_tile_private.h"
Expand Down Expand Up @@ -195,11 +198,6 @@ fd_topo_tile_to_config( fd_topo_tile_t const * tile ) {
ulong
fdctl_obj_align( fd_topo_t const * topo,
fd_topo_obj_t const * obj ) {
ulong align = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "obj.%lu.%s", obj->id, "align" );
if( align!=ULONG_MAX ) {
return align;
}

if( FD_UNLIKELY( !strcmp( obj->name, "tile" ) ) ) {
fd_topo_tile_t const * tile = NULL;
for( ulong i=0UL; i<topo->tile_cnt; i++ ) {
Expand All @@ -223,6 +221,12 @@ fdctl_obj_align( fd_topo_t const * topo,
return fd_fseq_align();
} else if( FD_UNLIKELY( !strcmp( obj->name, "metrics" ) ) ) {
return FD_METRICS_ALIGN;
} else if( FD_UNLIKELY( !strcmp( obj->name, "blockstore" ) ) ) {
return fd_blockstore_align();
} else if( FD_UNLIKELY( !strcmp( obj->name, "funk" ) ) ) {
return fd_funk_align();
} else if( FD_UNLIKELY( !strcmp( obj->name, "txncache" ) ) ) {
return fd_txncache_align();
} else {
FD_LOG_ERR(( "unknown object `%s`", obj->name ));
return 0UL;
Expand All @@ -237,11 +241,6 @@ fdctl_obj_footprint( fd_topo_t const * topo,
if( FD_UNLIKELY( __x==ULONG_MAX ) ) FD_LOG_ERR(( "obj.%lu.%s was not set", obj->id, name )); \
__x; }))

ulong sz = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "obj.%lu.%s", obj->id, "sz" );
if( sz!=ULONG_MAX ) {
return sz;
}

if( FD_UNLIKELY( !strcmp( obj->name, "tile" ) ) ) {
fd_topo_tile_t const * tile = NULL;
for( ulong i=0UL; i<topo->tile_cnt; i++ ) {
Expand All @@ -265,6 +264,12 @@ fdctl_obj_footprint( fd_topo_t const * topo,
return fd_fseq_footprint();
} else if( FD_UNLIKELY( !strcmp( obj->name, "metrics" ) ) ) {
return FD_METRICS_FOOTPRINT( VAL("in_cnt"), VAL("out_cnt") );
} else if( FD_UNLIKELY( !strcmp( obj->name, "blockstore" ) ) ) {
return fd_blockstore_footprint();
} else if( FD_UNLIKELY( !strcmp( obj->name, "funk" ) ) ) {
return fd_funk_footprint();
} else if( FD_UNLIKELY( !strcmp( obj->name, "txncache" ) ) ) {
return fd_txncache_footprint( VAL("max_rooted_slots"), VAL("max_live_slots"), VAL("max_txn_per_slot") );
} else {
FD_LOG_ERR(( "unknown object `%s`", obj->name ));
return 0UL;
Expand Down
21 changes: 9 additions & 12 deletions src/app/fdctl/run/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

#include "../../../disco/tiles.h"
#include "../../../disco/topo/fd_pod_format.h"
#include "../../../flamenco/runtime/fd_blockstore.h"
#include "../../../flamenco/runtime/fd_txncache.h"
#include "../../../funk/fd_funk.h"
#include "../configure/configure.h"

#include <dirent.h>
Expand Down Expand Up @@ -496,18 +499,6 @@ fdctl_obj_new( fd_topo_t const * topo,
if( FD_UNLIKELY( __x==ULONG_MAX ) ) FD_LOG_ERR(( "obj.%lu.%s was not set", obj->id, name )); \
__x; }))

ulong align = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "obj.%lu.align", obj->id );
ulong sz = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "obj.%lu.sz", obj->id );
ulong loose = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "obj.%lu.loose", obj->id );

if( align!=ULONG_MAX && sz!=ULONG_MAX && loose!=ULONG_MAX ) {
/* If the object specified the properities necessary to be concrete then
we should not call any sort of `new` function on it. The user is
responsible for initializing the data structure properly after topology
init time. */
return;
}

void * laddr = fd_topo_obj_laddr( topo, obj->id );

if( FD_UNLIKELY( !strcmp( obj->name, "tile" ) ) ) {
Expand All @@ -526,6 +517,12 @@ fdctl_obj_new( fd_topo_t const * topo,
fd_metrics_new( laddr, VAL("in_cnt"), VAL("out_cnt") );
} else if( FD_UNLIKELY( !strcmp( obj->name, "ulong" ) ) ) {
*(ulong*)laddr = 0;
} else if( FD_UNLIKELY( !strcmp( obj->name, "blockstore" ) ) ) {
fd_blockstore_new( laddr, VAL("wksp_tag"), VAL("seed"), VAL("shred_max"), VAL("slot_max"), VAL("lg_txn_max") );
} else if( FD_UNLIKELY( !strcmp( obj->name, "funk" ) ) ) {
fd_funk_new( laddr, VAL("wksp_tag"), VAL("seed"), VAL("txn_max"), VAL("rec_max") );
} else if( FD_UNLIKELY( !strcmp( obj->name, "txncache" ) ) ) {
fd_txncache_new( laddr, VAL("max_rooted_slots"), VAL("max_live_slots"), VAL("max_txn_per_slot") );
} else {
FD_LOG_ERR(( "unknown object `%s`", obj->name ));
}
Expand Down
15 changes: 3 additions & 12 deletions src/app/fdctl/run/tiles/fd_repair.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,16 +412,6 @@ after_credit( void * _ctx,
int * opt_poll_in FD_PARAM_UNUSED ) {
fd_repair_tile_ctx_t * ctx = (fd_repair_tile_ctx_t *)_ctx;

// Poll for blockstore
if ( FD_UNLIKELY( ctx->blockstore == NULL ) ) {
ulong tag = FD_BLOCKSTORE_MAGIC;
fd_wksp_tag_query_info_t info;
if ( fd_wksp_tag_query(ctx->blockstore_wksp, &tag, 1, &info, 1) > 0 ) {
void * shmem = fd_wksp_laddr_fast( ctx->blockstore_wksp, info.gaddr_lo );
ctx->blockstore = fd_blockstore_join( shmem );
}
}

fd_mcache_seq_update( ctx->net_out_sync, ctx->net_out_seq );

fd_repair_settime( ctx->repair, fd_log_wallclock() );
Expand Down Expand Up @@ -572,8 +562,9 @@ unprivileged_init( fd_topo_t * topo,
if( ctx->blockstore_wksp==NULL ) {
FD_LOG_ERR(( "no blocktore workspace" ));
}

ctx->blockstore = NULL;

ctx->blockstore = fd_blockstore_join( fd_topo_obj_laddr( topo, blockstore_obj_id ) );
FD_TEST( ctx->blockstore!=NULL );

fd_topo_link_t * netmux_link = &topo->links[ tile->in_link_id[ 0 ] ];

Expand Down
101 changes: 50 additions & 51 deletions src/app/fdctl/run/tiles/fd_replay.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ struct fd_replay_tile_ctx {
ulong * smr; /* supermajority root slot */
ulong * poh; /* proof-of-history slot */
uint poh_init_done;
int snapshot_init_done;

int vote;
fd_pubkey_t validator_identity_pubkey[ 1 ];
Expand Down Expand Up @@ -1316,6 +1317,40 @@ init_after_snapshot( fd_replay_tile_ctx_t * ctx ) {
FD_LOG_NOTICE( ( "total stake %lu", bank_hash_cmp->total_stake ) );
}

void
init_snapshot( fd_replay_tile_ctx_t * ctx,
fd_mux_context_t * mux_ctx ) {
FD_LOG_NOTICE(( "init snapshot" ));
/* Init slot_ctx */

fd_exec_slot_ctx_t slot_ctx = { 0 };
ctx->slot_ctx = fd_exec_slot_ctx_join( fd_exec_slot_ctx_new( &slot_ctx, ctx->valloc ) );
ctx->slot_ctx->acc_mgr = ctx->acc_mgr;
ctx->slot_ctx->blockstore = ctx->blockstore;
ctx->slot_ctx->epoch_ctx = ctx->epoch_ctx;
ctx->slot_ctx->status_cache = ctx->status_cache;

FD_SCRATCH_SCOPE_BEGIN {
uchar is_snapshot = strlen( ctx->snapshot ) > 0;
if( is_snapshot ) {
read_snapshot( ctx, ctx->snapshot, ctx->incremental );
}

fd_runtime_read_genesis( ctx->slot_ctx, ctx->genesis, is_snapshot, ctx->capture_ctx );
ctx->epoch_ctx->bank_hash_cmp = ctx->bank_hash_cmp;
init_after_snapshot( ctx );

publish_stake_weights( ctx, mux_ctx, ctx->slot_ctx );
} FD_SCRATCH_SCOPE_END;


/* Redirect ctx->slot_ctx to point to the memory inside forks. */

fd_fork_t * fork = fd_forks_query( ctx->forks, ctx->curr_slot );
ctx->slot_ctx = &fork->slot_ctx;
FD_TEST( ctx->slot_ctx );
}

/* after_credit runs on every iteration of the replay tile loop except
when backpressured.
Expand All @@ -1330,52 +1365,13 @@ init_after_snapshot( fd_replay_tile_ctx_t * ctx ) {
static void
after_credit( void * _ctx,
fd_mux_context_t * mux_ctx,
int * opt_poll_in ) {
(void)opt_poll_in;

int * opt_poll_in FD_PARAM_UNUSED ) {
fd_replay_tile_ctx_t * ctx = (fd_replay_tile_ctx_t *)_ctx;

// Poll for blockstore
if( FD_UNLIKELY( ctx->blockstore == NULL ) ) {
ulong tag = FD_BLOCKSTORE_MAGIC;
fd_wksp_tag_query_info_t info;
if( fd_wksp_tag_query( ctx->blockstore_wksp, &tag, 1, &info, 1 ) > 0 ) {
void * shmem = fd_wksp_laddr_fast( ctx->blockstore_wksp, info.gaddr_lo );
ctx->blockstore = fd_blockstore_join( shmem );
}

if ( ctx->blockstore != NULL ) {
FD_LOG_NOTICE(( "INIT BLOCKSTORE" ));
/* Init slot_ctx */

fd_exec_slot_ctx_t slot_ctx = { 0 };
ctx->slot_ctx = fd_exec_slot_ctx_join( fd_exec_slot_ctx_new( &slot_ctx, ctx->valloc ) );
ctx->slot_ctx->acc_mgr = ctx->acc_mgr;
ctx->slot_ctx->blockstore = ctx->blockstore;
ctx->slot_ctx->epoch_ctx = ctx->epoch_ctx;
ctx->slot_ctx->status_cache = ctx->status_cache;

FD_SCRATCH_SCOPE_BEGIN {
uchar is_snapshot = strlen( ctx->snapshot ) > 0;
if( is_snapshot ) {
read_snapshot( ctx, ctx->snapshot, ctx->incremental );
}

fd_runtime_read_genesis( ctx->slot_ctx, ctx->genesis, is_snapshot, ctx->capture_ctx );
ctx->epoch_ctx->bank_hash_cmp = ctx->bank_hash_cmp;
init_after_snapshot( ctx );

publish_stake_weights( ctx, mux_ctx, ctx->slot_ctx );
} FD_SCRATCH_SCOPE_END;


/* Redirect ctx->slot_ctx to point to the memory inside forks. */

fd_fork_t * fork = fd_forks_query( ctx->forks, ctx->curr_slot );
ctx->slot_ctx = &fork->slot_ctx;
FD_TEST( ctx->slot_ctx );
}
}
if( FD_UNLIKELY( ctx->snapshot_init_done==0 ) ) {
init_snapshot( ctx, mux_ctx );
ctx->snapshot_init_done = 1;
}
}


Expand Down Expand Up @@ -1480,6 +1476,9 @@ unprivileged_init( fd_topo_t * topo,
FD_LOG_ERR(( "no blockstore wksp" ));
}

ctx->blockstore = fd_blockstore_join( fd_topo_obj_laddr( topo, blockstore_obj_id ) );
FD_TEST( ctx->blockstore!=NULL );

ulong funk_obj_id = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "funk" );
FD_TEST( funk_obj_id!=ULONG_MAX );
ctx->funk_wksp = topo->workspaces[ topo->objs[ funk_obj_id ].wksp_id ].wksp;
Expand Down Expand Up @@ -1572,14 +1571,13 @@ unprivileged_init( fd_topo_t * topo,
FD_LOG_ERR(( "failed to tag query funk in %s", ctx->snapshot ));
}
} else {
void * funk_shmem = fd_wksp_alloc_laddr( ctx->funk_wksp, fd_funk_align(), fd_funk_footprint(), FD_FUNK_MAGIC );
if (funk_shmem == NULL) {
FD_LOG_ERR(( "failed to allocate funk" ));
void * funk_shmem = fd_topo_obj_laddr( topo, funk_obj_id );
if( funk_shmem==NULL ) {
FD_LOG_ERR(( "failed to find funk" ));
}
ctx->funk = fd_funk_join( fd_funk_new( funk_shmem, FD_FUNK_MAGIC, ctx->funk_seed, tile->replay.funk_txn_max, tile->replay.funk_rec_max ) );
if (ctx->funk == NULL) {
fd_wksp_free_laddr(funk_shmem);
FD_LOG_ERR(( "failed to join + new funk" ));
ctx->funk = fd_funk_join( funk_shmem );
if( ctx->funk==NULL ) {
FD_LOG_ERR(( "failed to join funk" ));
}
}

Expand Down Expand Up @@ -1722,6 +1720,7 @@ unprivileged_init( fd_topo_t * topo,
// FD_LOG_ERR( ( "replay tile %lu has no busy flag", tile->kind_id ) );

ctx->poh_init_done = 0U;
ctx->snapshot_init_done = 0;

/* set up vote related items */
ctx->vote = tile->replay.vote;
Expand Down
13 changes: 3 additions & 10 deletions src/app/fdctl/run/tiles/fd_store_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ struct fd_store_tile_ctx {

fd_stake_ci_t * stake_ci;

ulong blockstore_seed;

ulong * root_slot_fseq;

int sim;
Expand Down Expand Up @@ -297,8 +295,6 @@ privileged_init( fd_topo_t * topo FD_PARAM_UNUSED,
FD_LOG_ERR(( "identity_key_path not set" ));

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

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

static void
Expand Down Expand Up @@ -598,15 +594,12 @@ unprivileged_init( fd_topo_t * topo,
FD_LOG_WARNING(( "failed to find blockstore in workspace. making new blockstore." ));
}
} else {
void * blockstore_shmem = fd_wksp_alloc_laddr( ctx->blockstore_wksp,
fd_blockstore_align(),
fd_blockstore_footprint(),
FD_BLOCKSTORE_MAGIC );
void * blockstore_shmem = fd_topo_obj_laddr( topo, blockstore_obj_id );
if( blockstore_shmem == NULL ) {
FD_LOG_ERR(( "failed to alloc blockstore" ));
FD_LOG_ERR(( "failed to find blockstore" ));
}

ctx->blockstore = fd_blockstore_join( fd_blockstore_new( blockstore_shmem, 1, ctx->blockstore_seed, FD_BUF_SHRED_MAP_MAX, FD_BLOCK_MAX, FD_TXN_MAP_LG_MAX ) );
ctx->blockstore = fd_blockstore_join( blockstore_shmem );
}

FD_TEST( ctx->blockstore );
Expand Down
Loading

0 comments on commit 08e48e2

Please sign in to comment.