Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_runtime_fd_acc_mgr_h 2 : #define HEADER_fd_src_flamenco_runtime_fd_acc_mgr_h 3 : 4 : /* fd_acc_mgr provides APIs for the Solana account database. */ 5 : 6 : #include "../../funk/fd_funk_base.h" 7 : #include "../types/fd_types_custom.h" 8 : 9 : #if FD_HAS_AVX 10 : #include "../../util/simd/fd_avx.h" 11 : #endif 12 : 13 : /* FD_ACC_MGR_{SUCCESS,ERR{...}} are account management specific error codes. 14 : To be stored in an int. */ 15 : 16 1020 : #define FD_ACC_MGR_SUCCESS (0) 17 0 : #define FD_ACC_MGR_ERR_UNKNOWN_ACCOUNT (-1) 18 : 19 : #define FD_ACC_NONCE_SZ_MAX (80UL) /* 80 bytes */ 20 : 21 : /* FD_ACC_TOT_SZ_MAX is the size limit of a Solana account in the firedancer 22 : client. This means that it includes the max size of the account (10MiB) 23 : and the associated metadata. */ 24 : 25 0 : #define FD_ACC_TOT_SZ_MAX (FD_RUNTIME_ACC_SZ_MAX + sizeof(fd_account_meta_t)) 26 : 27 : #define FD_ACC_NONCE_TOT_SZ_MAX (FD_ACC_NONCE_SZ_MAX + sizeof(fd_account_meta_t)) 28 : 29 : FD_PROTOTYPES_BEGIN 30 : 31 : /* Account Management APIs **************************************************/ 32 : 33 : /* The following account management APIs are helpers for fd_account_meta_t creation, 34 : existence, and retrieval from funk */ 35 : 36 : static inline fd_account_meta_t * 37 690 : fd_account_meta_init( fd_account_meta_t * m ) { 38 690 : fd_memset( m, 0, sizeof(fd_account_meta_t) ); 39 690 : return m; 40 690 : } 41 : 42 : /* fd_account_meta_exists checks if the account in a funk record exists or was 43 : deleted. Handles NULL input safely. Returns 0 if the account was 44 : deleted (zero lamports, empty data, zero owner). Otherwise, returns 45 : 1. */ 46 : 47 : static inline int 48 204 : fd_account_meta_exists( fd_account_meta_t const * m ) { 49 : 50 204 : if( !m ) return 0; 51 : 52 204 : # if FD_HAS_AVX 53 204 : wl_t o = wl_ldu( m->owner ); 54 204 : int has_owner = !_mm256_testz_si256( o, o ); 55 : # else 56 : int has_owner = 0; 57 : for( ulong i=0UL; i<32UL; i++ ) 58 : has_owner |= m->owner[i]; 59 : has_owner = !!has_owner; 60 : # endif 61 : 62 204 : return ((m->lamports > 0UL) | 63 204 : (m->dlen > 0UL) | 64 204 : (has_owner ) ); 65 : 66 204 : } 67 : 68 : /* Account meta helpers */ 69 : static inline void * 70 351 : fd_account_meta_get_data( fd_account_meta_t * m ) { 71 351 : return ((uchar *) m) + sizeof(fd_account_meta_t); 72 351 : } 73 : 74 : static inline void const * 75 0 : fd_account_meta_get_data_const( fd_account_meta_t const * m ) { 76 0 : return ((uchar const *) m) + sizeof(fd_account_meta_t); 77 0 : } 78 : 79 : static inline ulong 80 0 : fd_account_meta_get_record_sz( fd_account_meta_t const * m ) { 81 0 : return sizeof(fd_account_meta_t) + m->dlen; 82 0 : } 83 : 84 : FD_PROTOTYPES_END 85 : 86 : #endif /* HEADER_fd_src_flamenco_runtime_fd_acc_mgr_h */