Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_runtime_fd_rent_lists_h 2 : #define HEADER_fd_src_flamenco_runtime_fd_rent_lists_h 3 : 4 : /* fd_rent_lists.h provides APIs for managing rent partitions. Rent 5 : partitions are sorted buckets containing the addresses of rent 6 : paying accounts. Due to be removed when rent collection is 7 : disabled on Solana mainnet. */ 8 : 9 : #include "../fd_flamenco_base.h" 10 : 11 : static inline ulong 12 0 : fd_rent_partition_width( ulong slots_per_epoch ) { 13 0 : if( FD_UNLIKELY( slots_per_epoch==1UL ) ) return ULONG_MAX; 14 0 : return (ULONG_MAX - slots_per_epoch + 1UL) / slots_per_epoch + 1UL; 15 0 : } 16 : 17 : /* fd_rent_key_to_partition returns the partition index that a pubkey 18 : falls into. Returns ULONG_MAX if this key is not part of any 19 : partition. Loosely corresponds to Bank::partition_from_pubkey @*/ 20 : 21 : static inline ulong 22 : fd_rent_key_to_partition( fd_pubkey_t const * pubkey, 23 : ulong part_width, 24 0 : ulong part_cnt ) { 25 : 26 0 : ulong prefixX_be = pubkey->ul[0]; 27 0 : ulong key = fd_ulong_bswap( prefixX_be ); 28 : 29 0 : if( part_cnt==1UL ) return 0UL; 30 0 : if( key==0UL ) return 0UL; 31 : 32 0 : ulong part = key / part_width; 33 0 : part = fd_ulong_if( part>=part_cnt, part_cnt-1UL, part ); 34 0 : return part; 35 : 36 0 : } 37 : 38 : /* fd_rent_partition_to_key returns the lower bound (inclusive) of the 39 : pubkey range that this rent partition spans. Loosely corresponds to 40 : Bank::pubkey_range_from_partition. if opt_last_key!=NULL then 41 : *opt_last_key is the last key of this partition. This is not 42 : necessarily (return_value + part_width). */ 43 : 44 : static inline ulong 45 : fd_rent_partition_to_key( ulong partition_idx, 46 : ulong part_width, 47 : ulong part_cnt, 48 0 : ulong * opt_last_key ) { 49 0 : 50 0 : ulong key0; 51 0 : ulong key1; 52 0 : 53 0 : if( part_cnt<=1UL ) { 54 0 : key0 = 0UL; 55 0 : key1 = ULONG_MAX; 56 0 : } else { 57 0 : key0 = partition_idx * part_width; 58 0 : key1 = fd_ulong_if( partition_idx==part_cnt-1UL, 59 0 : ULONG_MAX, 60 0 : key0 + part_width - 1UL ); 61 0 : } 62 0 : 63 0 : if( opt_last_key ) *opt_last_key = key1; 64 0 : return key0; 65 0 : 66 0 : } 67 : 68 : #endif /* HEADER_fd_src_flamenco_runtime_fd_rent_lists_h */