Line data Source code
1 : #include "../../shared/commands/configure/configure.h"
2 : #include "../../shared/commands/run/run.h" /* initialize_workspaces */
3 : #include "../../shared/fd_config.h" /* config_t */
4 : #include "../../../disco/topo/fd_topob.h"
5 : #include "../../../disco/net/fd_net_tile.h" /* fd_topos_net_tiles */
6 : #include "../../../disco/fd_clock_tile.h"
7 : #include "../../../discof/gossip/fd_gossip_tile.h"
8 :
9 : #include "../../firedancer/commands/monitor_gossip/gossip_diag.h"
10 :
11 : #include "core_subtopo.h"
12 : #include "gossip.h"
13 :
14 : #include <stdio.h> /* printf */
15 : #include <stdlib.h>
16 : #include <unistd.h> /* isatty */
17 : #include <sys/ioctl.h>
18 :
19 : extern fd_topo_obj_callbacks_t * CALLBACKS[];
20 :
21 : fd_topo_run_tile_t
22 : fdctl_tile_run( fd_topo_tile_t const * tile );
23 :
24 : void
25 : resolve_gossip_entrypoints( config_t * config );
26 :
27 : static void
28 0 : gossip_cmd_topo( config_t * config ) {
29 0 : resolve_gossip_entrypoints( config );
30 :
31 : /* Disable non-gossip listen ports */
32 0 : config->tiles.shred.shred_listen_port = 0U;
33 0 : config->tiles.quic.quic_transaction_listen_port = 0U;
34 0 : config->tiles.quic.regular_transaction_listen_port = 0U;
35 0 : config->tiles.repair.repair_client_listen_port = 0U;
36 0 : config->tiles.rserve.repair_serve_listen_port = 0U;
37 0 : config->tiles.txsend.txsend_src_port = 0U;
38 :
39 0 : static ulong tile_to_cpu[ FD_TILE_MAX ] = {0}; /* TODO */
40 :
41 0 : ulong net_tile_cnt = config->layout.net_tile_count;
42 :
43 : /* Reset topology from scratch */
44 0 : fd_topo_t * topo = &config->topo;
45 0 : fd_topob_new( &config->topo, config->name );
46 0 : topo->max_page_size = fd_cstr_to_shmem_page_sz( config->hugetlbfs.max_page_size );
47 :
48 0 : fd_core_subtopo( config, tile_to_cpu );
49 0 : fd_gossip_subtopo( config, tile_to_cpu );
50 :
51 0 : fd_topob_tile_in( topo, "gossip", 0UL, "metric_in", "sign_gossip", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_UNPOLLED );
52 0 : for( ulong i=0UL; i<net_tile_cnt; i++ ) fd_topos_net_tile_finish( topo, i );
53 0 : fd_topob_auto_layout( topo, 0 );
54 0 : fd_topob_finish( topo, CALLBACKS );
55 0 : }
56 :
57 : void
58 0 : fd_gossip_subtopo( config_t * config, ulong tile_to_cpu[ FD_TILE_MAX ] FD_PARAM_UNUSED ) {
59 0 : fd_topo_t * topo = &config->topo;
60 :
61 0 : ulong gossvf_tile_count = config->firedancer.layout.gossvf_tile_count;
62 0 : ulong net_tile_cnt = config->layout.net_tile_count;
63 :
64 0 : static char* const tiles_to_add[] = {
65 0 : "gossvf",
66 0 : "ipecho",
67 0 : "gossip",
68 0 : };
69 0 : for( int i=0; i<3; ++i) FD_TEST( fd_topo_find_tile( topo, tiles_to_add[i], 0UL ) == ULONG_MAX );
70 :
71 0 : fd_topob_wksp( topo, "gossip" );
72 0 : fd_topo_tile_t * gossip_tile = fd_topob_tile( topo, "gossip", "gossip", "metric_in", 0UL, 0, 1, 0 );
73 0 : fd_cstr_ncpy( gossip_tile->gossip.identity_key_path, config->paths.identity_key, sizeof(gossip_tile->gossip.identity_key_path) );
74 0 : gossip_tile->gossip.entrypoints_cnt = config->gossip.entrypoints_cnt;
75 0 : for( ulong i=0UL; i<config->gossip.entrypoints_cnt; i++ ) {
76 0 : gossip_tile->gossip.entrypoints[ i ] = config->gossip.resolved_entrypoints[ i ];
77 0 : }
78 0 : gossip_tile->gossip.ip_addr = config->net.ip_addr;
79 0 : gossip_tile->gossip.shred_version = config->consensus.expected_shred_version;
80 0 : gossip_tile->gossip.max_entries = config->tiles.gossip.max_entries;
81 0 : gossip_tile->gossip.ports.gossip = config->gossip.port;
82 0 : gossip_tile->gossip.ports.repair = 0;
83 0 : gossip_tile->gossip.ports.rserve = 0;
84 0 : gossip_tile->gossip.ports.tpu = 0;
85 0 : gossip_tile->gossip.ports.tpu_quic = 0;
86 0 : gossip_tile->gossip.ports.tvu = 0;
87 0 : gossip_tile->gossip.ports.tvu_quic = 0;
88 0 : gossip_tile->gossip.boot_timestamp_nanos = config->boot_timestamp_nanos;
89 :
90 0 : fd_topob_wksp( topo, "gossvf" );
91 0 : for( ulong i=0UL; i<gossvf_tile_count; i++ ) {
92 0 : fd_topo_tile_t * gossvf_tile = fd_topob_tile( topo, "gossvf", "gossvf", "metric_in", 0UL, 0, 1, 0 );
93 0 : fd_cstr_ncpy( gossvf_tile->gossvf.identity_key_path, config->paths.identity_key, sizeof(gossvf_tile->gossvf.identity_key_path) );
94 0 : gossvf_tile->gossvf.tcache_depth = 1UL<<22UL;
95 0 : gossvf_tile->gossvf.shred_version = config->consensus.expected_shred_version;
96 0 : gossvf_tile->gossvf.allow_private_address = config->development.gossip.allow_private_address;
97 0 : gossvf_tile->gossvf.entrypoints_cnt = config->gossip.entrypoints_cnt;
98 0 : gossvf_tile->gossvf.boot_timestamp_nanos = config->boot_timestamp_nanos;
99 0 : gossvf_tile->gossvf.gossip_addr.addr = config->net.ip_addr;
100 0 : gossvf_tile->gossvf.gossip_addr.port = fd_ushort_bswap( config->gossip.port );
101 0 : gossvf_tile->gossvf.src_addr.addr = config->net.ip_addr;
102 0 : gossvf_tile->gossvf.src_addr.port = fd_ushort_bswap( config->gossip.port );
103 0 : for( ulong i=0UL; i<config->gossip.entrypoints_cnt; i++ ) {
104 0 : gossvf_tile->gossvf.entrypoints[ i ] = config->gossip.resolved_entrypoints[ i ];
105 0 : }
106 0 : }
107 0 : for( ulong i=0UL; i<net_tile_cnt; i++ ) {
108 0 : fd_topos_net_rx_link( topo, "net_gossvf", i, config->net.ingress_buffer_size );
109 0 : }
110 0 : for( ulong i=0UL; i<gossvf_tile_count; i++ ) {
111 0 : for( ulong j=0UL; j<net_tile_cnt; j++ ) {
112 0 : fd_topob_tile_in( topo, "gossvf", i, "metric_in", "net_gossvf", j, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
113 0 : }
114 0 : }
115 :
116 0 : fd_topob_wksp( topo, "gossip_net" );
117 0 : fd_topob_link( topo, "gossip_net", "gossip_net", 65536*4UL, FD_NET_MTU, 1UL );
118 0 : fd_topos_tile_in_net( topo, "metric_in", "gossip_net", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
119 0 : fd_topob_tile_out( topo, "gossip", 0UL, "gossip_net", 0UL );
120 :
121 0 : fd_topob_wksp( topo, "ipecho" );
122 0 : fd_topo_tile_t * ipecho_tile = fd_topob_tile( topo, "ipecho", "ipecho", "metric_in", 0UL, 0, 0, 0 );
123 0 : ipecho_tile->ipecho.expected_shred_version = config->consensus.expected_shred_version;
124 0 : ipecho_tile->ipecho.bind_address = config->net.ip_addr;
125 0 : ipecho_tile->ipecho.bind_port = config->gossip.port;
126 0 : ipecho_tile->ipecho.entrypoints_cnt = config->gossip.entrypoints_cnt;
127 0 : for( ulong i=0UL; i<config->gossip.entrypoints_cnt; i++ ) {
128 0 : ipecho_tile->ipecho.entrypoints[ i ] = config->gossip.resolved_entrypoints[ i ];
129 0 : }
130 :
131 0 : fd_topob_wksp( topo, "ipecho_out" );
132 0 : fd_topob_link( topo, "ipecho_out", "ipecho_out", 4UL, 0UL, 1UL );
133 0 : fd_topob_tile_out( topo, "ipecho", 0UL, "ipecho_out", 0UL );
134 :
135 0 : for( ulong i=0UL; i<gossvf_tile_count; i++ ) {
136 0 : fd_topob_tile_in( topo, "gossvf", i, "metric_in", "ipecho_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
137 0 : }
138 0 : fd_topob_tile_in( topo, "gossip", 0UL, "metric_in", "ipecho_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
139 :
140 0 : fd_topob_wksp( topo, "gossvf_gossip" );
141 0 : fd_topob_wksp( topo, "gossip_gossvf" );
142 0 : fd_topob_wksp( topo, "gossip_out" );
143 :
144 0 : fd_topob_link( topo, "gossip_gossvf", "gossip_gossvf", 65536UL*4, sizeof(fd_gossip_ping_update_t), 1UL );
145 0 : fd_topob_tile_out( topo, "gossip", 0UL, "gossip_gossvf", 0UL );
146 :
147 0 : fd_topob_link( topo, "gossip_out", "gossip_out", 65536UL*4, sizeof(fd_gossip_update_message_t), 1UL );
148 0 : fd_topob_tile_out( topo, "gossip", 0UL, "gossip_out", 0UL );
149 0 : for( ulong i=0UL; i<gossvf_tile_count; i++ ) {
150 0 : fd_topob_link( topo, "gossvf_gossip", "gossvf_gossip", 65536UL*4, FD_GOSSIP_GOSSVF_MTU, 1UL );
151 0 : fd_topob_tile_out( topo, "gossvf", i, "gossvf_gossip", i );
152 0 : fd_topob_tile_in( topo, "gossip", 0UL, "metric_in", "gossvf_gossip", i, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
153 :
154 : /* Only one link_kind for gossip_out broadcast link */
155 0 : fd_topob_tile_in( topo, "gossvf", i, "metric_in", "gossip_gossvf", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
156 0 : fd_topob_tile_in( topo, "gossvf", i, "metric_in", "gossip_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
157 0 : }
158 :
159 0 : fd_topob_wksp( topo, "gossip_sign" );
160 0 : fd_topob_link( topo, "gossip_sign", "gossip_sign", 128UL, 2048UL, 1UL );
161 0 : fd_topob_tile_in( topo, "sign", 0UL, "metric_in", "gossip_sign", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
162 0 : fd_topob_wksp( topo, "sign_gossip" );
163 0 : fd_topob_link( topo, "sign_gossip", "sign_gossip", 128UL, 64UL, 1UL );
164 0 : fd_topob_tile_out( topo, "sign", 0UL, "sign_gossip", 0UL );
165 0 : fd_topob_tile_out( topo, "gossip", 0UL, "gossip_sign", 0UL );
166 0 : }
167 :
168 : static args_t
169 0 : configure_args( void ) {
170 0 : args_t args = {
171 0 : .configure.command = CONFIGURE_CMD_INIT,
172 0 : };
173 :
174 0 : ulong stage_idx = 0UL;
175 0 : args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_hugetlbfs;
176 0 : args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_sysctl;
177 0 : args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_bonding;
178 0 : args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_ethtool_channels;
179 0 : args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_ethtool_offloads;
180 0 : args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_ethtool_loopback;
181 0 : args.configure.stages[ stage_idx++ ] = NULL;
182 :
183 0 : return args;
184 0 : }
185 :
186 : void
187 : gossip_cmd_perm( args_t * args FD_PARAM_UNUSED,
188 : fd_cap_chk_t * chk,
189 0 : config_t const * config ) {
190 0 : args_t c_args = configure_args();
191 0 : configure_cmd_perm( &c_args, chk, config );
192 0 : run_cmd_perm( NULL, chk, config );
193 0 : }
194 :
195 : /* Display helper functions and types have been extracted to
196 : gossip_diag.h / gossip_diag.c in the shared commands directory. */
197 :
198 : static void
199 : gossip_args( int * pargc,
200 : char *** pargv,
201 0 : args_t * args ) {
202 0 : args->gossip.max_entries = fd_env_strip_cmdline_ulong ( pargc, pargv, "--max-entries", NULL, ULONG_MAX );
203 0 : args->gossip.max_contact = fd_env_strip_cmdline_ulong ( pargc, pargv, "--max-contact-infos", NULL, ULONG_MAX );
204 0 : args->gossip.compact_mode = fd_env_strip_cmdline_contains( pargc, pargv, "--compact" );
205 0 : }
206 :
207 : void
208 : gossip_cmd_fn( args_t * args,
209 0 : config_t * config ) {
210 0 : args_t c_args = configure_args();
211 0 : configure_cmd_fn( &c_args, config );
212 :
213 0 : run_firedancer_init( config, 1, 1 );
214 :
215 0 : int const is_xdp = ( 0==strcmp( config->net.provider, "xdp" ) );
216 0 : if( is_xdp ) fd_topo_install_xdp_simple( &config->topo, config->net.bind_address_parsed );
217 0 : fd_topo_join_workspaces( &config->topo, FD_SHMEM_JOIN_MODE_READ_WRITE, FD_TOPO_CORE_DUMP_LEVEL_DISABLED );
218 0 : fd_topo_fill( &config->topo );
219 :
220 : /* FIXME allow running sandboxed/multiprocess */
221 0 : fd_topo_run_single_process( &config->topo, 2, config->uid, config->gid, fdctl_tile_run );
222 :
223 0 : fd_gossip_diag_ctx_t diag_ctx[1];
224 0 : if( FD_UNLIKELY( fd_gossip_diag_init( diag_ctx, &config->topo, config ) ) )
225 0 : FD_LOG_ERR(( "Failed to initialize gossip diagnostics" ));
226 :
227 0 : fd_clock_tile_t clock[1];
228 0 : fd_clock_tile_init( clock );
229 :
230 0 : long start_time = fd_clock_tile_now( clock );
231 0 : long next_report_time = start_time + 1000000000L;
232 :
233 0 : for(;;) {
234 0 : long current_time = fd_clock_tile_now( clock );
235 :
236 0 : if( FD_LIKELY( current_time < next_report_time ) ) {
237 0 : continue;
238 0 : }
239 0 : next_report_time += 1000000000L;
240 :
241 0 : fd_gossip_diag_render( diag_ctx, args->gossip.compact_mode );
242 :
243 0 : if( FD_UNLIKELY( diag_ctx->last_total_crds >= args->gossip.max_entries ||
244 0 : diag_ctx->last_total_contact_infos >= args->gossip.max_contact ) ) {
245 0 : long elapsed = current_time - start_time;
246 0 : double elapsed_secs = (double)elapsed / 1000000000.0;
247 0 : printf( "User defined thresholds reached in %.2fs\n"
248 0 : " Table Size : %lu\n"
249 0 : " Contact Infos: %lu\n",
250 0 : elapsed_secs, diag_ctx->last_total_crds, diag_ctx->last_total_contact_infos );
251 0 : break;
252 0 : }
253 0 : fd_clock_tile_recal( clock );
254 0 : }
255 0 : }
256 :
257 : static void
258 0 : gossip_args_help( fd_action_help_t * help ) {
259 0 : fd_action_help_arg( help, "--max-entries", "<num>", "Exit once we see <num> CRDS entries in the table" );
260 0 : fd_action_help_arg( help, "--max-contact-infos", "<num>", "Exit once we see <num> contact infos in the table" );
261 : fd_action_help_arg( help, "--compact", NULL, "Use a denser output format" );
262 0 : }
263 :
264 : action_t fd_action_gossip = {
265 : .name = "gossip",
266 : .args = gossip_args,
267 : .fn = gossip_cmd_fn,
268 : .perm = gossip_cmd_perm,
269 : .topo = gossip_cmd_topo,
270 : .description = "Run a reduced topology that joins gossip and prints diagnostics",
271 : .detail = "Boots a minimal Firedancer topology containing the gossip tile, joins the\n"
272 : "cluster's gossip network, and periodically prints CRDS table and contact\n"
273 : "info statistics until the configured thresholds are reached.",
274 : .usage = "gossip [OPTIONS]",
275 : .args_help = gossip_args_help,
276 : };
|