Skip to content

Commit

Permalink
fdctl: wire up new toml parser
Browse files Browse the repository at this point in the history
  • Loading branch information
riptl authored and mmcgee-jump committed Jun 26, 2024
1 parent 5e68dd4 commit d11a36b
Show file tree
Hide file tree
Showing 9 changed files with 488 additions and 444 deletions.
3 changes: 2 additions & 1 deletion src/app/fdctl/Local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ $(OBJDIR)/obj/app/fdctl/version.d: src/app/fdctl/version.h
.PHONY: fdctl cargo-validator cargo-solana rust solana check-solana-hash

# fdctl core
$(call add-objs,main1 config caps utility keys ready mem spy help version,fd_fdctl)
$(call add-objs,main1 config config_parse caps utility keys ready mem spy help version,fd_fdctl)
$(call add-objs,run/run run/run1 run/run_solana run/topos/topos,fd_fdctl)
$(call add-objs,monitor/monitor monitor/helper,fd_fdctl)
$(call make-fuzz-test,fuzz_fdctl_config,fuzz_fdctl_config,fd_fdctl fd_ballet fd_util)

# fdctl tiles
$(call add-objs,run/tiles/fd_net,fd_fdctl)
Expand Down
492 changes: 59 additions & 433 deletions src/app/fdctl/config.c

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions src/app/fdctl/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,13 @@ typedef struct {
} metric;

/* Firedancer-only tile configs */

struct {
ulong entrypoints_cnt;
char entrypoints[16][256];
ushort gossip_listen_port;
ulong peer_ports_cnt;
uint peer_ports[16];
ushort peer_ports[16];
} gossip;

struct {
Expand Down Expand Up @@ -271,22 +271,24 @@ typedef struct {
ulong
memlock_max_bytes( config_t * const config );

/* config_parse() loads a full configuration object from the provided
/* fdctl_cfg_from_env() loads a full configuration object from the provided
arguments or the environment. First, the `default.toml` file is
loaded as a base, and then if a FIREDANCER_CONFIG_FILE environment
variable is provided, or a --config <path> command line argument, the
`toml` file at that path is loaded and applied on top of the default
configuration. This exits the program if it encounters any issue
while loading or parsing the configuration. */

void
config_parse( int * pargc,
char *** pargv,
config_t * config );
fdctl_cfg_from_env( int * pargc,
char *** pargv,
config_t * config );

/* Create a memfd and write the contents of the config struct into it.
Used when execve() a child process so that it can read back in the
same config as we did. */

int
config_write_memfd( config_t * config );
fdctl_cfg_to_memfd( config_t * config );

#endif /* HEADER_fd_src_app_fdctl_config_h */
362 changes: 362 additions & 0 deletions src/app/fdctl/config_parse.c

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions src/app/fdctl/config_parse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef HEADER_fd_src_app_fdctl_config_parse_h
#define HEADER_fd_src_app_fdctl_config_parse_h

#include "config.h"

FD_PROTOTYPES_BEGIN

/* fdctl_pod_to_cfg extracts configuration from pod to the typed config
struct. Any recognized keys are removed from pod. Logs errors to
warning log. Returns config on success, NULL on error.
Not thread safe (uses global buffer). */

config_t *
fdctl_pod_to_cfg( config_t * config,
uchar * pod );

FD_PROTOTYPES_END

#endif /* HEADER_fd_src_app_fdctl_config_parse_h */
33 changes: 33 additions & 0 deletions src/app/fdctl/fuzz_fdctl_config.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "config_parse.h"
#include "../../ballet/toml/fd_toml.h"
#include "../../util/fd_util.h"
#include "../../util/sanitize/fd_fuzz.h"

#include <assert.h>
#include <stdlib.h>

int
LLVMFuzzerInitialize( int * argc,
char *** argv ) {
putenv( "FD_LOG_BACKTRACE=0" );
fd_boot( argc, argv );
atexit( fd_halt );
fd_log_level_logfile_set( 4 );
fd_log_level_stderr_set( 4 );
return 0;
}

int
LLVMFuzzerTestOneInput( uchar const * data,
ulong size ) {

static uchar pod_mem[ 1UL<<16 ];
uchar * pod = fd_pod_join( fd_pod_new( pod_mem, sizeof(pod_mem) ) );

static uchar scratch[ 4096 ];
(void)fd_toml_parse( data, size, pod, scratch, sizeof(scratch) );

static config_t config = {0};
fdctl_pod_to_cfg( &config, pod );
return 0;
}
2 changes: 1 addition & 1 deletion src/app/fdctl/main1.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ fdctl_boot( int * pargc,
can coordinate on metrics measurement. */
fd_tempo_set_tick_per_ns( config->tick_per_ns_mu, config->tick_per_ns_sigma );
} else {
config_parse( pargc, pargv, config );
fdctl_cfg_from_env( pargc, pargv, config );
config->tick_per_ns_mu = fd_tempo_tick_per_ns( &config->tick_per_ns_sigma );
config->log.lock_fd = init_log_memfd();
config->log.log_fd = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/app/fdctl/run/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ main_pid_namespace( void * _args ) {
char child_names[ FD_TOPO_MAX_TILES+1 ][ 32 ];
struct pollfd fds[ FD_TOPO_MAX_TILES+2 ];

int config_memfd = config_write_memfd( config );
int config_memfd = fdctl_cfg_to_memfd( config );

if( FD_UNLIKELY( config->development.debug_tile ) ) {
fd_log_private_shared_lock[1] = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/app/fddev/tests/test_fddev.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fddev_test_run( int argc,
fd_log_thread_set( "supervisor" );

static config_t config[1];
config_parse( &argc, &argv, config );
fdctl_cfg_from_env( &argc, &argv, config );
config->log.log_fd = fd_log_private_logfile_fd();
config->log.lock_fd = init_log_memfd();
config->tick_per_ns_mu = fd_tempo_tick_per_ns( &config->tick_per_ns_sigma );
Expand Down

0 comments on commit d11a36b

Please sign in to comment.