LCOV - code coverage report
Current view: top level - discof/restore - fd_snapwr_tile.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 292 0.0 %
Date: 2026-06-29 05:51:35 Functions: 0 18 0.0 %

          Line data    Source code
       1             : #define _GNU_SOURCE
       2             : #include "utils/fd_ssctrl.h"
       3             : #include "utils/fd_ssparse.h"
       4             : #include "utils/fd_ssmanifest_parser.h"
       5             : 
       6             : #include "../../disco/topo/fd_topo.h"
       7             : #include "../../disco/metrics/fd_metrics.h"
       8             : 
       9             : #include "generated/fd_snapwr_tile_seccomp.h"
      10             : 
      11             : #include <errno.h>
      12             : #include <fcntl.h>
      13             : #include <unistd.h>
      14             : 
      15             : #define NAME "snapwr"
      16             : 
      17           0 : #define FD_SNAPWR_WRITE_BUF_SZ  (8UL<<20)   /* 8MiB */
      18             : 
      19             : struct fd_snapwr_out {
      20             :   ulong       idx;
      21             :   fd_wksp_t * mem;
      22             :   ulong       chunk0;
      23             :   ulong       wmark;
      24             :   ulong       chunk;
      25             :   ulong       mtu;
      26             : };
      27             : 
      28             : typedef struct fd_snapwr_out fd_snapwr_out_t;
      29             : 
      30             : struct fd_snapwr_tile {
      31             :   int full;
      32             :   int state;
      33             : 
      34             :   ulong partition_sz;
      35             : 
      36             :   ulong accounts_off;
      37             :   ulong flush_off;
      38             : 
      39             :   uchar * write_buf;
      40             :   ulong   write_buf_used;
      41             : 
      42             :   ulong seed;
      43             : 
      44             :   fd_ssparse_t ssparse[1];
      45             :   fd_ssmanifest_parser_t * manifest_parser;
      46             : 
      47             :   struct {
      48             :     fd_wksp_t * wksp;
      49             :     ulong       chunk0;
      50             :     ulong       wmark;
      51             :     ulong       mtu;
      52             :     ulong       pos;
      53             :   } in;
      54             : 
      55             :   fd_snapwr_out_t ct_out;
      56             : 
      57             :   struct {
      58             :     ulong accounts_off;
      59             :     ulong flush_off;
      60             :   } recovery;
      61             : 
      62             :   struct {
      63             :     ulong full_bytes_read;
      64             :     ulong incremental_bytes_read;
      65             :     ulong bytes_written;
      66             :     ulong accounts_written;
      67             :     ulong full_accounts_written;
      68             :   } metrics;
      69             : 
      70             :   fd_snapshot_manifest_t manifest[1];
      71             : };
      72             : 
      73             : typedef struct fd_snapwr_tile fd_snapwr_tile_t;
      74             : 
      75             : static inline int
      76           0 : should_shutdown( fd_snapwr_tile_t * ctx ) {
      77           0 :   return ctx->state==FD_SNAPSHOT_STATE_SHUTDOWN;
      78           0 : }
      79             : 
      80             : static void
      81           0 : metrics_write( fd_snapwr_tile_t * ctx ) {
      82           0 :   FD_MGAUGE_SET( SNAPWR, FULL_BYTES_READ,        ctx->metrics.full_bytes_read );
      83           0 :   FD_MGAUGE_SET( SNAPWR, INCREMENTAL_BYTES_READ, ctx->metrics.incremental_bytes_read );
      84           0 :   FD_MGAUGE_SET( SNAPWR, BYTES_WRITTEN,          ctx->metrics.bytes_written );
      85           0 :   FD_MGAUGE_SET( SNAPWR, ACCOUNTS_WRITTEN,       ctx->metrics.accounts_written );
      86           0 : }
      87             : 
      88             : static ulong
      89           0 : scratch_align( void ) {
      90           0 :   return 512UL;
      91           0 : }
      92             : 
      93             : static ulong
      94           0 : scratch_footprint( fd_topo_tile_t const * tile ) {
      95           0 :   (void)tile;
      96           0 :   ulong l = FD_LAYOUT_INIT;
      97           0 :   l = FD_LAYOUT_APPEND( l, alignof(fd_snapwr_tile_t),    sizeof(fd_snapwr_tile_t)         );
      98           0 :   l = FD_LAYOUT_APPEND( l, fd_ssmanifest_parser_align(), fd_ssmanifest_parser_footprint() );
      99           0 :   l = FD_LAYOUT_APPEND( l, 1UL,                          FD_SNAPWR_WRITE_BUF_SZ           );
     100           0 :   return FD_LAYOUT_FINI( l, scratch_align() );
     101           0 : }
     102             : 
     103             : static void
     104             : transition_malformed( fd_snapwr_tile_t *  ctx,
     105           0 :                       fd_stem_context_t * stem ) {
     106           0 :   if( FD_UNLIKELY( ctx->state==FD_SNAPSHOT_STATE_ERROR ) ) return;
     107           0 :   ctx->state = FD_SNAPSHOT_STATE_ERROR;
     108           0 :   fd_stem_publish( stem, ctx->ct_out.idx, FD_SNAPSHOT_MSG_CTRL_ERROR, 0UL, 0UL, 0UL, 0UL, 0UL );
     109           0 : }
     110             : 
     111             : static void
     112           0 : buffer_flush( fd_snapwr_tile_t * ctx ) {
     113           0 :   if( FD_UNLIKELY( !ctx->write_buf_used ) ) return;
     114             : 
     115           0 :   ulong sz  = ctx->write_buf_used;
     116           0 :   ulong off = ctx->flush_off;
     117           0 :   ulong bytes_written = 0UL;
     118           0 :   while( bytes_written<sz ) {
     119           0 :     long res = pwrite( FD_ACCDB_FD_RW, ctx->write_buf+bytes_written, sz-bytes_written, (long)(off+bytes_written) );
     120           0 :     if( FD_UNLIKELY( -1==res ) ) FD_LOG_ERR(( "error writing to disk (%d-%s)", errno, fd_io_strerror( errno ) ));
     121           0 :     bytes_written += (ulong)res;
     122           0 :     ctx->metrics.bytes_written += (ulong)res;
     123           0 :   }
     124           0 :   ctx->flush_off      += sz;
     125           0 :   ctx->write_buf_used  = 0UL;
     126           0 : }
     127             : 
     128             : static void
     129             : buffer_write( fd_snapwr_tile_t * ctx,
     130             :               uchar const *      data,
     131           0 :               ulong              sz ) {
     132           0 :   ctx->accounts_off += sz;
     133           0 :   while( sz ) {
     134           0 :     ulong avail = FD_SNAPWR_WRITE_BUF_SZ - ctx->write_buf_used;
     135           0 :     ulong n     = fd_ulong_min( sz, avail );
     136           0 :     fd_memcpy( ctx->write_buf + ctx->write_buf_used, data, n );
     137           0 :     ctx->write_buf_used += n;
     138           0 :     data += n;
     139           0 :     sz   -= n;
     140           0 :     if( FD_UNLIKELY( ctx->write_buf_used==FD_SNAPWR_WRITE_BUF_SZ ) ) buffer_flush( ctx );
     141           0 :   }
     142           0 : }
     143             : 
     144             : static void
     145             : buffer_skip( fd_snapwr_tile_t * ctx,
     146           0 :              ulong              sz ) {
     147           0 :   buffer_flush( ctx );
     148           0 :   ctx->accounts_off += sz;
     149           0 :   ctx->flush_off    += sz;
     150           0 : }
     151             : 
     152             : static void
     153             : process_account_header( fd_snapwr_tile_t *            ctx,
     154           0 :                         fd_ssparse_advance_result_t * result ) {
     155             :   /* Ensure header+data does not cross a partition boundary.  If it
     156             :      would, pad with zeros so the account starts at the next one. */
     157           0 :   ulong account_sz    = 68UL + (ulong)result->account_header.data_len;
     158           0 :   ulong cur_boundary  = ctx->accounts_off / ctx->partition_sz;
     159           0 :   ulong end_boundary  = (ctx->accounts_off + account_sz - 1UL) / ctx->partition_sz;
     160           0 :   if( FD_UNLIKELY( cur_boundary!=end_boundary ) ) {
     161           0 :     ulong next = (cur_boundary + 1UL) * ctx->partition_sz;
     162           0 :     buffer_skip( ctx, next - ctx->accounts_off );
     163           0 :   }
     164             : 
     165           0 :   uchar data[ 68UL ];
     166           0 :   fd_memcpy( data, result->account_header.pubkey, 32UL );
     167           0 :   fd_memcpy( data+32UL, &result->account_header.data_len, 4UL );
     168           0 :   fd_memcpy( data+36UL, result->account_header.owner, 32UL );
     169           0 :   buffer_write( ctx, data, 68UL );
     170           0 :   ctx->metrics.accounts_written++;
     171           0 : }
     172             : 
     173             : static void
     174             : process_account_data( fd_snapwr_tile_t *            ctx,
     175           0 :                       fd_ssparse_advance_result_t * result ) {
     176           0 :   buffer_write( ctx, result->account_data.data, result->account_data.data_sz );
     177           0 : }
     178             : 
     179             : static int
     180             : handle_data_frag( fd_snapwr_tile_t *  ctx,
     181             :                   ulong               chunk,
     182             :                   ulong               sz,
     183           0 :                   fd_stem_context_t * stem ) {
     184           0 :   if( FD_UNLIKELY( ctx->state==FD_SNAPSHOT_STATE_FINISHING ) ) {
     185           0 :     FD_LOG_WARNING(( "received unexpected data frag while in state %s (%lu)",
     186           0 :                      fd_ssctrl_state_str( (ulong)ctx->state ), (ulong)ctx->state  ));
     187           0 :     transition_malformed( ctx, stem );
     188           0 :     return 0;
     189           0 :   }
     190           0 :   if( FD_UNLIKELY( ctx->state==FD_SNAPSHOT_STATE_ERROR ) ) {
     191             :     /* Ignore all data frags after observing an error in the stream until
     192             :        we receive fail & init control messages to restart processing. */
     193           0 :     return 0;
     194           0 :   }
     195           0 :   if( FD_UNLIKELY( ctx->state!=FD_SNAPSHOT_STATE_PROCESSING ) ) {
     196           0 :     FD_LOG_ERR(( "received data frag during invalid state %s (%lu)",
     197           0 :                  fd_ssctrl_state_str( (ulong)ctx->state ), (ulong)ctx->state ));
     198           0 :   }
     199             : 
     200           0 :   FD_TEST( chunk>=ctx->in.chunk0 && chunk<=ctx->in.wmark && sz<=ctx->in.mtu );
     201             : 
     202           0 :   for(;;) {
     203           0 :     if( FD_UNLIKELY( sz-ctx->in.pos==0UL ) ) break;
     204             : 
     205           0 :     uchar const * data = (uchar const *)fd_chunk_to_laddr_const( ctx->in.wksp, chunk ) + ctx->in.pos;
     206             : 
     207           0 :     fd_ssparse_advance_result_t result[1];
     208           0 :     int res = fd_ssparse_advance( ctx->ssparse, data, sz-ctx->in.pos, result );
     209           0 :     switch( res ) {
     210           0 :       case FD_SSPARSE_ADVANCE_ERROR:
     211           0 :         FD_LOG_WARNING(( "error while parsing snapshot stream" ));
     212           0 :         transition_malformed( ctx, stem );
     213           0 :         return 0;
     214           0 :       case FD_SSPARSE_ADVANCE_AGAIN:
     215           0 :         break;
     216           0 :         case FD_SSPARSE_ADVANCE_MANIFEST:
     217           0 :         case FD_SSPARSE_ADVANCE_MANIFEST_DONE: {
     218           0 :           int res = fd_ssmanifest_parser_consume( ctx->manifest_parser,
     219           0 :                                                 result->manifest.data,
     220           0 :                                                 result->manifest.data_sz );
     221           0 :         if( FD_UNLIKELY( res==FD_SSMANIFEST_PARSER_ADVANCE_ERROR ) ) {
     222           0 :           FD_LOG_WARNING(( "error while parsing snapshot manifest" ));
     223           0 :           transition_malformed( ctx, stem );
     224           0 :           return 0;
     225           0 :         }
     226           0 :         break;
     227           0 :       }
     228           0 :       case FD_SSPARSE_ADVANCE_STATUS_CACHE:
     229           0 :         break;
     230           0 :       case FD_SSPARSE_ADVANCE_ACCOUNT_HEADER:
     231           0 :         process_account_header( ctx, result );
     232           0 :         break;
     233           0 :       case FD_SSPARSE_ADVANCE_ACCOUNT_DATA:
     234           0 :         process_account_data( ctx, result );
     235           0 :         break;
     236           0 :       case FD_SSPARSE_ADVANCE_ACCOUNT_BATCH:
     237           0 :         FD_TEST( 0 );
     238           0 :         break;
     239           0 :       case FD_SSPARSE_ADVANCE_DONE:
     240           0 :         buffer_flush( ctx );
     241           0 :         ctx->state = FD_SNAPSHOT_STATE_FINISHING;
     242           0 :         break;
     243           0 :       default:
     244           0 :         FD_LOG_ERR(( "unexpected fd_ssparse_advance result %d", res ));
     245           0 :         break;
     246           0 :     }
     247             : 
     248           0 :     ctx->in.pos += result->bytes_consumed;
     249           0 :     if( FD_LIKELY( ctx->full ) ) ctx->metrics.full_bytes_read        += result->bytes_consumed;
     250           0 :     else                         ctx->metrics.incremental_bytes_read += result->bytes_consumed;
     251           0 :   }
     252             : 
     253           0 :   int reprocess_frag = ctx->in.pos<sz;
     254           0 :   if( FD_LIKELY( !reprocess_frag ) ) ctx->in.pos = 0UL;
     255           0 :   return reprocess_frag;
     256           0 : }
     257             : 
     258             : static void
     259             : handle_control_frag( fd_snapwr_tile_t *  ctx,
     260             :                      fd_stem_context_t * stem,
     261           0 :                      ulong               sig ) {
     262           0 :   if( ctx->state==FD_SNAPSHOT_STATE_ERROR && sig!=FD_SNAPSHOT_MSG_CTRL_FAIL ) {
     263             :     /* Control messages move along the snapshot load pipeline.  Since
     264             :        error conditions can be triggered by any tile in the pipeline,
     265             :        it is possible to be in error state and still receive otherwise
     266             :        valid messages.  Only a fail message can revert this. */
     267           0 :     return;
     268           0 :   };
     269             : 
     270           0 :   int forward_msg = 1;
     271             : 
     272           0 :   switch( sig ) {
     273           0 :     case FD_SNAPSHOT_MSG_CTRL_INIT_FULL:
     274           0 :     case FD_SNAPSHOT_MSG_CTRL_INIT_INCR: {
     275           0 :       FD_TEST( ctx->state==FD_SNAPSHOT_STATE_IDLE );
     276           0 :       ctx->state = FD_SNAPSHOT_STATE_PROCESSING;
     277           0 :       ctx->full = sig==FD_SNAPSHOT_MSG_CTRL_INIT_FULL;
     278           0 :       ctx->in.pos = 0UL;
     279           0 :       fd_ssparse_init( ctx->ssparse );
     280           0 :       fd_ssmanifest_parser_init( ctx->manifest_parser, ctx->manifest );
     281             : 
     282             :       /* Rewind metric counters (no-op unless recovering from a fail) */
     283           0 :       if( sig==FD_SNAPSHOT_MSG_CTRL_INIT_FULL ) {
     284           0 :         ctx->metrics.full_bytes_read        = 0UL;
     285           0 :         ctx->metrics.incremental_bytes_read = 0UL;
     286           0 :         ctx->metrics.accounts_written       = ctx->metrics.full_accounts_written = 0UL;
     287           0 :       } else {
     288           0 :         ctx->metrics.incremental_bytes_read = 0UL;
     289           0 :         ctx->metrics.accounts_written       = ctx->metrics.full_accounts_written;
     290           0 :       }
     291           0 :       break;
     292           0 :     }
     293           0 :     case FD_SNAPSHOT_MSG_CTRL_FINI: {
     294             :       /* This is a special case: handle_data_frag must have already
     295             :          processed FD_SSPARSE_ADVANCE_DONE and moved the state into
     296             :          FD_SNAPSHOT_STATE_FINISHING.  Otherwise, treat this as a
     297             :          malformed snapshot so that the pipeline can retry. */
     298           0 :       if( FD_UNLIKELY( ctx->state!=FD_SNAPSHOT_STATE_FINISHING ) ) {
     299           0 :         FD_LOG_WARNING(( "received FINI while in state %s (%lu), expected FINISHING (possibly truncated tar stream)",
     300           0 :                          fd_ssctrl_state_str( (ulong)ctx->state ), (ulong)ctx->state ));
     301           0 :         transition_malformed( ctx, stem );
     302           0 :         forward_msg = 0;
     303           0 :         break;
     304           0 :       }
     305           0 :       break;
     306           0 :     }
     307             : 
     308           0 :     case FD_SNAPSHOT_MSG_CTRL_NEXT: {
     309           0 :       FD_TEST( ctx->state==FD_SNAPSHOT_STATE_FINISHING );
     310           0 :       ctx->state = FD_SNAPSHOT_STATE_IDLE;
     311           0 :       ctx->recovery.accounts_off = ctx->accounts_off;
     312           0 :       ctx->recovery.flush_off    = ctx->flush_off;
     313           0 :       ctx->metrics.full_accounts_written = ctx->metrics.accounts_written;
     314           0 :       break;
     315           0 :     }
     316             : 
     317           0 :     case FD_SNAPSHOT_MSG_CTRL_DONE: {
     318           0 :       FD_TEST( ctx->state==FD_SNAPSHOT_STATE_FINISHING );
     319           0 :       ctx->state = FD_SNAPSHOT_STATE_IDLE;
     320           0 :       break;
     321           0 :     }
     322             : 
     323           0 :     case FD_SNAPSHOT_MSG_CTRL_ERROR: {
     324           0 :       FD_TEST( ctx->state!=FD_SNAPSHOT_STATE_SHUTDOWN );
     325           0 :       ctx->state = FD_SNAPSHOT_STATE_ERROR;
     326           0 :       break;
     327           0 :     }
     328             : 
     329           0 :     case FD_SNAPSHOT_MSG_CTRL_FAIL: {
     330           0 :       FD_TEST( ctx->state!=FD_SNAPSHOT_STATE_SHUTDOWN );
     331           0 :       ctx->write_buf_used = 0UL;
     332           0 :       ctx->accounts_off = ctx->full ? 0UL : ctx->recovery.accounts_off;
     333           0 :       ctx->flush_off    = ctx->full ? 0UL : ctx->recovery.flush_off;
     334           0 :       ctx->state = FD_SNAPSHOT_STATE_IDLE;
     335           0 :       break;
     336           0 :     }
     337             : 
     338           0 :     case FD_SNAPSHOT_MSG_CTRL_SHUTDOWN: {
     339           0 :       FD_TEST( ctx->state==FD_SNAPSHOT_STATE_IDLE );
     340           0 :       ctx->state = FD_SNAPSHOT_STATE_SHUTDOWN;
     341           0 :       break;
     342           0 :     }
     343             : 
     344           0 :     default: {
     345           0 :       FD_LOG_ERR(( "unexpected control frag %s (%lu) in state %s (%lu)",
     346           0 :                    fd_ssctrl_msg_ctrl_str( sig ), sig,
     347           0 :                    fd_ssctrl_state_str( (ulong)ctx->state ), (ulong)ctx->state ));
     348           0 :       break;
     349           0 :     }
     350           0 :   }
     351             : 
     352           0 :   if( FD_LIKELY( forward_msg ) ) {
     353           0 :     fd_stem_publish( stem, ctx->ct_out.idx, sig, 0UL, 0UL, 0UL, 0UL, 0UL );
     354           0 :   }
     355           0 : }
     356             : 
     357             : static inline int
     358             : returnable_frag( fd_snapwr_tile_t *  ctx,
     359             :                  ulong               in_idx FD_PARAM_UNUSED,
     360             :                  ulong               seq    FD_PARAM_UNUSED,
     361             :                  ulong               sig,
     362             :                  ulong               chunk,
     363             :                  ulong               sz,
     364             :                  ulong               ctl    FD_PARAM_UNUSED,
     365             :                  ulong               tsorig FD_PARAM_UNUSED,
     366             :                  ulong               tspub  FD_PARAM_UNUSED,
     367           0 :                  fd_stem_context_t * stem ) {
     368           0 :   FD_TEST( ctx->state!=FD_SNAPSHOT_STATE_SHUTDOWN );
     369             : 
     370           0 :   if( FD_UNLIKELY( sig==FD_SNAPSHOT_MSG_DATA ) ) return handle_data_frag( ctx, chunk, sz, stem );
     371           0 :   else                                           handle_control_frag( ctx, stem, sig );
     372             : 
     373           0 :   return 0;
     374           0 : }
     375             : 
     376             : static ulong
     377             : populate_allowed_fds( fd_topo_t      const * topo FD_PARAM_UNUSED,
     378             :                       fd_topo_tile_t const * tile FD_PARAM_UNUSED,
     379             :                       ulong                  out_fds_cnt,
     380           0 :                       int *                  out_fds ) {
     381           0 :   if( FD_UNLIKELY( out_fds_cnt<3UL ) ) FD_LOG_ERR(( "invalid out_fds_cnt %lu", out_fds_cnt ));
     382             : 
     383           0 :   ulong out_cnt = 0;
     384           0 :   out_fds[ out_cnt++ ] = 2UL; /* stderr */
     385           0 :   if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) ) {
     386           0 :     out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
     387           0 :   }
     388           0 :   out_fds[ out_cnt++ ] = FD_ACCDB_FD_RW; /* accounts db */
     389             : 
     390           0 :   return out_cnt;
     391           0 : }
     392             : 
     393             : static ulong
     394             : populate_allowed_seccomp( fd_topo_t const *      topo,
     395             :                           fd_topo_tile_t const * tile,
     396             :                           ulong                  out_cnt,
     397           0 :                           struct sock_filter *   out ) {
     398           0 :   (void)topo; (void)tile;
     399             : 
     400           0 :   populate_sock_filter_policy_fd_snapwr_tile( out_cnt, out, (uint)fd_log_private_logfile_fd(), (uint)FD_ACCDB_FD_RW );
     401           0 :   return sock_filter_policy_fd_snapwr_tile_instr_cnt;
     402           0 : }
     403             : 
     404             : static inline fd_snapwr_out_t
     405             : out1( fd_topo_t const *      topo,
     406             :       fd_topo_tile_t const * tile,
     407           0 :       char const *           name ) {
     408           0 :   ulong idx = fd_topo_find_tile_out_link( topo, tile, name, 0UL );
     409             : 
     410           0 :   if( FD_UNLIKELY( idx==ULONG_MAX ) ) return (fd_snapwr_out_t){ .idx = ULONG_MAX, .mem = NULL, .chunk0 = 0, .wmark = 0, .chunk = 0, .mtu = 0 };
     411             : 
     412           0 :   ulong mtu = topo->links[ tile->out_link_id[ idx ] ].mtu;
     413           0 :   if( FD_UNLIKELY( mtu==0UL ) ) return (fd_snapwr_out_t){ .idx = idx, .mem = NULL, .chunk0 = ULONG_MAX, .wmark = ULONG_MAX, .chunk = ULONG_MAX, .mtu = mtu };
     414             : 
     415           0 :   void * mem   = topo->workspaces[ topo->objs[ topo->links[ tile->out_link_id[ idx ] ].dcache_obj_id ].wksp_id ].wksp;
     416           0 :   ulong chunk0 = fd_dcache_compact_chunk0( mem, topo->links[ tile->out_link_id[ idx ] ].dcache );
     417           0 :   ulong wmark  = fd_dcache_compact_wmark ( mem, topo->links[ tile->out_link_id[ idx ] ].dcache, mtu );
     418           0 :   return (fd_snapwr_out_t){ .idx = idx, .mem = mem, .chunk0 = chunk0, .wmark = wmark, .chunk = chunk0, .mtu = mtu };
     419           0 : }
     420             : 
     421             : static void
     422             : privileged_init( fd_topo_t const *      topo,
     423           0 :                  fd_topo_tile_t const * tile ) {
     424           0 :   fd_snapwr_tile_t * ctx = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     425           0 :   FD_TEST( fd_rng_secure( &ctx->seed, 8UL ) );
     426           0 : }
     427             : 
     428             : static void
     429             : unprivileged_init( fd_topo_t const *      topo,
     430           0 :                    fd_topo_tile_t const * tile ) {
     431           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     432             : 
     433           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     434           0 :   fd_snapwr_tile_t * ctx  = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_snapwr_tile_t),    sizeof(fd_snapwr_tile_t)          );
     435           0 :   void * _manifest_parser = FD_SCRATCH_ALLOC_APPEND( l, fd_ssmanifest_parser_align(), fd_ssmanifest_parser_footprint()  );
     436           0 :   void * _write_buf       = FD_SCRATCH_ALLOC_APPEND( l, 1UL,                          FD_SNAPWR_WRITE_BUF_SZ            );
     437             : 
     438           0 :   ctx->full = 1;
     439           0 :   ctx->state = FD_SNAPSHOT_STATE_IDLE;
     440             : 
     441           0 :   ctx->partition_sz = tile->snapwr.partition_sz;
     442           0 :   if( FD_UNLIKELY( !ctx->partition_sz ) ) FD_LOG_ERR(( "tile `" NAME "` partition_sz is 0" ));
     443             : 
     444           0 :   ctx->accounts_off          = 0UL;
     445           0 :   ctx->flush_off             = 0UL;
     446           0 :   ctx->recovery.accounts_off = 0UL;
     447           0 :   ctx->recovery.flush_off    = 0UL;
     448           0 :   ctx->write_buf             = _write_buf;
     449           0 :   ctx->write_buf_used        = 0UL;
     450             : 
     451           0 :   ctx->manifest_parser = fd_ssmanifest_parser_join( fd_ssmanifest_parser_new( _manifest_parser ) );
     452           0 :   FD_TEST( ctx->manifest_parser );
     453             : 
     454           0 :   fd_memset( &ctx->metrics, 0, sizeof(ctx->metrics) );
     455             : 
     456           0 :   if( FD_UNLIKELY( tile->in_cnt!=1UL ) ) FD_LOG_ERR(( "tile `" NAME "` has %lu ins, expected 1", tile->in_cnt ));
     457           0 :   ctx->ct_out = out1( topo, tile, "snapwr_ct" );
     458           0 :   if( FD_UNLIKELY( ctx->ct_out.idx==ULONG_MAX ) ) FD_LOG_ERR(( "tile `" NAME "` missing required out link `snapwr_ct`" ));
     459             : 
     460           0 :   fd_ssparse_init( ctx->ssparse );
     461           0 :   fd_ssparse_batch_enable( ctx->ssparse, 0 );
     462           0 :   fd_ssmanifest_parser_init( ctx->manifest_parser, ctx->manifest );
     463             : 
     464           0 :   fd_topo_link_t const * in_link = &topo->links[ tile->in_link_id[ 0UL ] ];
     465           0 :   FD_TEST( 0==strcmp( in_link->name, "snapdc_in" ) );
     466           0 :   fd_topo_wksp_t const * in_wksp = &topo->workspaces[ topo->objs[ in_link->dcache_obj_id ].wksp_id ];
     467           0 :   ctx->in.wksp   = in_wksp->wksp;
     468           0 :   ctx->in.chunk0 = fd_dcache_compact_chunk0( ctx->in.wksp, in_link->dcache );
     469           0 :   ctx->in.wmark  = fd_dcache_compact_wmark( ctx->in.wksp, in_link->dcache, in_link->mtu );
     470           0 :   ctx->in.mtu    = in_link->mtu;
     471           0 :   ctx->in.pos    = 0UL;
     472           0 : }
     473             : 
     474           0 : #define STEM_BURST 1UL
     475             : 
     476           0 : #define STEM_LAZY  (128L*3000L)
     477             : 
     478           0 : #define STEM_CALLBACK_CONTEXT_TYPE  fd_snapwr_tile_t
     479           0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_snapwr_tile_t)
     480             : 
     481             : #define STEM_CALLBACK_SHOULD_SHUTDOWN should_shutdown
     482           0 : #define STEM_CALLBACK_METRICS_WRITE   metrics_write
     483           0 : #define STEM_CALLBACK_RETURNABLE_FRAG returnable_frag
     484             : 
     485             : #include "../../disco/stem/fd_stem.c"
     486             : 
     487             : fd_topo_run_tile_t fd_tile_snapwr = {
     488             :   .name                     = NAME,
     489             :   .populate_allowed_fds     = populate_allowed_fds,
     490             :   .populate_allowed_seccomp = populate_allowed_seccomp,
     491             :   .scratch_align            = scratch_align,
     492             :   .scratch_footprint        = scratch_footprint,
     493             :   .privileged_init          = privileged_init,
     494             :   .unprivileged_init        = unprivileged_init,
     495             :   .run                      = stem_run,
     496             : };
     497             : 
     498             : #undef NAME

Generated by: LCOV version 1.14