LCOV - code coverage report
Current view: top level - app/firedancer/commands - get_identity.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 49 0.0 %
Date: 2026-08-14 04:54:57 Functions: 0 3 0.0 %

          Line data    Source code
       1             : #define _GNU_SOURCE
       2             : #include "adminctl_client.h"
       3             : #include "../../shared/fd_config.h"
       4             : #include "../../shared/fd_action.h"
       5             : 
       6             : #include "../../../ballet/base58/fd_base58.h"
       7             : 
       8             : #include <unistd.h>
       9             : 
      10             : void
      11             : get_identity_cmd_args( int *    pargc,
      12             :                        char *** pargv,
      13           0 :                        args_t * args ) {
      14           0 :   char const * name = fd_env_strip_cmdline_cstr( pargc, pargv, "--name", NULL, NULL );
      15           0 :   if( FD_UNLIKELY( name ) ) fd_cstr_ncpy( args->get_identity.name, name, sizeof(args->get_identity.name) );
      16           0 : }
      17             : 
      18             : void
      19             : get_identity_cmd_fn( args_t *   args,
      20           0 :                      config_t * config ) {
      21           0 :   fd_adminctl_t * adminctl = adminctl_client_attach( config, args->get_identity.name );
      22             : 
      23           0 :   void * payload     = NULL;
      24           0 :   ulong  payload_max = 0UL;
      25           0 :   ulong  slot_idx    = fd_adminctl_reserve( adminctl, &payload, &payload_max );
      26           0 :   if( FD_UNLIKELY( slot_idx==ULONG_MAX ) ) {
      27           0 :     FD_LOG_ERR(( "Failed to process `get-identity` command as there are other pending "
      28           0 :                  "commands that are being processed.  Please wait for other commands to complete "
      29           0 :                  "or forcefully terminate the other processes and retry the command." ));
      30           0 :   }
      31           0 :   if( FD_UNLIKELY( sizeof(fd_adminctl_get_identity_req_t)>payload_max ) ) FD_LOG_ERR(( "adminctl get-identity payload too large" ));
      32             : 
      33           0 :   fd_adminctl_get_identity_req_t * req = (fd_adminctl_get_identity_req_t *)payload;
      34           0 :   req->version = FD_ADMINCTL_GET_IDENTITY_PAYLOAD_VERSION;
      35             : 
      36           0 :   fd_adminctl_publish( adminctl, slot_idx, FD_ADMINCTL_CMD_GET_IDENTITY, sizeof(fd_adminctl_get_identity_req_t) );
      37             : 
      38           0 :   fd_adminctl_get_identity_resp_t resp = {0};
      39           0 :   ulong resp_sz = 0UL;
      40           0 :   ulong result  = fd_adminctl_wait_response( adminctl, slot_idx, &resp, sizeof(resp), &resp_sz );
      41           0 :   switch( result ) {
      42           0 :     case FD_ADMINCTL_RESULT_SUCCESS: {
      43           0 :       if( FD_UNLIKELY( resp_sz!=sizeof(resp) || resp.version!=FD_ADMINCTL_GET_IDENTITY_PAYLOAD_VERSION ) )
      44           0 :         FD_LOG_ERR(( "Failed to get identity: the running Firedancer process returned an unexpected "
      45           0 :                      "response.  It is possible that you are running the command from an older or "
      46           0 :                      "newer version of Firedancer that is no longer compatible." ));
      47           0 :       char identity_key_str[ FD_BASE58_ENCODED_32_SZ ];
      48           0 :       fd_base58_encode_32( resp.identity_pubkey, NULL, identity_key_str );
      49           0 :       FD_LOG_STDOUT(( "%s\n", identity_key_str ));
      50           0 :       break;
      51           0 :     }
      52           0 :     case FD_ADMINCTL_RESULT_UNKNOWN_COMMAND:
      53           0 :     case FD_GET_IDENTITY_RESULT_PAYLOAD_TOO_SMALL:
      54           0 :     case FD_GET_IDENTITY_RESULT_UNSUPPORTED_PAYLOAD_VERSION:
      55           0 :     case FD_GET_IDENTITY_RESULT_UNEXPECTED_PAYLOAD_SIZE:
      56           0 :       FD_LOG_ERR(( "Failed to get identity: the command was not able to successfully communicate "
      57           0 :                    "with the running Firedancer process. It is possible that you are running the "
      58           0 :                    "command from an older or newer version of Firedancer that is no longer compatible." ));
      59           0 :     default:
      60           0 :       FD_LOG_ERR(( "Unexpected get-identity result %lu.  This can be a result of a version mismatch "
      61           0 :                    "between the command and the running Firedancer process. Please report this to the "
      62           0 :                    "Firedancer team for investigation.", result ));
      63           0 :   }
      64           0 : }
      65             : 
      66             : static void
      67           0 : get_identity_args_help( fd_action_help_t * help ) {
      68           0 :   fd_action_help_arg( help, "--name", "<name>", "Name of the validator instance to attach to, if more than one is\n"
      69           0 :                                                 "running on this host" );
      70           0 : }
      71             : 
      72             : action_t fd_action_get_identity = {
      73             :   .name           = "get-identity",
      74             :   .args           = get_identity_cmd_args,
      75             :   .fn             = get_identity_cmd_fn,
      76             :   .require_config = 0,
      77             :   .perm           = NULL,
      78             :   .description    = "Get the current active identity of the running validator",
      79             :   .detail         = "Prints the base58 encoded identity public key the running validator is\n"
      80             :                     "currently using for gossip, voting, and block production.  This may differ\n"
      81             :                     "from [paths.identity_key] in the configuration file if the identity was\n"
      82             :                     "changed at runtime with `set-identity`.\n"
      83             :                     "\n"
      84             :                     "This command does not start a validator; it attaches to one that is already\n"
      85             :                     "running.  With no arguments it discovers the running validator automatically.\n"
      86             :                     "If multiple validators are running, pass --name to select one.  If --config is\n"
      87             :                     "given, the validator is instead located from the configuration file; only the\n"
      88             :                     "name and [hugetlbfs.mount_path] values are used, and they must match the\n"
      89             :                     "running validator.\n",
      90             :   .usage          = "get-identity [--name <name>]",
      91             :   .args_help      = get_identity_args_help,
      92             : };

Generated by: LCOV version 1.14