Skip to content

Commit e82cb5a

Browse files
committed
fdctl: add get-identity command to retrieve runtime validator identity
Add new fdctl command to query the current runtime identity of a running validator. This command reads the identity from the GUI tile's shared memory, which reflects any changes made by set-identity. The command requires GUI to be enabled, as it's the most reliable source for the current runtime identity that persists across identity switches. Usage: fdctl get-identity Returns the validator's current identity public key in base58 format.
1 parent eda6db8 commit e82cb5a

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

src/app/fdctl/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ extern action_t fd_action_ready;
9292
extern action_t fd_action_mem;
9393
extern action_t fd_action_netconf;
9494
extern action_t fd_action_set_identity;
95+
extern action_t fd_action_get_identity;
9596
extern action_t fd_action_help;
9697
extern action_t fd_action_version;
9798

@@ -106,6 +107,7 @@ action_t * ACTIONS[] = {
106107
&fd_action_mem,
107108
&fd_action_netconf,
108109
&fd_action_set_identity,
110+
&fd_action_get_identity,
109111
&fd_action_help,
110112
&fd_action_version,
111113
NULL,

src/app/shared/Local.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ $(call add-objs,commands/mem,fdctl_shared)
1818
$(call add-objs,commands/netconf,fdctl_shared)
1919
$(call add-objs,commands/ready,fdctl_shared)
2020
$(call add-objs,commands/set_identity,fdctl_shared)
21+
$(call add-objs,commands/get_identity,fdctl_shared)
2122
$(call add-objs,commands/version,fdctl_shared)
2223
$(call add-objs,commands/configure/configure,fdctl_shared)
2324
$(call add-objs,commands/configure/ethtool-channels,fdctl_shared)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include "../fd_config.h"
2+
#include "../fd_action.h"
3+
#include "../../../util/fd_util.h"
4+
#include "../../../ballet/base58/fd_base58.h"
5+
#include "../../../flamenco/types/fd_types_custom.h"
6+
#include <unistd.h>
7+
8+
/* Minimal shred tile context structure to access identity_key.
9+
Based on fd_shred_tile.c, the identity_key is the third field. */
10+
typedef struct {
11+
void * shredder; /* fd_shredder_t * */
12+
void * resolver; /* fd_fec_resolver_t * */
13+
fd_pubkey_t identity_key[1];
14+
/* ... other fields we don't need ... */
15+
} fd_shred_ctx_minimal_t;
16+
17+
void
18+
get_identity_cmd_fn( args_t * args FD_PARAM_UNUSED,
19+
config_t * config ) {
20+
/* Find the shred tile which is always present and has the current runtime identity */
21+
ulong shred_tile_idx = fd_topo_find_tile( &config->topo, "shred", 0UL );
22+
if( FD_UNLIKELY( shred_tile_idx==ULONG_MAX ) ) {
23+
FD_LOG_ERR(( "Shred tile not found in topology" ));
24+
}
25+
26+
fd_topo_tile_t const * shred_tile = &config->topo.tiles[ shred_tile_idx ];
27+
28+
/* Access shred tile object to find its workspace */
29+
if( FD_UNLIKELY( shred_tile->tile_obj_id==ULONG_MAX ) ) {
30+
FD_LOG_ERR(( "Shred tile object not found" ));
31+
}
32+
33+
/* Find the workspace containing the shred tile object */
34+
fd_topo_obj_t const * shred_obj = &config->topo.objs[ shred_tile->tile_obj_id ];
35+
ulong shred_wksp_id = shred_obj->wksp_id;
36+
37+
/* Join the workspace in read-only mode */
38+
fd_topo_join_workspace( &config->topo, &config->topo.workspaces[ shred_wksp_id ], FD_SHMEM_JOIN_MODE_READ_ONLY );
39+
fd_topo_workspace_fill( &config->topo, &config->topo.workspaces[ shred_wksp_id ] );
40+
41+
/* Access the shred context through the workspace */
42+
void * shred_mem = fd_topo_obj_laddr( &config->topo, shred_tile->tile_obj_id );
43+
if( FD_UNLIKELY( !shred_mem ) ) {
44+
fd_topo_leave_workspaces( &config->topo );
45+
FD_LOG_ERR(( "Failed to access shred tile object" ));
46+
}
47+
48+
/* Cast to our minimal context structure */
49+
fd_shred_ctx_minimal_t const * shred_ctx = (fd_shred_ctx_minimal_t const *)shred_mem;
50+
51+
/* The shred tile maintains the current identity in shred_ctx->identity_key */
52+
fd_pubkey_t const * identity_key = shred_ctx->identity_key;
53+
54+
/* Convert to base58 and print */
55+
char identity_key_str[ FD_BASE58_ENCODED_32_SZ ];
56+
fd_base58_encode_32( identity_key->uc, NULL, identity_key_str );
57+
58+
FD_LOG_STDOUT(( "%s\n", identity_key_str ));
59+
60+
/* Leave the workspace */
61+
fd_topo_leave_workspaces( &config->topo );
62+
}
63+
64+
action_t fd_action_get_identity = {
65+
.name = "get-identity",
66+
.args = NULL,
67+
.fn = get_identity_cmd_fn,
68+
.require_config = 1,
69+
.perm = NULL,
70+
.description = "Get the current active identity of the running validator",
71+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef HEADER_fd_src_app_shared_commands_get_identity_h
2+
#define HEADER_fd_src_app_shared_commands_get_identity_h
3+
4+
#include "../fd_config.h"
5+
6+
FD_PROTOTYPES_BEGIN
7+
8+
void get_identity_cmd_fn( args_t * args, config_t * config );
9+
10+
FD_PROTOTYPES_END
11+
12+
extern action_t fd_action_get_identity;
13+
14+
#endif /* HEADER_fd_src_app_shared_commands_get_identity_h */

0 commit comments

Comments
 (0)