Line data Source code
1 : #ifndef HEADER_fd_src_discof_backup_fd_backup_accidx_h 2 : #define HEADER_fd_src_discof_backup_fd_backup_accidx_h 3 : 4 : /* fd_backup_accidx.h provides a read-only view of the accdb in-memory 5 : account index for snapshot production. 6 : 7 : The index is a chained hash map keyed by account address. acc_map is 8 : an array of (chain_mask+1) chain heads, each an index into acc_pool 9 : or UINT_MAX for "end of chain". */ 10 : 11 : #include "../../flamenco/accdb/fd_accdb_private.h" 12 : 13 : struct fd_backup_accidx { 14 : uint const * acc_map; /* map chains */ 15 : fd_accdb_accmeta_t const * acc_pool; /* map ele pool */ 16 : ulong max_accounts; /* map ele pool max */ 17 : ulong seed; /* map hash function */ 18 : uint chain_mask; /* map chain count - 1 */ 19 : 20 : ulong * epoch_slot; /* epoch announced by this reader */ 21 : ulong const * epoch; /* accdb global epoch */ 22 : 23 : uint root_generation; /* newest generation in the snapshot */ 24 : }; 25 : 26 : typedef struct fd_backup_accidx fd_backup_accidx_t; 27 : 28 : FD_PROTOTYPES_BEGIN 29 : 30 : /* fd_backup_accidx_chain returns the acc_map chain that pubkey hashes 31 : to. */ 32 : 33 : FD_FN_PURE static inline ulong 34 : fd_backup_accidx_chain( fd_backup_accidx_t const * idx, 35 9 : uchar const pubkey[ static 32 ] ) { 36 9 : return fd_accdb_hash( pubkey, idx->seed ) & idx->chain_mask; 37 9 : } 38 : 39 : /* fd_backup_accidx_valid returns 1 if ele addresses an acc_pool element, 40 : 0 otherwise. The UINT_MAX chain terminator always fails this test 41 : because accdb rejects max_accounts>=UINT_MAX at creation, so callers 42 : walking a chain need only this one bound check. */ 43 : 44 : FD_FN_PURE static inline int 45 : fd_backup_accidx_valid( fd_backup_accidx_t const * idx, 46 4221 : uint ele ) { 47 4221 : return (ulong)ele < idx->max_accounts; 48 4221 : } 49 : 50 : /* fd_backup_accidx_rooted returns 1 if the account version described by 51 : (generation,lamports) belongs in the snapshot: committed at or below 52 : the root generation, and not a tombstone. */ 53 : 54 : FD_FN_PURE static inline int 55 : fd_backup_accidx_rooted( fd_backup_accidx_t const * idx, 56 : uint generation, 57 1989 : ulong lamports ) { 58 1989 : return ( generation<=idx->root_generation ) & ( lamports!=0UL ); 59 1989 : } 60 : 61 : FD_PROTOTYPES_END 62 : 63 : #endif /* HEADER_fd_src_discof_backup_fd_backup_accidx_h */