LCOV - code coverage report
Current view: top level - flamenco - fd_flamenco_base.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 28 49 57.1 %
Date: 2025-03-20 12:08:36 Functions: 5 905 0.6 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_fd_flamenco_base_h
       2             : #define HEADER_fd_src_flamenco_fd_flamenco_base_h
       3             : 
       4             : #include "../ballet/base58/fd_base58.h"
       5             : #include "../ballet/sha256/fd_sha256.h"
       6             : #include "types/fd_types_custom.h"
       7             : #include "types/fd_cast.h"
       8             : #include <alloca.h>
       9             : 
      10           0 : #define FD_DEFAULT_SLOTS_PER_EPOCH   ( 432000UL )
      11             : #define FD_DEFAULT_SHREDS_PER_EPOCH  ( ( 1 << 15UL ) * FD_DEFAULT_SLOTS_PER_EPOCH )
      12           0 : #define FD_SLOT_NULL                 ( ULONG_MAX )
      13           0 : #define FD_SHRED_IDX_NULL            ( UINT_MAX )
      14             : 
      15          63 : #define FD_FUNK_KEY_TYPE_ACC ((uchar)1)
      16           0 : #define FD_FUNK_KEY_TYPE_ELF_CACHE ((uchar)2)
      17             : 
      18             : /* CLUSTER_VERSION is the default value for the cluster version
      19             :    in the epoch context. This value will foll forward to the
      20             :    latest version.
      21             : */
      22           0 : #define FD_DEFAULT_AGAVE_CLUSTER_VERSION_MAJOR 2
      23           0 : #define FD_DEFAULT_AGAVE_CLUSTER_VERSION_MINOR 0
      24           0 : #define FD_DEFAULT_AGAVE_CLUSTER_VERSION_PATCH 0
      25             : 
      26             : #if FD_HAS_ALLOCA
      27             : 
      28             : /* FD_BASE58_ENC_{32,64}_ALLOCA is a shorthand for fd_base58_encode_{32,64},
      29             :    including defining a temp buffer.  With additional support for passing
      30             :    NULL.  Useful for printf-like functions.
      31             :    Example:
      32             : 
      33             :     fd_pubkey_t pk = ... ;
      34             :     printf("%s", FD_BASE58_ENC_32_ALLOCA( pk ) );
      35             : 
      36             :    The temp buffer is allocated on the stack and therefore invalidated
      37             :    when the function this is used in returns.  NULL will result in
      38             :    "<NULL>".
      39             :    Do NOT use this marco in a long loop or a recursive function.
      40             :    */
      41             : 
      42             : static inline char *
      43             : fd_base58_enc_32_fmt( char *        out,
      44          24 :                       uchar const * in ) {
      45          24 :   if( FD_UNLIKELY( !in ) ) {
      46           3 :     strcpy( out, "<NULL>");
      47          21 :   } else {
      48          21 :     fd_base58_encode_32( in, NULL, out );
      49          21 :   }
      50          24 :   return out;
      51          24 : }
      52             : 
      53           6 : #define FD_BASE58_ENC_32_ALLOCA( x ) __extension__({                   \
      54           6 :   char * _out = fd_alloca_check( 1UL, FD_BASE58_ENCODED_32_SZ );       \
      55           6 :   fd_base58_enc_32_fmt( _out, (uchar const *)(x) );                    \
      56           6 : })
      57             : 
      58             : static inline char *
      59             : fd_base58_enc_64_fmt( char *        out,
      60           6 :                       uchar const * in ) {
      61           6 :   if( FD_UNLIKELY( !in ) ) {
      62           3 :     strcpy( out, "<NULL>");
      63           3 :   } else {
      64           3 :     fd_base58_encode_64( in, NULL, out );
      65           3 :   }
      66           6 :   return out;
      67           6 : }
      68             : 
      69           6 : #define FD_BASE58_ENC_64_ALLOCA( x ) __extension__({                   \
      70           6 :   char * _out = fd_alloca_check( 1UL, FD_BASE58_ENCODED_64_SZ );       \
      71           6 :   fd_base58_enc_64_fmt( _out, (uchar const *)(x) );                    \
      72           6 : })
      73             : 
      74             : #endif /* FD_HAS_ALLOCA */
      75             : 
      76             : /* Forward declarations */
      77             : 
      78             : struct fd_exec_epoch_ctx;
      79             : typedef struct fd_exec_epoch_ctx fd_exec_epoch_ctx_t;
      80             : 
      81             : struct fd_exec_slot_ctx;
      82             : typedef struct fd_exec_slot_ctx fd_exec_slot_ctx_t;
      83             : 
      84             : struct fd_exec_txn_ctx;
      85             : typedef struct fd_exec_txn_ctx fd_exec_txn_ctx_t;
      86             : 
      87             : struct fd_exec_instr_ctx;
      88             : typedef struct fd_exec_instr_ctx fd_exec_instr_ctx_t;
      89             : 
      90             : struct fd_acc_mgr;
      91             : typedef struct fd_acc_mgr fd_acc_mgr_t;
      92             : 
      93             : struct fd_capture_ctx;
      94             : typedef struct fd_capture_ctx fd_capture_ctx_t;
      95             : 
      96             : /* fd_rawtxn_b_t is a convenience type to store a pointer to a
      97             :    serialized transaction.  Should probably be removed in the future. */
      98             : 
      99             : struct fd_rawtxn_b {
     100             :   void * raw;
     101             :   ushort txn_sz;
     102             : };
     103             : typedef struct fd_rawtxn_b fd_rawtxn_b_t;
     104             : 
     105             : FD_PROTOTYPES_BEGIN
     106             : 
     107             : /* fd_acct_addr_cstr converts the given Solana address into a base58-
     108             :    encoded cstr.  Returns cstr.  On return cstr contains a string with
     109             :    length in [32,44] (excluding NULL terminator). */
     110             : 
     111             : static inline char *
     112             : fd_acct_addr_cstr( char        cstr[ static FD_BASE58_ENCODED_32_SZ ],
     113           6 :                    uchar const addr[ static 32 ] ) {
     114           6 :   return fd_base58_encode_32( addr, NULL, cstr );
     115           6 : }
     116             : 
     117             : /* fd_pod utils */
     118             : 
     119             : FD_FN_UNUSED static fd_pubkey_t *
     120             : fd_pod_query_pubkey( uchar const * pod,
     121             :                      char const *  path,
     122           0 :                      fd_pubkey_t * val ) {
     123           0 : 
     124           0 :   ulong        bufsz = 0UL;
     125           0 :   void const * buf   = fd_pod_query_buf( pod, path, &bufsz );
     126           0 : 
     127           0 :   if( FD_UNLIKELY( (!buf) | (bufsz!=sizeof(fd_pubkey_t)) ) )
     128           0 :     return NULL;
     129           0 : 
     130           0 :   memcpy( val->uc, buf, sizeof(fd_pubkey_t) );
     131           0 :   return val;
     132           0 : }
     133             : 
     134             : static inline ulong
     135             : fd_pod_insert_pubkey( uchar *             pod,
     136             :                       char const *        path,
     137           0 :                       fd_pubkey_t const * val ) {
     138           0 :   return fd_pod_insert_buf( pod, path, val->uc, sizeof(fd_pubkey_t) );
     139           0 : }
     140             : 
     141             : FD_PROTOTYPES_END
     142             : 
     143             : #endif /* HEADER_fd_src_flamenco_fd_flamenco_base_h */

Generated by: LCOV version 1.14