Line data Source code
1 : #include "../shared/fd_config.h"
2 :
3 : #include "../../disco/net/fd_net_tile.h"
4 : #include "../../disco/quic/fd_tpu.h"
5 : #include "../../disco/tiles.h"
6 : #include "../../disco/topo/fd_topob.h"
7 : #include "../../disco/topo/fd_cpu_topo.h"
8 : #include "../../disco/plugin/fd_plugin.h"
9 : #include "../../util/pod/fd_pod_format.h"
10 : #include "../../util/net/fd_ip4.h"
11 : #include "../../util/tile/fd_tile_private.h"
12 :
13 : extern fd_topo_obj_callbacks_t * CALLBACKS[];
14 :
15 : static void
16 0 : parse_ip_port( const char * name, const char * ip_port, fd_topo_ip_port_t *parsed_ip_port) {
17 0 : char buf[ sizeof( "255.255.255.255:65536" ) ];
18 0 : memcpy( buf, ip_port, sizeof( buf ) );
19 0 : char *ip_end = strchr( buf, ':' );
20 0 : if( FD_UNLIKELY( !ip_end ) )
21 0 : FD_LOG_ERR(( "[%s] must in the form ip:port", name ));
22 0 : *ip_end = '\0';
23 :
24 0 : if( FD_UNLIKELY( !fd_cstr_to_ip4_addr( buf, &( parsed_ip_port->ip ) ) ) ) {
25 0 : FD_LOG_ERR(( "could not parse IP %s in [%s]", buf, name ));
26 0 : }
27 :
28 0 : parsed_ip_port->port = fd_cstr_to_ushort( ip_end+1 );
29 0 : if( FD_UNLIKELY( !parsed_ip_port->port ) )
30 0 : FD_LOG_ERR(( "could not parse port %s in [%s]", ip_end+1, name ));
31 0 : }
32 :
33 : void
34 0 : fd_topo_initialize( config_t * config ) {
35 0 : ulong net_tile_cnt = config->layout.net_tile_count;
36 0 : ulong quic_tile_cnt = config->layout.quic_tile_count;
37 0 : ulong verify_tile_cnt = config->layout.verify_tile_count;
38 0 : ulong resolv_tile_cnt = config->layout.resolv_tile_count;
39 0 : ulong bank_tile_cnt = config->layout.bank_tile_count;
40 0 : ulong shred_tile_cnt = config->layout.shred_tile_count;
41 :
42 0 : fd_topo_t * topo = { fd_topob_new( &config->topo, config->name ) };
43 0 : topo->max_page_size = fd_cstr_to_shmem_page_sz( config->hugetlbfs.max_page_size );
44 0 : topo->gigantic_page_threshold = config->hugetlbfs.gigantic_page_threshold_mib << 20;
45 :
46 : /* topo, name */
47 0 : fd_topob_wksp( topo, "metric_in" );
48 0 : fd_topob_wksp( topo, "net_quic" );
49 0 : fd_topob_wksp( topo, "net_shred" );
50 0 : fd_topob_wksp( topo, "quic_verify" );
51 0 : fd_topob_wksp( topo, "verify_dedup" );
52 0 : fd_topob_wksp( topo, "dedup_resolv" );
53 0 : fd_topob_wksp( topo, "resolv_pack" );
54 0 : fd_topob_wksp( topo, "pack_bank" );
55 0 : fd_topob_wksp( topo, "pack_poh" );
56 0 : fd_topob_wksp( topo, "bank_pack" );
57 0 : fd_topob_wksp( topo, "bank_poh" );
58 0 : fd_topob_wksp( topo, "bank_busy" );
59 0 : fd_topob_wksp( topo, "poh_shred" );
60 0 : fd_topob_wksp( topo, "gossip_dedup" );
61 0 : fd_topob_wksp( topo, "shred_store" );
62 0 : fd_topob_wksp( topo, "stake_out" );
63 0 : fd_topob_wksp( topo, "executed_txn" );
64 :
65 0 : fd_topob_wksp( topo, "shred_sign" );
66 0 : fd_topob_wksp( topo, "sign_shred" );
67 :
68 0 : fd_topob_wksp( topo, "quic" );
69 0 : fd_topob_wksp( topo, "verify" );
70 0 : fd_topob_wksp( topo, "dedup" );
71 0 : fd_topob_wksp( topo, "resolv" );
72 0 : fd_topob_wksp( topo, "pack" );
73 0 : fd_topob_wksp( topo, "bank" );
74 0 : fd_topob_wksp( topo, "poh" );
75 0 : fd_topob_wksp( topo, "shred" );
76 0 : fd_topob_wksp( topo, "store" );
77 0 : fd_topob_wksp( topo, "sign" );
78 0 : fd_topob_wksp( topo, "metric" );
79 0 : fd_topob_wksp( topo, "cswtch" );
80 :
81 0 : #define FOR(cnt) for( ulong i=0UL; i<cnt; i++ )
82 :
83 : /* topo, link_name, wksp_name, depth, mtu, burst */
84 0 : FOR(quic_tile_cnt) fd_topob_link( topo, "quic_net", "net_quic", config->net.ingress_buffer_size, FD_NET_MTU, 1UL );
85 0 : FOR(shred_tile_cnt) fd_topob_link( topo, "shred_net", "net_shred", 32768UL, FD_NET_MTU, 1UL );
86 0 : FOR(quic_tile_cnt) fd_topob_link( topo, "quic_verify", "quic_verify", config->tiles.verify.receive_buffer_size, FD_TPU_REASM_MTU, config->tiles.quic.txn_reassembly_count );
87 0 : FOR(verify_tile_cnt) fd_topob_link( topo, "verify_dedup", "verify_dedup", config->tiles.verify.receive_buffer_size, FD_TPU_PARSED_MTU, 1UL );
88 0 : /**/ fd_topob_link( topo, "gossip_dedup", "gossip_dedup", 2048UL, FD_TPU_MTU, 1UL );
89 : /* dedup_pack is large currently because pack can encounter stalls when running at very high throughput rates that would
90 : otherwise cause drops. */
91 0 : /**/ fd_topob_link( topo, "dedup_resolv", "dedup_resolv", 65536UL, FD_TPU_PARSED_MTU, 1UL );
92 0 : FOR(resolv_tile_cnt) fd_topob_link( topo, "resolv_pack", "resolv_pack", 65536UL, FD_TPU_RESOLVED_MTU, 1UL );
93 0 : /**/ fd_topob_link( topo, "stake_out", "stake_out", 128UL, FD_STAKE_OUT_MTU, 1UL );
94 : /* pack_bank is shared across all banks, so if one bank stalls due to complex transactions, the buffer neeeds to be large so that
95 : other banks can keep proceeding. */
96 0 : /**/ fd_topob_link( topo, "pack_bank", "pack_bank", 65536UL, USHORT_MAX, 1UL );
97 0 : /**/ fd_topob_link( topo, "pack_poh", "pack_poh", 65536UL, sizeof(fd_done_packing_t), 1UL );
98 0 : FOR(bank_tile_cnt) fd_topob_link( topo, "bank_poh", "bank_poh", 16384UL, USHORT_MAX, 1UL );
99 0 : FOR(bank_tile_cnt) fd_topob_link( topo, "bank_pack", "bank_pack", 16384UL, USHORT_MAX, 3UL );
100 0 : /**/ fd_topob_link( topo, "poh_pack", "bank_poh", 128UL, sizeof(fd_became_leader_t), 1UL );
101 0 : /**/ fd_topob_link( topo, "poh_shred", "poh_shred", 16384UL, USHORT_MAX, 2UL );
102 0 : /**/ fd_topob_link( topo, "crds_shred", "poh_shred", 128UL, 8UL + 40200UL * 38UL, 1UL );
103 0 : /**/ fd_topob_link( topo, "replay_resol", "bank_poh", 128UL, sizeof(fd_completed_bank_t), 1UL );
104 0 : /**/ fd_topob_link( topo, "executed_txn", "executed_txn", 16384UL, 64UL, 1UL );
105 : /* See long comment in fd_shred.c for an explanation about the size of this dcache. */
106 0 : FOR(shred_tile_cnt) fd_topob_link( topo, "shred_store", "shred_store", 65536UL, 4UL*FD_SHRED_STORE_MTU, 4UL+config->tiles.shred.max_pending_shred_sets );
107 :
108 0 : FOR(shred_tile_cnt) fd_topob_link( topo, "shred_sign", "shred_sign", 128UL, 32UL, 1UL );
109 0 : FOR(shred_tile_cnt) fd_topob_link( topo, "sign_shred", "sign_shred", 128UL, 64UL, 1UL );
110 :
111 0 : ushort parsed_tile_to_cpu[ FD_TILE_MAX ];
112 : /* Unassigned tiles will be floating, unless auto topology is enabled. */
113 0 : for( ulong i=0UL; i<FD_TILE_MAX; i++ ) parsed_tile_to_cpu[ i ] = USHORT_MAX;
114 :
115 0 : int is_auto_affinity = !strcmp( config->layout.affinity, "auto" );
116 0 : int is_agave_auto_affinity = !strcmp( config->frankendancer.layout.agave_affinity, "auto" );
117 :
118 0 : if( FD_UNLIKELY( is_auto_affinity != is_agave_auto_affinity ) ) {
119 0 : FD_LOG_ERR(( "The CPU affinity string in the configuration file under [layout.affinity] and [layout.agave_affinity] must both be set to 'auto' or both be set to a specific CPU affinity string." ));
120 0 : }
121 :
122 0 : fd_topo_cpus_t cpus[1];
123 0 : fd_topo_cpus_init( cpus );
124 :
125 0 : ulong affinity_tile_cnt = 0UL;
126 0 : if( FD_LIKELY( !is_auto_affinity ) ) affinity_tile_cnt = fd_tile_private_cpus_parse( config->layout.affinity, parsed_tile_to_cpu );
127 :
128 0 : ulong tile_to_cpu[ FD_TILE_MAX ] = {0};
129 0 : for( ulong i=0UL; i<affinity_tile_cnt; i++ ) {
130 0 : if( FD_UNLIKELY( parsed_tile_to_cpu[ i ]!=USHORT_MAX && parsed_tile_to_cpu[ i ]>=cpus->cpu_cnt ) )
131 0 : FD_LOG_ERR(( "The CPU affinity string in the configuration file under [layout.affinity] specifies a CPU index of %hu, but the system "
132 0 : "only has %lu CPUs. You should either change the CPU allocations in the affinity string, or increase the number of CPUs "
133 0 : "in the system.",
134 0 : parsed_tile_to_cpu[ i ], cpus->cpu_cnt ));
135 0 : tile_to_cpu[ i ] = fd_ulong_if( parsed_tile_to_cpu[ i ]==USHORT_MAX, ULONG_MAX, (ulong)parsed_tile_to_cpu[ i ] );
136 0 : }
137 :
138 0 : fd_topos_net_tiles( topo, config->layout.net_tile_count, &config->net, config->tiles.netlink.max_routes, config->tiles.netlink.max_peer_routes, config->tiles.netlink.max_neighbors, tile_to_cpu );
139 :
140 0 : FOR(net_tile_cnt) fd_topos_net_rx_link( topo, "net_quic", i, config->net.ingress_buffer_size );
141 0 : FOR(net_tile_cnt) fd_topos_net_rx_link( topo, "net_shred", i, config->net.ingress_buffer_size );
142 :
143 : /* topo, tile_name, tile_wksp, metrics_wksp, cpu_idx, is_agave, uses_keyswitch */
144 0 : FOR(quic_tile_cnt) fd_topob_tile( topo, "quic", "quic", "metric_in", tile_to_cpu[ topo->tile_cnt ], 0, 0 );
145 0 : FOR(verify_tile_cnt) fd_topob_tile( topo, "verify", "verify", "metric_in", tile_to_cpu[ topo->tile_cnt ], 0, 0 );
146 0 : /**/ fd_topob_tile( topo, "dedup", "dedup", "metric_in", tile_to_cpu[ topo->tile_cnt ], 0, 0 );
147 0 : FOR(resolv_tile_cnt) fd_topob_tile( topo, "resolv", "resolv", "metric_in", tile_to_cpu[ topo->tile_cnt ], 1, 0 );
148 0 : /**/ fd_topob_tile( topo, "pack", "pack", "metric_in", tile_to_cpu[ topo->tile_cnt ], 0, config->tiles.bundle.enabled );
149 0 : FOR(bank_tile_cnt) fd_topob_tile( topo, "bank", "bank", "metric_in", tile_to_cpu[ topo->tile_cnt ], 1, 0 );
150 0 : /**/ fd_topob_tile( topo, "poh", "poh", "metric_in", tile_to_cpu[ topo->tile_cnt ], 1, 1 );
151 0 : FOR(shred_tile_cnt) fd_topob_tile( topo, "shred", "shred", "metric_in", tile_to_cpu[ topo->tile_cnt ], 0, 1 );
152 0 : /**/ fd_topob_tile( topo, "store", "store", "metric_in", tile_to_cpu[ topo->tile_cnt ], 1, 0 );
153 0 : /**/ fd_topob_tile( topo, "sign", "sign", "metric_in", tile_to_cpu[ topo->tile_cnt ], 0, 1 );
154 0 : /**/ fd_topob_tile( topo, "metric", "metric", "metric_in", tile_to_cpu[ topo->tile_cnt ], 0, 0 );
155 0 : /**/ fd_topob_tile( topo, "cswtch", "cswtch", "metric_in", tile_to_cpu[ topo->tile_cnt ], 0, 0 );
156 :
157 : /* topo, tile_name, tile_kind_id, fseq_wksp, link_name, link_kind_id, reliable, polled */
158 0 : for( ulong j=0UL; j<quic_tile_cnt; j++ )
159 0 : fd_topos_tile_in_net( topo, "metric_in", "quic_net", j, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED ); /* No reliable consumers of networking fragments, may be dropped or overrun */
160 0 : for( ulong j=0UL; j<shred_tile_cnt; j++ )
161 0 : fd_topos_tile_in_net( topo, "metric_in", "shred_net", j, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED ); /* No reliable consumers of networking fragments, may be dropped or overrun */
162 :
163 0 : FOR(quic_tile_cnt) for( ulong j=0UL; j<net_tile_cnt; j++ )
164 0 : fd_topob_tile_in( topo, "quic", i, "metric_in", "net_quic", j, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED ); /* No reliable consumers of networking fragments, may be dropped or overrun */
165 0 : FOR(quic_tile_cnt) fd_topob_tile_out( topo, "quic", i, "quic_verify", i );
166 0 : FOR(quic_tile_cnt) fd_topob_tile_out( topo, "quic", i, "quic_net", i );
167 : /* All verify tiles read from all QUIC tiles, packets are round robin. */
168 0 : FOR(verify_tile_cnt) for( ulong j=0UL; j<quic_tile_cnt; j++ )
169 0 : fd_topob_tile_in( topo, "verify", i, "metric_in", "quic_verify", j, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED ); /* No reliable consumers, verify tiles may be overrun */
170 0 : FOR(verify_tile_cnt) fd_topob_tile_out( topo, "verify", i, "verify_dedup", i );
171 : /* Declare the single gossip link before the variable length verify-dedup links so we could have a compile-time index to the gossip link. */
172 0 : /**/ fd_topob_tile_in( topo, "dedup", 0UL, "metric_in", "gossip_dedup", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
173 0 : FOR(verify_tile_cnt) fd_topob_tile_in( topo, "dedup", 0UL, "metric_in", "verify_dedup", i, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
174 0 : /**/ fd_topob_tile_in( topo, "dedup", 0UL, "metric_in", "executed_txn", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
175 0 : /**/ fd_topob_tile_out( topo, "dedup", 0UL, "dedup_resolv", 0UL );
176 0 : FOR(resolv_tile_cnt) fd_topob_tile_in( topo, "resolv", i, "metric_in", "dedup_resolv", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
177 0 : FOR(resolv_tile_cnt) fd_topob_tile_in( topo, "resolv", i, "metric_in", "replay_resol", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
178 0 : FOR(resolv_tile_cnt) fd_topob_tile_out( topo, "resolv", i, "resolv_pack", i );
179 0 : /**/ fd_topob_tile_in( topo, "pack", 0UL, "metric_in", "resolv_pack", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
180 : /* The PoH to pack link is reliable, and must be. The fragments going
181 : across here are "you became leader" which pack must respond to
182 : by publishing microblocks, otherwise the leader TPU will hang
183 : forever.
184 :
185 : It's marked as unreliable since otherwise we have a reliable credit
186 : loop which will also starve the pack tile. This is OK because we
187 : will never send more than one leader message until the pack tile
188 : must acknowledge it with a packing done frag, so there will be at
189 : most one in flight at any time. */
190 0 : /**/ fd_topob_tile_in( topo, "pack", 0UL, "metric_in", "poh_pack", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
191 0 : /**/ fd_topob_tile_in( topo, "pack", 0UL, "metric_in", "executed_txn", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
192 0 : fd_topob_tile_out( topo, "pack", 0UL, "pack_bank", 0UL );
193 0 : fd_topob_tile_out( topo, "pack", 0UL, "pack_poh", 0UL );
194 0 : FOR(bank_tile_cnt) fd_topob_tile_in( topo, "bank", i, "metric_in", "pack_bank", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
195 0 : FOR(bank_tile_cnt) fd_topob_tile_out( topo, "bank", i, "bank_poh", i );
196 0 : FOR(bank_tile_cnt) fd_topob_tile_out( topo, "bank", i, "bank_pack", i );
197 0 : FOR(bank_tile_cnt) fd_topob_tile_in( topo, "poh", 0UL, "metric_in", "bank_poh", i, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
198 0 : if( FD_LIKELY( config->tiles.pack.use_consumed_cus ) )
199 0 : FOR(bank_tile_cnt) fd_topob_tile_in( topo, "pack", 0UL, "metric_in", "bank_pack", i, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
200 0 : /**/ fd_topob_tile_in( topo, "poh", 0UL, "metric_in", "stake_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
201 0 : /**/ fd_topob_tile_in( topo, "poh", 0UL, "metric_in", "pack_poh", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
202 0 : /**/ fd_topob_tile_out( topo, "poh", 0UL, "poh_shred", 0UL );
203 0 : /**/ fd_topob_tile_out( topo, "poh", 0UL, "poh_pack", 0UL );
204 0 : FOR(shred_tile_cnt) for( ulong j=0UL; j<net_tile_cnt; j++ )
205 0 : fd_topob_tile_in( topo, "shred", i, "metric_in", "net_shred", j, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED ); /* No reliable consumers of networking fragments, may be dropped or overrun */
206 0 : FOR(shred_tile_cnt) fd_topob_tile_in( topo, "shred", i, "metric_in", "poh_shred", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
207 0 : FOR(shred_tile_cnt) fd_topob_tile_in( topo, "shred", i, "metric_in", "stake_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
208 0 : FOR(shred_tile_cnt) fd_topob_tile_in( topo, "shred", i, "metric_in", "crds_shred", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
209 0 : FOR(shred_tile_cnt) fd_topob_tile_out( topo, "shred", i, "shred_store", i );
210 0 : FOR(shred_tile_cnt) fd_topob_tile_out( topo, "shred", i, "shred_net", i );
211 0 : FOR(shred_tile_cnt) fd_topob_tile_in( topo, "store", 0UL, "metric_in", "shred_store", i, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
212 :
213 : /* Sign links don't need to be reliable because they are synchronous,
214 : so there's at most one fragment in flight at a time anyway. The
215 : sign links are also not polled by fd_stem, instead the tiles will
216 : read the sign responses out of band in a dedicated spin loop. */
217 :
218 0 : for( ulong i=0UL; i<shred_tile_cnt; i++ ) {
219 0 : /**/ fd_topob_tile_in( topo, "sign", 0UL, "metric_in", "shred_sign", i, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
220 0 : /**/ fd_topob_tile_out( topo, "shred", i, "shred_sign", i );
221 0 : /**/ fd_topob_tile_in( topo, "shred", i, "metric_in", "sign_shred", i, FD_TOPOB_UNRELIABLE, FD_TOPOB_UNPOLLED );
222 0 : /**/ fd_topob_tile_out( topo, "sign", 0UL, "sign_shred", i );
223 0 : }
224 :
225 : /* PoH tile represents the Agave address space, so it's
226 : responsible for publishing Agave provided data to
227 : these links. */
228 : /**/ fd_topob_tile_out( topo, "poh", 0UL, "gossip_dedup", 0UL );
229 0 : /**/ fd_topob_tile_out( topo, "poh", 0UL, "stake_out", 0UL );
230 0 : /**/ fd_topob_tile_out( topo, "poh", 0UL, "crds_shred", 0UL );
231 0 : /**/ fd_topob_tile_out( topo, "poh", 0UL, "replay_resol", 0UL );
232 0 : /**/ fd_topob_tile_out( topo, "poh", 0UL, "executed_txn", 0UL );
233 :
234 : /* For now the only plugin consumer is the GUI */
235 0 : int plugins_enabled = config->tiles.gui.enabled;
236 0 : if( FD_LIKELY( plugins_enabled ) ) {
237 0 : fd_topob_wksp( topo, "plugin_in" );
238 0 : fd_topob_wksp( topo, "plugin_out" );
239 0 : fd_topob_wksp( topo, "plugin" );
240 :
241 : /**/ fd_topob_link( topo, "plugin_out", "plugin_out", 128UL, 8UL+40200UL*(58UL+12UL*34UL), 1UL );
242 0 : /**/ fd_topob_link( topo, "replay_plugi", "plugin_in", 128UL, 4098*8UL, 1UL );
243 0 : /**/ fd_topob_link( topo, "gossip_plugi", "plugin_in", 128UL, 8UL+40200UL*(58UL+12UL*34UL), 1UL );
244 0 : /**/ fd_topob_link( topo, "poh_plugin", "plugin_in", 128UL, 16UL, 1UL );
245 0 : /**/ fd_topob_link( topo, "startp_plugi", "plugin_in", 128UL, 56UL, 1UL );
246 0 : /**/ fd_topob_link( topo, "votel_plugin", "plugin_in", 128UL, 8UL, 1UL );
247 0 : /**/ fd_topob_link( topo, "valcfg_plugi", "plugin_in", 128UL, 608UL, 1UL );
248 :
249 : /**/ fd_topob_tile( topo, "plugin", "plugin", "metric_in", tile_to_cpu[ topo->tile_cnt ], 0, 0 );
250 :
251 : /**/ fd_topob_tile_out( topo, "poh", 0UL, "replay_plugi", 0UL );
252 0 : /**/ fd_topob_tile_out( topo, "poh", 0UL, "gossip_plugi", 0UL );
253 0 : /**/ fd_topob_tile_out( topo, "poh", 0UL, "poh_plugin", 0UL );
254 0 : /**/ fd_topob_tile_out( topo, "poh", 0UL, "startp_plugi", 0UL );
255 0 : /**/ fd_topob_tile_out( topo, "poh", 0UL, "votel_plugin", 0UL );
256 0 : /**/ fd_topob_tile_out( topo, "plugin", 0UL, "plugin_out", 0UL );
257 0 : /**/ fd_topob_tile_out( topo, "poh", 0UL, "valcfg_plugi", 0UL );
258 :
259 0 : /**/ fd_topob_tile_in( topo, "plugin", 0UL, "metric_in", "replay_plugi", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
260 0 : /**/ fd_topob_tile_in( topo, "plugin", 0UL, "metric_in", "gossip_plugi", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
261 0 : /**/ fd_topob_tile_in( topo, "plugin", 0UL, "metric_in", "stake_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
262 0 : /**/ fd_topob_tile_in( topo, "plugin", 0UL, "metric_in", "poh_plugin", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
263 0 : /**/ fd_topob_tile_in( topo, "plugin", 0UL, "metric_in", "startp_plugi", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
264 0 : /**/ fd_topob_tile_in( topo, "plugin", 0UL, "metric_in", "votel_plugin", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
265 0 : /**/ fd_topob_tile_in( topo, "plugin", 0UL, "metric_in", "valcfg_plugi", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
266 0 : }
267 :
268 0 : if( FD_LIKELY( config->tiles.gui.enabled ) ) {
269 0 : fd_topob_wksp( topo, "gui" );
270 0 : /**/ fd_topob_tile( topo, "gui", "gui", "metric_in", tile_to_cpu[ topo->tile_cnt ], 0, 1 );
271 0 : /**/ fd_topob_tile_in( topo, "gui", 0UL, "metric_in", "plugin_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
272 0 : /**/ fd_topob_tile_in( topo, "gui", 0UL, "metric_in", "poh_pack", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
273 0 : /**/ fd_topob_tile_in( topo, "gui", 0UL, "metric_in", "pack_bank", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
274 0 : /**/ fd_topob_tile_in( topo, "gui", 0UL, "metric_in", "pack_poh", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
275 0 : FOR(bank_tile_cnt) fd_topob_tile_in( topo, "gui", 0UL, "metric_in", "bank_poh", i, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
276 0 : }
277 :
278 0 : if( FD_UNLIKELY( config->tiles.bundle.enabled ) ) {
279 0 : fd_topob_wksp( topo, "bundle_verif" );
280 0 : fd_topob_wksp( topo, "bundle_sign" );
281 0 : fd_topob_wksp( topo, "sign_bundle" );
282 0 : fd_topob_wksp( topo, "pack_sign" );
283 0 : fd_topob_wksp( topo, "sign_pack" );
284 0 : fd_topob_wksp( topo, "bundle" );
285 :
286 0 : /**/ fd_topob_link( topo, "bundle_verif", "bundle_verif", config->tiles.verify.receive_buffer_size, FD_TPU_PARSED_MTU, 1UL );
287 0 : /**/ fd_topob_link( topo, "bundle_sign", "bundle_sign", 65536UL, 9UL, 1UL );
288 0 : /**/ fd_topob_link( topo, "sign_bundle", "sign_bundle", 128UL, 64UL, 1UL );
289 0 : /**/ fd_topob_link( topo, "pack_sign", "pack_sign", 65536UL, 1232UL, 1UL );
290 0 : /**/ fd_topob_link( topo, "sign_pack", "sign_pack", 128UL, 64UL, 1UL );
291 :
292 : /**/ fd_topob_tile( topo, "bundle", "bundle", "metric_in", tile_to_cpu[ topo->tile_cnt ], 0, 1 );
293 :
294 : /**/ fd_topob_tile_out( topo, "bundle", 0UL, "bundle_verif", 0UL );
295 0 : FOR(verify_tile_cnt) fd_topob_tile_in( topo, "verify", i, "metric_in", "bundle_verif", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
296 :
297 0 : /**/ fd_topob_tile_in( topo, "sign", 0UL, "metric_in", "bundle_sign", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
298 0 : /**/ fd_topob_tile_out( topo, "bundle", 0UL, "bundle_sign", 0UL );
299 0 : /**/ fd_topob_tile_in( topo, "bundle", 0UL, "metric_in", "sign_bundle", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_UNPOLLED );
300 0 : /**/ fd_topob_tile_out( topo, "sign", 0UL, "sign_bundle", 0UL );
301 :
302 0 : /**/ fd_topob_tile_in( topo, "sign", 0UL, "metric_in", "pack_sign", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
303 0 : /**/ fd_topob_tile_out( topo, "pack", 0UL, "pack_sign", 0UL );
304 0 : /**/ fd_topob_tile_in( topo, "pack", 0UL, "metric_in", "sign_pack", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_UNPOLLED );
305 0 : /**/ fd_topob_tile_out( topo, "sign", 0UL, "sign_pack", 0UL );
306 :
307 0 : if( plugins_enabled ) {
308 0 : fd_topob_wksp( topo, "bundle_plugi" );
309 : /* bundle_plugi must be kind of deep, to prevent exhausting shared
310 : flow control credits when publishing many packets at once. */
311 0 : fd_topob_link( topo, "bundle_plugi", "bundle_plugi", 65536UL, sizeof(fd_plugin_msg_block_engine_update_t), 1UL );
312 0 : fd_topob_tile_in( topo, "plugin", 0UL, "metric_in", "bundle_plugi", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
313 0 : fd_topob_tile_out( topo, "bundle", 0UL, "bundle_plugi", 0UL );
314 0 : }
315 0 : }
316 :
317 0 : if( FD_LIKELY( !is_auto_affinity ) ) {
318 0 : if( FD_UNLIKELY( affinity_tile_cnt<topo->tile_cnt ) )
319 0 : FD_LOG_ERR(( "The topology you are using has %lu tiles, but the CPU affinity specified in the config tile as [layout.affinity] only provides for %lu cores. "
320 0 : "You should either increase the number of cores dedicated to Firedancer in the affinity string, or decrease the number of cores needed by reducing "
321 0 : "the total tile count. You can reduce the tile count by decreasing individual tile counts in the [layout] section of the configuration file.",
322 0 : topo->tile_cnt, affinity_tile_cnt ));
323 0 : if( FD_UNLIKELY( affinity_tile_cnt>topo->tile_cnt ) )
324 0 : FD_LOG_WARNING(( "The topology you are using has %lu tiles, but the CPU affinity specified in the config tile as [layout.affinity] provides for %lu cores. "
325 0 : "Not all cores in the affinity will be used by Firedancer. You may wish to increase the number of tiles in the system by increasing "
326 0 : "individual tile counts in the [layout] section of the configuration file.",
327 0 : topo->tile_cnt, affinity_tile_cnt ));
328 :
329 0 : if( FD_LIKELY( strcmp( "", config->frankendancer.layout.agave_affinity ) ) ) {
330 0 : ushort agave_cpu[ FD_TILE_MAX ];
331 0 : ulong agave_cpu_cnt = fd_tile_private_cpus_parse( config->frankendancer.layout.agave_affinity, agave_cpu );
332 :
333 0 : for( ulong i=0UL; i<agave_cpu_cnt; i++ ) {
334 0 : if( FD_UNLIKELY( agave_cpu[ i ]>=cpus->cpu_cnt ) )
335 0 : FD_LOG_ERR(( "The CPU affinity string in the configuration file under [layout.agave_affinity] specifies a CPU index of %hu, but the system "
336 0 : "only has %lu CPUs. You should either change the CPU allocations in the affinity string, or increase the number of CPUs "
337 0 : "in the system.",
338 0 : agave_cpu[ i ], cpus->cpu_cnt ));
339 :
340 0 : for( ulong j=0UL; j<topo->tile_cnt; j++ ) {
341 0 : fd_topo_tile_t * tile = &topo->tiles[ j ];
342 0 : if( tile->cpu_idx==agave_cpu[ i ] ) FD_LOG_WARNING(( "Tile `%s:%lu` is already assigned to CPU %hu, but the CPU is also assigned to Agave. "
343 0 : "This may cause contention between the two tiles.", tile->name, tile->kind_id, agave_cpu[ i ] ));
344 0 : }
345 :
346 0 : if( FD_UNLIKELY( topo->agave_affinity_cnt>FD_TILE_MAX ) ) {
347 0 : FD_LOG_ERR(( "The CPU affinity string in the configuration file under [layout.agave_affinity] specifies more CPUs than Firedancer can use. "
348 0 : "You should either reduce the number of CPUs in the affinity string." ));
349 0 : }
350 0 : topo->agave_affinity_cpu_idx[ topo->agave_affinity_cnt++ ] = agave_cpu[ i ];
351 0 : }
352 0 : }
353 0 : }
354 :
355 : /* There is a special fseq that sits between the pack, bank, and poh
356 : tiles to indicate when the bank/poh tiles are done processing a
357 : microblock. Pack uses this to determine when to "unlock" accounts
358 : that it marked as locked because they were being used. */
359 :
360 0 : for( ulong i=0UL; i<bank_tile_cnt; i++ ) {
361 0 : fd_topo_obj_t * busy_obj = fd_topob_obj( topo, "fseq", "bank_busy" );
362 :
363 0 : fd_topo_tile_t * poh_tile = &topo->tiles[ fd_topo_find_tile( topo, "poh", 0UL ) ];
364 0 : fd_topo_tile_t * pack_tile = &topo->tiles[ fd_topo_find_tile( topo, "pack", 0UL ) ];
365 0 : fd_topob_tile_uses( topo, poh_tile, busy_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
366 0 : fd_topob_tile_uses( topo, pack_tile, busy_obj, FD_SHMEM_JOIN_MODE_READ_ONLY );
367 0 : FD_TEST( fd_pod_insertf_ulong( topo->props, busy_obj->id, "bank_busy.%lu", i ) );
368 0 : }
369 :
370 : /* There's another special fseq that's used to communicate the shred
371 : version from the Agave boot path to the shred tile. */
372 0 : fd_topo_obj_t * poh_shred_obj = fd_topob_obj( topo, "fseq", "poh_shred" );
373 0 : fd_topo_tile_t * poh_tile = &topo->tiles[ fd_topo_find_tile( topo, "poh", 0UL ) ];
374 0 : fd_topob_tile_uses( topo, poh_tile, poh_shred_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
375 0 : for( ulong i=0UL; i<shred_tile_cnt; i++ ) {
376 0 : fd_topo_tile_t * shred_tile = &topo->tiles[ fd_topo_find_tile( topo, "shred", i ) ];
377 0 : fd_topob_tile_uses( topo, shred_tile, poh_shred_obj, FD_SHMEM_JOIN_MODE_READ_ONLY );
378 0 : }
379 0 : FD_TEST( fd_pod_insertf_ulong( topo->props, poh_shred_obj->id, "poh_shred" ) );
380 :
381 0 : FOR(net_tile_cnt) fd_topos_net_tile_finish( topo, i );
382 :
383 0 : for( ulong i=0UL; i<topo->tile_cnt; i++ ) {
384 0 : fd_topo_tile_t * tile = &topo->tiles[ i ];
385 :
386 0 : if( FD_UNLIKELY( !strcmp( tile->name, "net" ) || !strcmp( tile->name, "sock" ) ) ) {
387 :
388 0 : tile->net.shred_listen_port = config->tiles.shred.shred_listen_port;
389 0 : tile->net.quic_transaction_listen_port = config->tiles.quic.quic_transaction_listen_port;
390 0 : tile->net.legacy_transaction_listen_port = config->tiles.quic.regular_transaction_listen_port;
391 :
392 0 : } else if( FD_UNLIKELY( !strcmp( tile->name, "netlnk" ) ) ) {
393 :
394 : /* already configured */
395 :
396 0 : } else if( FD_UNLIKELY( !strcmp( tile->name, "quic" ) ) ) {
397 :
398 0 : tile->quic.reasm_cnt = config->tiles.quic.txn_reassembly_count;
399 0 : tile->quic.out_depth = config->tiles.verify.receive_buffer_size;
400 0 : tile->quic.max_concurrent_connections = config->tiles.quic.max_concurrent_connections;
401 0 : tile->quic.max_concurrent_handshakes = config->tiles.quic.max_concurrent_handshakes;
402 0 : tile->quic.quic_transaction_listen_port = config->tiles.quic.quic_transaction_listen_port;
403 0 : tile->quic.idle_timeout_millis = config->tiles.quic.idle_timeout_millis;
404 0 : tile->quic.ack_delay_millis = config->tiles.quic.ack_delay_millis;
405 0 : tile->quic.retry = config->tiles.quic.retry;
406 0 : fd_cstr_fini( fd_cstr_append_cstr_safe( fd_cstr_init( tile->quic.key_log_path ), config->tiles.quic.ssl_key_log_file, sizeof(tile->quic.key_log_path) ) );
407 :
408 0 : } else if( FD_UNLIKELY( !strcmp( tile->name, "bundle" ) ) ) {
409 0 : strncpy( tile->bundle.url, config->tiles.bundle.url, sizeof(tile->bundle.url) );
410 0 : tile->bundle.url_len = strnlen( tile->bundle.url, 255 );
411 0 : strncpy( tile->bundle.sni, config->tiles.bundle.tls_domain_name, 256 );
412 0 : tile->bundle.sni_len = strnlen( tile->bundle.sni, 255 );
413 0 : strncpy( tile->bundle.identity_key_path, config->paths.identity_key, sizeof(tile->bundle.identity_key_path) );
414 0 : strncpy( tile->bundle.key_log_path, config->development.bundle.ssl_key_log_file, sizeof(tile->bundle.key_log_path) );
415 0 : tile->bundle.buf_sz = config->development.bundle.buffer_size_kib<<10;
416 0 : tile->bundle.ssl_heap_sz = config->development.bundle.ssl_heap_size_mib<<20;
417 0 : tile->bundle.keepalive_interval_nanos = config->tiles.bundle.keepalive_interval_millis * (ulong)1e6;
418 0 : tile->bundle.tls_cert_verify = !!config->tiles.bundle.tls_cert_verify;
419 0 : } else if( FD_UNLIKELY( !strcmp( tile->name, "verify" ) ) ) {
420 0 : tile->verify.tcache_depth = config->tiles.verify.signature_cache_size;
421 :
422 0 : } else if( FD_UNLIKELY( !strcmp( tile->name, "dedup" ) ) ) {
423 0 : tile->dedup.tcache_depth = config->tiles.dedup.signature_cache_size;
424 :
425 0 : } else if( FD_UNLIKELY( !strcmp( tile->name, "resolv" ) ) ) {
426 :
427 0 : } else if( FD_UNLIKELY( !strcmp( tile->name, "pack" ) ) ) {
428 0 : tile->pack.max_pending_transactions = config->tiles.pack.max_pending_transactions;
429 0 : tile->pack.bank_tile_count = config->layout.bank_tile_count;
430 0 : tile->pack.larger_max_cost_per_block = config->development.bench.larger_max_cost_per_block;
431 0 : tile->pack.larger_shred_limits_per_block = config->development.bench.larger_shred_limits_per_block;
432 0 : tile->pack.use_consumed_cus = config->tiles.pack.use_consumed_cus;
433 0 : tile->pack.schedule_strategy = config->tiles.pack.schedule_strategy_enum;
434 :
435 0 : if( FD_UNLIKELY( config->tiles.bundle.enabled ) ) {
436 0 : #define PARSE_PUBKEY( _tile, f ) \
437 0 : if( FD_UNLIKELY( !fd_base58_decode_32( config->tiles.bundle.f, tile->_tile.bundle.f ) ) ) \
438 0 : FD_LOG_ERR(( "[tiles.bundle.enabled] set to true, but failed to parse [tiles.bundle."#f"] %s", config->tiles.bundle.f ));
439 0 : tile->pack.bundle.enabled = 1;
440 0 : PARSE_PUBKEY( pack, tip_distribution_program_addr );
441 0 : PARSE_PUBKEY( pack, tip_payment_program_addr );
442 0 : PARSE_PUBKEY( pack, tip_distribution_authority );
443 0 : tile->pack.bundle.commission_bps = config->tiles.bundle.commission_bps;
444 0 : strncpy( tile->pack.bundle.identity_key_path, config->paths.identity_key, sizeof(tile->pack.bundle.identity_key_path) );
445 0 : strncpy( tile->pack.bundle.vote_account_path, config->paths.vote_account, sizeof(tile->pack.bundle.vote_account_path) );
446 0 : } else {
447 0 : fd_memset( &tile->pack.bundle, '\0', sizeof(tile->pack.bundle) );
448 0 : }
449 0 : } else if( FD_UNLIKELY( !strcmp( tile->name, "bank" ) ) ) {
450 :
451 0 : } else if( FD_UNLIKELY( !strcmp( tile->name, "poh" ) ) ) {
452 0 : strncpy( tile->poh.identity_key_path, config->paths.identity_key, sizeof(tile->poh.identity_key_path) );
453 :
454 0 : tile->poh.plugins_enabled = plugins_enabled;
455 0 : tile->poh.bank_cnt = config->layout.bank_tile_count;
456 0 : tile->poh.lagged_consecutive_leader_start = config->tiles.poh.lagged_consecutive_leader_start;
457 :
458 0 : if( FD_UNLIKELY( config->tiles.bundle.enabled ) ) {
459 0 : tile->poh.bundle.enabled = 1;
460 0 : PARSE_PUBKEY( poh, tip_distribution_program_addr );
461 0 : PARSE_PUBKEY( poh, tip_payment_program_addr );
462 0 : strncpy( tile->poh.bundle.vote_account_path, config->paths.vote_account, sizeof(tile->poh.bundle.vote_account_path) );
463 0 : #undef PARSE_PUBKEY
464 0 : } else {
465 0 : fd_memset( &tile->poh.bundle, '\0', sizeof(tile->poh.bundle) );
466 0 : }
467 :
468 0 : } else if( FD_UNLIKELY( !strcmp( tile->name, "shred" ) ) ) {
469 0 : strncpy( tile->shred.identity_key_path, config->paths.identity_key, sizeof(tile->shred.identity_key_path) );
470 :
471 0 : tile->shred.depth = topo->links[ tile->out_link_id[ 0 ] ].depth;
472 0 : tile->shred.fec_resolver_depth = config->tiles.shred.max_pending_shred_sets;
473 0 : tile->shred.expected_shred_version = config->consensus.expected_shred_version;
474 0 : tile->shred.shred_listen_port = config->tiles.shred.shred_listen_port;
475 0 : tile->shred.larger_shred_limits_per_block = config->development.bench.larger_shred_limits_per_block;
476 0 : for( ulong i=0UL; i<config->tiles.shred.additional_shred_destinations_retransmit_cnt; i++ ) {
477 0 : parse_ip_port( "tiles.shred.additional_shred_destinations_retransmit",
478 0 : config->tiles.shred.additional_shred_destinations_retransmit[ i ],
479 0 : &tile->shred.adtl_dests_retransmit[ i ] );
480 0 : }
481 0 : for( ulong i=0UL; i<config->tiles.shred.additional_shred_destinations_leader_cnt; i++ ) {
482 0 : parse_ip_port( "tiles.shred.additional_shred_destinations_leader",
483 0 : config->tiles.shred.additional_shred_destinations_leader[ i ],
484 0 : &tile->shred.adtl_dests_leader[ i ] );
485 0 : }
486 :
487 0 : } else if( FD_UNLIKELY( !strcmp( tile->name, "store" ) ) ) {
488 0 : tile->store.disable_blockstore_from_slot = config->development.bench.disable_blockstore_from_slot;
489 :
490 0 : } else if( FD_UNLIKELY( !strcmp( tile->name, "sign" ) ) ) {
491 0 : strncpy( tile->sign.identity_key_path, config->paths.identity_key, sizeof(tile->sign.identity_key_path) );
492 :
493 0 : } else if( FD_UNLIKELY( !strcmp( tile->name, "metric" ) ) ) {
494 0 : if( FD_UNLIKELY( !fd_cstr_to_ip4_addr( config->tiles.metric.prometheus_listen_address, &tile->metric.prometheus_listen_addr ) ) )
495 0 : FD_LOG_ERR(( "failed to parse prometheus listen address `%s`", config->tiles.metric.prometheus_listen_address ));
496 0 : tile->metric.prometheus_listen_port = config->tiles.metric.prometheus_listen_port;
497 :
498 0 : } else if( FD_UNLIKELY( !strcmp( tile->name, "cswtch" ) ) ) {
499 :
500 0 : } else if( FD_UNLIKELY( !strcmp( tile->name, "gui" ) ) ) {
501 0 : if( FD_UNLIKELY( !fd_cstr_to_ip4_addr( config->tiles.gui.gui_listen_address, &tile->gui.listen_addr ) ) )
502 0 : FD_LOG_ERR(( "failed to parse gui listen address `%s`", config->tiles.gui.gui_listen_address ));
503 0 : tile->gui.listen_port = config->tiles.gui.gui_listen_port;
504 0 : tile->gui.is_voting = strcmp( config->paths.vote_account, "" );
505 0 : strncpy( tile->gui.cluster, config->cluster, sizeof(tile->gui.cluster) );
506 0 : strncpy( tile->gui.identity_key_path, config->paths.identity_key, sizeof(tile->gui.identity_key_path) );
507 0 : strncpy( tile->gui.vote_key_path, config->paths.vote_account, sizeof(tile->gui.vote_key_path) );
508 0 : tile->gui.max_http_connections = config->tiles.gui.max_http_connections;
509 0 : tile->gui.max_websocket_connections = config->tiles.gui.max_websocket_connections;
510 0 : tile->gui.max_http_request_length = config->tiles.gui.max_http_request_length;
511 0 : tile->gui.send_buffer_size_mb = config->tiles.gui.send_buffer_size_mb;
512 0 : tile->gui.schedule_strategy = config->tiles.pack.schedule_strategy_enum;
513 0 : } else if( FD_UNLIKELY( !strcmp( tile->name, "plugin" ) ) ) {
514 :
515 0 : } else {
516 0 : FD_LOG_ERR(( "unknown tile name %lu `%s`", i, tile->name ));
517 0 : }
518 0 : }
519 :
520 0 : if( FD_UNLIKELY( is_auto_affinity ) ) fd_topob_auto_layout( topo, 1 );
521 :
522 0 : fd_topob_finish( topo, CALLBACKS );
523 0 : config->topo = *topo;
524 0 : }
|