Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion contrib/test/test-vectors-commit-sha.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0a97cc29937eaa6b31e27448f2c43adf758f021c
427914aeaf81891755d7b0eaa443620665b59681
20 changes: 2 additions & 18 deletions src/flamenco/rewards/fd_rewards.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,8 @@ calculate_stake_points_and_credits_recalculation( fd_stake_history_t const *

new_credits_observed = fd_ulong_max( new_credits_observed, final_epoch_credits );

fd_delegation_t delegation = {
.voter_pubkey = stake->vote_account,
.stake = stake->stake,
.activation_epoch = stake->activation_epoch,
.deactivation_epoch = stake->deactivation_epoch,
.warmup_cooldown_rate = stake->warmup_cooldown_rate,
};

ulong stake_amount = fd_stake_activating_and_deactivating(
&delegation,
stake,
recalc_vote_state_credits->epoch[ i ],
stake_history,
new_rate_activation_epoch ).effective;
Expand Down Expand Up @@ -260,16 +252,8 @@ calculate_stake_points_and_credits( fd_accdb_user_t * accdb,

new_credits_observed = fd_ulong_max( new_credits_observed, final_epoch_credits );

fd_delegation_t delegation = {
.voter_pubkey = stake->vote_account,
.stake = stake->stake,
.activation_epoch = stake->activation_epoch,
.deactivation_epoch = stake->deactivation_epoch,
.warmup_cooldown_rate = stake->warmup_cooldown_rate,
};

ulong stake_amount = fd_stake_activating_and_deactivating(
&delegation,
stake,
ele->epoch,
stake_history,
new_rate_activation_epoch ).effective;
Expand Down
2 changes: 1 addition & 1 deletion src/flamenco/runtime/fd_bank.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ fd_banks_stake_delegations_apply_delta( fd_bank_data_t * bank,
stake_delegation->activation_epoch,
stake_delegation->deactivation_epoch,
stake_delegation->credits_observed,
stake_delegation->warmup_cooldown_rate
fd_stake_delegations_warmup_cooldown_rate_to_double( stake_delegation->warmup_cooldown_rate )
);
} else {
fd_stake_delegations_remove( stake_delegations_base, &stake_delegation->stake_account );
Expand Down
9 changes: 0 additions & 9 deletions src/flamenco/runtime/fd_runtime_const.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ FD_PROTOTYPES_BEGIN

#define FD_RUNTIME_INITIAL_BLOCK_ID (0xF17EDA2CE7B1DUL)

/* The stake program is now a BPF program which means that there is a
variable cost in CUs to execute the stake program. This is the
absolute minimum cost of executing the stake program.
FIXME: This is a reasonable estimate based off of BPF withdraw
instructions. The hard bound still needs to be determined. */

#define FD_RUNTIME_MIN_STAKE_INSN_CUS (6000UL)

/* FD_RUNTIME_ACC_SZ_MAX is the protocol level hardcoded size limit of a
Solana account. */

Expand Down
19 changes: 14 additions & 5 deletions src/flamenco/runtime/program/fd_stake_program.c
Original file line number Diff line number Diff line change
Expand Up @@ -3297,10 +3297,19 @@ fd_stake_get_state( fd_account_meta_t const * meta,
}

fd_stake_history_entry_t
fd_stake_activating_and_deactivating( fd_delegation_t const * self,
ulong target_epoch,
fd_stake_history_t const * stake_history,
ulong * new_rate_activation_epoch ) {
fd_stake_activating_and_deactivating( fd_stake_delegation_t const * stake_delegation,
ulong target_epoch,
fd_stake_history_t const * stake_history,
ulong * new_rate_activation_epoch ) {
fd_delegation_t delegation = {
.voter_pubkey = stake_delegation->vote_account,
.stake = stake_delegation->stake,
.deactivation_epoch = stake_delegation->deactivation_epoch==USHORT_MAX ? ULONG_MAX : stake_delegation->deactivation_epoch,
.activation_epoch = stake_delegation->activation_epoch==USHORT_MAX ? ULONG_MAX : stake_delegation->activation_epoch,
.warmup_cooldown_rate = fd_stake_delegations_warmup_cooldown_rate_to_double( stake_delegation->warmup_cooldown_rate ),
};

return stake_activating_and_deactivating(
self, target_epoch, stake_history, new_rate_activation_epoch );
&delegation, target_epoch, stake_history, new_rate_activation_epoch );
}

15 changes: 11 additions & 4 deletions src/flamenco/runtime/program/fd_stake_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,18 @@ int
fd_stake_get_state( fd_account_meta_t const * meta,
fd_stake_state_v2_t * out );

/* TODO: This is a temporary hack to reuse stake program code which
should be refactored out when local ledgers no longer rely on the
deprecated native stake program. */

struct fd_stake_delegation;
typedef struct fd_stake_delegation fd_stake_delegation_t;

fd_stake_history_entry_t
fd_stake_activating_and_deactivating( fd_delegation_t const * self,
ulong target_epoch,
fd_stake_history_t const * stake_history,
ulong * new_rate_activation_epoch );
fd_stake_activating_and_deactivating( fd_stake_delegation_t const * self,
ulong target_epoch,
fd_stake_history_t const * stake_history,
ulong * new_rate_activation_epoch );

FD_PROTOTYPES_END

Expand Down
12 changes: 6 additions & 6 deletions src/flamenco/runtime/test_bank.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ main( int argc, char ** argv ) {
the larger combined frontier state. */

fd_stake_delegations_t * stake_delegations = fd_bank_stake_delegations_delta_locking_modify( bank );
fd_stake_delegations_update( stake_delegations, &key_0, &key_9, 100UL, 100UL, 100UL, 100UL, 100UL );
fd_stake_delegations_update( stake_delegations, &key_0, &key_9, 100UL, 100UL, 100UL, 100UL, 0.09 );

fd_stake_delegation_t const * stake_delegation = fd_stake_delegations_query( stake_delegations, &key_0 );
FD_TEST( fd_stake_delegations_cnt( stake_delegations ) == 1UL );
Expand Down Expand Up @@ -382,8 +382,8 @@ main( int argc, char ** argv ) {
/* Make updates to delta */

stake_delegations = fd_bank_stake_delegations_delta_locking_modify( bank2 );
fd_stake_delegations_update( stake_delegations, &key_0, &key_0, 200UL, 100UL, 100UL, 100UL, 100UL );
fd_stake_delegations_update( stake_delegations, &key_1, &key_8, 100UL, 100UL, 100UL, 100UL, 100UL );
fd_stake_delegations_update( stake_delegations, &key_0, &key_0, 200UL, 100UL, 100UL, 100UL, 0.09 );
fd_stake_delegations_update( stake_delegations, &key_1, &key_8, 100UL, 100UL, 100UL, 100UL, 0.09 );
FD_TEST( fd_stake_delegations_cnt( stake_delegations ) == 2UL );
stake_delegation = fd_stake_delegations_query( stake_delegations, &key_0 );
FD_TEST( stake_delegation );
Expand Down Expand Up @@ -417,7 +417,7 @@ main( int argc, char ** argv ) {
the updates don't get incorrectly applied. */

stake_delegations = fd_bank_stake_delegations_delta_locking_modify( bank3 );
fd_stake_delegations_update( stake_delegations, &key_2, &key_7, 10UL, 100UL, 100UL, 100UL, 100UL );
fd_stake_delegations_update( stake_delegations, &key_2, &key_7, 10UL, 100UL, 100UL, 100UL, 0.09 );
FD_TEST( fd_stake_delegations_cnt( stake_delegations ) == 1UL );
stake_delegation = fd_stake_delegations_query( stake_delegations, &key_2 );
FD_TEST( stake_delegation );
Expand Down Expand Up @@ -483,7 +483,7 @@ main( int argc, char ** argv ) {
FD_TEST( fd_bank_capitalization_get( bank7 ) == 2100UL );

stake_delegations = fd_bank_stake_delegations_delta_locking_modify( bank7 );
fd_stake_delegations_update( stake_delegations, &key_3, &key_6, 7UL, 100UL, 100UL, 100UL, 100UL );
fd_stake_delegations_update( stake_delegations, &key_3, &key_6, 7UL, 100UL, 100UL, 100UL, 0.09 );
stake_delegation = fd_stake_delegations_query( stake_delegations, &key_3 );
FD_TEST( stake_delegation );
FD_TEST( stake_delegation->stake == 7UL );
Expand Down Expand Up @@ -516,7 +516,7 @@ main( int argc, char ** argv ) {
FD_TEST( fd_bank_capitalization_get( bank8 ) == 2100UL );

stake_delegations = fd_bank_stake_delegations_delta_locking_modify( bank8 );
fd_stake_delegations_update( stake_delegations, &key_4, &key_5, 4UL, 100UL, 100UL, 100UL, 100UL );
fd_stake_delegations_update( stake_delegations, &key_4, &key_5, 4UL, 100UL, 100UL, 100UL, 0.09 );
fd_bank_stake_delegations_delta_end_locking_modify( bank8 );

stake_delegations = fd_bank_stake_delegations_frontier_query( banks, bank8 );
Expand Down
2 changes: 1 addition & 1 deletion src/flamenco/runtime/test_static_instruction_limit.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ main( int argc,
fd_boot( &argc, &argv );

char * _page_sz = "normal";
ulong page_cnt = 1000UL;
ulong page_cnt = 2000UL;
ulong numa_idx = fd_shmem_numa_idx( 0 );
fd_wksp_t * wksp = fd_wksp_new_anonymous( fd_cstr_to_shmem_page_sz( _page_sz ),
page_cnt,
Expand Down
49 changes: 31 additions & 18 deletions src/flamenco/stakes/fd_stake_delegations.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#include "../accdb/fd_accdb_pipe.h"
#include "../runtime/program/fd_stake_program.h"

#define POOL_NAME fd_stake_delegation_pool
#define POOL_T fd_stake_delegation_t
#define POOL_NEXT next_
#define POOL_NAME fd_stake_delegation_pool
#define POOL_T fd_stake_delegation_t
#define POOL_NEXT next_
#define POOL_IDX_T uint
#include "../../util/tmpl/fd_pool.c"

#define MAP_NAME fd_stake_delegation_map
Expand All @@ -14,8 +15,20 @@
#define MAP_KEY_EQ(k0,k1) (fd_pubkey_eq( k0, k1 ))
#define MAP_KEY_HASH(key,seed) (fd_funk_rec_key_hash1( key->uc, seed ))
#define MAP_NEXT next_
#define MAP_IDX_T uint
#include "../../util/tmpl/fd_map_chain.c"

static inline uchar
fd_stake_delegations_warmup_cooldown_rate_enum( double warmup_cooldown_rate ) {
if( FD_LIKELY( warmup_cooldown_rate == FD_STAKE_DELEGATIONS_WARMUP_COOLDOWN_RATE_025 ) ) {
return FD_STAKE_DELEGATIONS_WARMUP_COOLDOWN_RATE_ENUM_025;
} else if( FD_LIKELY( warmup_cooldown_rate == FD_STAKE_DELEGATIONS_WARMUP_COOLDOWN_RATE_009 ) ) {
return FD_STAKE_DELEGATIONS_WARMUP_COOLDOWN_RATE_ENUM_009;
} else {
FD_LOG_CRIT(( "Invalid warmup cooldown rate %f", warmup_cooldown_rate ));
}
}

static inline fd_stake_delegation_t *
fd_stake_delegations_get_pool( fd_stake_delegations_t const * stake_delegations ) {
return fd_stake_delegation_pool_join( (uchar *)stake_delegations + stake_delegations->pool_offset_ );
Expand Down Expand Up @@ -227,10 +240,10 @@ fd_stake_delegations_update( fd_stake_delegations_t * stake_delegations,
ulong idx = fd_stake_delegation_map_idx_query_const(
stake_delegation_map,
stake_account,
ULONG_MAX,
UINT_MAX,
stake_delegation_pool );

if( idx!=ULONG_MAX ) {
if( idx!=UINT_MAX ) {

fd_stake_delegation_t * stake_delegation = fd_stake_delegation_pool_ele( stake_delegation_pool, idx );
if( FD_UNLIKELY( !stake_delegation ) ) {
Expand All @@ -239,10 +252,10 @@ fd_stake_delegations_update( fd_stake_delegations_t * stake_delegations,

stake_delegation->vote_account = *vote_account;
stake_delegation->stake = stake;
stake_delegation->activation_epoch = activation_epoch;
stake_delegation->deactivation_epoch = deactivation_epoch;
stake_delegation->activation_epoch = (ushort)fd_ulong_min( activation_epoch, USHORT_MAX );
stake_delegation->deactivation_epoch = (ushort)fd_ulong_min( deactivation_epoch, USHORT_MAX );
stake_delegation->credits_observed = credits_observed;
stake_delegation->warmup_cooldown_rate = warmup_cooldown_rate;
stake_delegation->warmup_cooldown_rate = fd_stake_delegations_warmup_cooldown_rate_enum( warmup_cooldown_rate );
stake_delegation->is_tombstone = 0;
return;
}
Expand All @@ -257,10 +270,10 @@ fd_stake_delegations_update( fd_stake_delegations_t * stake_delegations,
stake_delegation->stake_account = *stake_account;
stake_delegation->vote_account = *vote_account;
stake_delegation->stake = stake;
stake_delegation->activation_epoch = activation_epoch;
stake_delegation->deactivation_epoch = deactivation_epoch;
stake_delegation->activation_epoch = (ushort)fd_ulong_min( activation_epoch, USHORT_MAX );
stake_delegation->deactivation_epoch = (ushort)fd_ulong_min( deactivation_epoch, USHORT_MAX );
stake_delegation->credits_observed = credits_observed;
stake_delegation->warmup_cooldown_rate = warmup_cooldown_rate;
stake_delegation->warmup_cooldown_rate = fd_stake_delegations_warmup_cooldown_rate_enum( warmup_cooldown_rate );
stake_delegation->is_tombstone = 0;

if( FD_UNLIKELY( !fd_stake_delegation_map_ele_insert(
Expand All @@ -287,15 +300,15 @@ fd_stake_delegations_remove( fd_stake_delegations_t * stake_delegations,
ulong delegation_idx = fd_stake_delegation_map_idx_query(
stake_delegation_map,
stake_account,
ULONG_MAX,
UINT_MAX,
stake_delegation_pool );

if( stake_delegations->leave_tombstones_==1 ) {
/* If we are configured to leave tombstones, we need to either
update the entry's is_tombstone flag or insert a new entry. */

fd_stake_delegation_t * stake_delegation = NULL;
if( delegation_idx!=ULONG_MAX ) {
if( delegation_idx!=UINT_MAX ) {
/* The delegation was found, update the is_tombstone flag. */
stake_delegation = fd_stake_delegation_pool_ele( stake_delegation_pool, delegation_idx );
} else {
Expand All @@ -310,7 +323,7 @@ fd_stake_delegations_remove( fd_stake_delegations_t * stake_delegations,
} else {
/* If we are not configured to leave tombstones, we need to remove
the entry from the map and release it from the pool. */
if( FD_UNLIKELY( delegation_idx == ULONG_MAX ) ) {
if( FD_UNLIKELY( delegation_idx==UINT_MAX ) ) {
/* The delegation was not found, nothing to do. */
return;
}
Expand All @@ -322,12 +335,12 @@ fd_stake_delegations_remove( fd_stake_delegations_t * stake_delegations,
FD_LOG_CRIT(( "unable to retrieve stake delegation" ));
}

ulong idx = fd_stake_delegation_map_idx_remove( stake_delegation_map, stake_account, ULONG_MAX, stake_delegation_pool );
if( FD_UNLIKELY( idx==ULONG_MAX ) ) {
ulong idx = fd_stake_delegation_map_idx_remove( stake_delegation_map, stake_account, UINT_MAX, stake_delegation_pool );
if( FD_UNLIKELY( idx==UINT_MAX ) ) {
FD_LOG_CRIT(( "unable to remove stake delegation" ));
}

stake_delegation->next_ = fd_stake_delegation_pool_idx_null( stake_delegation_pool );
stake_delegation->next_ = UINT_MAX;

fd_stake_delegation_pool_idx_release( stake_delegation_pool, delegation_idx );
}
Expand Down Expand Up @@ -385,7 +398,7 @@ fd_stake_delegations_refresh( fd_stake_delegations_t * stake_delegations,
continue; /* ok */

remove:
fd_stake_delegation_map_idx_remove( map, address, ULONG_MAX, pool );
fd_stake_delegation_map_idx_remove( map, address, UINT_MAX, pool );
fd_stake_delegation_pool_ele_release( pool, delegation );
}
}
Expand Down
Loading
Loading