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 : #include "../../util/fd_hash32.h" 13 : 14 : struct fd_backup_accidx { 15 : uint const * acc_map; /* map chains */ 16 : fd_accdb_accmeta_t const * acc_pool; /* map ele pool */ 17 : ulong max_accounts; /* map ele pool max */ 18 : ulong seed; /* map hash function */ 19 : uint chain_mask; /* map chain count - 1 */ 20 : 21 : ulong * epoch_slot; /* epoch announced by this reader */ 22 : ulong const * epoch; /* accdb global epoch */ 23 : 24 : uint root_generation; /* newest generation in the snapshot */ 25 : }; 26 : 27 : typedef struct fd_backup_accidx fd_backup_accidx_t; 28 : 29 : FD_PROTOTYPES_BEGIN 30 : 31 : /* fd_backup_accidx_chain returns the acc_map chain that pubkey hashes 32 : to. */ 33 : 34 : FD_FN_PURE static inline ulong 35 : fd_backup_accidx_chain( fd_backup_accidx_t const * idx, 36 60 : uchar const pubkey[ static 32 ] ) { 37 60 : return fd_hash32( pubkey, idx->seed ) & idx->chain_mask; 38 60 : } 39 : 40 : /* fd_backup_accidx_valid returns 1 if ele addresses an acc_pool element, 41 : 0 otherwise. The UINT_MAX chain terminator always fails this test 42 : because accdb rejects max_accounts>=UINT_MAX at creation, so callers 43 : walking a chain need only this one bound check. */ 44 : 45 : FD_FN_PURE static inline int 46 : fd_backup_accidx_valid( fd_backup_accidx_t const * idx, 47 4284 : uint ele ) { 48 4284 : return (ulong)ele < idx->max_accounts; 49 4284 : } 50 : 51 : /* fd_backup_accidx_rooted returns 1 if the account version described by 52 : (generation,lamports) belongs in the snapshot: committed at or below 53 : the root generation, and not a tombstone. */ 54 : 55 : FD_FN_PURE static inline int 56 : fd_backup_accidx_rooted( fd_backup_accidx_t const * idx, 57 : uint generation, 58 2013 : ulong lamports ) { 59 2013 : return ( generation<=idx->root_generation ) & ( lamports!=0UL ); 60 2013 : } 61 : 62 : FD_PROTOTYPES_END 63 : 64 : #endif /* HEADER_fd_src_discof_backup_fd_backup_accidx_h */