|
| 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 | +}; |
0 commit comments