LCOV - code coverage report
Current view: top level - flamenco - fd_flamenco_base.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 32 48 66.7 %
Date: 2025-01-08 12:08:44 Functions: 8 860 0.9 %

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

Generated by: LCOV version 1.14