Skip to content

Commit 437c8f8

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 437c8f8

File tree

4 files changed

+87
-0
lines changed

4 files changed

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