Line data Source code
1 : #include "../../shared/fd_config.h" 2 : #include "../../shared/fd_action.h" 3 : 4 : #include "../../../disco/topo/fd_topo.h" 5 : #include "../../../disco/topo/fd_dns_resolve.h" 6 : #include "../../../discof/ipecho/fd_ipecho_client.h" 7 : 8 : #include <stdlib.h> 9 : #include <unistd.h> 10 : 11 : void 12 : shred_version_cmd_fn( args_t * args, 13 0 : config_t * config ) { 14 0 : (void)args; 15 : 16 0 : void * _client = aligned_alloc( FD_IPECHO_CLIENT_ALIGN, fd_ipecho_client_footprint() ); 17 0 : FD_TEST( _client ); 18 0 : fd_ipecho_client_t * client = fd_ipecho_client_join( fd_ipecho_client_new( _client ) ); 19 0 : FD_TEST( client ); 20 : 21 0 : ulong tile_idx = fd_topo_find_tile( &config->topo, "gossip", 0UL ); 22 0 : FD_TEST( tile_idx!=ULONG_MAX ); 23 : 24 0 : fd_topo_tile_t * tile = &config->topo.tiles[ tile_idx ]; 25 : 26 0 : fd_ip4_port_t entrypoints[ FD_TOPO_GOSSIP_ENTRYPOINTS_MAX ]; 27 0 : fd_dns_resolve_peers( tile->gossip.entrypoints[ 0 ], sizeof(tile->gossip.entrypoints[ 0 ]), tile->gossip.entrypoints_cnt, "gossip.entrypoints", entrypoints ); 28 0 : fd_ipecho_client_init( client, entrypoints, tile->gossip.entrypoints_cnt ); 29 : 30 0 : for(;;) { 31 0 : ushort shred_version = 0; 32 0 : int _charge_busy; 33 0 : int err = fd_ipecho_client_poll( client, &shred_version, &_charge_busy ); 34 0 : if( FD_UNLIKELY( -1==err ) ) FD_LOG_ERR(( "couldn't get shred version" )); 35 0 : if( FD_UNLIKELY( !err) ) { 36 : FD_LOG_STDOUT(( "%hu\n", shred_version )); 37 0 : break; 38 0 : } 39 0 : } 40 0 : } 41 : 42 : action_t fd_action_shred_version = { 43 : .name = "shred-version", 44 : .fn = shred_version_cmd_fn, 45 : .description = "Retrieve the current shred version from the entrypoints", 46 : .detail = "Connects to the gossip entrypoints listed in the configuration file using the\n" 47 : "IP echo protocol, prints the cluster's current shred version to stdout, and\n" 48 : "exits. Useful for filling in [consensus.expected_shred_version]. Does not\n" 49 : "require a running validator, but the entrypoints must be reachable.", 50 : .usage = "shred-version", 51 : };