Line data Source code
1 : #ifndef HEADER_fd_src_disco_topo_fd_topo_h
2 : #define HEADER_fd_src_disco_topo_fd_topo_h
3 :
4 : #include "../stem/fd_stem.h"
5 : #include "../../tango/fd_tango.h"
6 : #include "../../waltz/xdp/fd_xdp1.h"
7 : #include "../../waltz/http/fd_url.h"
8 : #include "../../ballet/base58/fd_base58.h"
9 : #include "../../flamenco/fd_flamenco_base.h"
10 : #include "../../util/net/fd_net_headers.h"
11 : #include "../../util/net/fd_ip6.h"
12 : #include "../pack/fd_pack_acct_blocklist.h"
13 : #include "../keyguard/fd_keyguard.h"
14 :
15 : /* Maximum number of workspaces that may be present in a topology. */
16 : #define FD_TOPO_MAX_WKSPS ( 256UL)
17 : /* Maximum number of links that may be present in a topology. */
18 0 : #define FD_TOPO_MAX_LINKS (1024UL)
19 : /* Maximum number of tiles that may be present in a topology. */
20 0 : #define FD_TOPO_MAX_TILES ( 256UL)
21 : /* Maximum number of objects that may be present in a topology. */
22 : #define FD_TOPO_MAX_OBJS (4096UL)
23 : /* Maximum number of links that may go into any one tile in the
24 : topology. */
25 0 : #define FD_TOPO_MAX_TILE_IN_LINKS ( 256UL)
26 : /* Maximum number of links that a tile may write to. */
27 : #define FD_TOPO_MAX_TILE_OUT_LINKS ( 64UL)
28 : /* Maximum number of objects that a tile can use. */
29 : #define FD_TOPO_MAX_TILE_OBJS (1024UL)
30 :
31 : FD_STATIC_ASSERT( FD_SLEEP_LINK_MAX==FD_TOPO_MAX_LINKS, sleep_limits );
32 : FD_STATIC_ASSERT( FD_SLEEP_IN_MAX ==FD_TOPO_MAX_TILE_IN_LINKS, sleep_limits );
33 : FD_STATIC_ASSERT( FD_SLEEP_OUT_MAX ==FD_TOPO_MAX_TILE_OUT_LINKS, sleep_limits );
34 :
35 : /* Maximum number of additional ip addresses */
36 : #define FD_NET_MAX_SRC_ADDR 4
37 :
38 : /* Maximum number of additional destinations for leader shreds and for retransmitted shreds */
39 : #define FD_TOPO_ADTL_DESTS_MAX ( 32UL)
40 :
41 0 : #define FD_TOPO_CORE_DUMP_LEVEL_DISABLED (0)
42 0 : #define FD_TOPO_CORE_DUMP_LEVEL_MINIMAL (1)
43 0 : #define FD_TOPO_CORE_DUMP_LEVEL_REGULAR (2)
44 0 : #define FD_TOPO_CORE_DUMP_LEVEL_FULL (3)
45 0 : #define FD_TOPO_CORE_DUMP_LEVEL_NEVER (4)
46 :
47 : /* A workspace is a Firedancer specific memory management structure that
48 : sits on top of 1 or more memory mapped gigantic or huge pages mounted
49 : to the hugetlbfs. */
50 : typedef struct {
51 : ulong id; /* The ID of this workspace. Indexed from [0, wksp_cnt). When placed in a topology, the ID must be the index of the workspace in the workspaces list. */
52 : char name[ 14UL ]; /* The name of this workspace, like "pack". There can be at most one of each workspace name in a topology. */
53 :
54 : ulong numa_idx; /* The index of the NUMA node on the system that this workspace should be allocated from. */
55 :
56 : ulong min_part_max; /* Artificially raise part_max */
57 : ulong min_loose_sz; /* Artificially raise loose footprint */
58 :
59 : /* Computed fields. These are not supplied as configuration but calculated as needed. */
60 : struct {
61 : ulong page_sz; /* The size of the pages that this workspace is backed by. One of FD_PAGE_SIZE_*. */
62 : ulong page_cnt; /* The number of pages that must be mapped to this workspace to store all the data needed by consumers. */
63 : ulong part_max; /* The maximum number of partitions in the underlying workspace. There can only be this many allocations made at any one time. */
64 :
65 : int core_dump_level; /* The core dump level required to be set in the application configuration to have this workspace appear in core dumps. */
66 :
67 : fd_wksp_t * wksp; /* The workspace memory in the local process. */
68 : ulong known_footprint; /* Total size in bytes of all data in Firedancer that will be stored in this workspace at startup. */
69 : ulong total_footprint; /* Total size in bytes of all data in Firedancer that could be stored in this workspace, includes known data and loose data. */
70 : };
71 : } fd_topo_wksp_t;
72 :
73 : /* A link is an mcache in a workspace that has one producer and one or
74 : more consumers. A link may optionally also have a dcache, that holds
75 : fragments referred to by the mcache entries.
76 :
77 : A link belongs to exactly one workspace. A link has exactly one
78 : producer, and 1 or more consumers. Each consumer is either reliable
79 : or not reliable. A link has a depth and a MTU, which correspond to
80 : the depth and MTU of the mcache and dcache respectively. A MTU of
81 : zero means no dcache is needed, as there is no data. */
82 : typedef struct {
83 : ulong id; /* The ID of this link. Indexed from [0, link_cnt). When placed in a topology, the ID must be the index of the link in the links list. */
84 : char name[ 14UL ]; /* The name of this link, like "pack_execle". There can be multiple of each link name in a topology. */
85 : ulong kind_id; /* The ID of this link within its name. If there are N links of a particular name, they have IDs [0, N). The pair (name, kind_id) uniquely identifies a link, as does "id" on its own. */
86 :
87 : ulong depth; /* The depth of the mcache representing the link. */
88 : ulong mtu; /* The MTU of data fragments in the mcache. A value of 0 means there is no dcache. */
89 : ulong burst; /* The max amount of MTU sized data fragments that might be bursted to the dcache. */
90 :
91 : ulong mcache_obj_id;
92 : ulong dcache_obj_id;
93 :
94 : /* Computed fields. These are not supplied as configuration but calculated as needed. */
95 : struct {
96 : fd_frag_meta_t * mcache; /* The mcache of this link. */
97 : void * dcache; /* The dcache of this link, if it has one. */
98 : };
99 :
100 : uint permit_no_consumers : 1; /* Permit a topology where this link has no consumers */
101 : uint permit_no_producers : 1; /* Permit a topology where this link has no producers */
102 : } fd_topo_link_t;
103 :
104 : struct fd_topo_net_tile {
105 : ulong umem_dcache_obj_id; /* dcache for network UMEM frames */
106 : uint bind_address;
107 :
108 : ushort shred_listen_port;
109 : ushort quic_transaction_listen_port;
110 : ushort legacy_transaction_listen_port;
111 : ushort gossip_listen_port;
112 : ushort repair_client_listen_port;
113 : ushort repair_serve_listen_port;
114 : ushort votor_quic_client_listen_port;
115 : ushort votor_quic_server_listen_port;
116 : };
117 : typedef struct fd_topo_net_tile fd_topo_net_tile_t;
118 :
119 : /* A tile is a unique process that is spawned by Firedancer to represent
120 : one thread of execution. Firedancer sandboxes all tiles to their own
121 : process for security reasons.
122 :
123 : A tile belongs to exactly one workspace. A tile is a consumer of 0
124 : or more links, it's inputs. A tile is a producer of 0 or more output
125 : links.
126 :
127 : All input links will be automatically polled by the tile
128 : infrastructure, and output links will automatically source and manage
129 : credits from consumers. */
130 : struct fd_topo_tile {
131 : ulong id; /* The ID of this tile. Indexed from [0, tile_cnt). When placed in a topology, the ID must be the index of the tile in the tiles list. */
132 : char name[ 7UL ]; /* The name of this tile. There can be multiple of each tile name in a topology. */
133 : ulong kind_id; /* The ID of this tile within its name. If there are n tile of a particular name, they have IDs [0, N). The pair (name, kind_id) uniquely identifies a tile, as does "id" on its own. */
134 :
135 : int is_waker_client; /* Tile has file descriptors which must be serviced by the external waker tile. */
136 : int allow_shutdown; /* If the tile is allowed to shutdown gracefully. If false, when the tile exits it will tear down the entire application. */
137 :
138 : ulong cpu_idx; /* The CPU index to pin the tile on. A value of ULONG_MAX or more indicates the tile should be floating and not pinned to a core. */
139 : int floats; /* Scheduled by the kernel over the CPUs of the floating tiles on its NUMA node, never a pinned tile's CPU, instead of pinned to cpu_idx (efficient mode). cpu_idx still places memory and isolation, and is the fallback when no such CPU remains. */
140 : int sleep_eventfd; /* Parks in epoll on its own fds and is woken through the eventfd FD_SLEEP_EVENTFD( id ), not FUTEX_WAKE (efficient mode only) */
141 :
142 : ulong waker_client_idx; /* Client slot in the fixed inherited fd range (inner epoll fd FD_WAKER_INNER_FD( idx )), or ULONG_MAX if not a waker client */
143 : ulong waker_fseq_obj_id; /* fseq object holding the tile's waker readiness word or ULONG_MAX */
144 :
145 : ulong in_cnt; /* The number of links that this tile reads from. */
146 : ulong in_link_id[ FD_TOPO_MAX_TILE_IN_LINKS ]; /* The link_id of each link that this tile reads from, indexed in [0, in_cnt). */
147 : int in_link_reliable[ FD_TOPO_MAX_TILE_IN_LINKS ]; /* If each link that this tile reads from is a reliable or unreliable consumer, indexed in [0, in_cnt). */
148 : int in_link_poll[ FD_TOPO_MAX_TILE_IN_LINKS ]; /* If each link that this tile reads from should be polled by the tile infrastructure, indexed in [0, in_cnt).
149 : If the link is not polled, the tile will not receive frags for it and the tile writer is responsible for
150 : reading from the link. The link must be marked as unreliable as it is not flow controlled. */
151 :
152 : ulong out_cnt; /* The number of links that this tile writes to. */
153 : ulong out_link_id[ FD_TOPO_MAX_TILE_OUT_LINKS ]; /* The link_id of each link that this tile writes to, indexed in [0, link_cnt). */
154 :
155 : ulong event_link_id; /* If not ULONG_MAX, the link_id of a dedicated unreliable link to the event tile that this tile reports
156 : telemetry events on via the thread-local fd_event_report_* macros. This link is deliberately NOT part
157 : of out_link_id[] / out_cnt: it is written directly (outside fd_stem) by the thread-local reporter. */
158 :
159 : ulong tile_obj_id;
160 : ulong metrics_obj_id;
161 : ulong id_keyswitch_obj_id; /* keyswitch object id for identity key updates */
162 : ulong av_keyswitch_obj_id; /* keyswitch object id for authority key updates */
163 : ulong in_link_fseq_obj_id[ FD_TOPO_MAX_TILE_IN_LINKS ];
164 :
165 : ulong uses_obj_cnt;
166 : ulong uses_obj_id[ FD_TOPO_MAX_TILE_OBJS ];
167 : int uses_obj_mode[ FD_TOPO_MAX_TILE_OBJS ];
168 :
169 : /* Computed fields. These are not supplied as configuration but calculated as needed. */
170 : struct {
171 : ulong * metrics; /* The shared memory for metrics that this tile should write. Consumer by monitoring and metrics writing tiles. */
172 :
173 : /* The fseq of each link that this tile reads from. Multiple fseqs
174 : may point to the link, if there are multiple consumers. An fseq
175 : can be uniquely identified via (link_id, tile_id), or (link_kind,
176 : link_kind_id, tile_kind, tile_kind_id) */
177 : ulong * in_link_fseq[ FD_TOPO_MAX_TILE_IN_LINKS ];
178 : };
179 :
180 : /* Configuration fields. These are required to be known by the topology so it can determine the
181 : total size of Firedancer in memory. */
182 : union {
183 : fd_topo_net_tile_t net;
184 :
185 : struct {
186 : fd_topo_net_tile_t net;
187 :
188 : char if_virt[ 16 ]; /* device name (virtual, for routing) */
189 : char if_phys[ 16 ]; /* device name (physical, for RX/TX) */
190 : uint if_queue; /* device queue index */
191 :
192 : /* xdp specific options */
193 : ulong xdp_rx_queue_size;
194 : ulong xdp_tx_queue_size;
195 : ulong free_ring_depth;
196 : long tx_flush_timeout_ns;
197 : char xdp_mode[8];
198 : int zero_copy;
199 :
200 : char poll_mode[ 16 ]; /* "softirq" or "prefbusy" */
201 :
202 : ulong netdev_tbl_obj_id;
203 :
204 : ulong route_max;
205 : ulong route_peer_max;
206 : ulong route_peer_seed;
207 : ulong neigh4_obj_id; /* neigh4 hash map */
208 : } xdp;
209 :
210 : struct {
211 : fd_topo_net_tile_t net;
212 :
213 : char if_name[ 16 ];
214 : uint rx_queue_size;
215 : uint tx_queue_size;
216 : uint batch_size;
217 :
218 : ulong netdev_tbl_obj_id;
219 : ulong route_max;
220 : ulong route_peer_max;
221 : ulong route_peer_seed;
222 : ulong neigh4_obj_id;
223 : } mlx5;
224 :
225 : struct {
226 : fd_topo_net_tile_t net;
227 :
228 : char if_name[ 16 ];
229 : char members[ 16 ][ 16 ];
230 : ulong member_cnt;
231 : uint rx_queue_size;
232 : uint tx_queue_size;
233 :
234 : ulong netdev_tbl_obj_id;
235 : ulong route_max;
236 : ulong route_peer_max;
237 : ulong route_peer_seed;
238 : ulong neigh4_obj_id;
239 : } iavf;
240 :
241 : struct {
242 : fd_topo_net_tile_t net;
243 : /* sock specific options */
244 : int so_sndbuf;
245 : int so_rcvbuf;
246 : int only_recv_lo;
247 : ulong net_tile_id;
248 : } sock;
249 :
250 : struct {
251 : ulong netdev_tbl_obj_id;
252 : ulong route_max;
253 : ulong route_peer_max;
254 : char neigh_if[ 16 ]; /* neigh4 interface name */
255 : ulong neigh4_obj_id; /* neigh4 hash map */
256 : } netlink;
257 :
258 : struct {
259 : char identity_key_path[ PATH_MAX ];
260 : } admin;
261 :
262 : struct {
263 : char identity_key_path[ PATH_MAX ]; /* the key this machine boots under */
264 : char target_key_path[ PATH_MAX ]; /* the identity failover hands off, [paths.identity_key] */
265 : int listen; /* open the network listener so we can hand over our identity to another machine */
266 : uint listen_addr; /* network byte order */
267 : ushort port;
268 :
269 : char gossip_host[ FD_FQDN_BUF_MAX ];
270 : fd_ip4_port_t gossip_addr; /* our own gossip socket, gossip_host overrides the address */
271 : } failov;
272 :
273 0 : #define FD_TOPO_GOSSIP_ENTRYPOINTS_MAX 16UL
274 :
275 : struct {
276 : char identity_key_path[ PATH_MAX ];
277 :
278 : ulong entrypoints_cnt;
279 : char entrypoints[ FD_TOPO_GOSSIP_ENTRYPOINTS_MAX ][ FD_HOSTPORT_BUF_MAX ];
280 :
281 : long boot_timestamp_nanos;
282 :
283 : ulong tcache_depth;
284 :
285 : ushort shred_version;
286 : int allow_private_address;
287 :
288 : char gossip_host[ FD_FQDN_BUF_MAX ];
289 : fd_ip4_port_t gossip_addr;
290 : fd_ip4_port_t src_addr;
291 : } gossvf;
292 :
293 : struct {
294 : char identity_key_path[ PATH_MAX ];
295 :
296 : ulong entrypoints_cnt;
297 : char entrypoints[ FD_TOPO_GOSSIP_ENTRYPOINTS_MAX ][ FD_HOSTPORT_BUF_MAX ];
298 :
299 : long boot_timestamp_nanos;
300 :
301 : char gossip_host[ FD_FQDN_BUF_MAX ];
302 : uint net_ip_addr; /* net.ip_addr fallback when gossip_host empty */
303 : uint ip_addr;
304 : uint bind_ip_addr;
305 : ushort expected_shred_version;
306 :
307 : ulong max_entries;
308 : ulong max_purged;
309 : ulong max_failed;
310 :
311 : ulong wait_for_supermajority_at_slot;
312 : int wait_for_supermajority_hash_is_zero;
313 :
314 : struct {
315 : ushort gossip;
316 : ushort tvu;
317 : ushort tvu_quic;
318 : ushort tpu;
319 : ushort tpu_quic;
320 : ushort repair;
321 : ushort rserve;
322 : ushort votor;
323 : ushort rpc;
324 : } ports;
325 : } gossip;
326 :
327 : struct {
328 : uint out_depth;
329 : uint reasm_cnt;
330 : ulong max_concurrent_connections;
331 : ulong max_concurrent_handshakes;
332 : ushort quic_transaction_listen_port;
333 : long idle_timeout_millis;
334 : uint ack_delay_millis;
335 : int retry;
336 : char key_log_path[ PATH_MAX ];
337 : } quic;
338 :
339 : struct {
340 : ulong tcache_depth;
341 : } verify;
342 :
343 : struct {
344 : ulong tcache_depth;
345 : } dedup;
346 :
347 : struct {
348 : char url[ FD_URL_MAX ];
349 : ulong url_len;
350 : char sni[ FD_SNI_BUF_MAX ];
351 : ulong sni_len;
352 : char identity_key_path[ PATH_MAX ];
353 : char key_log_path[ PATH_MAX ];
354 : ulong buf_sz;
355 : ulong keepalive_interval_nanos;
356 : uchar tls_cert_verify : 1;
357 : } bundle;
358 :
359 : struct {
360 : char url[ FD_URL_MAX ];
361 : char identity_key_path[ PATH_MAX ];
362 : char action[ 16 ];
363 : uchar genesis_hash[ 32 ];
364 : ushort shred_version;
365 :
366 : char accounts_path [ PATH_MAX ];
367 : char snapshots_path[ PATH_MAX ];
368 : char log_path [ PATH_MAX ];
369 : char shredb_path [ PATH_MAX ];
370 : char guidb_path [ PATH_MAX ];
371 : char net_interface [ 16 ];
372 : long boot_timestamp_nanos;
373 : ulong launch_cpus[ 1024UL/64UL ];
374 : char launch_cgroup[ PATH_MAX ];
375 : ulong tx_rate_mbps;
376 : } event;
377 :
378 : struct {
379 : ulong max_pending_transactions;
380 : ulong execle_tile_count;
381 : ulong max_cost_per_block;
382 : ulong max_shreds_per_block;
383 : ulong bench_max_shreds_per_block; /* [development.bench], floors the leader's per-slot shred limit */
384 : int use_consumed_cus;
385 : int schedule_strategy;
386 : struct {
387 : int enabled;
388 : uchar tip_distribution_program_addr[ 32 ];
389 : uchar tip_payment_program_addr[ 32 ];
390 : uchar tip_distribution_authority[ 32 ];
391 : ulong commission_bps;
392 : char identity_key_path[ PATH_MAX ];
393 : char vote_account_path[ PATH_MAX ]; /* or pubkey is okay */
394 : } bundle;
395 : ulong acct_blocklist_cnt;
396 : fd_pubkey_t acct_blocklist[ FD_PACK_ACCT_BLOCKLIST_MAX ];
397 : } pack;
398 :
399 : struct {
400 : ulong execle_cnt;
401 : char identity_key_path[ PATH_MAX ];
402 : ulong max_txn_per_slot;
403 : } poh;
404 :
405 : struct {
406 : ulong execle_cnt;
407 : char identity_key_path[ PATH_MAX ];
408 : ulong max_txn_per_slot;
409 : } motor;
410 :
411 : struct {
412 : ulong fec_exposure;
413 : ulong fec_resolver_depth;
414 : ulong slot_max;
415 : char identity_key_path[ PATH_MAX ];
416 : ushort shred_listen_port;
417 : ulong max_shreds_per_block;
418 : ulong bench_max_shreds_per_block; /* [development.bench], floors the chain's per-slot limit */
419 : ushort expected_shred_version;
420 : ulong adtl_dests_retransmit_cnt;
421 : char adtl_dests_retransmit[ FD_TOPO_ADTL_DESTS_MAX ][ FD_HOSTPORT_BUF_MAX ];
422 : ulong adtl_dests_leader_cnt;
423 : char adtl_dests_leader[ FD_TOPO_ADTL_DESTS_MAX ][ FD_HOSTPORT_BUF_MAX ];
424 : } shred;
425 :
426 : struct {
427 : ulong disable_blockstore_from_slot;
428 : } store;
429 :
430 : struct {
431 : char identity_key_path[ PATH_MAX ];
432 : int failover_junk_fd; /* private startup pipe for the failover junk key, -1 without failover */
433 : int failover_enabled;
434 : ulong authorized_voter_paths_cnt;
435 : char authorized_voter_paths[ FD_KEYGUARD_AUTH_VOTERS_MAX ][ PATH_MAX ];
436 : struct {
437 : uchar tip_payment_program_addr[ 32 ];
438 : uchar tip_distribution_program_addr[ 32 ];
439 : } bundle;
440 : } sign;
441 :
442 : struct {
443 : uint listen_addr;
444 : ushort listen_port;
445 :
446 : int is_voting;
447 :
448 : char cluster[ 32 ];
449 : char identity_key_path[ PATH_MAX ];
450 : char vote_key_path[ PATH_MAX ];
451 : char accounts_database_path[ PATH_MAX ];
452 : char gui_database_path[ PATH_MAX ];
453 :
454 : ulong max_http_connections;
455 : ulong max_websocket_connections;
456 : ulong send_buffer_size_mb;
457 : ulong db_size_gib;
458 : int schedule_strategy;
459 :
460 : int websocket_compression;
461 : ulong tile_cnt;
462 : ulong max_live_slots;
463 :
464 : char wfs_bank_hash[ FD_BASE58_ENCODED_32_SZ ];
465 : ulong wfs_slot;
466 : ushort expected_shred_version;
467 : ulong cache_size_gib;
468 : ulong accdb_obj_id;
469 : ulong max_txn_per_slot;
470 : } gui;
471 :
472 : struct {
473 : fd_ip6_addr_t listen_addr;
474 : ushort listen_port;
475 :
476 : ulong max_http_connections;
477 : ulong max_websocket_connections;
478 : ulong send_buffer_size_mb;
479 :
480 : ulong max_live_slots;
481 : ulong genesis_max_message_size;
482 :
483 : ulong accdb_obj_id;
484 : ulong accdb_epoch_fseq_obj_id;
485 :
486 : char identity_key_path[ PATH_MAX ];
487 : int delay_startup;
488 :
489 : int snapshot_server_enabled;
490 : char snapshot_server_host[ FD_FQDN_BUF_MAX ];
491 : ushort snapshot_server_port;
492 : } rpc;
493 :
494 : struct {
495 : uint prometheus_listen_addr;
496 : ushort prometheus_listen_port;
497 : } metric;
498 :
499 : struct {
500 : int is_voting;
501 :
502 : char accounts_path [ PATH_MAX ];
503 : char shreds_path [ PATH_MAX ];
504 : char snapshots_path[ PATH_MAX ];
505 : char gui_path [ PATH_MAX ];
506 : char log_path [ PATH_MAX ];
507 : } diag;
508 :
509 : struct {
510 : ulong accdb_obj_id;
511 : ulong txncache_obj_id;
512 :
513 : char identity_key_path[ PATH_MAX ];
514 : char vote_account_path[ PATH_MAX ];
515 :
516 : fd_hash_t wait_for_supermajority_with_bank_hash;
517 : ulong wait_for_supermajority_at_slot;
518 : ushort expected_shred_version;
519 : int wait_for_vote_to_start_leader;
520 :
521 : ulong sched_depth;
522 : ulong max_live_slots;
523 : ulong genesis_max_message_size;
524 : ulong full_snapshot_interval_blocks;
525 : ulong incremental_snapshot_interval_blocks;
526 :
527 : /* not specified in TOML */
528 :
529 : long boot_timestamp_nanos;
530 :
531 : ulong enable_features_cnt;
532 : char enable_features[ 16 ][ FD_BASE58_ENCODED_32_SZ ];
533 :
534 : char genesis_path[ PATH_MAX ];
535 :
536 : ulong max_txn_per_slot; /* config->limits */
537 : ulong max_shreds_per_block;
538 :
539 : ulong capture_start_slot;
540 : char solcap_capture[ PATH_MAX ];
541 : char dump_proto_dir[ PATH_MAX ];
542 : int dump_block_to_pb;
543 : int report_runtime_diffs;
544 :
545 : struct {
546 : int enabled;
547 : uchar tip_payment_program_addr[ 32 ];
548 : uchar tip_distribution_program_addr[ 32 ];
549 : char vote_account_path[ PATH_MAX ];
550 : } bundle;
551 : } replay;
552 :
553 : struct {
554 : ulong txncache_obj_id;
555 : ulong progcache_obj_id;
556 : ulong accdb_obj_id;
557 : ulong bpf_frames_obj_id;
558 :
559 : ulong max_live_slots;
560 :
561 : ulong capture_start_slot;
562 : char solcap_capture[ PATH_MAX ];
563 : char dump_proto_dir[ PATH_MAX ];
564 : char dump_syscall_name_filter[ PATH_MAX ];
565 : char dump_instr_program_id_filter[ FD_BASE58_ENCODED_32_SZ ];
566 : int dump_instr_to_pb;
567 : int dump_txn_to_pb;
568 : int dump_txn_as_fixture;
569 : int dump_syscall_to_pb;
570 : int report_runtime_diffs;
571 : } execrp;
572 :
573 : struct {
574 : ushort send_to_port;
575 : uint send_to_ip_addr;
576 : ulong conn_cnt;
577 : int no_quic;
578 : } benchs;
579 :
580 : struct {
581 : ushort rpc_port;
582 : uint rpc_ip_addr;
583 : ulong duration_s;
584 : } bencho;
585 :
586 : struct {
587 : ulong accounts_cnt;
588 : int mode;
589 : float contending_fraction;
590 : float cu_price_spread;
591 : } benchg;
592 :
593 : struct {
594 : ushort repair_client_listen_port;
595 : char identity_key_path[ PATH_MAX ];
596 : ulong slot_max;
597 : ulong fec_max;
598 : ulong max_shreds_per_block;
599 : int allow_private_address;
600 : int report_repair_requests;
601 :
602 : ulong repair_sign_depth;
603 : ulong repair_sign_cnt;
604 : } repair;
605 :
606 : struct {
607 : ushort repair_serve_listen_port;
608 : char identity_key_path[ PATH_MAX ];
609 : ulong ping_cache_entries;
610 : ulong max_shreds_per_block;
611 : ulong blockdb_max; /* 0 disables the block metadata db */
612 : } rserve;
613 :
614 : struct {
615 : uint fake_dst_ip;
616 : ulong pkt_sz; /* size of the L3 header + payload */
617 : } pktgen;
618 :
619 : struct {
620 : char ledger_format[ 16 ];
621 : char ledger_path[ PATH_MAX ];
622 : ulong end_slot;
623 : ulong root_distance;
624 : long boot_timestamp_nanos;
625 : } backtest;
626 :
627 : struct {
628 : char identity_key_path[ PATH_MAX ];
629 : char vote_history_path[ PATH_MAX ];
630 : uint target_gid;
631 : uint target_uid;
632 : ulong authorized_voter_paths_cnt;
633 : ushort quic_client_listen_port;
634 : ushort quic_server_listen_port;
635 : uint ip_addr;
636 : ulong max_live_slots;
637 : ulong wait_for_supermajority_at_slot;
638 : int wait_for_supermajority_hash_is_zero;
639 : ushort expected_shred_version;
640 : } votor;
641 :
642 : struct {
643 : ulong accdb_obj_id;
644 : ulong max_live_slots;
645 :
646 : ulong rpc_epoch_obj_id;
647 : ulong resolv_epoch_obj_ids[ 16 ];
648 : ulong resolv_epoch_obj_cnt;
649 : ulong snapmk_epoch_obj_id;
650 : ulong snapzp_epoch_obj_ids[ 64 ];
651 : ulong snapzp_epoch_obj_cnt;
652 : } accdb;
653 :
654 : struct {
655 : ulong max_live_slots;
656 : ulong accdb_obj_id;
657 : ulong accdb_epoch_fseq_obj_id;
658 : } resolv;
659 :
660 :
661 : #define FD_TOPO_SNAPSHOTS_GOSSIP_LIST_MAX (32UL)
662 0 : #define FD_TOPO_SNAPSHOTS_SERVERS_MAX (16UL)
663 0 : #define FD_TOPO_MAX_RESOLVED_ADDRS ( 4UL)
664 0 : #define FD_TOPO_SNAPSHOTS_SERVERS_MAX_RESOLVED (FD_TOPO_MAX_RESOLVED_ADDRS*FD_TOPO_SNAPSHOTS_SERVERS_MAX)
665 :
666 : struct fd_topo_tile_snapct {
667 : char snapshots_path[ PATH_MAX ];
668 :
669 : ulong entrypoints_cnt;
670 : char entrypoints[ FD_TOPO_GOSSIP_ENTRYPOINTS_MAX ][ FD_HOSTPORT_BUF_MAX ];
671 :
672 : struct {
673 : uint max_local_full_effective_age;
674 : uint max_local_incremental_age;
675 :
676 : struct {
677 : int allow_any;
678 : ulong allow_list_cnt;
679 : fd_pubkey_t allow_list[ FD_TOPO_SNAPSHOTS_GOSSIP_LIST_MAX ];
680 : ulong block_list_cnt;
681 : fd_pubkey_t block_list[ FD_TOPO_SNAPSHOTS_GOSSIP_LIST_MAX ];
682 : } gossip;
683 :
684 : ulong servers_cnt;
685 : char servers[ FD_TOPO_SNAPSHOTS_SERVERS_MAX ][ FD_URL_MAX ];
686 : } sources;
687 :
688 : int incremental_snapshots;
689 : uint max_full_snapshots_to_keep;
690 : uint max_incremental_snapshots_to_keep;
691 : uint max_retry_abort;
692 : long wait_for_peers_timeout_nanos;
693 : ulong wfs_slot;
694 : int wfs_hash_is_zero;
695 : ushort wfs_shred_version;
696 : } snapct;
697 :
698 : struct {
699 : char snapshots_path[ PATH_MAX ];
700 : int incremental_snapshots;
701 : uint min_download_speed_mibs;
702 : ulong wfs_slot;
703 : int wfs_hash_is_zero;
704 : ushort wfs_shred_version;
705 : } snapld;
706 :
707 : struct {
708 : ulong wait_for_supermajority_at_slot;
709 : fd_hash_t wait_for_supermajority_with_bank_hash;
710 : ushort expected_shred_version;
711 : ulong max_live_slots;
712 : ulong accdb_obj_id;
713 : ulong txncache_obj_id;
714 : ulong banks_obj_id;
715 : ulong shmem_obj_id; /* shared parallel snapin state */
716 : ulong max_txn_per_slot;
717 : } snapin;
718 :
719 : struct {
720 :
721 : uint bind_address;
722 : ushort bind_port;
723 :
724 : ushort expected_shred_version;
725 : ulong entrypoints_cnt;
726 : char entrypoints[ FD_TOPO_GOSSIP_ENTRYPOINTS_MAX ][ FD_HOSTPORT_BUF_MAX ];
727 : } ipecho;
728 :
729 : struct {
730 : ulong max_live_slots;
731 : ulong txncache_obj_id;
732 : ulong progcache_obj_id;
733 : ulong accdb_obj_id;
734 : ulong bpf_frames_obj_id;
735 : int report_runtime_diffs;
736 : } execle;
737 :
738 : struct {
739 : int validate_genesis_hash;
740 : int allow_download;
741 :
742 : ushort expected_shred_version;
743 : ulong entrypoints_cnt;
744 : char entrypoints[ FD_TOPO_GOSSIP_ENTRYPOINTS_MAX ][ FD_HOSTPORT_BUF_MAX ];
745 :
746 : int has_expected_genesis_hash;
747 : uchar expected_genesis_hash[ 32UL ];
748 :
749 : char genesis_path[ PATH_MAX ];
750 :
751 : uint target_gid;
752 : uint target_uid;
753 :
754 : ulong max_live_slots;
755 : ulong accdb_obj_id;
756 : ulong max_message_size;
757 : } genesi;
758 :
759 : struct {
760 : ulong capture_start_slot;
761 : char solcap_capture[ PATH_MAX ];
762 : int recent_only;
763 : ulong recent_slots_per_file;
764 : } solcap;
765 :
766 : struct {
767 : ulong accdb_obj_id;
768 : ulong accdb_epoch_obj_id;
769 : ulong visited_set_obj_id;
770 : ulong banks_obj_id;
771 : ulong zp_fseq_id;
772 : ulong txncache_obj_id;
773 : ulong max_accounts;
774 : ulong max_live_slots;
775 : ulong max_txn_per_slot;
776 : uint max_full_snapshots_to_keep;
777 : char snapshots_path[ PATH_MAX ];
778 : uint max_incremental_snapshots_to_keep;
779 : } snapmk;
780 :
781 : struct {
782 : ulong accdb_obj_id;
783 : ulong accdb_epoch_obj_id;
784 : ulong visited_set_obj_id;
785 : ulong zp_fseq_id;
786 : ulong max_live_slots;
787 : uint snap_fd_cnt;
788 : } snapzp;
789 :
790 : struct {
791 : ulong accdb_obj_id;
792 : } snaprd;
793 :
794 : struct {
795 : ulong snap_max;
796 : ulong conn_max;
797 : uint io_worker_cnt;
798 : ulong idle_timeout_millis;
799 : ulong send_timeout_millis;
800 : ulong send_buffer_size_kib;
801 : fd_ip6_addr_t listen_addr;
802 : ushort listen_port;
803 : } snapsv;
804 : };
805 : };
806 :
807 : typedef struct fd_topo_tile fd_topo_tile_t;
808 :
809 : typedef struct {
810 : ulong id;
811 : char name[ 14UL ]; /* object type */
812 : ulong wksp_id;
813 :
814 : /* Optional label for object */
815 : char label[ 13UL ]; /* object label */
816 : ulong label_idx; /* index of object for this label (ULONG_MAX if not labelled) */
817 :
818 : ulong offset;
819 : ulong footprint;
820 : } fd_topo_obj_t;
821 :
822 : /* An fd_topo_t represents the overall structure of a Firedancer
823 : configuration, describing all the workspaces, tiles, and links
824 : between them. */
825 : struct fd_topo {
826 : char app_name[ 256UL ];
827 : uchar failover_junk[ 32 ]; /* public half of the junk key generated at boot for failover, zero without failover */
828 : uchar props[ 32768UL ];
829 :
830 : ulong sleep_obj_id;
831 :
832 : ulong wksp_cnt;
833 : ulong link_cnt;
834 : ulong tile_cnt;
835 : ulong obj_cnt;
836 :
837 : fd_topo_wksp_t workspaces[ FD_TOPO_MAX_WKSPS ];
838 : fd_topo_link_t links[ FD_TOPO_MAX_LINKS ];
839 : fd_topo_tile_t tiles[ FD_TOPO_MAX_TILES ];
840 : fd_topo_obj_t objs[ FD_TOPO_MAX_OBJS ];
841 :
842 : ulong blocklist_cores_cnt;
843 : ulong blocklist_cores_cpu_idx[ FD_TILE_MAX ];
844 :
845 : ulong max_page_size; /* 2^21 or 2^30 */
846 : ulong gigantic_page_threshold; /* see [hugetlbfs.gigantic_page_threshold_mib]*/
847 :
848 : /* Rendered configuration documents for the boot telemetry event,
849 : filled by the app during topology construction. */
850 : ulong resolved_config_json_len;
851 : char resolved_config_json[ 262144UL ];
852 : ulong user_config_json_len;
853 : char user_config_json[ 131072UL ];
854 :
855 : ulong layout_hash;
856 : };
857 : typedef struct fd_topo fd_topo_t;
858 :
859 : typedef struct {
860 : char const * name;
861 :
862 : int keep_host_networking;
863 : int allow_connect;
864 : int allow_renameat;
865 : ulong rlimit_file_cnt;
866 : ulong rlimit_address_space;
867 : ulong rlimit_data;
868 : ulong rlimit_nproc;
869 : int for_tpool;
870 :
871 : ulong (*max_event_sz )( fd_topo_tile_t const * tile );
872 : ulong (*populate_allowed_seccomp)( fd_topo_t const * topo, fd_topo_tile_t const * tile, ulong out_cnt, struct sock_filter * out );
873 : ulong (*populate_allowed_fds )( fd_topo_t const * topo, fd_topo_tile_t const * tile, ulong out_fds_sz, int * out_fds );
874 : ulong (*scratch_align )( void );
875 : ulong (*scratch_footprint )( fd_topo_tile_t const * tile );
876 : ulong (*loose_footprint )( fd_topo_tile_t const * tile );
877 : void (*privileged_init )( fd_topo_t const * topo, fd_topo_tile_t const * tile );
878 : void (*unprivileged_init )( fd_topo_t const * topo, fd_topo_tile_t const * tile );
879 : void (*run )( fd_topo_t * topo, fd_topo_tile_t * tile );
880 : ulong (*rlimit_file_cnt_fn )( fd_topo_t const * topo, fd_topo_tile_t const * tile );
881 : } fd_topo_run_tile_t;
882 :
883 : struct fd_topo_obj_callbacks {
884 : char const * name;
885 : ulong (* footprint )( fd_topo_t const * topo, fd_topo_obj_t const * obj );
886 : ulong (* align )( fd_topo_t const * topo, fd_topo_obj_t const * obj );
887 : ulong (* loose )( fd_topo_t const * topo, fd_topo_obj_t const * obj );
888 : void (* new )( fd_topo_t const * topo, fd_topo_obj_t const * obj );
889 : };
890 :
891 : typedef struct fd_topo_obj_callbacks fd_topo_obj_callbacks_t;
892 :
893 : FD_PROTOTYPES_BEGIN
894 :
895 : FD_FN_CONST static inline ulong
896 0 : fd_topo_workspace_align( void ) {
897 : /* This needs to be the max( align ) of all the child members that
898 : could be aligned into this workspace, otherwise our footprint
899 : calculation will not be correct. For now just set to 4096 but this
900 : should probably be calculated dynamically, or we should reduce
901 : those child aligns if we can. */
902 0 : return 4096UL;
903 0 : }
904 :
905 : void *
906 : fd_topo_obj_laddr( fd_topo_t const * topo,
907 : ulong obj_id );
908 :
909 : /* Returns a pointer in the local address space to the base address of
910 : the workspace out of which the given object was allocated. */
911 :
912 : static inline void *
913 : fd_topo_obj_wksp_base( fd_topo_t const * topo,
914 0 : ulong obj_id ) {
915 0 : FD_TEST( obj_id<FD_TOPO_MAX_OBJS );
916 0 : fd_topo_obj_t const * obj = &topo->objs[ obj_id ];
917 0 : FD_TEST( obj->id == obj_id );
918 0 : ulong const wksp_id = obj->wksp_id;
919 :
920 0 : FD_TEST( wksp_id<FD_TOPO_MAX_WKSPS );
921 0 : fd_topo_wksp_t const * wksp = &topo->workspaces[ wksp_id ];
922 0 : FD_TEST( wksp->id == wksp_id );
923 0 : return wksp->wksp;
924 0 : }
925 :
926 : FD_FN_PURE static inline ulong
927 : fd_topo_tile_name_cnt( fd_topo_t const * topo,
928 0 : char const * name ) {
929 0 : ulong cnt = 0;
930 0 : for( ulong i=0; i<topo->tile_cnt; i++ ) {
931 0 : if( FD_UNLIKELY( !strcmp( topo->tiles[ i ].name, name ) ) ) cnt++;
932 0 : }
933 0 : return cnt;
934 0 : }
935 :
936 : /* Finds the workspace of a given name in the topology. Returns
937 : ULONG_MAX if there is no such workspace. There can be at most one
938 : workspace of a given name. */
939 :
940 : FD_FN_PURE static inline ulong
941 : fd_topo_find_wksp( fd_topo_t const * topo,
942 0 : char const * name ) {
943 0 : for( ulong i=0; i<topo->wksp_cnt; i++ ) {
944 0 : if( FD_UNLIKELY( !strcmp( topo->workspaces[ i ].name, name ) ) ) return i;
945 0 : }
946 0 : return ULONG_MAX;
947 0 : }
948 :
949 : /* Find the tile of a given name and kind_id in the topology, there will
950 : be at most one such tile, since kind_id is unique among the name.
951 : Returns ULONG_MAX if there is no such tile. */
952 :
953 : FD_FN_PURE static inline ulong
954 : fd_topo_find_tile( fd_topo_t const * topo,
955 : char const * name,
956 0 : ulong kind_id ) {
957 0 : for( ulong i=0; i<topo->tile_cnt; i++ ) {
958 0 : if( FD_UNLIKELY( !strcmp( topo->tiles[ i ].name, name ) ) && topo->tiles[ i ].kind_id == kind_id ) return i;
959 0 : }
960 0 : return ULONG_MAX;
961 0 : }
962 :
963 : /* Find the link of a given name and kind_id in the topology, there will
964 : be at most one such link, since kind_id is unique among the name.
965 : Returns ULONG_MAX if there is no such link. */
966 :
967 : FD_FN_PURE static inline ulong
968 : fd_topo_find_link( fd_topo_t const * topo,
969 : char const * name,
970 0 : ulong kind_id ) {
971 0 : for( ulong i=0; i<topo->link_cnt; i++ ) {
972 0 : if( FD_UNLIKELY( !strcmp( topo->links[ i ].name, name ) ) && topo->links[ i ].kind_id == kind_id ) return i;
973 0 : }
974 0 : return ULONG_MAX;
975 0 : }
976 :
977 : FD_FN_PURE static inline ulong
978 : fd_topo_find_tile_in_link( fd_topo_t const * topo,
979 : fd_topo_tile_t const * tile,
980 : char const * name,
981 0 : ulong kind_id ) {
982 0 : for( ulong i=0; i<tile->in_cnt; i++ ) {
983 0 : if( FD_UNLIKELY( !strcmp( topo->links[ tile->in_link_id[ i ] ].name, name ) )
984 0 : && topo->links[ tile->in_link_id[ i ] ].kind_id == kind_id ) return i;
985 0 : }
986 0 : return ULONG_MAX;
987 0 : }
988 :
989 : FD_FN_PURE static inline ulong
990 : fd_topo_find_tile_out_link( fd_topo_t const * topo,
991 : fd_topo_tile_t const * tile,
992 : char const * name,
993 0 : ulong kind_id ) {
994 0 : for( ulong i=0; i<tile->out_cnt; i++ ) {
995 0 : if( FD_UNLIKELY( !strcmp( topo->links[ tile->out_link_id[ i ] ].name, name ) )
996 0 : && topo->links[ tile->out_link_id[ i ] ].kind_id == kind_id ) return i;
997 0 : }
998 0 : return ULONG_MAX;
999 0 : }
1000 :
1001 : /* Find the id of the tile which is a producer for the given link. If
1002 : no tile is a producer for the link, returns ULONG_MAX. This should
1003 : not be possible for a well formed and validated topology. */
1004 : FD_FN_PURE static inline ulong
1005 : fd_topo_find_link_producer( fd_topo_t const * topo,
1006 0 : fd_topo_link_t const * link ) {
1007 0 : for( ulong i=0; i<topo->tile_cnt; i++ ) {
1008 0 : fd_topo_tile_t const * tile = &topo->tiles[ i ];
1009 :
1010 0 : for( ulong j=0; j<tile->out_cnt; j++ ) {
1011 0 : if( FD_UNLIKELY( tile->out_link_id[ j ] == link->id ) ) return i;
1012 0 : }
1013 0 : }
1014 0 : return ULONG_MAX;
1015 0 : }
1016 :
1017 : /* Find the id of the tile which is a consumer of the given link. If
1018 : no tile is a consumer of the link, returns ULONG_MAX. */
1019 : FD_FN_PURE static inline ulong
1020 : fd_topo_find_link_consumer( fd_topo_t const * topo,
1021 0 : fd_topo_link_t const * link ) {
1022 0 : for( ulong i=0; i<topo->tile_cnt; i++ ) {
1023 0 : fd_topo_tile_t const * tile = &topo->tiles[ i ];
1024 :
1025 0 : for( ulong j=0; j<tile->in_cnt; j++ ) {
1026 0 : if( FD_UNLIKELY( tile->in_link_id[ j ] == link->id ) ) return i;
1027 0 : }
1028 0 : }
1029 0 : return ULONG_MAX;
1030 0 : }
1031 :
1032 : /* Given a link, count the number of consumers of that link among all
1033 : the tiles in the topology. */
1034 : FD_FN_PURE static inline ulong
1035 : fd_topo_link_consumer_cnt( fd_topo_t const * topo,
1036 0 : fd_topo_link_t const * link ) {
1037 0 : ulong cnt = 0;
1038 0 : for( ulong i=0; i<topo->tile_cnt; i++ ) {
1039 0 : fd_topo_tile_t const * tile = &topo->tiles[ i ];
1040 0 : for( ulong j=0; j<tile->in_cnt; j++ ) {
1041 0 : if( FD_UNLIKELY( tile->in_link_id[ j ] == link->id ) ) cnt++;
1042 0 : }
1043 0 : }
1044 :
1045 0 : return cnt;
1046 0 : }
1047 :
1048 : /* Given a link, count the number of reliable consumers of that link
1049 : among all the tiles in the topology. */
1050 : FD_FN_PURE static inline ulong
1051 : fd_topo_link_reliable_consumer_cnt( fd_topo_t const * topo,
1052 0 : fd_topo_link_t const * link ) {
1053 0 : ulong cnt = 0;
1054 0 : for( ulong i=0; i<topo->tile_cnt; i++ ) {
1055 0 : fd_topo_tile_t const * tile = &topo->tiles[ i ];
1056 0 : for( ulong j=0; j<tile->in_cnt; j++ ) {
1057 0 : if( FD_UNLIKELY( tile->in_link_id[ j ] == link->id && tile->in_link_reliable[ j ] ) ) cnt++;
1058 0 : }
1059 0 : }
1060 0 :
1061 0 : return cnt;
1062 0 : }
1063 :
1064 : FD_FN_PURE static inline ulong
1065 : fd_topo_tile_consumer_cnt( fd_topo_t const * topo,
1066 0 : fd_topo_tile_t const * tile ) {
1067 0 : (void)topo;
1068 0 : return tile->out_cnt;
1069 0 : }
1070 :
1071 : FD_FN_PURE static inline ulong
1072 : fd_topo_tile_reliable_consumer_cnt( fd_topo_t const * topo,
1073 0 : fd_topo_tile_t const * tile ) {
1074 0 : ulong reliable_cons_cnt = 0UL;
1075 0 : for( ulong i=0UL; i<topo->tile_cnt; i++ ) {
1076 0 : fd_topo_tile_t const * consumer_tile = &topo->tiles[ i ];
1077 0 : for( ulong j=0UL; j<consumer_tile->in_cnt; j++ ) {
1078 0 : for( ulong k=0UL; k<tile->out_cnt; k++ ) {
1079 0 : if( FD_UNLIKELY( consumer_tile->in_link_id[ j ]==tile->out_link_id[ k ] && consumer_tile->in_link_reliable[ j ] ) ) {
1080 0 : reliable_cons_cnt++;
1081 0 : }
1082 0 : }
1083 0 : }
1084 0 : }
1085 0 : return reliable_cons_cnt;
1086 0 : }
1087 :
1088 : FD_FN_PURE static inline ulong
1089 : fd_topo_tile_producer_cnt( fd_topo_t const * topo,
1090 0 : fd_topo_tile_t const * tile ) {
1091 0 : (void)topo;
1092 0 : ulong in_cnt = 0UL;
1093 0 : for( ulong i=0UL; i<tile->in_cnt; i++ ) {
1094 0 : if( FD_UNLIKELY( !tile->in_link_poll[ i ] ) ) continue;
1095 0 : in_cnt++;
1096 0 : }
1097 0 : return in_cnt;
1098 0 : }
1099 :
1100 : FD_FN_PURE FD_FN_UNUSED static ulong
1101 : fd_topo_obj_cnt( fd_topo_t const * topo,
1102 : char const * obj_type,
1103 0 : char const * label ) {
1104 0 : ulong cnt = 0UL;
1105 0 : for( ulong i=0UL; i<topo->obj_cnt; i++ ) {
1106 0 : fd_topo_obj_t const * obj = &topo->objs[ i ];
1107 0 : if( strncmp( obj->name, obj_type, sizeof(obj->name) ) ) continue;
1108 0 : if( label &&
1109 0 : strncmp( obj->label, label, sizeof(obj->label) ) ) continue;
1110 0 : cnt++;
1111 0 : }
1112 0 : return cnt;
1113 0 : }
1114 :
1115 : FD_FN_PURE FD_FN_UNUSED static fd_topo_obj_t const *
1116 : fd_topo_find_obj( fd_topo_t const * topo,
1117 : char const * obj_type,
1118 : char const * label,
1119 0 : ulong label_idx ) {
1120 0 : for( ulong i=0UL; i<topo->obj_cnt; i++ ) {
1121 0 : fd_topo_obj_t const * obj = &topo->objs[ i ];
1122 0 : if( strncmp( obj->name, obj_type, sizeof(obj->name) ) ) continue;
1123 0 : if( label &&
1124 0 : strncmp( obj->label, label, sizeof(obj->label) ) ) continue;
1125 0 : if( label_idx != ULONG_MAX && obj->label_idx != label_idx ) continue;
1126 0 : return obj;
1127 0 : }
1128 0 : return NULL;
1129 0 : }
1130 :
1131 : FD_FN_PURE FD_FN_UNUSED static fd_topo_obj_t const *
1132 : fd_topo_find_tile_obj( fd_topo_t const * topo,
1133 : fd_topo_tile_t const * tile,
1134 0 : char const * obj_type ) {
1135 0 : for( ulong i=0UL; i<(tile->uses_obj_cnt); i++ ) {
1136 0 : fd_topo_obj_t const * obj = &topo->objs[ tile->uses_obj_id[ i ] ];
1137 0 : if( strncmp( obj->name, obj_type, sizeof(obj->name) ) ) continue;
1138 0 : return obj;
1139 0 : }
1140 0 : return NULL;
1141 0 : }
1142 :
1143 : /* Join (map into the process) all shared memory (huge/gigantic pages)
1144 : needed by the tile, in the given topology. All memory associated
1145 : with the tile (aka. used by links that the tile either produces to or
1146 : consumes from, or used by the tile itself for its cnc) will be
1147 : attached (mapped into the process).
1148 :
1149 : This is needed to play nicely with the sandbox. Once a process is
1150 : sandboxed we can no longer map any memory. */
1151 : void
1152 : fd_topo_join_tile_workspaces( fd_topo_t * topo,
1153 : fd_topo_tile_t * tile,
1154 : int core_dump_level );
1155 :
1156 : /* Join (map into the process) the shared memory (huge/gigantic pages)
1157 : for the given workspace. Mode is one of
1158 : FD_SHMEM_JOIN_MODE_READ_WRITE or FD_SHMEM_JOIN_MODE_READ_ONLY and
1159 : determines the prot argument that will be passed to mmap when mapping
1160 : the pages in (PROT_WRITE or PROT_READ respectively).
1161 :
1162 : Dump should be set to 1 if the workspace memory should be dumpable
1163 : when the process crashes, or 0 if not. */
1164 : void
1165 : fd_topo_join_workspace( fd_topo_t * topo,
1166 : fd_topo_wksp_t * wksp,
1167 : int mode,
1168 : int dump );
1169 :
1170 : /* Join (map into the process) all shared memory (huge/gigantic pages)
1171 : needed by all tiles in the topology. Mode is one of
1172 : FD_SHMEM_JOIN_MODE_READ_WRITE or FD_SHMEM_JOIN_MODE_READ_ONLY and
1173 : determines the prot argument that will be passed to mmap when
1174 : mapping the pages in (PROT_WRITE or PROT_READ respectively). */
1175 : void
1176 : fd_topo_join_workspaces( fd_topo_t * topo,
1177 : int mode,
1178 : int core_dump_level );
1179 :
1180 : /* Leave (unmap from the process) the shared memory needed for the
1181 : given workspace in the topology, if it was previously mapped.
1182 :
1183 : topo and wksp are assumed non-NULL. It is OK if the workspace
1184 : has not been previously joined, in which case this is a no-op. */
1185 :
1186 : void
1187 : fd_topo_leave_workspace( fd_topo_t * topo,
1188 : fd_topo_wksp_t * wksp );
1189 :
1190 : /* Leave (unmap from the process) all shared memory needed by all
1191 : tiles in the topology, if each of them was mapped.
1192 :
1193 : topo is assumed non-NULL. Only workspaces which were previously
1194 : joined are unmapped. */
1195 :
1196 : void
1197 : fd_topo_leave_workspaces( fd_topo_t * topo );
1198 :
1199 : /* Create the given workspace needed by the topology on the system.
1200 : This does not "join" the workspaces (map their memory into the
1201 : process), but only creates the .wksp file and formats it correctly
1202 : as a workspace.
1203 :
1204 : Returns 0 on success and -1 on failure, with errno set to the error.
1205 : The only reason for failure currently that will be returned is
1206 : ENOMEM, as other unexpected errors will cause the program to exit.
1207 :
1208 : If update_existing is 1, the workspace will not be created from
1209 : scratch but it will be assumed that it already exists from a prior
1210 : run and needs to be maybe resized and then have the header
1211 : structures reinitialized. This can save a very expensive operation
1212 : of zeroing all of the workspace pages. This is dangerous in
1213 : production because it can leave stray memory from prior runs around,
1214 : and should only be used in development environments. */
1215 :
1216 : int
1217 : fd_topo_create_workspace( fd_topo_t * topo,
1218 : fd_topo_wksp_t * wksp,
1219 : int update_existing );
1220 :
1221 : /* Join the standard IPC objects needed by the topology of this particular
1222 : tile */
1223 :
1224 : void
1225 : fd_topo_fill_tile( fd_topo_t * topo,
1226 : fd_topo_tile_t * tile );
1227 :
1228 : /* Same as fd_topo_fill_tile but fills in all the objects for a
1229 : particular workspace with the given mode. */
1230 : void
1231 : fd_topo_workspace_fill( fd_topo_t * topo,
1232 : fd_topo_wksp_t * wksp );
1233 :
1234 : /* Apply a new function to every object that is resident in the given
1235 : workspace in the topology. */
1236 :
1237 : void
1238 : fd_topo_wksp_new( fd_topo_t const * topo,
1239 : fd_topo_wksp_t const * wksp,
1240 : fd_topo_obj_callbacks_t ** callbacks );
1241 :
1242 : /* Same as fd_topo_fill_tile but fills in all tiles in the topology. */
1243 :
1244 : void
1245 : fd_topo_fill( fd_topo_t * topo );
1246 :
1247 : /* fd_topo_tile_stack_join joins a huge page optimized stack for the
1248 : provided tile. The stack is assumed to already exist at a known
1249 : path in the hugetlbfs mount. */
1250 :
1251 : void *
1252 : fd_topo_tile_stack_join( char const * app_name,
1253 : char const * tile_name,
1254 : ulong tile_kind_id );
1255 :
1256 : /* fd_topo_run_single_process runs all the tiles in a single process
1257 : (the calling process). This spawns a thread for each tile, switches
1258 : that thread to the given UID and GID and then runs the tile in it.
1259 : Each thread will never exit, as tiles are expected to run forever.
1260 : An error is logged and the application will exit if a tile exits.
1261 : The function itself does return after spawning all the threads.
1262 :
1263 : The threads will not be sandboxed in any way, except switching to the
1264 : provided UID and GID, so they will share the same address space, and
1265 : not have any seccomp restrictions or use any Linux namespaces. The
1266 : calling thread will also switch to the provided UID and GID before
1267 : it returns.
1268 :
1269 : This is useful for tooling and debugging, but is not how the main
1270 : production Firedancer process runs. For production, each tile is run
1271 : in its own address space with a separate process and full security
1272 : sandbox. */
1273 :
1274 : void
1275 : fd_topo_run_single_process( fd_topo_t * topo,
1276 : uint uid,
1277 : uint gid,
1278 : fd_topo_run_tile_t (* tile_run )( fd_topo_tile_t const * tile ) );
1279 :
1280 : /* fd_topo_run_tile runs the given tile directly within the current
1281 : process (and thread). The function will never return, as tiles are
1282 : expected to run forever. An error is logged and the application will
1283 : exit if the tile exits.
1284 :
1285 : The sandbox argument determines if the current process will be
1286 : sandboxed fully before starting the tile. The thread will switch to
1287 : the UID and GID provided before starting the tile, even if the thread
1288 : is not being sandboxed. Although POSIX specifies that all threads in
1289 : a process must share a UID and GID, this is not the case on Linux.
1290 : The thread will switch to the provided UID and GID without switching
1291 : the other threads in the process.
1292 :
1293 : If keep_controlling_terminal is set to 0, and the sandbox is enabled
1294 : the controlling terminal will be detached as an additional sandbox
1295 : measure, but you will not be able to send Ctrl+C or other signals
1296 : from the terminal. See fd_sandbox.h for more information.
1297 :
1298 : The allow_fd argument is only used if sandbox is true, and is a file
1299 : descriptor which will be allowed to exist in the process. Normally
1300 : the sandbox code rejects and aborts if there is an unexpected file
1301 : descriptor present on boot. This is helpful to allow a parent
1302 : process to be notified on termination of the tile by waiting for a
1303 : pipe file descriptor to get closed.
1304 :
1305 : wait and debugger are both used in debugging. If wait is non-NULL,
1306 : the runner will wait until the value pointed to by wait is non-zero
1307 : before launching the tile. Likewise, if debugger is non-NULL, the
1308 : runner will wait until a debugger is attached before setting the
1309 : value pointed to by debugger to non-zero. These are intended to be
1310 : used as a pair, where many tiles share a waiting reference, and then
1311 : one of the tiles (a tile you want to attach the debugger to) has the
1312 : same reference provided as the debugger, so all tiles will stop and
1313 : wait for the debugger to attach to it before proceeding. */
1314 :
1315 : void
1316 : fd_topo_run_tile( fd_topo_t * topo,
1317 : fd_topo_tile_t * tile,
1318 : int sandbox,
1319 : int keep_controlling_terminal,
1320 : int dumpable,
1321 : uint uid,
1322 : uint gid,
1323 : int allow_fd,
1324 : fd_topo_run_tile_t * tile_run );
1325 :
1326 : /* This is for determining the value of RLIMIT_MLOCK that we need to
1327 : successfully run all tiles in separate processes. The value returned
1328 : is the maximum amount of memory that will be locked with mlock() by
1329 : any individual process in the tree. Specifically, if we have three
1330 : tile processes, and they each need to lock 5, 9, and 2 MiB of memory
1331 : respectively, RLIMIT_MLOCK needs to be 9 MiB to allow all three
1332 : process mlock() calls to succeed.
1333 :
1334 : Tiles lock memory in four ways. Any workspace they are using, they
1335 : lock the entire workspace. Then each tile uses huge pages for the
1336 : stack which are also locked, and finally some tiles use private
1337 : locked mmaps outside the workspace for storing key material. Every
1338 : tile also locks the executable code. The results here include all of
1339 : this memory together.
1340 :
1341 : The result is not necessarily the amount of memory used by the tile
1342 : process, although it will be quite close. Tiles could potentially
1343 : allocate memory (eg, with brk) without needing to lock it, which
1344 : would not need to included, and some kernel memory that tiles cause
1345 : to be allocated (for example XSK buffers) is also not included. The
1346 : actual amount of memory used will not be less than this value. */
1347 : FD_FN_PURE ulong
1348 : fd_topo_mlock_max_tile( fd_topo_t const * topo );
1349 :
1350 : /* fd_topo_mlock_code locks the code, rodata and initialized data of
1351 : every loaded ELF object into DRAM, so tiles cannot stall on major
1352 : faults when the page cache is evicted under memory pressure. */
1353 :
1354 : void
1355 : fd_topo_mlock_code( void );
1356 :
1357 : /* fd_topo_code_footprint returns the bytes that would be locked by
1358 : fd_topo_mlock_code, either the read-only segments (writable==0),
1359 : which are page cache shared by all tiles, or the writable segments
1360 : (writable==1), which are private to each tile process. */
1361 :
1362 : ulong
1363 : fd_topo_code_footprint( int writable );
1364 :
1365 : /* Same as fd_topo_mlock_max_tile, but for loading the entire topology
1366 : into one process, rather than a separate process per tile. This is
1367 : used, for example, by the configuration code when it creates all the
1368 : workspaces, or the monitor that maps the entire system into one
1369 : address space. */
1370 : FD_FN_PURE ulong
1371 : fd_topo_mlock( fd_topo_t const * topo );
1372 :
1373 : /* This returns the number of gigantic pages needed by the topology on
1374 : the provided numa node. It includes pages needed by the workspaces,
1375 : as well as additional allocations like huge pages for process stacks
1376 : and private key storage. */
1377 :
1378 : FD_FN_PURE ulong
1379 : fd_topo_gigantic_page_cnt( fd_topo_t const * topo,
1380 : ulong numa_idx );
1381 :
1382 : /* This returns the number of huge pages in the application needed by
1383 : the topology on the provided numa node. It includes pages needed by
1384 : things placed in the hugetlbfs (workspaces, process stacks). If
1385 : include_anonymous is true, it also includes anonymous hugepages which
1386 : are needed but are not placed in the hugetlbfs. */
1387 :
1388 : FD_FN_PURE ulong
1389 : fd_topo_huge_page_cnt( fd_topo_t const * topo,
1390 : ulong numa_idx,
1391 : int include_anonymous );
1392 :
1393 : /* Returns the number of normal (4 KiB) pages needed by the topology
1394 : for extra allocations like private key storage and XSK rings, plus
1395 : the locked code (read-only segments once, writable ones per tile). */
1396 :
1397 : FD_FN_PURE ulong
1398 : fd_topo_normal_page_cnt( fd_topo_t const * topo );
1399 :
1400 : /* Prints a message describing the topology to an output stream. If
1401 : stdout is true, will be written to stdout, otherwise will be written
1402 : as a NOTICE log message to the log file. */
1403 : void
1404 : fd_topo_print_log( int stdout,
1405 : fd_topo_t * topo );
1406 :
1407 : /* fd_topo_print_json prints the same topology description as
1408 : fd_topo_print_log to stdout, as a JSON document. */
1409 : void
1410 : fd_topo_print_json( fd_topo_t * topo );
1411 :
1412 : FD_PROTOTYPES_END
1413 :
1414 : #endif /* HEADER_fd_src_disco_topo_fd_topo_h */
|