Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: add fd_rent_lists.h #1062

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/flamenco/runtime/Local.mk
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
65 changes: 65 additions & 0 deletions src/flamenco/runtime/fd_rent_lists.h
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 */