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( ulong key, 23 : ulong part_width, 24 0 : ulong part_cnt ) { 25 : 26 0 : if( part_cnt==1UL ) return 0UL; 27 0 : if( key==0UL ) return 0UL; 28 : 29 0 : ulong part = key / part_width; 30 0 : part = fd_ulong_if( part>=part_cnt, part_cnt-1UL, part ); 31 0 : return part; 32 : 33 0 : } 34 : 35 : /* fd_rent_partition_to_key returns the lower bound (inclusive) of the 36 : pubkey range that this rent partition spans. Loosely corresponds to 37 : Bank::pubkey_range_from_partition. if opt_last_key!=NULL then 38 : *opt_last_key is the last key of this partition. This is not 39 : necessarily (return_value + part_width). */ 40 : 41 : static inline ulong 42 : fd_rent_partition_to_key( ulong partition_idx, 43 : ulong part_width, 44 : ulong part_cnt, 45 0 : ulong * opt_last_key ) { 46 0 : 47 0 : ulong key0; 48 0 : ulong key1; 49 0 : 50 0 : if( part_cnt<=1UL ) { 51 0 : key0 = 0UL; 52 0 : key1 = ULONG_MAX; 53 0 : } else { 54 0 : key0 = partition_idx * part_width; 55 0 : key1 = fd_ulong_if( partition_idx==part_cnt-1UL, 56 0 : ULONG_MAX, 57 0 : key0 + part_width - 1UL ); 58 0 : } 59 0 : 60 0 : if( opt_last_key ) *opt_last_key = key1; 61 0 : return key0; 62 0 : 63 0 : } 64 : 65 : #endif /* HEADER_fd_src_flamenco_runtime_fd_rent_lists_h */