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