LCOV - code coverage report
Current view: top level - app/firedancer-dev/commands - backtest.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 285 0.0 %
Date: 2026-08-13 04:56:22 Functions: 0 7 0.0 %

          Line data    Source code
       1             : /* The backtest topology exercises offline replay with mocked consensus.
       2             : 
       3             :    The smaller topology is:
       4             :            shred_out             replay_execr
       5             :    backtest-------------->replay------------->execrp
       6             :      ^                    |^ | ^                |
       7             :      |____________________|| | |________________|
       8             :           replay_out       | |   execrp_replay
       9             :                            | |------------------------------>no consumer
      10             :     no producer-------------  stake_out, txsend_out, poh_out
      11             :                 store_replay
      12             : 
      13             : */
      14             : #define _GNU_SOURCE
      15             : #include "../../firedancer/topology.h"
      16             : #include "../../shared/commands/configure/configure.h"
      17             : #include "../../shared/commands/run/run.h" /* initialize_workspaces */
      18             : #include "../../shared/commands/watch/watch.h"
      19             : #include "../../shared/fd_config.h" /* config_t */
      20             : #include "../../../disco/topo/fd_topob.h"
      21             : #include "../../../util/pod/fd_pod_format.h"
      22             : #include "../../../disco/gui/fd_gui_config_parse.h"
      23             : #include "../../../ballet/base58/fd_base58.h"
      24             : #include "../../../disco/genesis/fd_genesis_cluster.h"
      25             : #include "../../../discof/genesis/fd_genesi_tile.h"
      26             : #include "../../../discof/genesis/genesis_hash.h"
      27             : #include "../../../discof/replay/fd_replay_tile.h"
      28             : #include "../../../discof/restore/fd_snapct_tile.h"
      29             : #include "../../../discof/restore/utils/fd_ssctrl.h"
      30             : #include "../../../discof/restore/utils/fd_ssmsg.h"
      31             : #include "../../../discof/tower/fd_tower_tile.h"
      32             : #include "../../../discof/replay/fd_execrp.h"
      33             : #include "../../../disco/shred/fd_shred_tile.h"
      34             : #include "../../../flamenco/capture/fd_capture_ctx.h"
      35             : #include "../../../disco/pack/fd_pack_cost.h"
      36             : #include "../../../flamenco/progcache/fd_progcache_admin.h"
      37             : #include "../../../flamenco/runtime/fd_cost_tracker.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             : void
      47             : backtest_cmd_args( int *    pargc,
      48             :                    char *** pargv,
      49           0 :                    args_t * args ) {
      50           0 :   args->backtest.no_watch = fd_env_strip_cmdline_contains( pargc, pargv, "--no-watch" );
      51           0 : }
      52             : 
      53             : static void
      54           0 : backtest_topo( config_t * config ) {
      55             : 
      56           0 :   config->development.sandbox  = 0;
      57           0 :   config->development.no_clone = 1;
      58             : 
      59           0 :   config->firedancer.layout.resolv_tile_count = 0;
      60             : 
      61           0 :   ulong execrp_tile_cnt = config->firedancer.layout.execrp_tile_count;
      62             : 
      63           0 :   int disable_snap_loader      = !config->gossip.entrypoints_cnt;
      64           0 :   int solcap_enabled           = strlen( config->capture.solcap_capture )>0;
      65           0 :   int telemetry_enabled        = config->telemetry && strcmp( config->tiles.event.url, "" );
      66             : 
      67           0 :   fd_topo_t * topo = { fd_topob_new( &config->topo, config->name ) };
      68           0 :   topo->max_page_size = fd_cstr_to_shmem_page_sz( config->hugetlbfs.max_page_size );
      69           0 :   topo->gigantic_page_threshold = config->hugetlbfs.gigantic_page_threshold_mib << 20;
      70             : 
      71           0 :   ulong cpu_idx = 0;
      72             : 
      73           0 :   fd_topob_wksp( topo, "metric" );
      74           0 :   fd_topob_wksp( topo, "metric_in" );
      75           0 :   fd_topob_tile( topo, "metric", "metric", "metric_in", ULONG_MAX, 0, 0, 0 );
      76             : 
      77           0 :   fd_topob_wksp( topo, "backt" );
      78           0 :   fd_topo_tile_t * backt_tile = fd_topob_tile( topo, "backt", "backt", "metric_in", cpu_idx++, 0, 0, 0 );
      79             : 
      80           0 :   fd_topob_wksp( topo, "replay" );
      81           0 :   fd_topo_tile_t * replay_tile = fd_topob_tile( topo, "replay", "replay", "metric_in", cpu_idx++, 0, 1, 0 );
      82             : 
      83           0 :   fd_topo_obj_t * node_info_obj = fd_topob_obj( topo, "node_info", "replay" );
      84           0 :   fd_topob_tile_uses( topo, replay_tile, node_info_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
      85           0 :   FD_TEST( fd_pod_insertf_ulong( topo->props, node_info_obj->id, "node_info" ) );
      86             : 
      87           0 :   fd_topob_wksp( topo, "accdb" )->core_dump_level = FD_TOPO_CORE_DUMP_LEVEL_FULL;
      88           0 :   fd_topo_tile_t * accdb_tile = fd_topob_tile( topo, "accdb", "accdb", "metric_in", cpu_idx++, 0, 0, 0 );
      89             : 
      90           0 :   fd_topob_wksp( topo, "progcache" );
      91           0 :   setup_topo_progcache( topo, "progcache",
      92           0 :       fd_progcache_est_rec_max( config->firedancer.runtime.program_cache.heap_size_mib<<20,
      93           0 :                                 config->firedancer.runtime.program_cache.mean_cache_entry_size ),
      94           0 :       config->firedancer.runtime.max_live_slots,
      95           0 :       config->firedancer.runtime.program_cache.heap_size_mib<<20 );
      96           0 :   ulong progcache_obj_id; FD_TEST( (progcache_obj_id = fd_pod_query_ulong( topo->props, "progcache", ULONG_MAX ) )!=ULONG_MAX );
      97           0 :   fd_topob_tile_uses( topo, replay_tile, &topo->objs[ progcache_obj_id ], FD_SHMEM_JOIN_MODE_READ_WRITE );
      98             : 
      99           0 :   fd_topob_wksp( topo, "accdb_data" );
     100           0 :   fd_topo_obj_t * accdb_obj = setup_topo_accdb( topo, "accdb_data",
     101           0 :       config->firedancer.accounts.max_accounts,
     102           0 :       config->firedancer.runtime.max_live_slots,
     103           0 :       FD_RUNTIME_MAX_WRITABLE_ACCOUNTS_PER_SLOT,
     104           0 :       8192UL,
     105           0 :       1UL<<35UL,
     106           0 :       config->firedancer.accounts.cache_size_gib*(1UL<<30UL),
     107           0 :       config->tiles.bundle.enabled,
     108           0 :       execrp_tile_cnt+3UL,
     109           0 :       0UL );
     110           0 :   FD_TEST( fd_pod_insertf_ulong( topo->props, accdb_obj->id, "accdb" ) );
     111             : 
     112             :   /**********************************************************************/
     113             :   /* Add the executor tiles to topo                                     */
     114             :   /**********************************************************************/
     115           0 :   fd_topob_wksp( topo, "execrp" );
     116           0 :   #define FOR(cnt) for( ulong i=0UL; i<cnt; i++ )
     117           0 :   FOR(execrp_tile_cnt) fd_topob_tile( topo, "execrp", "execrp", "metric_in", cpu_idx++, 0, 0, 0 );
     118             : 
     119             :   /**********************************************************************/
     120             :   /* Add the capture tile to topo                                       */
     121             :   /**********************************************************************/
     122           0 :   if( solcap_enabled ) {
     123           0 :     fd_topob_wksp( topo, "solcap" );
     124           0 :     fd_topob_tile( topo, "solcap", "solcap", "metric_in", cpu_idx++, 0, 0, 0 );
     125           0 :   }
     126             : 
     127           0 :   fd_topob_wksp( topo, "diag" );
     128           0 :   fd_topob_tile( topo, "diag", "diag", "metric_in", ULONG_MAX, 0, 0, 0 );
     129             : 
     130             :   /**********************************************************************/
     131             :   /* Add the snapshot tiles to topo                                       */
     132             :   /**********************************************************************/
     133           0 :   fd_topo_tile_t * snapin_tile = NULL;
     134           0 :   if( FD_UNLIKELY( !disable_snap_loader ) ) {
     135           0 :     fd_topob_wksp( topo, "snapct" );
     136           0 :     fd_topob_wksp( topo, "snapld" );
     137           0 :     fd_topob_wksp( topo, "snapdc" );
     138           0 :     fd_topob_wksp( topo, "snapin" );
     139           0 :     fd_topob_wksp( topo, "snapwr" );
     140             : 
     141           0 :     fd_topo_tile_t * snapct_tile = fd_topob_tile( topo, "snapct",  "snapct",  "metric_in",  cpu_idx++, 0, 0, 0 );
     142           0 :     fd_topo_tile_t * snapld_tile = fd_topob_tile( topo, "snapld",  "snapld",  "metric_in",  cpu_idx++, 0, 0, 0 );
     143           0 :     fd_topo_tile_t * snapdc_tile = fd_topob_tile( topo, "snapdc",  "snapdc",  "metric_in",  cpu_idx++, 0, 0, 0 );
     144           0 :                      snapin_tile = fd_topob_tile( topo, "snapin",  "snapin",  "metric_in",  cpu_idx++, 0, 0, 0 );
     145           0 :     fd_topo_tile_t * snapwr_tile = fd_topob_tile( topo, "snapwr",  "snapwr",  "metric_in",  cpu_idx++, 0, 0, 0 );
     146             : 
     147           0 :     snapct_tile->allow_shutdown = 1;
     148           0 :     snapld_tile->allow_shutdown = 1;
     149           0 :     snapdc_tile->allow_shutdown = 1;
     150           0 :     snapin_tile->allow_shutdown = 1;
     151           0 :     snapwr_tile->allow_shutdown = 1;
     152           0 :   } else {
     153           0 :     fd_topob_wksp( topo, "genesi" );
     154           0 :     fd_topob_tile( topo, "genesi",  "genesi",  "metric_in",  cpu_idx++, 0, 0, 0 )->allow_shutdown = 1;
     155           0 :   }
     156             : 
     157             :   /**********************************************************************/
     158             :   /* Add the event + sign tiles to topo                                 */
     159             :   /**********************************************************************/
     160           0 :   if( FD_LIKELY( telemetry_enabled ) ) {
     161           0 :     fd_topob_wksp( topo, "sign"       );
     162           0 :     fd_topob_wksp( topo, "event"      );
     163           0 :     fd_topob_wksp( topo, "event_sign" );
     164           0 :     fd_topob_wksp( topo, "sign_event" );
     165             : 
     166           0 :     fd_topob_tile( topo, "sign",  "sign",  "metric_in", cpu_idx++, 0, 1, 1 );
     167           0 :     fd_topo_tile_t * event_tile = fd_topob_tile( topo, "event", "event", "metric_in", cpu_idx++, 0, 1, 0 );
     168             : 
     169           0 :     ushort shred_version = 0;
     170           0 :     uchar  genesis_hash[ 32 ] = {0};
     171           0 :     if( FD_UNLIKELY( -1==read_genesis_bin( config->paths.genesis, &shred_version, genesis_hash ) ) ) {
     172           0 :       FD_LOG_ERR(( "could not read genesis `%s` for the event tile (%i-%s)",
     173           0 :                        config->paths.genesis, errno, fd_io_strerror( errno ) ));
     174           0 :     }
     175           0 :     fd_memcpy( event_tile->event.genesis_hash, genesis_hash, 32UL );
     176           0 :     event_tile->event.shred_version = shred_version;
     177             : 
     178           0 :     fd_topob_link( topo, "event_sign", "event_sign", 128UL, 317UL, 1UL );
     179           0 :     fd_topob_link( topo, "sign_event", "sign_event", 128UL, 64UL,  1UL );
     180             : 
     181           0 :     fd_topob_tile_in ( topo, "sign",  0UL, "metric_in", "event_sign", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED   );
     182           0 :     fd_topob_tile_out( topo, "event", 0UL,              "event_sign", 0UL                                         );
     183           0 :     fd_topob_tile_in ( topo, "event", 0UL, "metric_in", "sign_event", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_UNPOLLED );
     184           0 :     fd_topob_tile_out( topo, "sign",  0UL,              "sign_event", 0UL                                         );
     185           0 :   }
     186             : 
     187             :   /**********************************************************************/
     188             :   /* Setup backtest->replay link (repair_out) in topo                 */
     189             :   /**********************************************************************/
     190             : 
     191             :   /* The repair tile is replaced by the backtest tile for the repair to
     192             :      replay link.  The frag interface is a "slice", ie. entry batch,
     193             :      which is provided by the backtest tile, which reads in the entry
     194             :      batches from the CLI-specified source (eg. pcap/pcapng file). */
     195             : 
     196           0 :   fd_topob_wksp( topo, "repair_out" );
     197           0 :   fd_topob_link( topo, "repair_out", "repair_out", 65536UL, sizeof(fd_fec_complete_t), 1UL );
     198           0 :   fd_topob_tile_in( topo, "replay", 0UL, "metric_in", "repair_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     199           0 :   fd_topob_tile_out( topo, "backt", 0UL, "repair_out", 0UL );
     200             : 
     201             :   /**********************************************************************/
     202             :   /* Setup snapshot links in topo                                       */
     203             :   /**********************************************************************/
     204           0 :   if( FD_LIKELY( !disable_snap_loader ) ) {
     205           0 :     fd_topob_wksp( topo, "snapct_ld"    );
     206           0 :     fd_topob_wksp( topo, "snapld_dc"    );
     207           0 :     fd_topob_wksp( topo, "snapdc_in"    );
     208             : 
     209           0 :     fd_topob_wksp( topo, "snapin_manif" );
     210           0 :     fd_topob_wksp( topo, "snapct_repr"  );
     211             : 
     212           0 :     fd_topob_wksp( topo, "snapin_ct" );
     213           0 :     fd_topob_wksp( topo, "snapwr_ct" );
     214             : 
     215           0 :     fd_topob_link( topo, "snapct_ld",    "snapct_ld",    128UL,   sizeof(fd_ssctrl_init_t),       1UL );
     216           0 :     fd_topob_link( topo, "snapld_dc",    "snapld_dc",    16384UL, FD_SNAPSHOT_DATA_MTU,           1UL );
     217           0 :     fd_topob_link( topo, "snapdc_in",    "snapdc_in",    16384UL, FD_SNAPSHOT_DATA_MTU,           1UL );
     218             : 
     219           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 */
     220           0 :     fd_topob_link( topo, "snapct_repr",  "snapct_repr",  128UL,   0UL,                            1UL )->permit_no_consumers = 1;
     221             : 
     222           0 :     fd_topob_link( topo, "snapin_ct",    "snapin_ct",    128UL,   0UL,                            1UL );
     223           0 :     fd_topob_link( topo, "snapwr_ct",    "snapwr_ct",    128UL,   0UL,                            1UL );
     224             : 
     225           0 :     fd_topob_tile_in ( topo, "snapct",  0UL, "metric_in", "snapin_ct",    0UL, FD_TOPOB_RELIABLE,   FD_TOPOB_POLLED );
     226           0 :     fd_topob_tile_in ( topo, "snapct",  0UL, "metric_in", "snapwr_ct",    0UL, FD_TOPOB_RELIABLE,   FD_TOPOB_POLLED );
     227           0 :     fd_topob_tile_in ( topo, "snapct",  0UL, "metric_in", "snapld_dc",    0UL, FD_TOPOB_RELIABLE,   FD_TOPOB_POLLED );
     228           0 :     fd_topob_tile_out( topo, "snapct",  0UL,              "snapct_ld",    0UL                                       );
     229           0 :     fd_topob_tile_out( topo, "snapct",  0UL,              "snapct_repr",  0UL                                       );
     230           0 :     fd_topob_tile_in ( topo, "snapld",  0UL, "metric_in", "snapct_ld",    0UL, FD_TOPOB_RELIABLE,   FD_TOPOB_POLLED );
     231           0 :     fd_topob_tile_out( topo, "snapld",  0UL,              "snapld_dc",    0UL                                       );
     232           0 :     fd_topob_tile_in ( topo, "snapdc",  0UL, "metric_in", "snapld_dc",    0UL, FD_TOPOB_RELIABLE,   FD_TOPOB_POLLED );
     233           0 :     fd_topob_tile_out( topo, "snapdc",  0UL,              "snapdc_in",    0UL                                       );
     234           0 :     fd_topob_tile_in ( topo, "snapin",  0UL, "metric_in", "snapdc_in",    0UL, FD_TOPOB_RELIABLE,   FD_TOPOB_POLLED );
     235           0 :     fd_topob_tile_in ( topo, "snapwr",  0UL, "metric_in", "snapdc_in",    0UL, FD_TOPOB_RELIABLE,   FD_TOPOB_POLLED );
     236             : 
     237           0 :     fd_topob_tile_out( topo, "snapin",  0UL,              "snapin_manif", 0UL                                       );
     238           0 :     fd_topob_tile_in ( topo, "replay",  0UL, "metric_in", "snapin_manif", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED   );
     239             : 
     240           0 :     fd_topob_tile_out( topo, "snapin", 0UL,               "snapin_ct",    0UL                                       );
     241           0 :     fd_topob_tile_out( topo, "snapwr", 0UL,               "snapwr_ct",    0UL                                       );
     242           0 :   } else {
     243           0 :     fd_topob_wksp( topo, "genesi_out" );
     244           0 :     fd_topob_link( topo, "genesi_out", "genesi_out", 1UL, FD_GENESIS_TILE_MTU, 0UL );
     245           0 :     fd_topob_tile_out( topo, "genesi", 0UL, "genesi_out", 0UL );
     246           0 :     fd_topob_tile_in ( topo, "replay", 0UL, "metric_in", "genesi_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     247           0 :   }
     248             : 
     249             :   /**********************************************************************/
     250             :   /* More backtest->replay links in topo                                */
     251             :   /**********************************************************************/
     252             : 
     253             :   /* The tower tile is replaced by the backtest tile for the tower to
     254             :      replay link.  The backtest tile simply sends monotonically
     255             :      increasing rooted slot numbers to the replay tile, once after each
     256             :      "replayed a full slot" notification received from the replay tile.
     257             :      This allows the replay tile to advance its watermark, and publish
     258             :      various data structures.  This is an oversimplified barebones mock
     259             :      of the tower tile. */
     260           0 :   fd_topob_wksp( topo, "tower_out" );
     261           0 :   fd_topob_link( topo, "tower_out", "tower_out", 1024UL, sizeof(fd_tower_slot_done_t), 1UL );
     262           0 :   fd_topob_tile_in( topo, "replay", 0UL, "metric_in", "tower_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     263           0 :   fd_topob_tile_out( topo, "backt", 0UL, "tower_out", 0UL );
     264             : 
     265             :   /**********************************************************************/
     266             :   /* Setup replay->stake/send/poh links in topo w/o consumers         */
     267             :   /**********************************************************************/
     268           0 :   fd_topob_wksp( topo, "replay_epoch"    );
     269           0 :   fd_topob_link( topo, "replay_epoch", "replay_epoch", 16UL, FD_EPOCH_OUT_MTU, 1UL );
     270           0 :   fd_topob_tile_out( topo, "replay", 0UL, "replay_epoch",   0UL );
     271           0 :   topo->links[ replay_tile->out_link_id[ fd_topo_find_tile_out_link( topo, replay_tile, "replay_epoch",   0 ) ] ].permit_no_consumers = 1;
     272             : 
     273             :   /**********************************************************************/
     274             :   /* Setup replay->backtest link (replay_notif) in topo                 */
     275             :   /**********************************************************************/
     276             : 
     277           0 :   fd_topob_wksp( topo, "replay_out" );
     278           0 :   fd_topob_link( topo, "replay_out", "replay_out", 8192UL, sizeof( fd_replay_message_t ), 1UL );
     279           0 :   fd_topob_tile_out( topo, "replay", 0UL, "replay_out", 0UL );
     280           0 :   fd_topob_tile_in ( topo, "backt", 0UL, "metric_in", "replay_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     281           0 :   if( FD_LIKELY( !disable_snap_loader ) ) {
     282           0 :     fd_topob_tile_in ( topo, "backt", 0UL, "metric_in", "snapin_manif", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     283           0 :   } else {
     284           0 :     fd_topob_tile_in ( topo, "backt", 0UL, "metric_in", "genesi_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     285           0 :   }
     286             : 
     287             :   /**********************************************************************/
     288             :   /* Setup replay->exec link in topo                                    */
     289             :   /**********************************************************************/
     290           0 :   fd_topob_wksp( topo, "replay_execrp" );
     291           0 :   fd_topob_link( topo, "replay_execrp", "replay_execrp", 16384UL, 2240UL, 1UL );
     292           0 :   fd_topob_tile_out( topo, "replay", 0UL, "replay_execrp", 0UL );
     293           0 :   for( ulong i=0UL; i<execrp_tile_cnt; i++ ) {
     294           0 :     fd_topob_tile_in( topo, "execrp", i, "metric_in", "replay_execrp", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     295           0 :   }
     296             : 
     297             :   /**********************************************************************/
     298             :   /* Setup exec->replay links in topo, to send solcap account updates
     299             :      so that they are serialized, and to notify replay tile that a txn
     300             :      has been finalized by the exec tile. */
     301             :   /**********************************************************************/
     302           0 :   fd_topob_wksp( topo, "execrp_replay" );
     303             : 
     304           0 :   FOR(execrp_tile_cnt) fd_topob_link( topo, "execrp_replay", "execrp_replay", 16384UL, sizeof(fd_execrp_task_done_msg_t), 1UL );
     305             : 
     306           0 :   FOR(execrp_tile_cnt) fd_topob_tile_out( topo, "execrp", i, "execrp_replay", i );
     307           0 :   FOR(execrp_tile_cnt) fd_topob_tile_in( topo, "replay", 0UL, "metric_in", "execrp_replay", i, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     308             : 
     309             :   /**********************************************************************/
     310             :   /* Add the gui tile to topo                                           */
     311             :   /**********************************************************************/
     312             : 
     313             :   /* The gui tile consumes the subset of its usual inputs that exist in
     314             :      the backtest topology (there is no networking, gossip, shred or
     315             :      leader pipeline here).  This is enough for the frontend to show
     316             :      snapshot load and replay progress.  Genesis-mode backtest (no
     317             :      snapshot loader) is not supported: the gui boot-progress sampler
     318             :      requires the snapshot tiles. */
     319           0 :   if( FD_UNLIKELY( config->tiles.gui.enabled && !disable_snap_loader ) ) {
     320           0 :     fd_topob_wksp( topo, "gui" );
     321           0 :     fd_topo_tile_t * gui_tile = fd_topob_tile( topo, "gui", "gui", "metric_in", cpu_idx++, 0, 1, 0 );
     322             : 
     323           0 :     fd_topob_wksp( topo, "snapct_gui" );
     324           0 :     fd_topob_wksp( topo, "snapin_gui" );
     325           0 :     fd_topob_link( topo, "snapct_gui", "snapct_gui", 128UL, sizeof(fd_snapct_update_t),            1UL );
     326           0 :     fd_topob_link( topo, "snapin_gui", "snapin_gui", 128UL, FD_GUI_CONFIG_PARSE_MAX_VALID_ACCT_SZ, 1UL );
     327           0 :     fd_topob_tile_out( topo, "snapct", 0UL, "snapct_gui", 0UL );
     328           0 :     fd_topob_tile_out( topo, "snapin", 0UL, "snapin_gui", 0UL );
     329             : 
     330           0 :     /**/                 fd_topob_tile_in( topo, "gui", 0UL, "metric_in", "tower_out",     0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     331           0 :     /**/                 fd_topob_tile_in( topo, "gui", 0UL, "metric_in", "replay_out",    0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     332           0 :     /**/                 fd_topob_tile_in( topo, "gui", 0UL, "metric_in", "replay_epoch",  0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     333           0 :     FOR(execrp_tile_cnt) fd_topob_tile_in( topo, "gui", 0UL, "metric_in", "execrp_replay", i,   FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     334           0 :     /**/                 fd_topob_tile_in( topo, "gui", 0UL, "metric_in", "snapct_gui",    0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     335           0 :     /**/                 fd_topob_tile_in( topo, "gui", 0UL, "metric_in", "snapin_gui",    0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     336           0 :     /**/                 fd_topob_tile_in( topo, "gui", 0UL, "metric_in", "snapin_manif",  0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     337             : 
     338           0 :     fd_topob_tile_uses( topo, gui_tile, accdb_obj, FD_SHMEM_JOIN_MODE_READ_ONLY );
     339           0 :   }
     340             : 
     341             :   /**********************************************************************/
     342             :   /* Setup the shared objs used by replay and exec tiles                */
     343             :   /**********************************************************************/
     344             : 
     345           0 :   if( FD_UNLIKELY( solcap_enabled ) ) {
     346             :     /* 32 sections of SOLCAP_WRITE_ACCOUNT_DATA_MTU bytes each ≈ 4MB.
     347             :        This is done to ideally avoid cache thrashing and allow for all
     348             :        the links to sit on L3 cache. */
     349           0 :     fd_topob_link( topo, "cap_repl", "solcap", 32UL, SOLCAP_WRITE_ACCOUNT_DATA_MTU, 1UL );
     350           0 :     fd_topob_tile_out( topo, "replay", 0UL, "cap_repl", 0UL );
     351           0 :     fd_topob_tile_in( topo, "solcap", 0UL, "metric_in", "cap_repl", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     352           0 :     FOR(execrp_tile_cnt) fd_topob_link( topo, "cap_execrp", "solcap", 32UL, SOLCAP_WRITE_ACCOUNT_DATA_MTU, 1UL );
     353           0 :     FOR(execrp_tile_cnt) fd_topob_tile_out( topo, "execrp", i, "cap_execrp", i );
     354           0 :     FOR(execrp_tile_cnt) fd_topob_tile_in( topo, "solcap", 0UL, "metric_in", "cap_execrp", i, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     355           0 :   }
     356             : 
     357           0 :   fd_topob_wksp( topo, "store" );
     358           0 :   ulong store_fec_data_max = fd_ulong_if( config->firedancer.development.fixed_fec_sets, 31840UL, 63985UL );
     359           0 :   fd_topo_obj_t * store_obj = setup_topo_store( topo, "store", config->firedancer.runtime.max_live_slots * FD_SHRED_BLK_MAX, 1, store_fec_data_max );
     360           0 :   fd_topob_tile_uses( topo, backt_tile, store_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
     361           0 :   fd_topob_tile_uses( topo, replay_tile, store_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
     362           0 :   FD_TEST( fd_pod_insertf_ulong( topo->props, store_obj->id, "store" ) );
     363             : 
     364           0 :   fd_topob_wksp( topo, "banks" );
     365           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 );
     366           0 :   fd_topob_tile_uses( topo, replay_tile, banks_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
     367           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 );
     368           0 :   FD_TEST( fd_pod_insertf_ulong( topo->props, banks_obj->id, "banks" ) );
     369             : 
     370           0 :   fd_topob_wksp( topo, "txncache"    );
     371           0 :   fd_topo_obj_t * txncache_obj = setup_topo_txncache( topo, "txncache", config->firedancer.runtime.max_live_slots, FD_PACK_MAX_TXNCACHE_TXN_PER_SLOT, config->development.bench.larger_max_cost_per_block );
     372           0 :   fd_topob_tile_uses( topo, replay_tile, txncache_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
     373           0 :   if( FD_LIKELY( !disable_snap_loader ) ) fd_topob_tile_uses( topo, snapin_tile, txncache_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
     374           0 :   for( ulong i=0UL; i<execrp_tile_cnt; i++ ) {
     375           0 :     fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "execrp", i ) ], txncache_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
     376           0 :   }
     377           0 :   FD_TEST( fd_pod_insertf_ulong( topo->props, txncache_obj->id, "txncache" ) );
     378             : 
     379           0 :   if( snapin_tile ) fd_topob_tile_uses( topo, snapin_tile, accdb_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
     380           0 :   fd_topob_tile_uses( topo, accdb_tile,  accdb_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
     381           0 :   fd_topob_tile_uses( topo, replay_tile, accdb_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
     382           0 :   FOR( execrp_tile_cnt ) fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "execrp", i ) ], accdb_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
     383             : 
     384           0 :   for( ulong i=0UL; i<topo->tile_cnt; i++ ) {
     385           0 :     fd_topo_tile_t * tile = &topo->tiles[ i ];
     386           0 :     fd_topo_configure_tile( tile, config );
     387             : 
     388           0 :     if( FD_UNLIKELY( !strcmp( tile->name, "gui" ) ) ) {
     389           0 :       tile->gui.tile_cnt = topo->tile_cnt;
     390             : 
     391           0 :       uchar genesis_hash[ 32 ] = {0};
     392           0 :       if( FD_LIKELY( -1!=read_genesis_bin( config->paths.genesis, NULL, genesis_hash ) ) ) {
     393           0 :         char genesis_hash_b58[ FD_BASE58_ENCODED_32_SZ ];
     394           0 :         fd_base58_encode_32( genesis_hash, NULL, genesis_hash_b58 );
     395           0 :         strcpy( tile->gui.cluster, fd_genesis_cluster_name( fd_genesis_cluster_identify( genesis_hash_b58 ) ) );
     396           0 :       }
     397           0 :     }
     398             : 
     399           0 :     if( !strcmp( tile->name, "replay" ) ) {
     400           0 :       tile->replay.enable_features_cnt = config->tiles.replay.enable_features_cnt;
     401           0 :       for( ulong i = 0; i < tile->replay.enable_features_cnt; i++ ) {
     402           0 :         fd_cstr_ncpy( tile->replay.enable_features[i], config->tiles.replay.enable_features[i], sizeof(tile->replay.enable_features[i]) );
     403           0 :       }
     404           0 :     }
     405           0 :   }
     406             : 
     407           0 :   if( FD_LIKELY( telemetry_enabled ) ) wire_event_links( topo );
     408             : 
     409             :   // fd_topob_auto_layout( topo, 0 );
     410           0 :   fd_topob_finish( topo, CALLBACKS );
     411           0 : }
     412             : 
     413             : static void
     414           0 : backtest_cmd_topo( config_t * config ) {
     415           0 :   backtest_topo( config );
     416           0 : }
     417             : 
     418             : extern configure_stage_t fd_cfg_stage_keys;
     419             : 
     420             : static args_t
     421           0 : configure_args( void ) {
     422           0 :   args_t args = {
     423           0 :     .configure.command = CONFIGURE_CMD_INIT,
     424           0 :   };
     425             : 
     426           0 :   ulong stage_idx = 0UL;
     427           0 :   args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_hugetlbfs;
     428           0 :   args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_snapshots;
     429           0 :   args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_keys;
     430           0 :   args.configure.stages[ stage_idx++ ] = NULL;
     431             : 
     432           0 :   return args;
     433           0 : }
     434             : 
     435             : void
     436             : backtest_cmd_perm( args_t *         args FD_PARAM_UNUSED,
     437             :                    fd_cap_chk_t *   chk,
     438           0 :                    config_t const * config ) {
     439           0 :   args_t c_args = configure_args();
     440           0 :   configure_cmd_perm( &c_args, chk, config );
     441           0 :   run_cmd_perm( NULL, chk, config );
     442           0 : }
     443             : 
     444             : static void
     445           0 : fixup_config( config_t * config ) {
     446             : 
     447             :   /* FIXME Unfortunately, the fdctl boot procedure constructs the
     448             :            topology before parsing command-line arguments.  So, here,
     449             :            we construct the topology again (a third time ... sigh). */
     450           0 :   backtest_topo( config );
     451           0 : }
     452             : 
     453             : static void
     454             : backtest_cmd_fn( args_t *   args,
     455           0 :                  config_t * config ) {
     456           0 :   fixup_config( config );
     457           0 :   args_t c_args = configure_args();
     458           0 :   configure_cmd_fn( &c_args, config );
     459             : 
     460           0 :   initialize_workspaces( config );
     461           0 :   initialize_stacks( config );
     462           0 :   initialize_accdb_fd( config );
     463           0 :   initialize_snapshot_fds( config );
     464             : 
     465           0 :   fd_topo_join_workspaces( &config->topo, FD_SHMEM_JOIN_MODE_READ_WRITE, FD_TOPO_CORE_DUMP_LEVEL_DISABLED );
     466           0 :   fd_topo_fill( &config->topo );
     467             : 
     468           0 :   args_t watch_args;
     469           0 :   int pipefd[2];
     470           0 :   if( !args->backtest.no_watch ) {
     471           0 :     if( FD_UNLIKELY( pipe2( pipefd, O_NONBLOCK ) ) ) FD_LOG_ERR(( "pipe2() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
     472             : 
     473           0 :     watch_args.watch.drain_output_fd = pipefd[0];
     474           0 :     watch_args.watch.full = 1;
     475           0 :     if( FD_UNLIKELY( -1==dup2( pipefd[ 1 ], STDERR_FILENO ) ) ) FD_LOG_ERR(( "dup2() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
     476           0 :     if( FD_UNLIKELY( -1==close( pipefd[1] ) ) ) FD_LOG_ERR(( "close() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
     477           0 :   }
     478             : 
     479           0 :   fd_topo_run_single_process( &config->topo, 2, config->uid, config->gid, fdctl_tile_run );
     480           0 :   if( args->backtest.no_watch ) {
     481           0 :     for(;;) pause();
     482           0 :   } else {
     483           0 :     watch_cmd_fn( &watch_args, config );
     484           0 :   }
     485           0 : }
     486             : 
     487             : action_t fd_action_backtest = {
     488             :   .name        = "backtest",
     489             :   .args        = backtest_cmd_args,
     490             :   .fn          = backtest_cmd_fn,
     491             :   .perm        = backtest_cmd_perm,
     492             :   .topo        = backtest_cmd_topo,
     493             :   .description = "Replay a ledger offline through the replay tile with mocked consensus",
     494             : };

Generated by: LCOV version 1.14