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