Skip to content

Commit

Permalink
fddev: allow diagnostic commands in production
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcgee-jump committed Nov 18, 2024
1 parent 1c1d27b commit 11a8d10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
22 changes: 2 additions & 20 deletions src/app/fdctl/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,21 +365,13 @@ validate_ports( config_t * result ) {
#define FD_CONFIG_CLUSTER_MAINNET_BETA (5UL)

FD_FN_PURE static ulong
determine_cluster( ulong entrypoints_cnt,
char entrypoints[16][256],
char * expected_genesis_hash ) {
determine_cluster( char * expected_genesis_hash ) {
char const * DEVNET_GENESIS_HASH = "EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG";
char const * TESTNET_GENESIS_HASH = "4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY";
char const * MAINNET_BETA_GENESIS_HASH = "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d";
char const * PYTHTEST_GENESIS_HASH = "EkCkB7RWVrgkcpariRpd3pjf7GwiCMZaMHKUpB5Na1Ve";
char const * PYTHNET_GENESIS_HASH = "GLKkBUr6r72nBtGrtBPJLRqtsh8wXZanX4xfnqKnWwKq";

char const * DEVNET_ENTRYPOINT_URI = "devnet.solana.com";
char const * TESTNET_ENTRYPOINT_URI = "testnet.solana.com";
char const * MAINNET_BETA_ENTRYPOINT_URI = "mainnet-beta.solana.com";
char const * PYTHTEST_ENTRYPOINT_URI = "pythtest.pyth.network";
char const * PYTHNET_ENTRYPOINT_URI = "pythnet.pyth.network";

ulong cluster = FD_CONFIG_CLUSTER_UNKNOWN;
if( FD_LIKELY( expected_genesis_hash ) ) {
if( FD_UNLIKELY( !strcmp( expected_genesis_hash, DEVNET_GENESIS_HASH ) ) ) cluster = FD_CONFIG_CLUSTER_DEVNET;
Expand All @@ -389,14 +381,6 @@ determine_cluster( ulong entrypoints_cnt,
else if( FD_UNLIKELY( !strcmp( expected_genesis_hash, PYTHNET_GENESIS_HASH ) ) ) cluster = FD_CONFIG_CLUSTER_PYTHNET;
}

for( ulong i=0; i<entrypoints_cnt; i++ ) {
if( FD_UNLIKELY( strstr( entrypoints[ i ], DEVNET_ENTRYPOINT_URI ) ) ) cluster = fd_ulong_max( cluster, FD_CONFIG_CLUSTER_DEVNET );
else if( FD_UNLIKELY( strstr( entrypoints[ i ], TESTNET_ENTRYPOINT_URI ) ) ) cluster = fd_ulong_max( cluster, FD_CONFIG_CLUSTER_TESTNET );
else if( FD_UNLIKELY( strstr( entrypoints[ i ], MAINNET_BETA_ENTRYPOINT_URI ) ) ) cluster = fd_ulong_max( cluster, FD_CONFIG_CLUSTER_MAINNET_BETA );
else if( FD_UNLIKELY( strstr( entrypoints[ i ], PYTHTEST_ENTRYPOINT_URI ) ) ) cluster = fd_ulong_max( cluster, FD_CONFIG_CLUSTER_PYTHTEST );
else if( FD_UNLIKELY( strstr( entrypoints[ i ], PYTHNET_ENTRYPOINT_URI ) ) ) cluster = fd_ulong_max( cluster, FD_CONFIG_CLUSTER_PYTHNET );
}

return cluster;
}

Expand Down Expand Up @@ -523,9 +507,7 @@ fdctl_cfg_from_env( int * pargc,
FD_LOG_ERR(( "could not get name of interface with index %d", ifindex ));
}

ulong cluster = determine_cluster( config->gossip.entrypoints_cnt,
config->gossip.entrypoints,
config->consensus.expected_genesis_hash );
ulong cluster = determine_cluster( config->consensus.expected_genesis_hash );
config->is_live_cluster = cluster != FD_CONFIG_CLUSTER_UNKNOWN;

if( FD_UNLIKELY( config->development.netns.enabled ) ) {
Expand Down
12 changes: 6 additions & 6 deletions src/app/fddev/main1.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,6 @@ fddev_main( int argc,

fdctl_boot( &argc, &argv, &config, log_path );

/* load configuration and command line parsing */
if( FD_UNLIKELY( config.is_live_cluster ) )
FD_LOG_ERR(( "The `fddev` command is for development and test environments but your "
"configuration targets a live cluster. Use `fdctl` if this is a "
"production environment" ));

int no_sandbox = fd_env_strip_cmdline_contains( &argc, &argv, "--no-sandbox" );
int no_clone = fd_env_strip_cmdline_contains( &argc, &argv, "--no-clone" );
config.development.no_clone = config.development.no_clone || no_clone;
Expand Down Expand Up @@ -202,6 +196,12 @@ fddev_main( int argc,

if( FD_UNLIKELY( !action ) ) FD_LOG_ERR(( "unknown subcommand `%s`", action_name ));

int is_allowed_live = !strcmp( action->name, "flame" ) || !strcmp( action->name, "dump" );
if( FD_UNLIKELY( config.is_live_cluster && !is_allowed_live ) )
FD_LOG_ERR(( "The `fddev` command is for development and test environments but your "
"configuration targets a live cluster. Use `fdctl` if this is a "
"production environment" ));

args_t args = {0};
if( FD_LIKELY( action->args ) ) action->args( &argc, &argv, &args );
if( FD_UNLIKELY( argc ) ) FD_LOG_ERR(( "unknown argument `%s`", argv[ 0 ] ));
Expand Down

0 comments on commit 11a8d10

Please sign in to comment.