Skip to content

Feature/cmdline overrides #5546

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

Closed
wants to merge 3 commits into from
Closed
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
32 changes: 30 additions & 2 deletions src/app/shared/boot/fd_boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <stdio.h>

extern action_t * ACTIONS[];
extern fd_topo_run_tile_t * TILES[];
Expand Down Expand Up @@ -71,6 +72,29 @@ should_colorize( void ) {
return 0;
}

/* Applies command-line overrides of the form --section.option value
Only add supported keys here. Extend this function as needed. */
static void
apply_cmdline_overrides(int *pargc, char ***pargv, config_t *config) {
for (int i = 1; i < *pargc - 1; i++) {
// Match keys like --section.option value
if (strncmp((*pargv)[i], "--", 2) == 0 && strchr((*pargv)[i], '.')) {
const char *key = (*pargv)[i] + 2; // Skip leading "--"
const char *value = (*pargv)[i + 1]; // Next arg is value

if (!strcmp(key, "hugetlbfs.max_page_size")) {
strncpy(config->hugetlbfs.max_page_size, value, sizeof(config->hugetlbfs.max_page_size) - 1);
config->hugetlbfs.max_page_size[sizeof(config->hugetlbfs.max_page_size) - 1] = '\0';
} else {
// Print a warning for unknown override keys
FD_LOG_WARNING(("Unknown override option: --%s (ignored)", key));
}

i++; // Skip value
}
}
}

void
fd_main_init( int * pargc,
char *** pargv,
Expand All @@ -94,7 +118,7 @@ fd_main_init( int * pargc,
if( FD_UNLIKELY( config_fd >= 0 ) ) {
copy_config_from_fd( config_fd, config );
/* tick_per_ns needs to be synchronized across processes so that
they can coordinate on metrics measurement. */
they can coordinate on metrics measurement. */
fd_tempo_set_tick_per_ns( config->tick_per_ns_mu, config->tick_per_ns_sigma );
} else {
char * user_config = NULL;
Expand All @@ -108,6 +132,10 @@ fd_main_init( int * pargc,
fd_config_load( is_firedancer, netns, is_local_cluster, default_config, default_config_sz, user_config, user_config_sz, opt_user_config_path, config );
topo_init( config );

/* --- APPLY COMMAND-LINE OVERRIDES --- */
apply_cmdline_overrides(pargc, pargv, config);
/* --- END OVERRIDES --- */

if( FD_UNLIKELY( user_config && -1==munmap( user_config, user_config_sz ) ) ) FD_LOG_ERR(( "munmap() failed (%i-%s)", errno, fd_io_strerror( errno ) ));

config->log.lock_fd = init_log_memfd();
Expand All @@ -132,7 +160,7 @@ fd_main_init( int * pargc,
if( FD_LIKELY( config->log.path[ 0 ]=='\0' ) ) log_path = NULL;

/* Switch to the sandbox uid/gid for log file creation, so it's always
owned by that user. */
owned by that user. */

gid_t gid = getgid();
uid_t uid = getuid();
Expand Down
4 changes: 2 additions & 2 deletions src/discof/bank/fd_bank_abi.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ fd_bank_abi_resolve_address_lookup_tables( void const * bank FD_PARAM_UNUSED
}

/* Look up the pubkeys from the ALTs */
fd_slot_hashes_global_t const * slot_hashes_global = fd_sysvar_cache_slot_hashes(
ctx->slot_ctx->sysvar_cache, ctx->runtime_public_wksp );
fd_slot_hashes_global_t const * slot_hashes_global = fd_sysvar_slot_hashes_read(
ctx->txn_ctx->funk, ctx->txn_ctx->funk_txn, ctx->txn_ctx->spad );
if( FD_UNLIKELY( !slot_hashes_global ) ) {
FD_LOG_ERR(( "failed to get slot hashes global" ));
}
Expand Down
59 changes: 48 additions & 11 deletions src/flamenco/vm/syscall/fd_vm_syscall_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,55 @@ fd_vm_syscall_sol_get_sysvar( /**/ void * _vm,
return FD_VM_SUCCESS;
}

/* we know that the account data won't be changed for the lifetime of this view, because sysvars don't change inter-block */
FD_TXN_ACCOUNT_DECL( sysvar_account );
err = fd_txn_account_init_from_funk_readonly( sysvar_account, sysvar_id, vm->instr_ctx->txn_ctx->funk, vm->instr_ctx->txn_ctx->funk_txn );
if( FD_UNLIKELY( err ) ) {
*_ret = 2UL;
return FD_VM_SUCCESS;
/* Select the correct sysvar by pubkey and read it directly from the sysvar cache. */
const uchar * sysvar_buf = NULL;
ulong sysvar_buf_len = 0;

if( memcmp( sysvar_id->uc, fd_sysvar_clock_id.uc, FD_PUBKEY_FOOTPRINT ) == 0 ) {
const fd_sol_sysvar_clock_t *clock = fd_sysvar_clock_read(
vm->instr_ctx->txn_ctx->funk,
vm->instr_ctx->txn_ctx->funk_txn,
vm->instr_ctx->txn_ctx->spad
);
sysvar_buf = (const uchar *)clock;
sysvar_buf_len = sizeof(fd_sol_sysvar_clock_t);
} else if( memcmp( sysvar_id->uc, fd_sysvar_epoch_schedule_id.uc, FD_PUBKEY_FOOTPRINT ) == 0 ) {
const fd_epoch_schedule_t *schedule = fd_sysvar_epoch_schedule_read(
vm->instr_ctx->txn_ctx->funk,
vm->instr_ctx->txn_ctx->funk_txn,
vm->instr_ctx->txn_ctx->spad
);
sysvar_buf = (const uchar *)schedule;
sysvar_buf_len = sizeof(fd_epoch_schedule_t);
} else if( memcmp( sysvar_id->uc, fd_sysvar_epoch_rewards_id.uc, FD_PUBKEY_FOOTPRINT ) == 0 ) {
const fd_sysvar_epoch_rewards_t *epoch_rewards = fd_sysvar_epoch_rewards_read(
vm->instr_ctx->txn_ctx->funk,
vm->instr_ctx->txn_ctx->funk_txn,
vm->instr_ctx->txn_ctx->spad
);
sysvar_buf = (const uchar *)epoch_rewards;
sysvar_buf_len = sizeof(fd_sysvar_epoch_rewards_t);
} else if( memcmp( sysvar_id->uc, fd_sysvar_rent_id.uc, FD_PUBKEY_FOOTPRINT ) == 0 ) {
const fd_rent_t *rent = fd_sysvar_rent_read(
vm->instr_ctx->txn_ctx->funk,
vm->instr_ctx->txn_ctx->funk_txn,
vm->instr_ctx->txn_ctx->spad
);
sysvar_buf = (const uchar *)rent;
sysvar_buf_len = sizeof(fd_rent_t);
} else if( memcmp( sysvar_id->uc, fd_sysvar_last_restart_slot_id.uc, FD_PUBKEY_FOOTPRINT ) == 0 ) {
const fd_sol_sysvar_last_restart_slot_t *slot = fd_sysvar_last_restart_slot_read(
vm->instr_ctx->txn_ctx->funk,
vm->instr_ctx->txn_ctx->funk_txn,
vm->instr_ctx->txn_ctx->spad
);
sysvar_buf = (const uchar *)slot;
sysvar_buf_len = sizeof(fd_sol_sysvar_last_restart_slot_t);
} else {
*_ret = 2UL;
return FD_VM_SUCCESS;
}

/* https://github.com/anza-xyz/agave/blob/v2.1.0/programs/bpf_loader/src/syscalls/sysvar.rs#L223-L228
Note the length check is at the very end to fail after performing sufficient checks. */
const uchar * sysvar_buf = sysvar_account->vt->get_data( sysvar_account );
ulong sysvar_buf_len = sysvar_account->vt->get_data_len( sysvar_account );


if( FD_UNLIKELY( offset_length>sysvar_buf_len ) ) {
*_ret = 1UL;
Expand Down