LCOV - code coverage report
Current view: top level - flamenco/accdb - fd_accdb_user.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 7 13 53.8 %
Date: 2026-01-23 05:02:40 Functions: 5 615 0.8 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_accdb_fd_accdb_user_h
       2             : #define HEADER_fd_src_flamenco_accdb_fd_accdb_user_h
       3             : 
       4             : #include "fd_accdb_base.h"
       5             : #include "fd_accdb_ref.h"
       6             : #include "../../funk/fd_funk_base.h"
       7             : 
       8        7662 : #define FD_ACCDB_FLAG_CREATE   (1)
       9        6993 : #define FD_ACCDB_FLAG_TRUNCATE (2)
      10        1488 : #define FD_ACCDB_FLAG_DONTZERO (3)
      11             : 
      12             : /* fd_accdb_user_vt_t specifies the interface (vtable) for the account
      13             :    DB client. */
      14             : 
      15             : struct fd_accdb_user_vt {
      16             : 
      17             :   /* fini destroys the accdb_user object implementing this interface.
      18             :      It is assumed that all accdb_ref handles created by the object have
      19             :      been released before calling fini. */
      20             : 
      21             :   void
      22             :   (* fini)( fd_accdb_user_t * accdb );
      23             : 
      24             :   /* Config APIs */
      25             : 
      26             :   /* batch_max returns the largest 'cnt' argument that is guaranteed to
      27             :      be accepted by open_ro_multi/close_ro_multi when no other refs are
      28             :      open. */
      29             : 
      30             :   ulong
      31             :   (* batch_max)( fd_accdb_user_t * accdb );
      32             : 
      33             :   /* Query APIs */
      34             : 
      35             :   /* open_ro_multi opens a batch of accounts for read.  ro[i] is
      36             :      initialized with an account handle.  xid is the fork ID.
      37             :      address[i] gives the account address to query (conflicts are fine).
      38             :      cnt is the number of accounts to query.
      39             : 
      40             :      If account i is not found, ro[i] gives an account with zero
      41             :      lamports and no data.
      42             : 
      43             :      On return, the caller owns cnt accdb_ro database handles. */
      44             : 
      45             :   void
      46             :   (* open_ro_multi)( fd_accdb_user_t *         accdb,
      47             :                      fd_accdb_ro_t *           ro,       /* array */
      48             :                      fd_funk_txn_xid_t const * xid,
      49             :                      void const *              address,  /* array (stride 32) */
      50             :                      ulong                     cnt );
      51             : 
      52             :   /* open_rw_multi opens a batch of accounts for read-write.  rw[i] is
      53             :      either initialized with an account handle or marked as invalid (see
      54             :      below).  xid is the fork ID.  address[i] gives the account address
      55             :      to query (conflicts are forbidden).  data_min[i] specifies the
      56             :      requested minimum account data byte capacity (grows account buffers
      57             :      if necessary).  cnt is the number of accounts to query.
      58             : 
      59             :      Supported flags:
      60             : 
      61             :        CREATE: if set, and account i does not exist, rw[i] gives a valid
      62             :                handle with zero lamports and zero data length (but with
      63             :                requested buffer capacity).
      64             :                if not set, and account i does not exist, then sets
      65             :                rw[i]->ref->accdb_type=INVAL.
      66             : 
      67             :        TRUNCATE: reset the account's data length to zero (useful as a
      68             :                  hit to the database engine to avoid copies)
      69             : 
      70             :        DONTZERO: do not zero unused account data buffer space (useful
      71             :                  as a performance hint when the caller plans to
      72             :                  overwrite all data bytes anyway)
      73             : 
      74             :      On return, the caller owns cnt accdb_rw database handles (some of
      75             :      which may be invalid). */
      76             : 
      77             :   void
      78             :   (* open_rw_multi)( fd_accdb_user_t *         accdb,
      79             :                      fd_accdb_rw_t *           rw,       /* array */
      80             :                      fd_funk_txn_xid_t const * xid,
      81             :                      void const *              address,  /* array (stride 32) */
      82             :                      ulong const *             data_min, /* array */
      83             :                      int                       flags,
      84             :                      ulong                     cnt );
      85             : 
      86             :   /* close_ref_multi closes a batch of account handles.  Handles that
      87             :      are invalid are silently ignored (such that a call to open_rw_multi
      88             :      without the CREATE flag set is still fine).  It is U.B. to pass the
      89             :      same handle twice.  */
      90             : 
      91             :   void
      92             :   (* close_ref_multi)( fd_accdb_user_t * accdb,
      93             :                        fd_accdb_ref_t *  ref,    /* array */
      94             :                        ulong             cnt );
      95             : 
      96             :   /* Resize APIs */
      97             : 
      98             :   ulong
      99             :   (* rw_data_max)( fd_accdb_user_t *     accdb,
     100             :                    fd_accdb_rw_t const * rw );
     101             : 
     102             :   void
     103             :   (* rw_data_sz_set)( fd_accdb_user_t * accdb,
     104             :                       fd_accdb_rw_t *   rw,
     105             :                       ulong             data_sz,
     106             :                       int               flags );
     107             : 
     108             : };
     109             : 
     110             : typedef struct fd_accdb_user_vt fd_accdb_user_vt_t;
     111             : 
     112             : struct fd_accdb_user_base {
     113             :   fd_accdb_user_vt_t const * vt;
     114             :   uint                       accdb_type;
     115             : 
     116             :   ulong rw_active;
     117             :   ulong ro_active;
     118             :   ulong created_cnt;
     119             : };
     120             : 
     121             : typedef struct fd_accdb_user_base fd_accdb_user_base_t;
     122             : 
     123             : struct fd_accdb_user {
     124             :   fd_accdb_user_base_t base;
     125             : 
     126             :   uchar impl[ 4096 ] __attribute__((aligned(64)));
     127             : };
     128             : 
     129             : FD_PROTOTYPES_BEGIN
     130             : 
     131             : static inline ulong
     132           0 : fd_accdb_user_align( void ) {
     133           0 :   return alignof(fd_accdb_user_t);
     134           0 : }
     135             : 
     136             : static inline ulong
     137           0 : fd_accdb_user_footprint( void ) {
     138           0 :   return sizeof(fd_accdb_user_t);
     139           0 : }
     140             : 
     141             : static inline void
     142          66 : fd_accdb_user_fini( fd_accdb_user_t * accdb ) {
     143          66 :   accdb->base.vt->fini( accdb );
     144          66 :   accdb->base.accdb_type = 0;
     145          66 : }
     146             : 
     147             : FD_PROTOTYPES_END
     148             : 
     149             : #endif /* HEADER_fd_src_flamenco_accdb_fd_accdb_user_h */

Generated by: LCOV version 1.14