Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_runtime_fd_acc_pool_h 2 : #define HEADER_fd_src_flamenco_runtime_fd_acc_pool_h 3 : 4 : #include "../../util/fd_util_base.h" 5 : 6 : FD_PROTOTYPES_BEGIN 7 : 8 : struct fd_acc_pool; 9 : typedef struct fd_acc_pool fd_acc_pool_t; 10 : 11 : /* We need to determine the minimum number of accounts that are required 12 : to be able to execute at least one transaction. We will make the 13 : assumption that we can have up to MAX_TX_ACCOUNT_LOCKS (128) writable 14 : accounts. We can also have 2 more writable accounts for the rollback 15 : fee payer and nonce. 16 : 17 : However, in the case where bundles are enabled, we will need to 18 : support the max number of accounts that can be in a bundle. There 19 : can be up to FD_PACK_MAX_TXN_PER_BUNDLE transactions in a bundle. 20 : We also know that each transaction can have up to 21 : MAX_TX_ACCOUNT_LOCKS accounts (and 2 more for the rollback fee payer 22 : and nonce). Technically, the rollback accounts don't need to be 23 : considered for the bundle, but currently the memory for the rollback 24 : accounts is allocated anyway. */ 25 : 26 54 : #define FD_ACC_POOL_MIN_ACCOUNT_CNT_PER_TX (MAX_TX_ACCOUNT_LOCKS + 2UL) 27 : #define FD_ACC_POOL_MIN_ACCOUNT_CNT_PER_BUNDLE (FD_ACC_POOL_MIN_ACCOUNT_CNT_PER_TX * FD_PACK_MAX_TXN_PER_BUNDLE) 28 : 29 : /* fd_acc_pool_align returns the minimum alignment required for a 30 : fd_acc_pool struct. */ 31 : 32 : FD_FN_CONST ulong 33 : fd_acc_pool_align( void ); 34 : 35 : /* fd_acc_pool_footprint returns the footprint of the fd_acc_pool 36 : struct for a given amount of account count. */ 37 : 38 : FD_FN_CONST ulong 39 : fd_acc_pool_footprint( ulong account_cnt ); 40 : 41 : /* fd_acc_pool_new formats a memory region to be an fd_acc_pool_t 42 : object with a given amount of accounts. */ 43 : 44 : void * 45 : fd_acc_pool_new( void * shmem, 46 : ulong account_cnt ); 47 : 48 : /* fd_acc_pool_join joins an fd_acc_pool_t object from a memory 49 : region. There can be multiple valid joins for a given memory 50 : region corresponding to an fd_acc_pool_t object. */ 51 : 52 : fd_acc_pool_t * 53 : fd_acc_pool_join( void * shmem ); 54 : 55 : /* fd_acc_pool_try_acquire attempts to acquire the memory for 56 : request_cnt accounts from the fd_acc_pool_t object. If the requested 57 : number of accounts are not available, returns 1. If successful, 58 : returns 0 and stores the pointers to the accounts in accounts_out. 59 : The caller is responsible for freeing the accounts after use via a 60 : call to fd_acc_pool_release. This function is thread-safe. For i in 61 : [0, request_cnt), accounts_out[i] points to the first byte of the 62 : returned account's buffer. */ 63 : 64 : int 65 : fd_acc_pool_try_acquire( fd_acc_pool_t * acc_pool, 66 : ulong request_cnt, 67 : uchar * * accounts_out ); 68 : 69 : /* fd_acc_pool_acquire is the blocking and non-speculative version of 70 : fd_acc_pool_try_acquire. It will keep trying to acquire the 71 : requested number of accounts until successful. This function 72 : is thread-safe. For i in [0, request_cnt), accounts_out[i] points to 73 : the first byte of the returned account's buffer. */ 74 : 75 : void 76 : fd_acc_pool_acquire( fd_acc_pool_t * acc_pool, 77 : ulong request_cnt, 78 : uchar * * accounts_out ); 79 : 80 : /* fd_acc_pool_release releases the memory for an account back to the 81 : fd_acc_pool_t object. After this is called, the account will be 82 : available for reuse. This function is thread-safe. */ 83 : 84 : void 85 : fd_acc_pool_release( fd_acc_pool_t * acc_pool, 86 : uchar * account ); 87 : 88 : /* fd_acc_pool_free returns the number of free acc_pool elements 89 : atomically. */ 90 : ulong 91 : fd_acc_pool_free( fd_acc_pool_t * acc_pool ); 92 : 93 : FD_PROTOTYPES_END 94 : 95 : #endif /* HEADER_fd_src_flamenco_runtime_fd_acc_pool_h */