Skip to content

Commit d291afd

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 d291afd

File tree

5 files changed

+118
-0
lines changed

5 files changed

+118
-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: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 "../../../disco/shred/fd_shred_tile.h"
7+
#include <unistd.h>
8+
9+
void
10+
get_identity_cmd_fn( args_t * args FD_PARAM_UNUSED,
11+
config_t * config ) {
12+
/* Find the shred tile which is always present and has the current runtime identity */
13+
ulong shred_tile_idx = fd_topo_find_tile( &config->topo, "shred", 0UL );
14+
if( FD_UNLIKELY( shred_tile_idx==ULONG_MAX ) ) {
15+
FD_LOG_ERR(( "Shred tile not found in topology" ));
16+
}
17+
18+
fd_topo_tile_t const * shred_tile = &config->topo.tiles[ shred_tile_idx ];
19+
20+
/* Access shred tile object to find its workspace */
21+
if( FD_UNLIKELY( shred_tile->tile_obj_id==ULONG_MAX ) ) {
22+
FD_LOG_ERR(( "Shred tile object not found" ));
23+
}
24+
25+
/* Find the workspace containing the shred tile object */
26+
fd_topo_obj_t const * shred_obj = &config->topo.objs[ shred_tile->tile_obj_id ];
27+
ulong shred_wksp_id = shred_obj->wksp_id;
28+
29+
/* Join the workspace in read-only mode */
30+
fd_topo_join_workspace( &config->topo, &config->topo.workspaces[ shred_wksp_id ], FD_SHMEM_JOIN_MODE_READ_ONLY );
31+
fd_topo_workspace_fill( &config->topo, &config->topo.workspaces[ shred_wksp_id ] );
32+
33+
/* Access the shred context through the workspace */
34+
void * shred_mem = fd_topo_obj_laddr( &config->topo, shred_tile->tile_obj_id );
35+
if( FD_UNLIKELY( !shred_mem ) ) {
36+
fd_topo_leave_workspaces( &config->topo );
37+
FD_LOG_ERR(( "Failed to access shred tile object" ));
38+
}
39+
40+
/* Cast to shred context structure */
41+
fd_shred_ctx_t const * shred_ctx = (fd_shred_ctx_t const *)shred_mem;
42+
43+
/* The shred tile maintains the current identity in shred_ctx->identity_key.
44+
TODO: There's a potential edge case where this could return a torn/corrupt
45+
identity key if the shred tile is currently processing a set-identity command
46+
and has only overwritten half of the bytes. This is exceedingly rare but
47+
should be addressed in the future with proper synchronization. */
48+
fd_pubkey_t const * identity_key = shred_ctx->identity_key;
49+
50+
/* Convert to base58 and print */
51+
char identity_key_str[ FD_BASE58_ENCODED_32_SZ ];
52+
fd_base58_encode_32( identity_key->uc, NULL, identity_key_str );
53+
54+
FD_LOG_STDOUT(( "%s\n", identity_key_str ));
55+
}
56+
57+
action_t fd_action_get_identity = {
58+
.name = "get-identity",
59+
.args = NULL,
60+
.fn = get_identity_cmd_fn,
61+
.require_config = 1,
62+
.perm = NULL, /* TODO: This command may require RLIMIT_MLOCK permissions
63+
to mlock(2) the workspace in memory. This should be
64+
addressed in future updates. */
65+
.description = "Get the current active identity of the running validator",
66+
};
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 */

src/disco/shred/fd_shred_tile.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#ifndef HEADER_fd_src_disco_shred_fd_shred_tile_h
2+
#define HEADER_fd_src_disco_shred_fd_shred_tile_h
3+
4+
#include "../tiles.h"
5+
#include "../../flamenco/types/fd_types_custom.h"
6+
7+
/* Forward declarations */
8+
typedef struct fd_shredder fd_shredder_t;
9+
typedef struct fd_fec_resolver fd_fec_resolver_t;
10+
typedef struct fd_keyswitch fd_keyswitch_t;
11+
typedef struct fd_keyguard_client fd_keyguard_client_t;
12+
13+
/* Shred tile context structure */
14+
typedef struct {
15+
fd_shredder_t * shredder;
16+
fd_fec_resolver_t * resolver;
17+
fd_pubkey_t identity_key[1]; /* Just the public key */
18+
19+
ulong round_robin_id;
20+
ulong round_robin_cnt;
21+
/* Number of batches shredded from PoH during the current slot.
22+
This should be the same for all the shred tiles. */
23+
ulong batch_cnt;
24+
/* Slot of the most recent microblock we've seen from PoH,
25+
or 0 if we haven't seen one yet */
26+
ulong slot;
27+
28+
fd_keyswitch_t * keyswitch;
29+
fd_keyguard_client_t keyguard_client[1];
30+
/* ... rest of the structure members ... */
31+
} fd_shred_ctx_t;
32+
33+
#endif /* HEADER_fd_src_disco_shred_fd_shred_tile_h */
34+
35+

0 commit comments

Comments
 (0)