LCOV - code coverage report
Current view: top level - discof/backup - fd_backup_cache.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 9 0.0 %
Date: 2026-08-16 04:31:21 Functions: 0 3 0.0 %

          Line data    Source code
       1             : 
       2             : #ifndef HEADER_fd_src_discof_backup_fd_backup_cache_h
       3             : #define HEADER_fd_src_discof_backup_fd_backup_cache_h
       4             : 
       5             : /* fd_backup_cache.h finds rooted accounts that are in accdb cache.
       6             :    Publishes discovered accounts (by pubkey and account index) onto
       7             :    mcache/dcache. */
       8             : 
       9             : #include "fd_backup.h"
      10             : #include "fd_backup_accidx.h"
      11             : #include "../../flamenco/accdb/fd_accdb_cache.h"
      12             : #include "../../flamenco/runtime/fd_runtime_const.h"
      13             : 
      14           0 : #define SNAPZP_TILE_MAX 64
      15             : 
      16             : /* fd_backup_cache_t scans accdb caches for rooted accounts.
      17             :    Assumes compaction and rooting is disabled during the scan.
      18             :    Concurrent access (e.g. cache eviction) during the scan is fine.
      19             :    May produce duplicates.
      20             :    Usage like:
      21             :      fd_backup_cache_t scan[1];
      22             :      fd_backup_cache_msg_t frag[1];
      23             :      while( fd_backup_cache_scan( scan, frag ) ) {
      24             :        for( ulong i=0UL; i<FD_BACKUP_CACHE_PARA; i++ ) {
      25             :          fd_pubkey_t const * pubkey  = &frag->pubkey [ i ];
      26             :          uint                acc_idx =  frag->acc_idx[ i ];
      27             :          if( acc_idx==UINT_MAX ) continue;
      28             :          if( fd_backup_cache_read( ..., pubkey, acc_idx, ... ) ) {
      29             :            // ... process account ...
      30             :          }
      31             :        }
      32             :      }
      33             :    Designed to be send frags to a remote thread via IPC. */
      34             : 
      35             : struct fd_backup_cache {
      36             :   uchar const * cache    [ FD_ACCDB_CACHE_CLASS_CNT ];
      37             :   ulong         cache_max[ FD_ACCDB_CACHE_CLASS_CNT ];
      38             : 
      39             :   fd_backup_accidx_t idx;
      40             : 
      41             :   ulong cache_class;
      42             :   ulong cache_idx;
      43             : 
      44             :   /* scratch memory
      45             :      (slightly faster to use struct memory than stack) */
      46             :   ulong              chain_idx[ FD_BACKUP_CACHE_PARA ];
      47             :   fd_accdb_accmeta_t meta     [ FD_BACKUP_CACHE_PARA ];
      48             : };
      49             : 
      50             : typedef struct fd_backup_cache fd_backup_cache_t;
      51             : 
      52             : struct fd_backup_acc {
      53             :   uchar pubkey[ 32 ];
      54             :   uchar owner [ 32 ];
      55             :   ulong lamports;
      56             :   ulong data_len : 32;
      57             :   ulong executable : 1;
      58             :   uchar data[ FD_RUNTIME_ACC_SZ_MAX ];
      59             : };
      60             : 
      61             : typedef struct fd_backup_acc fd_backup_acc_t;
      62             : 
      63             : FD_PROTOTYPES_BEGIN
      64             : 
      65             : /* fd_backup_cache_init creates a new cache scanner object over the
      66             :    given shared memory cache size classes and accdb account index. */
      67             : 
      68             : fd_backup_cache_t *
      69             : fd_backup_cache_init( fd_backup_cache_t *        backup,
      70             :                       uchar const * const        cache    [ FD_ACCDB_CACHE_CLASS_CNT ],
      71             :                       ulong const                cache_max[ FD_ACCDB_CACHE_CLASS_CNT ],
      72             :                       fd_backup_accidx_t const * idx );
      73             : 
      74             : /* fd_backup_cache_join is a convenience API for joining an accdb_shmem.
      75             :    epoch_fseq is the tile-owned external epoch slot that accdb scans
      76             :    during deferred reclamation. */
      77             : 
      78             : fd_backup_cache_t *
      79             : fd_backup_cache_join( fd_backup_cache_t * backup,
      80             :                       fd_accdb_shmem_t *  accdb_shmem,
      81             :                       ulong *             epoch_fseq );
      82             : 
      83             : /* fd_backup_cache_scan yields a batch of rooted accounts found in
      84             :    cache.  Returns NULL once the scan completes. */
      85             : 
      86             : fd_backup_cache_msg_t *
      87             : fd_backup_cache_scan( fd_backup_cache_t *     backup,
      88             :                       fd_backup_cache_msg_t * frag );
      89             : 
      90             : /* fd_backup_cache_reset rewinds the scanner. */
      91             : 
      92             : static inline void
      93             : fd_backup_cache_reset( fd_backup_cache_t * backup,
      94           0 :                        ulong               root_generation ) {
      95           0 :   backup->idx.root_generation = (uint)root_generation;
      96           0 :   backup->cache_class         = 0;
      97           0 :   backup->cache_idx           = 0;
      98           0 : }
      99             : 
     100             : /* fd_backup_cache_read copy-reads a possibly cached account into out.
     101             :    *out_sz is the current size of out and is advanced on success.  The
     102             :    account is laid out in snapshot storage format. */
     103             : 
     104           0 : #define FD_BACKUP_CACHE_SUCCESS   0 /* ok */
     105           0 : #define FD_BACKUP_CACHE_ERR_SPACE 1 /* not enough buffer space */
     106           0 : #define FD_BACKUP_CACHE_ERR_MISS  2 /* not in cache */
     107             : 
     108             : int
     109             : fd_backup_cache_read( fd_backup_cache_t * ctx,
     110             :                       fd_pubkey_t const * pubkey,
     111             :                       uint                acc_idx,
     112             :                       uchar *             out,
     113             :                       ulong *             out_sz,
     114             :                       ulong               out_max );
     115             : 
     116             : FD_PROTOTYPES_END
     117             : 
     118             : #endif /* HEADER_fd_src_discof_backup_fd_backup_cache_h */

Generated by: LCOV version 1.14