-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Richard Patel <[email protected]>
- Loading branch information
1 parent
84aefd0
commit 08996aa
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ifdef FD_HAS_INT128 | ||
$(call add-hdrs,fd_rent_lists.h) | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#ifndef HEADER_fd_src_flamenco_runtime_fd_rent_lists_h | ||
#define HEADER_fd_src_flamenco_runtime_fd_rent_lists_h | ||
|
||
/* fd_rent_lists.h provides APIs for managing rent partitions. Rent | ||
partitions are sorted buckets containing the addresses of rent | ||
paying accounts. Due to be removed when rent collection is | ||
disabled on Solana mainnet. */ | ||
|
||
#include "../fd_flamenco_base.h" | ||
|
||
static inline ulong | ||
fd_rent_partition_width( ulong slots_per_epoch ) { | ||
if( FD_UNLIKELY( slots_per_epoch==1UL ) ) return ULONG_MAX; | ||
return (ULONG_MAX - slots_per_epoch + 1UL) / slots_per_epoch + 1UL; | ||
} | ||
|
||
/* fd_rent_key_to_partition returns the partition index that a pubkey | ||
falls into. Returns ULONG_MAX if this key is not part of any | ||
partition. Loosely corresponds to Bank::partition_from_pubkey @*/ | ||
|
||
static inline ulong | ||
fd_rent_key_to_partition( ulong key, | ||
ulong part_width, | ||
ulong part_cnt ) { | ||
|
||
if( part_cnt==1UL ) return 0UL; | ||
if( key==0UL ) return 0UL; | ||
|
||
ulong part = key / part_width; | ||
part = fd_ulong_if( part>=part_cnt, part_cnt-1UL, part ); | ||
return part; | ||
|
||
} | ||
|
||
/* fd_rent_partition_to_key returns the lower bound (inclusive) of the | ||
pubkey range that this rent partition spans. Loosely corresponds to | ||
Bank::pubkey_range_from_partition. if opt_last_key!=NULL then | ||
*opt_last_key is the last key of this partition. This is not | ||
necessarily (return_value + part_width). */ | ||
|
||
static inline ulong | ||
fd_rent_partition_to_key( ulong partition_idx, | ||
ulong part_width, | ||
ulong part_cnt, | ||
ulong * opt_last_key ) { | ||
|
||
ulong key0; | ||
ulong key1; | ||
|
||
if( part_cnt<=1UL ) { | ||
key0 = 0UL; | ||
key1 = ULONG_MAX; | ||
} else { | ||
key0 = partition_idx * part_width; | ||
key1 = fd_ulong_if( partition_idx==part_cnt-1UL, | ||
ULONG_MAX, | ||
key0 + part_width - 1UL ); | ||
} | ||
|
||
if( opt_last_key ) *opt_last_key = key1; | ||
return key0; | ||
|
||
} | ||
|
||
#endif /* HEADER_fd_src_flamenco_runtime_fd_rent_lists_h */ |