LCOV - code coverage report
Current view: top level - app/firedancer-dev/commands - backtest.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 332 0.0 %
Date: 2026-09-17 04:28:31 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 "../../shared/fd_config_json.h"
      21             : #include "../../../disco/topo/fd_topob.h"
      22             : #include "../../../disco/topo/fd_cpu_topo.h"
      23             : #include "../../../util/pod/fd_pod_format.h"
      24             : #include "../../../disco/gui/fd_gui_config_parse.h"
      25             : #include "../../../disco/diag/fd_diag_tile.h"
      26             : #include "../../../ballet/base58/fd_base58.h"
      27             : #include "../../../disco/genesis/fd_genesis_cluster.h"
      28             : #include "../../../discof/genesis/fd_genesi_tile.h"
      29             : #include "../../../discof/genesis/genesis_hash.h"
      30             : #include "../../../discof/replay/fd_replay_tile.h"
      31             : #include "../../../discof/restore/fd_snapct_tile.h"
      32             : #include "../../../discof/restore/utils/fd_ssctrl.h"
      33             : #include "../../../discof/restore/utils/fd_ssmsg.h"
      34             : #include "../../../discof/tower/fd_tower_tile.h"
      35             : #include "../../../discof/votor/fd_votor_tile.h"
      36             : #include "../../../discof/replay/fd_execrp.h"
      37             : #include "../../../disco/shred/fd_shred_tile.h"
      38             : #include "../../../discof/repair/fd_repair_tile.h"
      39             : #include "../../../flamenco/capture/fd_capture_ctx.h"
      40             : #include "../../../disco/pack/fd_pack_cost.h"
      41             : #include "../../../flamenco/runtime/fd_cost_tracker.h"
      42             : 
      43             : #include <errno.h>
      44             : #include <stdlib.h> /* getenv */
      45             : #include <unistd.h>
      46             : #include <fcntl.h>
      47             : 
      48             : extern fd_topo_obj_callbacks_t * CALLBACKS[];
      49             : fd_topo_run_tile_t fdctl_tile_run( fd_topo_tile_t const * tile );
      50             : 
      51             : void
      52             : backtest_cmd_args( int *    pargc,
      53             :                    char *** pargv,
      54           0 :                    args_t * args ) {
      55           0 :   args->backtest.no_watch = fd_env_strip_cmdline_contains( pargc, pargv, "--no-watch" );
      56           0 : }
      57             : 
      58             : static void
      59           0 : backtest_topo( config_t * config ) {
      60             : 
      61           0 :   config->development.sandbox  = 0;
      62           0 :   config->development.no_clone = 1;
      63             : 
      64           0 :   config->firedancer.layout.resolv_tile_count = 0;
      65             : 
      66           0 :   ulong execrp_tile_cnt = config->firedancer.layout.execrp_tile_count;
      67           0 :   ulong snapdc_tile_cnt = config->firedancer.layout.snapdc_tile_count;
      68             : 
      69           0 :   int disable_snap_loader      = !config->gossip.entrypoints_cnt;
      70           0 :   int solcap_enabled           = strlen( config->capture.solcap_capture )>0;
      71           0 :   int telemetry_enabled        = config->telemetry && strcmp( config->tiles.event.url, "" );
      72             : 
      73           0 :   fd_topo_t * topo = { fd_topob_new( &config->topo, config->name ) };
      74           0 :   topo->max_page_size = fd_cstr_to_shmem_page_sz( config->hugetlbfs.max_page_size );
      75           0 :   topo->gigantic_page_threshold = config->hugetlbfs.gigantic_page_threshold_mib << 20;
      76             : 
      77           0 :   ushort parsed_tile_to_cpu[ FD_TILE_MAX ];
      78             :   /* Unassigned tiles will be floating, unless auto topology is enabled. */
      79           0 :   for( ulong i=0UL; i<FD_TILE_MAX; i++ ) parsed_tile_to_cpu[ i ] = USHORT_MAX;
      80             : 
      81           0 :   int is_auto_affinity = !strcmp( config->layout.affinity, "auto" );
      82             : 
      83           0 :   fd_topo_cpus_t cpus[1];
      84           0 :   fd_topo_cpus_init( cpus );
      85             : 
      86           0 :   ulong affinity_tile_cnt = 0UL;
      87           0 :   if( FD_LIKELY( !is_auto_affinity ) ) affinity_tile_cnt = fd_topob_parse_affinity_cstr( config->layout.affinity, parsed_tile_to_cpu, 1, 1 );
      88             : 
      89           0 :   ulong tile_to_cpu[ FD_TILE_MAX ] = {0};
      90           0 :   for( ulong i=0UL; i<affinity_tile_cnt; i++ ) {
      91           0 :     ushort cpu = (ushort)( parsed_tile_to_cpu[ i ] & ~FD_TOPOB_CPU_SHARED );
      92           0 :     if( FD_UNLIKELY( parsed_tile_to_cpu[ i ]!=USHORT_MAX && cpu>=cpus->cpu_cnt ) )
      93           0 :       FD_LOG_ERR(( "[layout.affinity] specifies CPU %hu but the system only has %lu CPUs", cpu, cpus->cpu_cnt ));
      94           0 :     tile_to_cpu[ i ] = fd_ulong_if( parsed_tile_to_cpu[ i ]==USHORT_MAX, ULONG_MAX, (ulong)parsed_tile_to_cpu[ i ] );
      95           0 :   }
      96             : 
      97           0 :   ulong cpu_idx = 1;
      98           0 : # define NEXT_CPU  ( is_auto_affinity ? cpu_idx++  : tile_to_cpu[ topo->tile_cnt ] )
      99           0 : # define FLOAT_CPU ( is_auto_affinity ? ULONG_MAX  : tile_to_cpu[ topo->tile_cnt ] )
     100             : 
     101           0 :   fd_topob_wksp( topo, "metric" );
     102           0 :   fd_topob_wksp( topo, "metric_in" );
     103           0 :   fd_topob_tile( topo, "metric", "metric", "metric_in", FLOAT_CPU, 0, 0, 0, 1 );
     104             : 
     105           0 :   fd_topob_wksp( topo, "backt" );
     106           0 :   fd_topo_tile_t * backt_tile = fd_topob_tile( topo, "backt", "backt", "metric_in", NEXT_CPU, 0, 0, 0, 0 );
     107             : 
     108           0 :   fd_topob_wksp( topo, "replay" );
     109           0 :   fd_topo_tile_t * replay_tile = fd_topob_tile( topo, "replay", "replay", "metric_in", NEXT_CPU, 0, 1, 0, 0 );
     110             : 
     111           0 :   fd_topo_obj_t * node_info_obj = fd_topob_obj( topo, "node_info", "replay" );
     112           0 :   fd_topob_tile_uses( topo, replay_tile, node_info_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
     113           0 :   FD_TEST( fd_pod_insertf_ulong( topo->props, node_info_obj->id, "node_info" ) );
     114             : 
     115           0 :   fd_topob_wksp( topo, "accdb" )->core_dump_level = FD_TOPO_CORE_DUMP_LEVEL_FULL;
     116           0 :   fd_topo_tile_t * accdb_tile = fd_topob_tile( topo, "accdb", "accdb", "metric_in", NEXT_CPU, 0, 0, 0, 0 );
     117             : 
     118           0 :   fd_topob_wksp( topo, "progcache" );
     119           0 :   setup_topo_progcache( topo, "progcache",
     120           0 :       config->firedancer.runtime.max_live_slots,
     121           0 :       config->firedancer.runtime.program_cache_size_mib<<20 );
     122           0 :   ulong progcache_obj_id; FD_TEST( (progcache_obj_id = fd_pod_query_ulong( topo->props, "progcache", ULONG_MAX ) )!=ULONG_MAX );
     123           0 :   fd_topob_tile_uses( topo, replay_tile, &topo->objs[ progcache_obj_id ], FD_SHMEM_JOIN_MODE_READ_WRITE );
     124           0 :   fd_topob_tile_uses( topo, accdb_tile,  &topo->objs[ progcache_obj_id ], FD_SHMEM_JOIN_MODE_READ_WRITE );
     125             : 
     126           0 :   fd_topob_wksp( topo, "accdb_data" );
     127           0 :   fd_topo_obj_t * accdb_obj = setup_topo_accdb( topo, "accdb_data",
     128           0 :       config->firedancer.accounts.max_accounts,
     129           0 :       config->firedancer.runtime.max_live_slots,
     130           0 :       FD_RUNTIME_MAX_ACC_WRITES_PER_SLOT,
     131           0 :       8192UL,
     132           0 :       1UL<<35UL,
     133           0 :       config->firedancer.accounts.cache_size_gib*(1UL<<30UL),
     134           0 :       config->tiles.bundle.enabled,
     135           0 :       execrp_tile_cnt+3UL,
     136           0 :       0UL );
     137           0 :   FD_TEST( fd_pod_insertf_ulong( topo->props, accdb_obj->id, "accdb" ) );
     138             : 
     139             :   /**********************************************************************/
     140             :   /* Add the executor tiles to topo                                     */
     141             :   /**********************************************************************/
     142           0 :   fd_topob_wksp( topo, "execrp" );
     143           0 :   #define FOR(cnt) for( ulong i=0UL; i<cnt; i++ )
     144           0 :   FOR(execrp_tile_cnt) fd_topob_tile( topo, "execrp", "execrp", "metric_in", NEXT_CPU, 0, 0, 0, 0 );
     145             : 
     146             :   /**********************************************************************/
     147             :   /* Add the capture tile to topo                                       */
     148             :   /**********************************************************************/
     149           0 :   if( solcap_enabled ) {
     150           0 :     fd_topob_wksp( topo, "solcap" );
     151           0 :     fd_topob_tile( topo, "solcap", "solcap", "metric_in", NEXT_CPU, 0, 0, 0, 0 );
     152           0 :   }
     153             : 
     154           0 :   fd_topob_wksp( topo, "diag" );
     155           0 :   fd_topob_tile( topo, "diag", "diag", "metric_in", FLOAT_CPU, 0, 0, 0, 0 );
     156             : 
     157             :   /**********************************************************************/
     158             :   /* Add the snapshot tiles to topo                                       */
     159             :   /**********************************************************************/
     160           0 :   fd_topo_tile_t * snapin_tile = NULL;
     161           0 :   if( FD_UNLIKELY( !disable_snap_loader ) ) {
     162           0 :     fd_topob_wksp( topo, "snapct" );
     163           0 :     fd_topob_wksp( topo, "snapld" );
     164           0 :     fd_topob_wksp( topo, "snapdc" );
     165           0 :     fd_topob_wksp( topo, "snapin" );
     166           0 :     fd_topob_wksp( topo, "snapwr" );
     167             : 
     168           0 :     fd_topo_tile_t * snapct_tile = fd_topob_tile( topo, "snapct",  "snapct",  "metric_in",  NEXT_CPU, 0, 0, 0, 0 );
     169           0 :     fd_topo_tile_t * snapld_tile = fd_topob_tile( topo, "snapld",  "snapld",  "metric_in",  NEXT_CPU, 0, 0, 0, 0 );
     170           0 :     FOR(snapdc_tile_cnt)           fd_topob_tile( topo, "snapdc",  "snapdc",  "metric_in",  NEXT_CPU, 0, 0, 0, 0 )->allow_shutdown = 1;
     171           0 :                      snapin_tile = fd_topob_tile( topo, "snapin",  "snapin",  "metric_in",  NEXT_CPU, 0, 0, 0, 0 );
     172           0 :     fd_topo_tile_t * snapwr_tile = fd_topob_tile( topo, "snapwr",  "snapwr",  "metric_in",  NEXT_CPU, 0, 0, 0, 0 );
     173             : 
     174           0 :     snapct_tile->allow_shutdown = 1;
     175           0 :     snapld_tile->allow_shutdown = 1;
     176           0 :     snapin_tile->allow_shutdown = 1;
     177           0 :     snapwr_tile->allow_shutdown = 1;
     178           0 :   } else {
     179           0 :     fd_topob_wksp( topo, "genesi" );
     180           0 :     fd_topob_tile( topo, "genesi",  "genesi",  "metric_in",  NEXT_CPU, 0, 0, 0, 0 )->allow_shutdown = 1;
     181           0 :   }
     182             : 
     183             :   /**********************************************************************/
     184             :   /* Add the event + sign tiles to topo                                 */
     185             :   /**********************************************************************/
     186           0 :   if( FD_LIKELY( telemetry_enabled ) ) {
     187           0 :     fd_topob_wksp( topo, "sign"       );
     188           0 :     fd_topob_wksp( topo, "event"      );
     189           0 :     fd_topob_wksp( topo, "event_sign" );
     190           0 :     fd_topob_wksp( topo, "sign_event" );
     191             : 
     192           0 :     fd_topob_tile( topo, "sign",  "sign",  "metric_in", NEXT_CPU, 0, 1, 1, 0 );
     193           0 :     fd_topo_tile_t * event_tile = fd_topob_tile( topo, "event", "event", "metric_in", NEXT_CPU, 0, 1, 0, 1 );
     194             : 
     195           0 :     ushort shred_version = 0;
     196           0 :     uchar  genesis_hash[ 32 ] = {0};
     197           0 :     if( FD_UNLIKELY( -1==read_genesis_bin( config->paths.genesis, &shred_version, genesis_hash ) ) ) {
     198           0 :       FD_LOG_ERR(( "could not read genesis `%s` for the event tile (%i-%s)",
     199           0 :                        config->paths.genesis, errno, fd_io_strerror( errno ) ));
     200           0 :     }
     201           0 :     fd_memcpy( event_tile->event.genesis_hash, genesis_hash, 32UL );
     202           0 :     event_tile->event.shred_version = shred_version;
     203             : 
     204           0 :     topo->resolved_config_json_len = fd_config_to_json( config, topo->resolved_config_json, sizeof(topo->resolved_config_json) );
     205           0 :     topo->user_config_json_len     = fd_config_user_toml_to_json( config, topo->user_config_json, sizeof(topo->user_config_json) );
     206             : 
     207           0 :     fd_topob_link( topo, "event_sign", "event_sign", 128UL, 317UL, 1UL );
     208           0 :     fd_topob_link( topo, "sign_event", "sign_event", 128UL, 64UL,  1UL );
     209             : 
     210           0 :     fd_topob_tile_in ( topo, "sign",  0UL, "metric_in", "event_sign", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED   );
     211           0 :     fd_topob_tile_out( topo, "event", 0UL,              "event_sign", 0UL                                         );
     212           0 :     fd_topob_tile_in ( topo, "event", 0UL, "metric_in", "sign_event", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_UNPOLLED );
     213           0 :     fd_topob_tile_out( topo, "sign",  0UL,              "sign_event", 0UL                                         );
     214           0 :   }
     215             : 
     216             :   /**********************************************************************/
     217             :   /* Setup backtest->replay link (repair_out) in topo                 */
     218             :   /**********************************************************************/
     219             : 
     220             :   /* The repair tile is replaced by the backtest tile for the repair to
     221             :      replay link.  The frag interface is a "slice", ie. entry batch,
     222             :      which is provided by the backtest tile, which reads in the entry
     223             :      batches from the CLI-specified source (eg. pcap/pcapng file). */
     224             : 
     225           0 :   fd_topob_wksp( topo, "repair_out" );
     226           0 :   fd_topob_link( topo, "repair_out", "repair_out", 65536UL, sizeof(fd_repair_fec_complete_t), 1UL );
     227           0 :   fd_topob_tile_in( topo, "replay", 0UL, "metric_in", "repair_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     228           0 :   fd_topob_tile_out( topo, "backt", 0UL, "repair_out", 0UL );
     229             : 
     230             :   /**********************************************************************/
     231             :   /* Setup snapshot links in topo                                       */
     232             :   /**********************************************************************/
     233           0 :   if( FD_LIKELY( !disable_snap_loader ) ) {
     234           0 :     fd_topob_wksp( topo, "snapct_ld"    );
     235           0 :     fd_topob_wksp( topo, "snapld_dc"    );
     236           0 :     fd_topob_wksp( topo, "snapdc_in"    );
     237             : 
     238           0 :     fd_topob_wksp( topo, "snapin_manif" );
     239           0 :     fd_topob_wksp( topo, "snapct_repr"  );
     240             : 
     241           0 :     fd_topob_wksp( topo, "snapin_ct" );
     242           0 :     fd_topob_wksp( topo, "snapwr_ct" );
     243             : 
     244           0 :     fd_topob_link( topo, "snapct_ld",    "snapct_ld",    128UL,   sizeof(fd_ssctrl_init_t),       1UL );
     245           0 :     fd_topob_link( topo, "snapld_dc",    "snapld_dc",    FD_SNAPSHOT_DATA_DEPTH, FD_SNAPSHOT_DATA_MTU,           1UL );
     246           0 :     FOR(snapdc_tile_cnt) fd_topob_link( topo, "snapdc_in", "snapdc_in", FD_SNAPSHOT_DATA_DEPTH, FD_SNAPSHOT_DATA_MTU, 1UL );
     247             : 
     248           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 */
     249           0 :     fd_topob_link( topo, "snapct_repr",  "snapct_repr",  128UL,   0UL,                            1UL )->permit_no_consumers = 1;
     250             : 
     251           0 :     fd_topob_link( topo, "snapin_ct",    "snapin_ct",    128UL,   0UL,                            1UL );
     252           0 :     fd_topob_link( topo, "snapwr_ct",    "snapwr_ct",    128UL,   0UL,                            1UL );
     253             : 
     254           0 :     fd_topob_tile_in ( topo, "snapct",  0UL, "metric_in", "snapin_ct",    0UL, FD_TOPOB_RELIABLE,   FD_TOPOB_POLLED );
     255           0 :     fd_topob_tile_in ( topo, "snapct",  0UL, "metric_in", "snapwr_ct",    0UL, FD_TOPOB_RELIABLE,   FD_TOPOB_POLLED );
     256           0 :     fd_topob_tile_in ( topo, "snapct",  0UL, "metric_in", "snapld_dc",    0UL, FD_TOPOB_RELIABLE,   FD_TOPOB_POLLED );
     257           0 :     fd_topob_tile_out( topo, "snapct",  0UL,              "snapct_ld",    0UL                                       );
     258           0 :     fd_topob_tile_out( topo, "snapct",  0UL,              "snapct_repr",  0UL                                       );
     259           0 :     fd_topob_tile_in ( topo, "snapld",  0UL, "metric_in", "snapct_ld",    0UL, FD_TOPOB_RELIABLE,   FD_TOPOB_POLLED );
     260           0 :     fd_topob_tile_out( topo, "snapld",  0UL,              "snapld_dc",    0UL                                       );
     261           0 :     FOR(snapdc_tile_cnt) fd_topob_tile_in ( topo, "snapdc", i,   "metric_in", "snapld_dc", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     262           0 :     FOR(snapdc_tile_cnt) fd_topob_tile_out( topo, "snapdc", i,               "snapdc_in", i                                         );
     263           0 :     FOR(snapdc_tile_cnt) fd_topob_tile_in ( topo, "snapin", 0UL, "metric_in", "snapdc_in", i,   FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     264           0 :     FOR(snapdc_tile_cnt) fd_topob_tile_in ( topo, "snapwr", 0UL, "metric_in", "snapdc_in", i,   FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     265             : 
     266           0 :     fd_topob_tile_out( topo, "snapin",  0UL,              "snapin_manif", 0UL                                       );
     267           0 :     fd_topob_tile_in ( topo, "replay",  0UL, "metric_in", "snapin_manif", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED   );
     268             : 
     269           0 :     fd_topob_tile_out( topo, "snapin", 0UL,               "snapin_ct",    0UL                                       );
     270           0 :     fd_topob_tile_out( topo, "snapwr", 0UL,               "snapwr_ct",    0UL                                       );
     271           0 :   } else {
     272           0 :     fd_topob_wksp( topo, "genesi_out" );
     273           0 :     fd_topob_link( topo, "genesi_out", "genesi_out", 1UL,
     274           0 :                    fd_genesi_tile_mtu( config->firedancer.development.genesis.max_file_size_mib<<20 ), 1UL );
     275           0 :     fd_topob_tile_out( topo, "genesi", 0UL, "genesi_out", 0UL );
     276           0 :     fd_topob_tile_in ( topo, "replay", 0UL, "metric_in", "genesi_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     277           0 :   }
     278             : 
     279             :   /**********************************************************************/
     280             :   /* More backtest->replay links in topo                                */
     281             :   /**********************************************************************/
     282             : 
     283             :   /* The tower tile is replaced by the backtest tile for the tower to
     284             :      replay link.  The backtest tile simply sends monotonically
     285             :      increasing rooted slot numbers to the replay tile, once after each
     286             :      "replayed a full slot" notification received from the replay tile.
     287             :      This allows the replay tile to advance its watermark, and publish
     288             :      various data structures.  This is an oversimplified barebones mock
     289             :      of the tower tile. */
     290           0 :   fd_topob_wksp( topo, "tower_out" );
     291           0 :   fd_topob_link( topo, "tower_out", "tower_out", 1024UL, sizeof(fd_tower_slot_done_t), 1UL );
     292           0 :   fd_topob_tile_in( topo, "replay", 0UL, "metric_in", "tower_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     293           0 :   fd_topob_tile_out( topo, "backt", 0UL, "tower_out", 0UL );
     294             : 
     295           0 :   if( FD_UNLIKELY( config->firedancer.development.alpenglow ) ) {
     296           0 :     fd_topob_wksp( topo, "votor_out" );
     297           0 :     fd_topob_link( topo, "votor_out", "votor_out", 1024UL, sizeof(fd_votor_msg_t), 2UL );
     298           0 :     fd_topob_tile_in( topo, "replay", 0UL, "metric_in", "votor_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     299           0 :     fd_topob_tile_out( topo, "backt", 0UL, "votor_out", 0UL );
     300           0 :   }
     301             : 
     302             :   /**********************************************************************/
     303             :   /* Setup replay->stake/send/poh links in topo w/o consumers         */
     304             :   /**********************************************************************/
     305           0 :   fd_topob_wksp( topo, "replay_epoch"    );
     306           0 :   fd_topob_link( topo, "replay_epoch", "replay_epoch", 16UL, FD_EPOCH_OUT_MTU, 1UL );
     307           0 :   fd_topob_tile_out( topo, "replay", 0UL, "replay_epoch",   0UL );
     308           0 :   topo->links[ replay_tile->out_link_id[ fd_topo_find_tile_out_link( topo, replay_tile, "replay_epoch",   0 ) ] ].permit_no_consumers = 1;
     309             : 
     310             :   /**********************************************************************/
     311             :   /* Setup replay->backtest link (replay_notif) in topo                 */
     312             :   /**********************************************************************/
     313             : 
     314           0 :   fd_topob_wksp( topo, "replay_out" );
     315           0 :   fd_topob_link( topo, "replay_out", "replay_out", 8192UL, sizeof( fd_replay_message_t ), 1UL );
     316           0 :   fd_topob_tile_out( topo, "replay", 0UL, "replay_out", 0UL );
     317           0 :   fd_topob_tile_in ( topo, "backt", 0UL, "metric_in", "replay_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     318           0 :   if( FD_LIKELY( !disable_snap_loader ) ) {
     319           0 :     fd_topob_tile_in ( topo, "backt", 0UL, "metric_in", "snapin_manif", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     320           0 :   } else {
     321           0 :     fd_topob_tile_in ( topo, "backt", 0UL, "metric_in", "genesi_out", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     322           0 :   }
     323             : 
     324             :   /**********************************************************************/
     325             :   /* Setup replay->exec link in topo                                    */
     326             :   /**********************************************************************/
     327           0 :   fd_topob_wksp( topo, "replay_execrp" );
     328           0 :   fd_topob_link( topo, "replay_execrp", "replay_execrp", 16384UL, sizeof(fd_execrp_task_msg_t), 1UL );
     329           0 :   fd_topob_tile_out( topo, "replay", 0UL, "replay_execrp", 0UL );
     330           0 :   for( ulong i=0UL; i<execrp_tile_cnt; i++ ) {
     331           0 :     fd_topob_tile_in( topo, "execrp", i, "metric_in", "replay_execrp", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     332           0 :   }
     333             : 
     334             :   /**********************************************************************/
     335             :   /* Setup exec->replay links in topo, to send solcap account updates
     336             :      so that they are serialized, and to notify replay tile that a txn
     337             :      has been finalized by the exec tile. */
     338             :   /**********************************************************************/
     339           0 :   fd_topob_wksp( topo, "execrp_replay" );
     340             : 
     341           0 :   FOR(execrp_tile_cnt) fd_topob_link( topo, "execrp_replay", "execrp_replay", 16384UL, sizeof(fd_execrp_task_done_msg_t), 1UL );
     342             : 
     343           0 :   FOR(execrp_tile_cnt) fd_topob_tile_out( topo, "execrp", i, "execrp_replay", i );
     344           0 :   FOR(execrp_tile_cnt) fd_topob_tile_in( topo, "replay", 0UL, "metric_in", "execrp_replay", i, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     345             : 
     346             :   /**********************************************************************/
     347             :   /* Add the gui tile to topo                                           */
     348             :   /**********************************************************************/
     349             : 
     350             :   /* The gui tile consumes the subset of its usual inputs that exist in
     351             :      the backtest topology (there is no networking, gossip, shred or
     352             :      leader pipeline here).  This is enough for the frontend to show
     353             :      snapshot load and replay progress.  Genesis-mode backtest (no
     354             :      snapshot loader) is not supported: the gui boot-progress sampler
     355             :      requires the snapshot tiles. */
     356           0 :   if( FD_UNLIKELY( config->tiles.gui.enabled && !disable_snap_loader ) ) {
     357           0 :     fd_topob_wksp( topo, "gui" );
     358           0 :     fd_topo_tile_t * gui_tile = fd_topob_tile( topo, "gui", "gui", "metric_in", NEXT_CPU, 0, 1, 0, 1 );
     359             : 
     360           0 :     fd_topob_wksp( topo, "diag_gui" );
     361           0 :     fd_topob_link( topo, "diag_gui", "diag_gui", 4UL, sizeof(fd_diag_system_resources_t), 1UL );
     362           0 :     fd_topob_tile_out( topo, "diag", 0UL, "diag_gui", 0UL );
     363           0 :     fd_topob_tile_in( topo, "gui", 0UL, "metric_in", "diag_gui", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
     364             : 
     365           0 :     fd_topob_wksp( topo, "snapct_gui" );
     366           0 :     fd_topob_wksp( topo, "snapin_gui" );
     367           0 :     fd_topob_link( topo, "snapct_gui", "snapct_gui", 128UL, sizeof(fd_snapct_update_t),            1UL );
     368           0 :     fd_topob_link( topo, "snapin_gui", "snapin_gui", 128UL, FD_GUI_CONFIG_PARSE_MAX_VALID_ACCT_SZ, 1UL );
     369           0 :     fd_topob_tile_out( topo, "snapct", 0UL, "snapct_gui", 0UL );
     370           0 :     fd_topob_tile_out( topo, "snapin", 0UL, "snapin_gui", 0UL );
     371             : 
     372           0 :     /**/                 fd_topob_tile_in( topo, "gui", 0UL, "metric_in", "tower_out",     0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     373           0 :     /**/                 fd_topob_tile_in( topo, "gui", 0UL, "metric_in", "replay_out",    0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     374           0 :     /**/                 fd_topob_tile_in( topo, "gui", 0UL, "metric_in", "replay_epoch",  0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     375           0 :     FOR(execrp_tile_cnt) fd_topob_tile_in( topo, "gui", 0UL, "metric_in", "execrp_replay", i,   FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     376           0 :     /**/                 fd_topob_tile_in( topo, "gui", 0UL, "metric_in", "snapct_gui",    0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     377           0 :     /**/                 fd_topob_tile_in( topo, "gui", 0UL, "metric_in", "snapin_gui",    0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     378           0 :     /**/                 fd_topob_tile_in( topo, "gui", 0UL, "metric_in", "snapin_manif",  0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     379             : 
     380           0 :     fd_topob_tile_uses( topo, gui_tile, accdb_obj, FD_SHMEM_JOIN_MODE_READ_ONLY );
     381           0 :   }
     382             : 
     383             :   /**********************************************************************/
     384             :   /* Setup the shared objs used by replay and exec tiles                */
     385             :   /**********************************************************************/
     386             : 
     387           0 :   if( FD_UNLIKELY( solcap_enabled ) ) {
     388             :     /* 32 sections of SOLCAP_WRITE_ACCOUNT_DATA_MTU bytes each ≈ 4MB.
     389             :        This is done to ideally avoid cache thrashing and allow for all
     390             :        the links to sit on L3 cache. */
     391           0 :     fd_topob_link( topo, "cap_repl", "solcap", 32UL, SOLCAP_WRITE_ACCOUNT_DATA_MTU, 1UL );
     392           0 :     fd_topob_tile_out( topo, "replay", 0UL, "cap_repl", 0UL );
     393           0 :     fd_topob_tile_in( topo, "solcap", 0UL, "metric_in", "cap_repl", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     394           0 :     FOR(execrp_tile_cnt) fd_topob_link( topo, "cap_execrp", "solcap", 32UL, SOLCAP_WRITE_ACCOUNT_DATA_MTU, 1UL );
     395           0 :     FOR(execrp_tile_cnt) fd_topob_tile_out( topo, "execrp", i, "cap_execrp", i );
     396           0 :     FOR(execrp_tile_cnt) fd_topob_tile_in( topo, "solcap", 0UL, "metric_in", "cap_execrp", i, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
     397           0 :   }
     398             : 
     399           0 :   fd_topob_wksp( topo, "store" );
     400           0 :   fd_topo_link_t const * repair_out_link = &topo->links[ fd_topo_find_link( topo, "repair_out", 0UL ) ];
     401           0 :   ulong fec_sets_per_slot = fd_ulong_if( config->firedancer.development.fixed_fec_sets,
     402           0 :                                          config->limits.max_shreds_per_block/FD_FEC_SHRED_CNT, config->limits.max_shreds_per_block );
     403           0 :   ulong store_fec_max = config->firedancer.runtime.max_live_slots * fec_sets_per_slot + repair_out_link->depth + 1UL;
     404           0 :   ulong store_fec_data_max = fd_ulong_if( config->firedancer.development.fixed_fec_sets, 31840UL, 63985UL );
     405           0 :   fd_topo_obj_t * store_obj = setup_topo_store( topo, "store", store_fec_max, store_fec_data_max, 0UL, config->tiles.shred.shred_cache_size_mib, 0UL, config->limits.max_shreds_per_block, config->paths.shredb );
     406           0 :   fd_topob_tile_uses( topo, backt_tile, store_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
     407           0 :   fd_topob_tile_uses( topo, replay_tile, store_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
     408           0 :   FD_TEST( fd_pod_insertf_ulong( topo->props, store_obj->id, "store" ) );
     409             : 
     410           0 :   fd_topob_wksp( topo, "banks" );
     411           0 :   fd_topo_obj_t * banks_obj = setup_topo_banks( topo, "banks", config->firedancer.runtime.max_live_slots, config->firedancer.runtime.max_fork_width, config->development.bench.max_cost_per_block );
     412           0 :   fd_topob_tile_uses( topo, replay_tile, banks_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
     413           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 );
     414           0 :   FD_TEST( fd_pod_insertf_ulong( topo->props, banks_obj->id, "banks" ) );
     415             : 
     416           0 :   fd_topob_wksp( topo, "txncache"    );
     417           0 :   fd_topo_obj_t * txncache_obj = setup_topo_txncache( topo, "txncache", config->firedancer.runtime.max_live_slots, 2UL*config->limits.max_txn_per_slot );
     418           0 :   fd_topob_tile_uses( topo, replay_tile, txncache_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
     419           0 :   if( FD_LIKELY( !disable_snap_loader ) ) fd_topob_tile_uses( topo, snapin_tile, txncache_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
     420           0 :   for( ulong i=0UL; i<execrp_tile_cnt; i++ ) {
     421           0 :     fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "execrp", i ) ], txncache_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
     422           0 :   }
     423           0 :   FD_TEST( fd_pod_insertf_ulong( topo->props, txncache_obj->id, "txncache" ) );
     424             : 
     425           0 :   if( snapin_tile ) fd_topob_tile_uses( topo, snapin_tile, accdb_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
     426           0 :   fd_topob_tile_uses( topo, accdb_tile,  accdb_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
     427           0 :   fd_topob_tile_uses( topo, replay_tile, accdb_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
     428           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 );
     429             : 
     430           0 :   for( ulong i=0UL; i<topo->tile_cnt; i++ ) {
     431           0 :     fd_topo_tile_t * tile = &topo->tiles[ i ];
     432           0 :     fd_topo_configure_tile( tile, config );
     433             : 
     434           0 :     if( FD_UNLIKELY( !strcmp( tile->name, "gui" ) ) ) {
     435           0 :       tile->gui.tile_cnt = topo->tile_cnt;
     436             : 
     437           0 :       uchar genesis_hash[ 32 ] = {0};
     438           0 :       if( FD_LIKELY( -1!=read_genesis_bin( config->paths.genesis, NULL, genesis_hash ) ) ) {
     439           0 :         char genesis_hash_b58[ FD_BASE58_ENCODED_32_SZ ];
     440           0 :         fd_base58_encode_32( genesis_hash, NULL, genesis_hash_b58 );
     441           0 :         strcpy( tile->gui.cluster, fd_genesis_cluster_name( fd_genesis_cluster_identify( genesis_hash_b58 ) ) );
     442           0 :       }
     443           0 :     }
     444             : 
     445           0 :     if( !strcmp( tile->name, "replay" ) ) {
     446           0 :       tile->replay.fec_max = config->firedancer.runtime.max_live_slots * fec_sets_per_slot;
     447           0 :       tile->replay.enable_features_cnt = config->tiles.replay.enable_features_cnt;
     448           0 :       for( ulong i = 0; i < tile->replay.enable_features_cnt; i++ ) {
     449           0 :         fd_cstr_ncpy( tile->replay.enable_features[i], config->tiles.replay.enable_features[i], sizeof(tile->replay.enable_features[i]) );
     450           0 :       }
     451           0 :     }
     452           0 :   }
     453             : 
     454           0 :   if( FD_LIKELY( telemetry_enabled ) ) wire_event_links( topo );
     455             : 
     456             :   // fd_topob_auto_layout( topo, 0 );
     457           0 :   if( FD_UNLIKELY( !is_auto_affinity ) ) {
     458           0 :     if( FD_UNLIKELY( affinity_tile_cnt<topo->tile_cnt ) )
     459           0 :       FD_LOG_ERR(( "topology has %lu tiles but [layout.affinity] only provides %lu entries", topo->tile_cnt, affinity_tile_cnt ));
     460           0 :     if( FD_UNLIKELY( affinity_tile_cnt>topo->tile_cnt ) )
     461           0 :       FD_LOG_WARNING(( "topology has %lu tiles but [layout.affinity] provides %lu entries, extra entries will be unused", topo->tile_cnt, affinity_tile_cnt ));
     462           0 :   }
     463             : 
     464           0 :   fd_topob_waker( topo );
     465             : 
     466           0 :   fd_topob_finish( topo, CALLBACKS );
     467           0 : }
     468             : 
     469             : static void
     470           0 : backtest_cmd_topo( config_t * config ) {
     471           0 :   backtest_topo( config );
     472           0 : }
     473             : 
     474             : extern configure_stage_t fd_cfg_stage_keys;
     475             : 
     476             : static args_t
     477           0 : configure_args( void ) {
     478           0 :   args_t args = {
     479           0 :     .configure.command = CONFIGURE_CMD_INIT,
     480           0 :   };
     481             : 
     482             :   /* FD_BACKTEST_SHARED_HOST skips the host-global stages (irq-affinity,
     483             :      kworkers) so multiple backtest instances can share a host. */
     484           0 :   int shared_host = !!getenv( "FD_BACKTEST_SHARED_HOST" );
     485             : 
     486           0 :   ulong stage_idx = 0UL;
     487           0 :   args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_hugetlbfs;
     488           0 :   if( FD_LIKELY( !shared_host ) ) {
     489           0 :     args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_irq_affinity;
     490           0 :     args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_kworkers;
     491           0 :   }
     492           0 :   args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_cpuset;
     493           0 :   args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_snapshots;
     494           0 :   args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_keys;
     495           0 :   args.configure.stages[ stage_idx++ ] = NULL;
     496             : 
     497           0 :   return args;
     498           0 : }
     499             : 
     500             : void
     501             : backtest_cmd_perm( args_t *         args FD_PARAM_UNUSED,
     502             :                    fd_cap_chk_t *   chk,
     503           0 :                    config_t const * config ) {
     504           0 :   args_t c_args = configure_args();
     505           0 :   configure_cmd_perm( &c_args, chk, config );
     506           0 :   run_cmd_perm( NULL, chk, config );
     507           0 : }
     508             : 
     509             : static void
     510           0 : fixup_config( config_t * config ) {
     511             : 
     512             :   /* FIXME Unfortunately, the fdctl boot procedure constructs the
     513             :            topology before parsing command-line arguments.  So, here,
     514             :            we construct the topology again (a third time ... sigh). */
     515           0 :   backtest_topo( config );
     516           0 : }
     517             : 
     518             : static void
     519             : backtest_cmd_fn( args_t *   args,
     520           0 :                  config_t * config ) {
     521           0 :   fixup_config( config );
     522           0 :   args_t c_args = configure_args();
     523           0 :   configure_cmd_fn( &c_args, config );
     524             : 
     525           0 :   initialize_workspaces( config );
     526           0 :   initialize_stacks( config );
     527           0 :   initialize_accdb_fd( config );
     528           0 :   initialize_store_fds( config );
     529           0 :   initialize_snapshot_fds( config );
     530             : 
     531           0 :   fd_topo_join_workspaces( &config->topo, FD_SHMEM_JOIN_MODE_READ_WRITE, FD_TOPO_CORE_DUMP_LEVEL_DISABLED );
     532           0 :   fd_topo_fill( &config->topo );
     533             : 
     534           0 :   args_t watch_args;
     535           0 :   int pipefd[2];
     536           0 :   if( !args->backtest.no_watch ) {
     537           0 :     if( FD_UNLIKELY( pipe2( pipefd, O_NONBLOCK ) ) ) FD_LOG_ERR(( "pipe2() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
     538             : 
     539           0 :     watch_args.watch.drain_output_fd = pipefd[0];
     540           0 :     watch_args.watch.full = 1;
     541           0 :     if( FD_UNLIKELY( -1==dup2( pipefd[ 1 ], STDERR_FILENO ) ) ) FD_LOG_ERR(( "dup2() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
     542           0 :     if( FD_UNLIKELY( -1==close( pipefd[1] ) ) ) FD_LOG_ERR(( "close() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
     543           0 :   }
     544             : 
     545           0 :   fd_topo_run_single_process( &config->topo, 2, config->uid, config->gid, fdctl_tile_run );
     546           0 :   if( args->backtest.no_watch ) {
     547           0 :     for(;;) pause();
     548           0 :   } else {
     549           0 :     watch_cmd_fn( &watch_args, config );
     550           0 :   }
     551           0 : }
     552             : 
     553             : action_t fd_action_backtest = {
     554             :   .name        = "backtest",
     555             :   .args        = backtest_cmd_args,
     556             :   .fn          = backtest_cmd_fn,
     557             :   .perm        = backtest_cmd_perm,
     558             :   .topo        = backtest_cmd_topo,
     559             :   .description = "Replay a ledger offline through the replay tile with mocked consensus",
     560             : };

Generated by: LCOV version 1.14