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