Skip to content
Open
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
9 changes: 8 additions & 1 deletion src/app/firedancer-dev/commands/backtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,16 @@ backtest_topo( config_t * config ) {
config->firedancer.funk.max_database_transactions,
config->firedancer.funk.heap_size_gib,
config->firedancer.funk.lock_pages );

fd_topob_tile_uses( topo, replay_tile, funk_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );

fd_topob_wksp( topo, "progcache" );
fd_topo_obj_t * progcache_obj = setup_topo_progcache( topo, "progcache",
fd_progcache_est_rec_max( config->firedancer.runtime.program_cache.heap_size_mib<<20,
config->firedancer.runtime.program_cache.mean_cache_entry_size_kib<<10 ),
config->firedancer.funk.max_database_transactions,
config->firedancer.runtime.program_cache.heap_size_mib<<20 );
fd_topob_tile_uses( topo, replay_tile, progcache_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );

/**********************************************************************/
/* Add the executor tiles to topo */
/**********************************************************************/
Expand Down
11 changes: 11 additions & 0 deletions src/app/firedancer/config/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,17 @@ user = ""
# max_fork_width, the client will crash.
max_fork_width = 32

# The program cache pre-loads frequently executed programs for
# faster transaction execution.
[runtime.program_cache]
# The size of the loaded program cache in MiB.
heap_size_mib = 1024

# The mean expected heap utilization of a cache entry. Controls
# the size of metadata structures (e.g. cache entry table). It
# is not recommended to change this setting.
mean_cache_entry_size_kib = 131072

# This section configures the "groove" persistent account database.
# [groove]
# ...
Expand Down
55 changes: 48 additions & 7 deletions src/app/firedancer/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,35 @@ setup_topo_funk( fd_topo_t * topo,
return obj;
}

fd_topo_obj_t *
setup_topo_progcache( fd_topo_t * topo,
char const * wksp_name,
ulong max_cache_entries,
ulong max_database_transactions,
ulong heap_size ) {
fd_topo_obj_t * obj = fd_topob_obj( topo, "funk", wksp_name );
FD_TEST( fd_pod_insert_ulong( topo->props, "progcache", obj->id ) );
FD_TEST( fd_pod_insertf_ulong( topo->props, max_cache_entries, "obj.%lu.rec_max", obj->id ) );
FD_TEST( fd_pod_insertf_ulong( topo->props, max_database_transactions, "obj.%lu.txn_max", obj->id ) );
FD_TEST( fd_pod_insertf_ulong( topo->props, heap_size, "obj.%lu.heap_max", obj->id ) );
ulong funk_footprint = fd_funk_footprint( max_database_transactions, max_cache_entries );
if( FD_UNLIKELY( !funk_footprint ) ) FD_LOG_ERR(( "Invalid [runtime.program_cache] parameters" ));
if( FD_UNLIKELY( heap_size<(2*funk_footprint) ) ) {
FD_LOG_ERR(( "Invalid [runtime.program_cache] parameters: heap_size_mib should be at least %lu",
( 4*funk_footprint )>>20 ));
}

/* Increase workspace partition count */
ulong wksp_idx = fd_topo_find_wksp( topo, wksp_name );
FD_TEST( wksp_idx!=ULONG_MAX );
fd_topo_wksp_t * wksp = &topo->workspaces[ wksp_idx ];
ulong part_max = fd_wksp_part_max_est( heap_size, 1U<<14U );
if( FD_UNLIKELY( !part_max ) ) FD_LOG_ERR(( "fd_wksp_part_max_est(%lu,16KiB) failed", funk_footprint ));
wksp->part_max += part_max;

return obj;
}

fd_topo_obj_t *
setup_topo_store( fd_topo_t * topo,
char const * wksp_name,
Expand Down Expand Up @@ -275,8 +304,8 @@ fd_topo_initialize( config_t * config ) {
fd_topob_wksp( topo, "poh_shred" );
fd_topob_wksp( topo, "poh_replay" );

/* TODO: WTF are these for? */
fd_topob_wksp( topo, "funk" );
fd_topob_wksp( topo, "progcache" );
fd_topob_wksp( topo, "bh_cmp" );
fd_topob_wksp( topo, "fec_sets" );
fd_topob_wksp( topo, "txncache" );
Expand Down Expand Up @@ -720,6 +749,15 @@ fd_topo_initialize( config_t * config ) {
FOR(resolv_tile_cnt) fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "resolv", i ) ], banks_obj, FD_SHMEM_JOIN_MODE_READ_ONLY );
FD_TEST( fd_pod_insertf_ulong( topo->props, banks_obj->id, "banks" ) );

fd_topo_obj_t * progcache_obj = setup_topo_progcache( topo, "progcache",
fd_progcache_est_rec_max( config->firedancer.runtime.program_cache.heap_size_mib<<20,
config->firedancer.runtime.program_cache.mean_cache_entry_size_kib<<10 ),
config->firedancer.funk.max_database_transactions,
config->firedancer.runtime.program_cache.heap_size_mib<<20 );
/**/ fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "replay", 0UL ) ], progcache_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
FOR(exec_tile_cnt) fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "exec", i ) ], progcache_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
FOR(bank_tile_cnt) fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "bank", i ) ], progcache_obj, FD_SHMEM_JOIN_MODE_READ_ONLY );

/* TODO: This should not exist in production */
fd_topo_obj_t * bank_hash_cmp_obj = setup_topo_bank_hash_cmp( topo, "bh_cmp" );
/**/ fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "replay", 0UL ) ], bank_hash_cmp_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
Expand Down Expand Up @@ -913,8 +951,9 @@ fd_topo_configure_tile( fd_topo_tile_t * tile,

tile->replay.tx_metadata_storage = config->rpc.extended_tx_metadata_storage;

tile->replay.txncache_obj_id = fd_pod_query_ulong( config->topo.props, "txncache", ULONG_MAX );
tile->replay.funk_obj_id = fd_pod_query_ulong( config->topo.props, "funk", ULONG_MAX );
tile->replay.txncache_obj_id = fd_pod_query_ulong( config->topo.props, "txncache", ULONG_MAX ); FD_TEST( tile->replay.txncache_obj_id !=ULONG_MAX );
tile->replay.funk_obj_id = fd_pod_query_ulong( config->topo.props, "funk", ULONG_MAX ); FD_TEST( tile->replay.funk_obj_id !=ULONG_MAX );
tile->replay.progcache_obj_id = fd_pod_query_ulong( config->topo.props, "progcache", ULONG_MAX ); FD_TEST( tile->replay.progcache_obj_id!=ULONG_MAX );

strncpy( tile->replay.cluster_version, config->tiles.replay.cluster_version, sizeof(tile->replay.cluster_version) );

Expand All @@ -937,8 +976,9 @@ fd_topo_configure_tile( fd_topo_tile_t * tile,

} else if( FD_UNLIKELY( !strcmp( tile->name, "exec" ) ) ) {

tile->exec.funk_obj_id = fd_pod_query_ulong( config->topo.props, "funk", ULONG_MAX );
tile->exec.txncache_obj_id = fd_pod_query_ulong( config->topo.props, "txncache", ULONG_MAX );
tile->exec.funk_obj_id = fd_pod_query_ulong( config->topo.props, "funk", ULONG_MAX ); FD_TEST( tile->exec.funk_obj_id !=ULONG_MAX );
tile->exec.txncache_obj_id = fd_pod_query_ulong( config->topo.props, "txncache", ULONG_MAX ); FD_TEST( tile->exec.txncache_obj_id !=ULONG_MAX );
tile->exec.progcache_obj_id = fd_pod_query_ulong( config->topo.props, "progcache", ULONG_MAX ); FD_TEST( tile->exec.progcache_obj_id!=ULONG_MAX );

tile->exec.max_live_slots = config->firedancer.runtime.max_live_slots;

Expand Down Expand Up @@ -1011,8 +1051,9 @@ fd_topo_configure_tile( fd_topo_tile_t * tile,
}

} else if( FD_UNLIKELY( !strcmp( tile->name, "bank" ) ) ) {
tile->bank.txncache_obj_id = fd_pod_query_ulong( config->topo.props, "txncache", ULONG_MAX );
tile->bank.funk_obj_id = fd_pod_query_ulong( config->topo.props, "funk", ULONG_MAX );
tile->bank.txncache_obj_id = fd_pod_query_ulong( config->topo.props, "txncache", ULONG_MAX );
tile->bank.funk_obj_id = fd_pod_query_ulong( config->topo.props, "funk", ULONG_MAX );
tile->bank.progcache_obj_id = fd_pod_query_ulong( config->topo.props, "progcache", ULONG_MAX );

tile->bank.max_live_slots = config->firedancer.runtime.max_live_slots;

Expand Down
7 changes: 7 additions & 0 deletions src/app/firedancer/topology.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ setup_topo_funk( fd_topo_t * topo,
ulong heap_size_gib,
int lock_pages );

fd_topo_obj_t *
setup_topo_progcache( fd_topo_t * topo,
char const * wksp_name,
ulong max_cache_entries,
ulong max_database_transactions,
ulong heap_size_gib );

fd_topo_obj_t *
setup_topo_runtime_pub( fd_topo_t * topo,
char const * wksp_name,
Expand Down
5 changes: 5 additions & 0 deletions src/app/shared/fd_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ struct fd_configf {
ulong max_live_slots;
ulong max_vote_accounts;
ulong max_fork_width;

struct {
ulong heap_size_mib;
ulong mean_cache_entry_size_kib;
} program_cache;
} runtime;

struct {
Expand Down
3 changes: 3 additions & 0 deletions src/app/shared/fd_config_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ fd_config_extract_podf( uchar * pod,
CFG_POP ( ulong, runtime.max_vote_accounts );
CFG_POP ( ulong, runtime.max_fork_width );

CFG_POP ( ulong, runtime.program_cache.heap_size_mib );
CFG_POP ( ulong, runtime.program_cache.mean_cache_entry_size_kib );

CFG_POP ( ulong, store.max_completed_shred_sets );

CFG_POP ( bool, snapshots.incremental_snapshots );
Expand Down
Binary file added src/ballet/sbpf/fixtures/malformed_bytecode.so
Binary file not shown.
11 changes: 11 additions & 0 deletions src/disco/topo/fd_topo.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
#include <unistd.h>
#include <sys/stat.h>

void *
fd_topo_obj_laddr( fd_topo_t const * topo,
ulong obj_id ) {
fd_topo_obj_t const * obj = &topo->objs[ obj_id ];
if( FD_UNLIKELY( obj_id==ULONG_MAX ) ) FD_LOG_CRIT(( "invalid obj_id ULONG_MAX" ));
if( FD_UNLIKELY( obj_id>=FD_TOPO_MAX_OBJS ) ) FD_LOG_CRIT(( "invalid obj_id %lu", obj_id ));
FD_TEST( obj->id == obj_id );
FD_TEST( obj->offset );
return (void *)((ulong)topo->workspaces[ obj->wksp_id ].wksp + obj->offset);
}

void
fd_topo_join_workspace( fd_topo_t * topo,
fd_topo_wksp_t * wksp,
Expand Down
13 changes: 5 additions & 8 deletions src/disco/topo/fd_topo.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ struct fd_topo_tile {
int tx_metadata_storage;
ulong funk_obj_id;
ulong txncache_obj_id;
ulong progcache_obj_id;

char shred_cap[ PATH_MAX ];
char cluster_version[ 32 ];
Expand Down Expand Up @@ -381,6 +382,7 @@ struct fd_topo_tile {
struct {
ulong funk_obj_id;
ulong txncache_obj_id;
ulong progcache_obj_id;

ulong max_live_slots;

Expand Down Expand Up @@ -543,6 +545,7 @@ struct fd_topo_tile {

ulong txncache_obj_id;
ulong funk_obj_id;
ulong progcache_obj_id;
} bank;

struct {
Expand Down Expand Up @@ -643,15 +646,9 @@ fd_topo_workspace_align( void ) {
return 4096UL;
}

static inline void *
void *
fd_topo_obj_laddr( fd_topo_t const * topo,
ulong obj_id ) {
fd_topo_obj_t const * obj = &topo->objs[ obj_id ];
FD_TEST( obj_id<FD_TOPO_MAX_OBJS );
FD_TEST( obj->id == obj_id );
FD_TEST( obj->offset );
return (void *)((ulong)topo->workspaces[ obj->wksp_id ].wksp + obj->offset);
}
ulong obj_id );

/* Returns a pointer in the local address space to the base address of
the workspace out of which the given object was allocated. */
Expand Down
2 changes: 1 addition & 1 deletion src/discof/bank/fd_bank_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ handle_microblock( fd_bank_ctx_t * ctx,
if that happens. We cannot reject the transaction here as there
would be no way to undo the partially applied changes to the bank
in finalize anyway. */
fd_runtime_finalize_txn( ctx->txn_ctx->funk, txn_ctx->status_cache, txn_ctx->xid, txn_ctx, bank, NULL );
fd_runtime_finalize_txn( ctx->txn_ctx->funk, ctx->txn_ctx->progcache, txn_ctx->status_cache, txn_ctx->xid, txn_ctx, bank, NULL );
FD_TEST( txn->flags );
}

Expand Down
30 changes: 20 additions & 10 deletions src/discof/exec/fd_exec_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ typedef struct fd_exec_tile_ctx {
fd_funk_t.
TODO: These should probably be made read-only handles. */
fd_banks_t * banks;
fd_funk_t funk[ 1 ];
void * shfunk;
void * shprogcache;
fd_funk_t funk[1];
fd_progcache_t progcache[1];

fd_txncache_t * txncache;

Expand Down Expand Up @@ -174,6 +177,7 @@ after_frag( fd_exec_tile_ctx_t * ctx,
if( FD_LIKELY( ctx->txn_ctx->flags & FD_TXN_P_FLAGS_EXECUTE_SUCCESS ) ) {
fd_runtime_finalize_txn(
ctx->funk,
ctx->progcache,
ctx->txncache,
&xid,
ctx->txn_ctx,
Expand Down Expand Up @@ -309,15 +313,15 @@ unprivileged_init( fd_topo_t * topo,
FD_LOG_ERR(( "Failed to join bank hash cmp" ));
}

/********************************************************************/
/* funk-specific setup */
/********************************************************************/

FD_TEST( fd_funk_join( ctx->funk, fd_topo_obj_laddr( topo, tile->exec.funk_obj_id ) ) );
void * shfunk = fd_topo_obj_laddr( topo, tile->exec.funk_obj_id );
if( FD_UNLIKELY( !fd_funk_join( ctx->funk, shfunk ) ) ) {
FD_LOG_CRIT(( "fd_funk_join(accdb) failed" ));
}

/********************************************************************/
/* setup txncache */
/********************************************************************/
void * shprogcache = fd_topo_obj_laddr( topo, tile->exec.progcache_obj_id );
if( FD_UNLIKELY( !fd_progcache_join( ctx->progcache, shprogcache ) ) ) {
FD_LOG_CRIT(( "fd_progcache_join() failed" ));
}

void * _txncache_shmem = fd_topo_obj_laddr( topo, tile->exec.txncache_obj_id );
fd_txncache_shmem_t * txncache_shmem = fd_txncache_shmem_join( _txncache_shmem );
Expand All @@ -332,7 +336,13 @@ unprivileged_init( fd_topo_t * topo,
fd_spad_push( ctx->exec_spad );
uchar * txn_ctx_mem = fd_spad_alloc_check( ctx->exec_spad, FD_EXEC_TXN_CTX_ALIGN, FD_EXEC_TXN_CTX_FOOTPRINT );
ctx->txn_ctx = fd_exec_txn_ctx_join( fd_exec_txn_ctx_new( txn_ctx_mem ), ctx->exec_spad, ctx->exec_spad_wksp );
ctx->txn_ctx->funk[0] = *ctx->funk;
if( FD_UNLIKELY( !fd_funk_join( ctx->txn_ctx->funk, shfunk ) ) ) {
FD_LOG_CRIT(( "fd_funk_join(accdb) failed" ));
}
ctx->txn_ctx->progcache = fd_progcache_join( ctx->txn_ctx->_progcache, shprogcache );
if( FD_UNLIKELY( !ctx->txn_ctx->progcache ) ) {
FD_LOG_CRIT(( "fd_progcache_join() failed" ));
}
ctx->txn_ctx->status_cache = ctx->txncache;
ctx->txn_ctx->bank_hash_cmp = ctx->bank_hash_cmp;
ctx->txn_ctx->spad = ctx->exec_spad;
Expand Down
Loading
Loading