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