Line data Source code
1 : /* The backtest command spawns a smaller topology for replaying shreds from
2 : rocksdb (or other sources TBD) and reproduce the behavior of replay tile.
3 :
4 : The smaller topology is:
5 : shred_out replay_execr
6 : backtest-------------->replay------------->execrp
7 : ^ |^ | ^ |
8 : |____________________|| | |________________|
9 : replay_out | | execrp_replay
10 : | |------------------------------>no consumer
11 : no producer------------- stake_out, txsend_out, poh_out
12 : store_replay
13 :
14 : */
15 : #define _GNU_SOURCE
16 : #include "../../firedancer/topology.h"
17 : #include "../../shared/commands/configure/configure.h"
18 : #include "../../shared/commands/run/run.h" /* initialize_workspaces */
19 : #include "../../shared/commands/watch/watch.h"
20 : #include "../../shared/fd_config.h" /* config_t */
21 : #include "../../../disco/tiles.h"
22 : #include "../../../disco/topo/fd_topob.h"
23 : #include "../../../disco/topo/fd_topob_vinyl.h"
24 : #include "../../../util/pod/fd_pod_format.h"
25 : #include "../../../discof/replay/fd_replay_tile.h"
26 : #include "../../../discof/restore/fd_snapin_tile_private.h"
27 : #include "../../../discof/restore/fd_snaplv_tile_private.h"
28 : #include "../../../discof/restore/fd_snapwm_tile_private.h"
29 : #include "../../../discof/restore/utils/fd_slot_delta_parser.h"
30 : #include "../../../discof/restore/utils/fd_ssctrl.h"
31 : #include "../../../discof/restore/utils/fd_ssmsg.h"
32 : #include "../../../discof/tower/fd_tower_tile.h"
33 : #include "../../../discof/replay/fd_execrp.h"
34 : #include "../../../ballet/lthash/fd_lthash.h"
35 : #include "../../../flamenco/capture/fd_capture_ctx.h"
36 : #include "../../../disco/pack/fd_pack_cost.h"
37 : #include "../../../flamenco/progcache/fd_progcache_admin.h"
38 :
39 : #include <errno.h>
40 : #include <unistd.h>
41 : #include <fcntl.h>
42 :
43 : extern fd_topo_obj_callbacks_t * CALLBACKS[];
44 : fd_topo_run_tile_t fdctl_tile_run( fd_topo_tile_t const * tile );
45 :
46 : static void
47 0 : backtest_topo( config_t * config ) {
48 :
49 0 : config->development.sandbox = 0;
50 0 : config->development.no_clone = 1;
51 :
52 0 : ulong execrp_tile_cnt = config->firedancer.layout.execrp_tile_count;
53 0 : ulong lta_tile_cnt = config->firedancer.layout.snapshot_hash_tile_count;
54 0 : ulong snapwr_tile_cnt = config->firedancer.layout.snapwr_tile_count;
55 0 : ulong snaplh_tile_cnt = config->firedancer.layout.snapshot_hash_tile_count;
56 :
57 0 : int disable_snap_loader = !config->gossip.entrypoints_cnt;
58 0 : int vinyl_enabled = !!config->firedancer.vinyl.enabled;
59 0 : int solcap_enabled = strlen( config->capture.solcap_capture )>0;
60 0 : int snapshot_lthash_disabled = config->development.snapshots.disable_lthash_verification;
61 :
62 0 : fd_topo_t * topo = { fd_topob_new( &config->topo, config->name ) };
63 0 : topo->max_page_size = fd_cstr_to_shmem_page_sz( config->hugetlbfs.max_page_size );
64 0 : topo->gigantic_page_threshold = config->hugetlbfs.gigantic_page_threshold_mib << 20;
65 :
66 0 : ulong cpu_idx = 0;
67 :
68 0 : fd_topob_wksp( topo, "metric" );
69 0 : fd_topob_wksp( topo, "metric_in" );
70 0 : fd_topob_tile( topo, "metric", "metric", "metric_in", ULONG_MAX, 0, 0 );
71 :
72 0 : fd_topob_wksp( topo, "backt" );
73 0 : fd_topo_tile_t * backt_tile = fd_topob_tile( topo, "backt", "backt", "metric_in", cpu_idx++, 0, 0 );
74 :
75 0 : fd_topob_wksp( topo, "replay" );
76 0 : fd_topo_tile_t * replay_tile = fd_topob_tile( topo, "replay", "replay", "metric_in", cpu_idx++, 0, 0 );
77 :
78 : /* specified by [tiles.replay] */
79 :
80 0 : fd_topob_wksp( topo, "funk" );
81 0 : fd_topo_obj_t * funk_obj = setup_topo_funk( topo, "funk",
82 0 : config->firedancer.funk.max_account_records,
83 0 : config->firedancer.runtime.max_live_slots + config->firedancer.vinyl.write_delay_slots,
84 0 : config->firedancer.funk.heap_size_gib );
85 0 : fd_topob_tile_uses( topo, replay_tile, funk_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
86 :
87 0 : fd_topob_wksp( topo, "progcache" );
88 0 : fd_topo_obj_t * progcache_obj = setup_topo_progcache( topo, "progcache",
89 0 : fd_progcache_est_rec_max( config->firedancer.runtime.program_cache.heap_size_mib<<20,
90 0 : config->firedancer.runtime.program_cache.mean_cache_entry_size ),
91 0 : config->firedancer.runtime.max_live_slots,
92 0 : config->firedancer.runtime.program_cache.heap_size_mib<<20 );
93 0 : fd_topob_tile_uses( topo, replay_tile, progcache_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
94 :
95 : /**********************************************************************/
96 : /* Add the executor tiles to topo */
97 : /**********************************************************************/
98 0 : fd_topob_wksp( topo, "execrp" );
99 0 : #define FOR(cnt) for( ulong i=0UL; i<cnt; i++ )
100 0 : FOR(execrp_tile_cnt) fd_topob_tile( topo, "execrp", "execrp", "metric_in", cpu_idx++, 0, 0 );
101 :
102 : /**********************************************************************/
103 : /* Add the capture tile to topo */
104 : /**********************************************************************/
105 0 : if( solcap_enabled ) {
106 0 : fd_topob_wksp( topo, "solcap" );
107 0 : fd_topob_tile( topo, "solcap", "solcap", "metric_in", cpu_idx++, 0, 0 );
108 0 : }
109 :
110 : /**********************************************************************/
111 : /* Add the snapshot tiles to topo */
112 : /**********************************************************************/
113 0 : fd_topo_tile_t * snapin_tile = NULL;
114 0 : if( FD_UNLIKELY( !disable_snap_loader ) ) {
115 0 : fd_topob_wksp( topo, "snapct" );
116 0 : fd_topob_wksp( topo, "snapld" );
117 0 : fd_topob_wksp( topo, "snapdc" );
118 0 : fd_topob_wksp( topo, "snapin" );
119 :
120 0 : fd_topo_tile_t * snapct_tile = fd_topob_tile( topo, "snapct", "snapct", "metric_in", cpu_idx++, 0, 0 );
121 0 : fd_topo_tile_t * snapld_tile = fd_topob_tile( topo, "snapld", "snapld", "metric_in", cpu_idx++, 0, 0 );
122 0 : fd_topo_tile_t * snapdc_tile = fd_topob_tile( topo, "snapdc", "snapdc", "metric_in", cpu_idx++, 0, 0 );
123 0 : snapin_tile = fd_topob_tile( topo, "snapin", "snapin", "metric_in", cpu_idx++, 0, 0 );
124 :
125 0 : snapct_tile->allow_shutdown = 1;
126 0 : snapld_tile->allow_shutdown = 1;
127 0 : snapdc_tile->allow_shutdown = 1;
128 0 : snapin_tile->allow_shutdown = 1;
129 :
130 0 : if( vinyl_enabled ) {
131 0 : fd_topob_wksp( topo, "snapwm" );
132 0 : fd_topo_tile_t * snapwm_tile = fd_topob_tile( topo, "snapwm", "snapwm", "metric_in", cpu_idx++, 0, 0 );
133 0 : snapwm_tile->allow_shutdown = 1;
134 :
135 0 : fd_topob_wksp( topo, "snapwh" );
136 0 : fd_topo_tile_t * snapwh_tile = fd_topob_tile( topo, "snapwh", "snapwh", "metric_in", cpu_idx++, 0, 0 );
137 0 : snapwh_tile->allow_shutdown = 1;
138 :
139 0 : fd_topob_wksp( topo, "snapwr" );
140 0 : FOR(snapwr_tile_cnt) fd_topob_tile( topo, "snapwr", "snapwr", "metric_in", cpu_idx++, 0, 0 )->allow_shutdown = 1;
141 0 : }
142 :
143 0 : if( snapshot_lthash_disabled ) {
144 : /* nothing to do here */
145 0 : } else {
146 0 : if( vinyl_enabled ) {
147 0 : fd_topob_wksp( topo, "snaplh" );
148 0 : fd_topob_wksp( topo, "snaplv" );
149 0 : FOR(snaplh_tile_cnt) fd_topob_tile( topo, "snaplh", "snaplh", "metric_in", ULONG_MAX, 0, 0 )->allow_shutdown = 1;
150 0 : /**/ fd_topob_tile( topo, "snaplv", "snaplv", "metric_in", ULONG_MAX, 0, 0 )->allow_shutdown = 1;
151 0 : fd_topob_wksp( topo, "vinyl_admin" );
152 0 : } else {
153 0 : fd_topob_wksp( topo, "snapla" );
154 0 : fd_topob_wksp( topo, "snapls" );
155 0 : FOR(lta_tile_cnt) fd_topob_tile( topo, "snapla", "snapla", "metric_in", cpu_idx++, 0, 0 )->allow_shutdown = 1;
156 0 : /**/ fd_topob_tile( topo, "snapls", "snapls", "metric_in", cpu_idx++, 0, 0 )->allow_shutdown = 1;
157 0 : }
158 0 : }
159 :
160 0 : } else {
161 0 : fd_topob_wksp( topo, "genesi" );
162 0 : fd_topob_tile( topo, "genesi", "genesi", "metric_in", cpu_idx++, 0, 0 )->allow_shutdown = 1;
163 0 : }
164 :
165 : /**********************************************************************/
166 : /* Setup backtest->replay link (shred_out) in topo */
167 : /**********************************************************************/
168 :
169 : /* The repair tile is replaced by the backtest tile for the repair to
170 : replay link. The frag interface is a "slice", ie. entry batch,
171 : which is provided by the backtest tile, which reads in the entry
172 : batches from the CLI-specified source (eg. RocksDB). */
173 :
174 0 : fd_topob_wksp( topo, "shred_out" );
175 0 : fd_topob_link( topo, "shred_out", "shred_out", 65536UL, FD_SHRED_OUT_MTU, 1UL );
176 0 : fd_topob_tile_in( topo, "replay", 0UL, "metric_in", "shred_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
177 0 : fd_topob_tile_out( topo, "backt", 0UL, "shred_out", 0UL );
178 :
179 : /**********************************************************************/
180 : /* Setup snapshot links in topo */
181 : /**********************************************************************/
182 0 : if( FD_LIKELY( !disable_snap_loader ) ) {
183 0 : fd_topob_wksp( topo, "snapct_ld" );
184 0 : fd_topob_wksp( topo, "snapld_dc" );
185 0 : fd_topob_wksp( topo, "snapdc_in" );
186 :
187 0 : fd_topob_wksp( topo, "snapin_manif" );
188 0 : fd_topob_wksp( topo, "snapct_repr" );
189 :
190 0 : if( vinyl_enabled ) {
191 0 : fd_topob_wksp( topo, "snapin_txn");
192 0 : fd_topob_wksp( topo, "snapin_wm" );
193 0 : fd_topob_wksp( topo, "snapwm_wr" );
194 0 : }
195 0 : if( snapshot_lthash_disabled ) {
196 0 : if( vinyl_enabled ) {
197 0 : fd_topob_wksp( topo, "snapwm_ct" );
198 0 : } else {
199 0 : fd_topob_wksp( topo, "snapin_ct" );
200 0 : }
201 0 : } else {
202 0 : if( vinyl_enabled ) {
203 0 : fd_topob_wksp( topo, "snaplv_lh" );
204 0 : fd_topob_wksp( topo, "snaplh_lv" );
205 0 : fd_topob_wksp( topo, "snapwm_lv" );
206 0 : fd_topob_wksp( topo, "snaplv_ct" );
207 0 : } else {
208 0 : fd_topob_wksp( topo, "snapla_ls" );
209 0 : fd_topob_wksp( topo, "snapin_ls" );
210 0 : fd_topob_wksp( topo, "snapls_ct" );
211 0 : }
212 0 : }
213 :
214 0 : fd_topob_link( topo, "snapct_ld", "snapct_ld", 128UL, sizeof(fd_ssctrl_init_t), 1UL );
215 0 : fd_topob_link( topo, "snapld_dc", "snapld_dc", 16384UL, USHORT_MAX, 1UL );
216 0 : fd_topob_link( topo, "snapdc_in", "snapdc_in", 16384UL, USHORT_MAX, 1UL );
217 :
218 0 : fd_topob_link( topo, "snapin_manif", "snapin_manif", 4UL, sizeof(fd_snapshot_manifest_t), 1UL ); /* TODO: Should be depth 1 or 2 but replay backpressures */
219 0 : fd_topob_link( topo, "snapct_repr", "snapct_repr", 128UL, 0UL, 1UL )->permit_no_consumers = 1;
220 :
221 0 : if( vinyl_enabled ) {
222 : /* snapwm needs all txn_cache data in order to verify the slot
223 : deltas with the slot history. To make this possible, snapin
224 : uses the dcache of the snapin_txn link as the scratch memory.
225 : The depth of the link should match that of snapin_wm, just to
226 : guarantee enough mcache credits. The mtu needs to be adjusted
227 : so that the total dcache size matches what snapin requires.
228 : Round up the mtu (ulong) size using: (...+(depth-1))/depth. */
229 0 : fd_topob_link( topo, "snapin_txn", "snapin_txn", 16UL, (sizeof(fd_sstxncache_entry_t)*FD_SNAPIN_TXNCACHE_MAX_ENTRIES+15UL/*depth-1*/)/16UL/*depth*/, 1UL );
230 0 : fd_topob_link( topo, "snapin_wm", "snapin_wm", 16UL, FD_SNAPWM_PAIR_BATCH_SZ_MAX, 1UL );
231 : /* snapwh and snapwr both use snapwm_wh's dcache. snapwh sends
232 : control messages to snapwr, using snapwh_wr link, instructing
233 : which chunks in the dcache are ready to be consumed by snapwr. */
234 0 : fd_topo_link_t * snapwm_wh =
235 0 : fd_topob_link( topo, "snapwm_wh", "snapwm_wr", 64UL, FD_SNAPWM_WR_MTU, 1UL );
236 0 : fd_topob_link( topo, "snapwh_wr", "snapwm_wr", 64UL, 0UL, 1UL );
237 0 : fd_pod_insertf_ulong( topo->props, 8UL, "obj.%lu.app_sz", snapwm_wh->dcache_obj_id );
238 0 : }
239 0 : if( snapshot_lthash_disabled ) {
240 0 : if( vinyl_enabled ) {
241 0 : fd_topob_link( topo, "snapwm_ct", "snapwm_ct", 128UL, 0UL, 1UL );
242 0 : } else {
243 0 : fd_topob_link( topo, "snapin_ct", "snapin_ct", 128UL, 0UL, 1UL );
244 0 : }
245 0 : } else {
246 0 : if( vinyl_enabled ) {
247 0 : FOR(snaplh_tile_cnt) fd_topob_link( topo, "snaplh_lv", "snaplh_lv", 128UL, sizeof(fd_lthash_value_t), 1UL );
248 0 : /**/ fd_topob_link( topo, "snapwm_lv", "snapwm_lv", 32768UL, FD_SNAPWM_DUP_META_BATCH_SZ, 1UL );
249 0 : /**/ fd_topob_link( topo, "snaplv_lh", "snaplv_lh", 262144UL, FD_SNAPLV_DUP_META_SZ, FD_SNAPLV_STEM_BURST ); /* FD_SNAPWM_DUP_META_BATCH_CNT_MAX times the depth of snapwm_lv */
250 0 : /**/ fd_topob_link( topo, "snaplv_ct", "snaplv_ct", 128UL, 0UL, 1UL );
251 0 : } else {
252 0 : FOR(lta_tile_cnt) fd_topob_link( topo, "snapla_ls", "snapla_ls", 128UL, sizeof(fd_lthash_value_t), 1UL );
253 0 : /**/ fd_topob_link( topo, "snapin_ls", "snapin_ls", 256UL, sizeof(fd_snapshot_full_account_t), 1UL );
254 0 : /**/ fd_topob_link( topo, "snapls_ct", "snapls_ct", 128UL, 0UL, 1UL );
255 0 : }
256 0 : }
257 :
258 0 : if( snapshot_lthash_disabled ) {
259 0 : if( vinyl_enabled ) {
260 0 : fd_topob_tile_in ( topo, "snapct", 0UL, "metric_in", "snapwm_ct", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
261 0 : } else {
262 0 : fd_topob_tile_in ( topo, "snapct", 0UL, "metric_in", "snapin_ct", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
263 0 : }
264 0 : } else {
265 0 : if( vinyl_enabled ) {
266 0 : fd_topob_tile_in ( topo, "snapct", 0UL, "metric_in", "snaplv_ct", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
267 0 : } else {
268 0 : fd_topob_tile_in ( topo, "snapct", 0UL, "metric_in", "snapls_ct", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
269 0 : }
270 0 : }
271 :
272 0 : fd_topob_tile_in ( topo, "snapct", 0UL, "metric_in", "snapld_dc", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
273 0 : fd_topob_tile_out( topo, "snapct", 0UL, "snapct_ld", 0UL );
274 0 : fd_topob_tile_out( topo, "snapct", 0UL, "snapct_repr", 0UL );
275 0 : fd_topob_tile_in ( topo, "snapld", 0UL, "metric_in", "snapct_ld", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
276 0 : fd_topob_tile_out( topo, "snapld", 0UL, "snapld_dc", 0UL );
277 0 : fd_topob_tile_in ( topo, "snapdc", 0UL, "metric_in", "snapld_dc", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
278 0 : fd_topob_tile_out( topo, "snapdc", 0UL, "snapdc_in", 0UL );
279 0 : fd_topob_tile_in ( topo, "snapin", 0UL, "metric_in", "snapdc_in", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
280 :
281 0 : fd_topob_tile_out( topo, "snapin", 0UL, "snapin_manif", 0UL );
282 0 : fd_topob_tile_in ( topo, "replay", 0UL, "metric_in", "snapin_manif", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
283 :
284 0 : if( vinyl_enabled ) {
285 0 : fd_topob_tile_out( topo, "snapin", 0UL, "snapin_wm", 0UL );
286 0 : fd_topob_tile_in ( topo, "snapwm", 0UL, "metric_in", "snapin_wm", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
287 0 : fd_topob_tile_out( topo, "snapin", 0UL, "snapin_txn",0UL );
288 0 : fd_topob_tile_in ( topo, "snapwm", 0UL, "metric_in", "snapin_txn",0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
289 0 : fd_topob_tile_out( topo, "snapwm", 0UL, "snapwm_wh", 0UL );
290 0 : fd_topob_tile_in ( topo, "snapwh", 0UL, "metric_in", "snapwm_wh", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
291 0 : fd_topob_tile_out( topo, "snapwh", 0UL, "snapwh_wr", 0UL );
292 : /* snapwh and snapwr both access snapwm_wh's dcache, avoiding a
293 : memcpy for every account (vinyl pair) that is being processed
294 : (loaded) from the snapshot. */
295 0 : FOR(snapwr_tile_cnt) fd_topob_tile_in ( topo, "snapwr", i, "metric_in", "snapwh_wr", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
296 0 : FOR(snapwr_tile_cnt) fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "snapwr", i ) ], &topo->objs[ topo->links[ fd_topo_find_link( topo, "snapwm_wh", 0UL ) ].dcache_obj_id ], FD_SHMEM_JOIN_MODE_READ_ONLY );
297 0 : }
298 0 : if( snapshot_lthash_disabled ) {
299 0 : if( vinyl_enabled ) {
300 0 : /**/ fd_topob_tile_out( topo, "snapwm", 0UL, "snapwm_ct", 0UL );
301 0 : } else {
302 0 : /**/ fd_topob_tile_out( topo, "snapin", 0UL, "snapin_ct", 0UL );
303 0 : }
304 0 : } else {
305 0 : if( vinyl_enabled ) {
306 0 : FOR(snaplh_tile_cnt) fd_topob_tile_in ( topo, "snaplh", i, "metric_in", "snapwh_wr", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
307 0 : FOR(snaplh_tile_cnt) fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "snaplh", i ) ], &topo->objs[ topo->links[ fd_topo_find_link( topo, "snapwm_wh", 0UL ) ].dcache_obj_id ], FD_SHMEM_JOIN_MODE_READ_ONLY );
308 0 : FOR(snaplh_tile_cnt) fd_topob_tile_in ( topo, "snaplh", i, "metric_in", "snaplv_lh", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
309 0 : /**/ fd_topob_tile_out( topo, "snaplv", 0UL, "snaplv_lh", 0UL );
310 0 : FOR(snaplh_tile_cnt) fd_topob_tile_out( topo, "snaplh", i, "snaplh_lv", i );
311 0 : /**/ fd_topob_tile_in ( topo, "snaplv", 0UL, "metric_in", "snapwm_lv", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
312 0 : FOR(snaplh_tile_cnt) fd_topob_tile_in ( topo, "snaplv", 0UL, "metric_in", "snaplh_lv", i, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
313 0 : /**/ fd_topob_tile_out( topo, "snaplv", 0UL, "snaplv_ct", 0UL );
314 0 : /**/ fd_topob_tile_out( topo, "snapwm", 0UL, "snapwm_lv", 0UL );
315 :
316 0 : fd_topo_obj_t * vinyl_admin_obj = setup_topo_vinyl_admin( topo, "vinyl_admin" );
317 0 : /**/ fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "snapwm", 0UL ) ], vinyl_admin_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
318 0 : FOR(snapwr_tile_cnt) fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "snapwr", i ) ], vinyl_admin_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
319 0 : /**/ fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "snaplv", 0UL ) ], vinyl_admin_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
320 0 : FOR(snaplh_tile_cnt) fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "snaplh", i ) ], vinyl_admin_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
321 0 : FD_TEST( fd_pod_insertf_ulong( topo->props, vinyl_admin_obj->id, "vinyl_admin" ) );
322 0 : } else {
323 0 : FOR(lta_tile_cnt) fd_topob_tile_in ( topo, "snapla", i, "metric_in", "snapdc_in", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
324 0 : FOR(lta_tile_cnt) fd_topob_tile_out( topo, "snapla", i, "snapla_ls", i );
325 0 : /**/ fd_topob_tile_in ( topo, "snapls", 0UL, "metric_in", "snapin_ls", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
326 0 : FOR(lta_tile_cnt) fd_topob_tile_in ( topo, "snapls", 0UL, "metric_in", "snapla_ls", i, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
327 0 : /**/ fd_topob_tile_out( topo, "snapls", 0UL, "snapls_ct", 0UL );
328 0 : /**/ fd_topob_tile_out( topo, "snapin", 0UL, "snapin_ls", 0UL );
329 0 : }
330 0 : }
331 0 : } else {
332 0 : fd_topob_wksp( topo, "genesi_out" );
333 0 : fd_topob_link( topo, "genesi_out", "genesi_out", 2UL, 10UL*1024UL*1024UL+32UL+sizeof(fd_lthash_value_t), 1UL );
334 0 : fd_topob_tile_out( topo, "genesi", 0UL, "genesi_out", 0UL );
335 0 : fd_topob_tile_in ( topo, "replay", 0UL, "metric_in", "genesi_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
336 0 : }
337 :
338 0 : if( vinyl_enabled ) {
339 0 : setup_topo_accdb_meta( topo, &config->firedancer );
340 :
341 0 : fd_topo_obj_t * accdb_data = setup_topo_accdb_cache( topo, &config->firedancer );
342 :
343 0 : fd_topob_wksp( topo, "accdb_execrp" );
344 0 : fd_topo_tile_t * accdb_tile = fd_topob_tile( topo, "accdb", "accdb_execrp", "metric_in", cpu_idx++, 0, 0 );
345 0 : fd_topob_tile_uses( topo, accdb_tile, accdb_data, FD_SHMEM_JOIN_MODE_READ_WRITE );
346 0 : fd_topob_tile_uses( topo, replay_tile, accdb_data, FD_SHMEM_JOIN_MODE_READ_WRITE );
347 0 : for( ulong i=0UL; i<execrp_tile_cnt; i++ ) {
348 0 : fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "execrp", i ) ], accdb_data, FD_SHMEM_JOIN_MODE_READ_WRITE );
349 0 : }
350 :
351 0 : fd_topob_wksp( topo, "accdb_replay" );
352 0 : }
353 :
354 : /**********************************************************************/
355 : /* More backtest->replay links in topo */
356 : /**********************************************************************/
357 :
358 : /* The tower tile is replaced by the backtest tile for the tower to
359 : replay link. The backtest tile simply sends monotonically
360 : increasing rooted slot numbers to the replay tile, once after each
361 : "replayed a full slot" notification received from the replay tile.
362 : This allows the replay tile to advance its watermark, and publish
363 : various data structures. This is an oversimplified barebones mock
364 : of the tower tile. */
365 0 : fd_topob_wksp( topo, "tower_out" );
366 0 : fd_topob_link( topo, "tower_out", "tower_out", 1024UL, sizeof(fd_tower_slot_done_t), 1UL );
367 0 : fd_topob_tile_in( topo, "replay", 0UL, "metric_in", "tower_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
368 0 : fd_topob_tile_out( topo, "backt", 0UL, "tower_out", 0UL );
369 :
370 : /**********************************************************************/
371 : /* Setup replay->stake/send/poh links in topo w/o consumers */
372 : /**********************************************************************/
373 0 : fd_topob_wksp( topo, "replay_epoch" );
374 0 : fd_topob_wksp( topo, "replay_poh" );
375 :
376 0 : fd_topob_link( topo, "replay_epoch", "replay_epoch", 128UL, FD_EPOCH_OUT_MTU, 1UL );
377 0 : ulong execle_tile_cnt = config->firedancer.layout.execle_tile_count;
378 0 : FOR(execle_tile_cnt) fd_topob_link( topo, "replay_poh", "replay_poh", 128UL, (4096UL*sizeof(fd_txn_p_t))+sizeof(fd_microblock_trailer_t), 1UL );
379 :
380 0 : fd_topob_tile_out( topo, "replay", 0UL, "replay_epoch", 0UL );
381 0 : FOR(execle_tile_cnt) fd_topob_tile_out( topo, "replay", 0UL, "replay_poh", i );
382 :
383 0 : topo->links[ replay_tile->out_link_id[ fd_topo_find_tile_out_link( topo, replay_tile, "replay_epoch", 0 ) ] ].permit_no_consumers = 1;
384 0 : FOR(execle_tile_cnt) topo->links[ replay_tile->out_link_id[ fd_topo_find_tile_out_link( topo, replay_tile, "replay_poh", i ) ] ].permit_no_consumers = 1;
385 :
386 : /**********************************************************************/
387 : /* Setup replay->backtest link (replay_notif) in topo */
388 : /**********************************************************************/
389 :
390 0 : fd_topob_wksp( topo, "replay_out" );
391 0 : fd_topob_link( topo, "replay_out", "replay_out", 8192UL, sizeof( fd_replay_message_t ), 1UL );
392 0 : fd_topob_tile_out( topo, "replay", 0UL, "replay_out", 0UL );
393 0 : fd_topob_tile_in ( topo, "backt", 0UL, "metric_in", "replay_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
394 0 : if( FD_LIKELY( !disable_snap_loader ) ) {
395 0 : fd_topob_tile_in ( topo, "backt", 0UL, "metric_in", "snapin_manif", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
396 0 : } else {
397 0 : fd_topob_tile_in ( topo, "backt", 0UL, "metric_in", "genesi_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
398 0 : }
399 :
400 : /**********************************************************************/
401 : /* Setup replay->exec link in topo */
402 : /**********************************************************************/
403 0 : fd_topob_wksp( topo, "replay_execrp" );
404 0 : fd_topob_link( topo, "replay_execrp", "replay_execrp", 16384UL, 2240UL, 1UL );
405 0 : fd_topob_tile_out( topo, "replay", 0UL, "replay_execrp", 0UL );
406 0 : for( ulong i=0UL; i<execrp_tile_cnt; i++ ) {
407 0 : fd_topob_tile_in( topo, "execrp", i, "metric_in", "replay_execrp", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
408 0 : }
409 :
410 : /**********************************************************************/
411 : /* Setup exec->replay links in topo, to send solcap account updates
412 : so that they are serialized, and to notify replay tile that a txn
413 : has been finalized by the exec tile. */
414 : /**********************************************************************/
415 0 : fd_topob_wksp( topo, "execrp_replay" );
416 :
417 0 : FOR(execrp_tile_cnt) fd_topob_link( topo, "execrp_replay", "execrp_replay", 16384UL, sizeof(fd_execrp_task_done_msg_t), 1UL );
418 :
419 0 : FOR(execrp_tile_cnt) fd_topob_tile_out( topo, "execrp", i, "execrp_replay", i );
420 0 : FOR(execrp_tile_cnt) fd_topob_tile_in( topo, "replay", 0UL, "metric_in", "execrp_replay", i, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
421 :
422 : /**********************************************************************/
423 : /* Setup the shared objs used by replay and exec tiles */
424 : /**********************************************************************/
425 :
426 0 : if( FD_UNLIKELY( solcap_enabled ) ) {
427 : /* 32 sections of SOLCAP_WRITE_ACCOUNT_DATA_MTU bytes each ≈ 4MB.
428 : This is done to ideally avoid cache thrashing and allow for all
429 : the links to sit on L3 cache. */
430 0 : fd_topob_link( topo, "cap_repl", "solcap", 32UL, SOLCAP_WRITE_ACCOUNT_DATA_MTU, 1UL );
431 0 : fd_topob_tile_out( topo, "replay", 0UL, "cap_repl", 0UL );
432 0 : fd_topob_tile_in( topo, "solcap", 0UL, "metric_in", "cap_repl", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
433 0 : FOR(execrp_tile_cnt) fd_topob_link( topo, "cap_execrp", "solcap", 32UL, SOLCAP_WRITE_ACCOUNT_DATA_MTU, 1UL );
434 0 : FOR(execrp_tile_cnt) fd_topob_tile_out( topo, "execrp", i, "cap_execrp", i );
435 0 : FOR(execrp_tile_cnt) fd_topob_tile_in( topo, "solcap", 0UL, "metric_in", "cap_execrp", i, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
436 0 : }
437 :
438 0 : fd_topob_wksp( topo, "store" );
439 0 : fd_topo_obj_t * store_obj = setup_topo_store( topo, "store", config->firedancer.runtime.max_live_slots * FD_SHRED_BLK_MAX, 1 );
440 0 : fd_topob_tile_uses( topo, backt_tile, store_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
441 0 : fd_topob_tile_uses( topo, replay_tile, store_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
442 0 : FD_TEST( fd_pod_insertf_ulong( topo->props, store_obj->id, "store" ) );
443 :
444 0 : fd_topo_obj_t * acc_pool_obj = setup_topo_acc_pool( topo, config->firedancer.runtime.max_account_cnt );
445 0 : fd_topob_tile_uses( topo, replay_tile, acc_pool_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
446 0 : FOR(execrp_tile_cnt) fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "execrp", i ) ], acc_pool_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
447 0 : FD_TEST( fd_pod_insertf_ulong( topo->props, acc_pool_obj->id, "acc_pool" ) );
448 :
449 : /* banks_obj shared by replay and exec tiles */
450 0 : fd_topob_wksp( topo, "banks" );
451 0 : fd_topo_obj_t * banks_obj = setup_topo_banks( topo, "banks", config->firedancer.runtime.max_live_slots, config->firedancer.runtime.max_fork_width, 0 );
452 0 : fd_topob_tile_uses( topo, replay_tile, banks_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
453 0 : FOR(execrp_tile_cnt) fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "execrp", i ) ], banks_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
454 0 : FD_TEST( fd_pod_insertf_ulong( topo->props, banks_obj->id, "banks" ) );
455 :
456 : /* banks_locks_obj shared by replay and exec tiles */
457 0 : fd_topob_wksp( topo, "banks_locks" );
458 0 : fd_topo_obj_t * banks_locks_obj = setup_topo_banks_locks( topo, "banks_locks" );
459 0 : fd_topob_tile_uses( topo, replay_tile, banks_locks_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
460 0 : FOR(execrp_tile_cnt) fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "execrp", i ) ], banks_locks_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
461 0 : FD_TEST( fd_pod_insertf_ulong( topo->props, banks_locks_obj->id, "banks_locks" ) );
462 :
463 : /* txncache_obj, busy_obj and poh_slot_obj only by replay tile */
464 0 : fd_topob_wksp( topo, "txncache" );
465 0 : fd_topob_wksp( topo, "execle_busy" );
466 0 : fd_topo_obj_t * txncache_obj = setup_topo_txncache( topo, "txncache",
467 0 : config->firedancer.runtime.max_live_slots,
468 0 : fd_ulong_pow2_up( FD_PACK_MAX_TXNCACHE_TXN_PER_SLOT ) );
469 0 : fd_topob_tile_uses( topo, replay_tile, txncache_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
470 0 : if( FD_LIKELY( !disable_snap_loader ) ) {
471 0 : fd_topob_tile_uses( topo, snapin_tile, txncache_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
472 0 : if( vinyl_enabled ) {
473 0 : ulong vinyl_map_obj_id = fd_pod_query_ulong( topo->props, "accdb.meta_map", ULONG_MAX ); FD_TEST( vinyl_map_obj_id !=ULONG_MAX );
474 0 : ulong vinyl_pool_obj_id = fd_pod_query_ulong( topo->props, "accdb.meta_pool", ULONG_MAX ); FD_TEST( vinyl_pool_obj_id!=ULONG_MAX );
475 0 : fd_topo_obj_t * vinyl_map_obj = &topo->objs[ vinyl_map_obj_id ];
476 0 : fd_topo_obj_t * vinyl_pool_obj = &topo->objs[ vinyl_pool_obj_id ];
477 0 : fd_topob_tile_uses( topo, snapin_tile, vinyl_map_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
478 0 : fd_topob_tile_uses( topo, snapin_tile, vinyl_pool_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
479 0 : }
480 0 : }
481 0 : for( ulong i=0UL; i<execrp_tile_cnt; i++ ) {
482 0 : fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "execrp", i ) ], txncache_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
483 0 : }
484 :
485 0 : FD_TEST( fd_pod_insertf_ulong( topo->props, txncache_obj->id, "txncache" ) );
486 0 : for( ulong i=0UL; i<execle_tile_cnt; i++ ) {
487 0 : fd_topo_obj_t * busy_obj = fd_topob_obj( topo, "fseq", "execle_busy" );
488 0 : fd_topob_tile_uses( topo, replay_tile, busy_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
489 0 : FD_TEST( fd_pod_insertf_ulong( topo->props, busy_obj->id, "execle_busy.%lu", i ) );
490 0 : }
491 :
492 0 : if( FD_LIKELY( !disable_snap_loader ) ) {
493 0 : fd_topob_tile_uses( topo, snapin_tile, funk_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
494 0 : }
495 :
496 0 : if( vinyl_enabled ) {
497 0 : fd_topob_vinyl_rq( topo, "replay", 0UL, "accdb_replay", "replay", 4UL, 1024UL, 1024UL );
498 0 : for( ulong i=0UL; i<execrp_tile_cnt; i++ ) {
499 0 : fd_topob_vinyl_rq( topo, "execrp", i, "accdb_execrp", "execrp", 4UL, 1024UL, 1024UL );
500 0 : }
501 0 : }
502 :
503 0 : for( ulong i=0UL; i<topo->tile_cnt; i++ ) {
504 0 : fd_topo_tile_t * tile = &topo->tiles[ i ];
505 0 : fd_topo_configure_tile( tile, config );
506 :
507 0 : if( !strcmp( tile->name, "replay" ) ) {
508 0 : tile->replay.enable_features_cnt = config->tiles.replay.enable_features_cnt;
509 0 : for( ulong i = 0; i < tile->replay.enable_features_cnt; i++ ) {
510 0 : strncpy( tile->replay.enable_features[i], config->tiles.replay.enable_features[i], sizeof(tile->replay.enable_features[i]) );
511 0 : }
512 0 : }
513 0 : }
514 :
515 : // fd_topob_auto_layout( topo, 0 );
516 0 : fd_topob_finish( topo, CALLBACKS );
517 0 : }
518 :
519 : extern int * fd_log_private_shared_lock;
520 :
521 : static void
522 0 : backtest_cmd_topo( config_t * config ) {
523 0 : config->firedancer.development.replay.scheduler_depth = 8192UL;
524 0 : backtest_topo( config );
525 0 : }
526 :
527 : extern configure_stage_t fd_cfg_stage_accdb;
528 : extern configure_stage_t fd_cfg_stage_keys;
529 :
530 : static args_t
531 0 : configure_args( void ) {
532 0 : args_t args = {
533 0 : .configure.command = CONFIGURE_CMD_INIT,
534 0 : };
535 :
536 0 : ulong stage_idx = 0UL;
537 0 : args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_hugetlbfs;
538 0 : args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_snapshots;
539 0 : args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_accdb;
540 0 : args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_keys;
541 0 : args.configure.stages[ stage_idx++ ] = NULL;
542 :
543 0 : return args;
544 0 : }
545 :
546 : void
547 : backtest_cmd_args( int * pargc,
548 : char *** pargv,
549 0 : args_t * args ) {
550 0 : char const * db = fd_env_strip_cmdline_cstr( pargc, pargv, "--db", NULL, "funk" );
551 0 : char const * vinyl_path = fd_env_strip_cmdline_cstr( pargc, pargv, "--vinyl-path", NULL, NULL );
552 0 : char const * vinyl_io = fd_env_strip_cmdline_cstr( pargc, pargv, "--vinyl-io", NULL, "bd" );
553 :
554 0 : args->backtest.no_watch = fd_env_strip_cmdline_contains( pargc, pargv, "--no-watch" );
555 :
556 0 : if( 0==strcmp( db, "funk" ) ) args->backtest.is_vinyl = 0;
557 0 : else if( 0==strcmp( db, "vinyl" ) ) args->backtest.is_vinyl = 1;
558 0 : else FD_LOG_ERR(( "invalid --db '%s' (must be 'funk' or 'vinyl')", db ));
559 :
560 0 : fd_cstr_ncpy( args->backtest.vinyl_path, vinyl_path, sizeof(args->backtest.vinyl_path) );
561 :
562 0 : if( FD_UNLIKELY( strlen( vinyl_io )!=2UL ) ) FD_LOG_ERR(( "invalid --vinyl-io '%s'", vinyl_io ));
563 0 : fd_cstr_ncpy( args->backtest.vinyl_io, vinyl_io, sizeof(args->backtest.vinyl_io) );
564 0 : }
565 :
566 : void
567 : backtest_cmd_perm( args_t * args FD_PARAM_UNUSED,
568 : fd_cap_chk_t * chk,
569 0 : config_t const * config ) {
570 0 : args_t c_args = configure_args();
571 0 : configure_cmd_perm( &c_args, chk, config );
572 0 : run_cmd_perm( NULL, chk, config );
573 0 : }
574 :
575 : static void
576 : fixup_config( config_t * config,
577 0 : args_t const * args ) {
578 0 : if( args->backtest.vinyl_path[0] ) {
579 0 : fd_cstr_ncpy( config->paths.accounts, args->backtest.vinyl_path, sizeof(config->paths.accounts) );
580 0 : }
581 :
582 0 : if( args->backtest.is_vinyl ) {
583 0 : config->firedancer.vinyl.enabled = 1;
584 :
585 0 : config->firedancer.vinyl.file_size_gib = config->firedancer.funk.heap_size_gib;
586 0 : config->firedancer.vinyl.max_account_records = config->firedancer.funk.max_account_records;
587 :
588 0 : char const * io_mode = args->backtest.vinyl_io;
589 0 : if( 0==strcmp( io_mode, "ur" ) ) config->firedancer.vinyl.io_uring.enabled = 1;
590 0 : else if( 0==strcmp( io_mode, "bd" ) ) {}
591 0 : else FD_LOG_ERR(( "unsupported --vinyl-io '%s' (valid options are 'bd' and 'ur')", io_mode ));
592 0 : }
593 :
594 : /* FIXME Unfortunately, the fdctl boot procedure constructs the
595 : topology before parsing command-line arguments. So, here,
596 : we construct the topology again (a third time ... sigh). */
597 0 : backtest_topo( config );
598 0 : }
599 :
600 : static void
601 : backtest_cmd_fn( args_t * args,
602 0 : config_t * config ) {
603 0 : fixup_config( config, args );
604 0 : args_t c_args = configure_args();
605 0 : configure_cmd_fn( &c_args, config );
606 :
607 0 : initialize_workspaces( config );
608 0 : initialize_stacks( config );
609 :
610 0 : fd_log_private_shared_lock[ 1 ] = 0;
611 0 : fd_topo_join_workspaces( &config->topo, FD_SHMEM_JOIN_MODE_READ_WRITE, FD_TOPO_CORE_DUMP_LEVEL_DISABLED );
612 0 : fd_topo_fill( &config->topo );
613 :
614 0 : args_t watch_args;
615 0 : int pipefd[2];
616 0 : if( !args->backtest.no_watch ) {
617 0 : if( FD_UNLIKELY( pipe2( pipefd, O_NONBLOCK ) ) ) FD_LOG_ERR(( "pipe2() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
618 :
619 0 : watch_args.watch.drain_output_fd = pipefd[0];
620 0 : if( FD_UNLIKELY( -1==dup2( pipefd[ 1 ], STDERR_FILENO ) ) ) FD_LOG_ERR(( "dup2() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
621 0 : }
622 :
623 0 : fd_topo_run_single_process( &config->topo, 2, config->uid, config->gid, fdctl_tile_run );
624 0 : if( args->backtest.no_watch ) {
625 0 : for(;;) pause();
626 0 : } else {
627 0 : watch_cmd_fn( &watch_args, config );
628 0 : }
629 0 : }
630 :
631 : action_t fd_action_backtest = {
632 : .name = "backtest",
633 : .args = backtest_cmd_args,
634 : .fn = backtest_cmd_fn,
635 : .perm = backtest_cmd_perm,
636 : .topo = backtest_cmd_topo,
637 : };
|