LCOV - code coverage report
Current view: top level - app/firedancer-dev/commands - tower.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 106 0.0 %
Date: 2026-03-31 06:22:16 Functions: 0 8 0.0 %

          Line data    Source code
       1             : /* The tower command prints the tower forks tree structure and leaves.
       2             :    This is a standalone application that can be run to inspect the tower
       3             :    tile's fork structure. */
       4             : 
       5             : #include "../../shared/fd_config.h" /* config_t */
       6             : #include "../../shared_dev/commands/dev.h"
       7             : #include "../../../discof/tower/fd_tower_tile.c"
       8             : #include "../../../choreo/tower/fd_tower_blocks.h"
       9             : 
      10             : #include <stdio.h>
      11             : #include <unistd.h>
      12             : 
      13             : fd_topo_run_tile_t
      14             : fdctl_tile_run( fd_topo_tile_t const * tile );
      15             : 
      16             : /* fd_tower_tile_t is defined in fd_tower_tile.c, we just need to access it */
      17             : 
      18             : static void
      19             : tower_ctx_wksp( args_t *           args,
      20             :                 config_t *         config,
      21             :                 fd_tower_tile_t ** tower_ctx,
      22           0 :                 fd_topo_wksp_t **  tower_wksp ) {
      23           0 :   (void)args;
      24             : 
      25           0 :   fd_topo_t * topo = &config->topo;
      26             : 
      27           0 :   ulong tile_id = fd_topo_find_tile( topo, "tower", 0UL );
      28           0 :   if( FD_UNLIKELY( tile_id==ULONG_MAX ) ) FD_LOG_ERR(( "tower tile not found" ));
      29             : 
      30           0 :   fd_topo_tile_t * tile = &topo->tiles[ tile_id ];
      31             : 
      32             :   /* Get the workspace that contains the tile's scratch memory */
      33           0 :   ulong scratch_wksp_id = topo->objs[ tile->tile_obj_id ].wksp_id;
      34           0 :   if( FD_UNLIKELY( scratch_wksp_id>=topo->wksp_cnt ) ) FD_LOG_ERR(( "invalid workspace id %lu for tile scratch", scratch_wksp_id ));
      35             : 
      36           0 :   fd_topo_wksp_t * _tower_wksp = &topo->workspaces[ scratch_wksp_id ];
      37           0 :   fd_topo_join_workspace( topo, _tower_wksp, FD_SHMEM_JOIN_MODE_READ_ONLY, FD_TOPO_CORE_DUMP_LEVEL_DISABLED );
      38             : 
      39             :   /* Access the tower tile scratch memory where tower_tile_ctx is stored */
      40           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
      41           0 :   if( FD_UNLIKELY( !scratch ) ) FD_LOG_ERR(( "Failed to access tower tile scratch memory" ));
      42             : 
      43           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
      44           0 :   fd_tower_tile_t * _tower_ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_tower_tile_t), sizeof(fd_tower_tile_t) );
      45             : 
      46           0 :   *tower_ctx  = _tower_ctx;
      47           0 :   *tower_wksp = _tower_wksp;
      48           0 : }
      49             : 
      50             : static void
      51           0 : print_all_forks( fd_wksp_t * wksp, fd_tower_tile_t * tower_ctx, fd_tower_blocks_t * forks ) {
      52           0 :   printf( "\n[Tower Forks]\n" );
      53           0 :   printf( "=============\n" );
      54           0 :   printf( "%-15s | %-15s | %-10s | %-10s\n", "Slot", "Parent Slot", "Voted", "Confirmed" );
      55           0 :   printf( "%-15s-+-%-15s-+-%-10s-+-%-10s\n", "---------------", "---------------", "----------", "----------" );
      56             : 
      57             :   /* Iterate through all map slots */
      58           0 :   ulong tower_forks_gaddr = fd_wksp_gaddr_fast( tower_ctx->wksp, forks->blk_map );
      59           0 :   fd_tower_blk_t * map = (fd_tower_blk_t *)fd_wksp_laddr_fast( wksp, tower_forks_gaddr );
      60           0 :   ulong slot_count = 0;
      61             : 
      62           0 :   for( ulong slot_idx = 0UL; slot_idx < fd_tower_blk_slot_cnt( map ); slot_idx++ ) {
      63           0 :     fd_tower_blk_t * fork = &map[ slot_idx ];
      64             :     /* Check if key is valid (not MAP_KEY_NULL which is ULONG_MAX) */
      65           0 :     if( !fd_tower_blk_key_inval( fork->slot ) ) {
      66           0 :       printf( "%-15lu | ", fork->slot );
      67           0 :       if( fork->parent_slot == ULONG_MAX ) {
      68           0 :         printf( "%-15s | ", "NULL" );
      69           0 :       } else {
      70           0 :         printf( "%-15lu | ", fork->parent_slot );
      71           0 :       }
      72           0 :       printf( "%-10s | ", fork->voted ? "Yes" : "No" );
      73           0 :       printf( "%-10s\n", fork->confirmed ? "Yes" : "No" );
      74           0 :       slot_count++;
      75           0 :     }
      76           0 :   }
      77             : 
      78           0 :   printf( "Total slots: %lu\n", slot_count );
      79           0 :   printf( "\n" );
      80           0 : }
      81             : 
      82             : static const char * HELP =
      83             :   "\n\n"
      84             :   "usage: tower [-h] {forks}\n"
      85             :   "\n"
      86             :   "positional arguments:\n"
      87             :   "  {forks}\n"
      88             :   "    forks              prints the tower forks tree structure and leaves\n"
      89             :   "    ghost              prints the ghost fork choice structure\n"
      90             :   "    tower              prints the local tower\n"
      91             :   "\n"
      92             :   "optional arguments:\n"
      93             :   "  -h, --help            show this help message and exit\n";
      94             : 
      95             : static const char * FORKS_HELP =
      96             :   "\n\n"
      97             :   "usage: tower forks [-h]\n"
      98             :   "\n"
      99             :   "optional arguments:\n"
     100             :   "  -h, --help            show this help message and exit\n";
     101             : 
     102             : static const char * GHOST_HELP =
     103             :   "\n\n"
     104             :   "usage: tower ghost [-h]\n"
     105             :   "\n"
     106             :   "optional arguments:\n"
     107             :   "  -h, --help            show this help message and exit\n";
     108             : 
     109             : static const char * TOWER_HELP =
     110             :   "\n\n"
     111             :   "usage: tower tower [-h]\n"
     112             :   "\n"
     113             :   "optional arguments:\n"
     114             :   "  -h, --help            show this help message and exit\n";
     115             : 
     116             : void
     117           0 : tower_cmd_help( char const * arg ) {
     118           0 :   if      ( FD_LIKELY( !arg                    ) ) FD_LOG_NOTICE(( "%s", HELP       ));
     119           0 :   else if ( FD_LIKELY( !strcmp( arg, "forks" ) ) ) FD_LOG_NOTICE(( "%s", FORKS_HELP ));
     120           0 :   else if ( FD_LIKELY( !strcmp( arg, "ghost" ) ) ) FD_LOG_NOTICE(( "%s", GHOST_HELP ));
     121           0 :   else if ( FD_LIKELY( !strcmp( arg, "tower" ) ) ) FD_LOG_NOTICE(( "%s", TOWER_HELP ));
     122           0 :   else                                             FD_LOG_NOTICE(( "%s", HELP       ));
     123           0 : }
     124             : 
     125             : static void
     126             : tower_cmd_fn_forks( args_t *   args,
     127           0 :                     config_t * config ) {
     128           0 :   fd_tower_tile_t *          tower_ctx;
     129           0 :   fd_topo_wksp_t * tower_wksp;
     130           0 :   tower_ctx_wksp( args, config, &tower_ctx, &tower_wksp );
     131             : 
     132           0 :   ulong forks_gaddr = fd_wksp_gaddr_fast( tower_ctx->wksp, tower_ctx->tower_blocks );
     133           0 :   fd_tower_blocks_t * forks = (fd_tower_blocks_t *)fd_wksp_laddr( tower_wksp->wksp, forks_gaddr );
     134             : 
     135           0 :   for( ;; ) {
     136           0 :     print_all_forks( tower_wksp->wksp, tower_ctx, forks );
     137           0 :     sleep( 1 );
     138           0 :   }
     139           0 : }
     140             : 
     141             : static void
     142             : tower_cmd_fn_ghost( args_t *   args,
     143           0 :                     config_t * config ) {
     144           0 :   fd_tower_tile_t *          tower_ctx;
     145           0 :   fd_topo_wksp_t * tower_wksp;
     146           0 :   tower_ctx_wksp( args, config, &tower_ctx, &tower_wksp );
     147             : 
     148           0 :   ulong ghost_gaddr = fd_wksp_gaddr_fast( tower_ctx->wksp, tower_ctx->ghost );
     149           0 :   fd_ghost_t * ghost = (fd_ghost_t *)fd_wksp_laddr( tower_wksp->wksp, ghost_gaddr );
     150           0 :   fd_ghost_root( ghost );
     151           0 :   FD_LOG_NOTICE(( "root slot %lu", fd_ghost_root( ghost )->slot ));
     152             : 
     153           0 :   for( ;; ) {
     154           0 :     char cstr[4096]; cstr[4095] = '\0'; ulong sz;
     155           0 :     FD_LOG_NOTICE(( "\n\n%s", fd_ghost_to_cstr( ghost, fd_ghost_root( ghost ), cstr, sizeof(cstr), &sz ) ));
     156           0 :     sleep( 1 );
     157           0 :   }
     158           0 : }
     159             : 
     160             : static void
     161             : tower_cmd_fn_tower( args_t    * args,
     162           0 :                      config_t * config ) {
     163           0 :   fd_tower_tile_t *          tower_ctx;
     164           0 :   fd_topo_wksp_t * tower_wksp;
     165           0 :   tower_ctx_wksp( args, config, &tower_ctx, &tower_wksp );
     166             : 
     167           0 :   ulong tower_laddr = fd_wksp_gaddr_fast( tower_ctx->wksp, tower_ctx->tower );
     168           0 :   fd_tower_t * tower = (fd_tower_t *)fd_wksp_laddr( tower_wksp->wksp, tower_laddr );
     169             : 
     170           0 :   for( ;; ) {
     171           0 :     char cstr[4096]; cstr[4095] = '\0';
     172           0 :     FD_LOG_DEBUG(( "\n\n%s", fd_tower_to_cstr( tower, tower_ctx->root_slot, cstr ) ));
     173           0 :     sleep( 1 );
     174           0 :   }
     175           0 : }
     176             : 
     177             : void
     178             : tower_cmd_args( int *    pargc,
     179             :                 char *** pargv,
     180           0 :                 args_t * args ) {
     181             : 
     182             :   /* help */
     183           0 :   args->tower.help = fd_env_strip_cmdline_contains( pargc, pargv, "--help" );
     184           0 :   args->tower.help = args->tower.help || fd_env_strip_cmdline_contains( pargc, pargv, "-h" );
     185             : 
     186             :   /* positional arg */
     187           0 :   args->tower.pos_arg = (*pargv)[0];
     188           0 :   if( FD_UNLIKELY( !args->tower.pos_arg ) ) {
     189           0 :     args->tower.help = 1;
     190           0 :     return;
     191           0 :   }
     192             : 
     193           0 :   (*pargc)--;
     194           0 : }
     195             : 
     196             : static void
     197             : tower_cmd_fn( args_t *   args,
     198           0 :               config_t * config ) {
     199             : 
     200           0 :   if( args->tower.help ) {
     201           0 :     tower_cmd_help( args->tower.pos_arg );
     202           0 :     return;
     203           0 :   }
     204             : 
     205           0 :   if     ( !strcmp( args->tower.pos_arg, "forks" ) ) tower_cmd_fn_forks( args, config );
     206           0 :   else if( !strcmp( args->tower.pos_arg, "ghost" ) ) tower_cmd_fn_ghost( args, config );
     207           0 :   else if( !strcmp( args->tower.pos_arg, "tower" ) ) tower_cmd_fn_tower( args, config );
     208           0 :   else                                               tower_cmd_help( NULL );
     209           0 : }
     210             : 
     211             : action_t fd_action_tower = {
     212             :   .name = "tower",
     213             :   .args = tower_cmd_args,
     214             :   .fn   = tower_cmd_fn,
     215             :   .perm = dev_cmd_perm,
     216             : };

Generated by: LCOV version 1.14