Skip to content

Commit 39375b6

Browse files
wip
1 parent 2bb6f23 commit 39375b6

File tree

3 files changed

+19
-69
lines changed

3 files changed

+19
-69
lines changed

src/flamenco/rewards/fd_rewards.c

Lines changed: 13 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ calculate_stake_points_and_credits( fd_stake_history_t const * stake_history
172172
static int
173173
calculate_stake_rewards( fd_stake_history_t const * stake_history,
174174
fd_stake_delegation_t const * stake,
175-
fd_vote_state_versioned_t * vote_state_versioned,
175+
uchar commission,
176176
fd_vote_state_ele_t const * vote_state,
177177
ulong rewarded_epoch,
178178
fd_point_value_t * point_value,
@@ -211,7 +211,7 @@ calculate_stake_rewards( fd_stake_history_t const * stake_history,
211211
}
212212

213213
fd_commission_split_t split_result;
214-
fd_vote_commission_split( vote_state_versioned, rewards, &split_result );
214+
fd_vote_commission_split( commission, rewards, &split_result );
215215
if( split_result.is_split && (split_result.voter_portion == 0 || split_result.staker_portion == 0) ) {
216216
return 1;
217217
}
@@ -226,7 +226,6 @@ calculate_stake_rewards( fd_stake_history_t const * stake_history,
226226
static int
227227
redeem_rewards( fd_stake_history_t const * stake_history,
228228
fd_stake_delegation_t const * stake,
229-
fd_vote_state_versioned_t * vote_state_versioned,
230229
fd_vote_state_ele_t const * vote_state,
231230
ulong rewarded_epoch,
232231
fd_point_value_t * point_value,
@@ -236,7 +235,7 @@ redeem_rewards( fd_stake_history_t const * stake_history,
236235
int rc = calculate_stake_rewards(
237236
stake_history,
238237
stake,
239-
vote_state_versioned,
238+
vote_state->commission,
240239
vote_state,
241240
rewarded_epoch,
242241
point_value,
@@ -315,34 +314,6 @@ get_minimum_stake_delegation( fd_exec_slot_ctx_t const * slot_ctx ) {
315314
return 1;
316315
}
317316

318-
static fd_vote_state_versioned_t *
319-
deserialize_vote_account( fd_exec_slot_ctx_t const * slot_ctx,
320-
fd_pubkey_t const * vote_account_pubkey,
321-
fd_spad_t * runtime_spad ) {
322-
323-
FD_TXN_ACCOUNT_DECL( vote_account );
324-
if( FD_UNLIKELY( fd_txn_account_init_from_funk_readonly( vote_account,
325-
vote_account_pubkey,
326-
slot_ctx->funk,
327-
slot_ctx->funk_txn ) ) ) {
328-
FD_LOG_DEBUG(( "Vote account not found" ));
329-
return NULL;
330-
}
331-
332-
// Deserialize the vote account and ensure its in the correct state
333-
int err;
334-
fd_vote_state_versioned_t * res = fd_bincode_decode_spad(
335-
vote_state_versioned, runtime_spad,
336-
fd_txn_account_get_data( vote_account ),
337-
fd_txn_account_get_data_len( vote_account ),
338-
&err );
339-
if( FD_UNLIKELY( err ) ) {
340-
return NULL;
341-
}
342-
343-
return res;
344-
}
345-
346317
static uint128
347318
calculate_points_all( fd_exec_slot_ctx_t const * slot_ctx,
348319
fd_bank_t * bank,
@@ -359,6 +330,8 @@ calculate_points_all( fd_exec_slot_ctx_t const * slot_ctx,
359330
fd_stake_delegation_map_t * stake_delegation_map = fd_stake_delegations_get_map( stake_delegations );
360331
fd_stake_delegation_t * stake_delegation_pool = fd_stake_delegations_get_pool( stake_delegations );
361332

333+
334+
ulong curr_epoch = fd_bank_epoch_get( bank );
362335
for( fd_stake_delegation_map_iter_t iter = fd_stake_delegation_map_iter_init( stake_delegation_map, stake_delegation_pool );
363336
!fd_stake_delegation_map_iter_done( iter, stake_delegation_map, stake_delegation_pool );
364337
iter = fd_stake_delegation_map_iter_next( iter, stake_delegation_map, stake_delegation_pool ) ) {
@@ -371,8 +344,10 @@ calculate_points_all( fd_exec_slot_ctx_t const * slot_ctx,
371344
fd_vote_states_t const * vote_states = fd_bank_vote_states_locking_query( slot_ctx->bank );
372345
fd_vote_state_ele_t * vote_state_ele = fd_vote_states_query( vote_states, &stake_delegation->vote_account );
373346
if( FD_UNLIKELY( !vote_state_ele ) ) {
374-
FD_LOG_WARNING(( "failed to query vote state" ));
347+
FD_LOG_WARNING(( "failed to query vote state %lu %lu %lu %lu", stake_delegation->stake, stake_delegation->activation_epoch, stake_delegation->deactivation_epoch, curr_epoch ));
375348
continue;
349+
} else {
350+
FD_LOG_WARNING(( "queried vote state %lu %lu %lu %lu", stake_delegation->stake, stake_delegation->activation_epoch, stake_delegation->deactivation_epoch, curr_epoch ));
376351
}
377352

378353
uint128 account_points;
@@ -474,15 +449,9 @@ calculate_stake_vote_rewards_account( fd_exec_slot_ctx_t const *
474449
}
475450
}
476451

477-
fd_pubkey_t const * voter_acc = &stake_delegation->vote_account;
478-
fd_vote_state_versioned_t * vote_state = deserialize_vote_account( slot_ctx, voter_acc, spad );
479-
if( FD_UNLIKELY( !vote_state ) ) {
480-
FD_LOG_WARNING(( "failed to deserialize vote account" ));
481-
continue;
482-
}
483-
484-
fd_vote_states_t const * vote_states = fd_bank_vote_states_locking_query( slot_ctx->bank );
485-
fd_vote_state_ele_t * vote_state_ele = fd_vote_states_query( vote_states, voter_acc );
452+
fd_pubkey_t const * voter_acc = &stake_delegation->vote_account;
453+
fd_vote_states_t const * vote_states = fd_bank_vote_states_locking_query( slot_ctx->bank );
454+
fd_vote_state_ele_t * vote_state_ele = fd_vote_states_query( vote_states, voter_acc );
486455
if( FD_UNLIKELY( !vote_state_ele ) ) {
487456
FD_LOG_WARNING(( "failed to query vote state" ));
488457
continue;
@@ -494,7 +463,6 @@ calculate_stake_vote_rewards_account( fd_exec_slot_ctx_t const *
494463
int err = redeem_rewards(
495464
stake_history,
496465
stake_delegation,
497-
vote_state,
498466
vote_state_ele,
499467
rewarded_epoch,
500468
point_value,
@@ -511,29 +479,12 @@ calculate_stake_vote_rewards_account( fd_exec_slot_ctx_t const *
511479
fd_solcap_write_stake_reward_event( capture_ctx->capture,
512480
&stake_delegation->stake_account,
513481
voter_acc,
514-
fd_vote_account_commission( vote_state ),
482+
vote_state_ele->commission,
515483
(long)calculated_stake_rewards->voter_rewards,
516484
(long)calculated_stake_rewards->staker_rewards,
517485
(long)calculated_stake_rewards->new_credits_observed );
518486
}
519487

520-
/* Fetch the comission for the vote account */
521-
uchar commission = 0;
522-
switch( vote_state->discriminant ) {
523-
case fd_vote_state_versioned_enum_current:
524-
commission = vote_state->inner.current.commission;
525-
break;
526-
case fd_vote_state_versioned_enum_v0_23_5:
527-
commission = vote_state->inner.v0_23_5.commission;
528-
break;
529-
case fd_vote_state_versioned_enum_v1_14_11:
530-
commission = vote_state->inner.v1_14_11.commission;
531-
break;
532-
default:
533-
FD_LOG_DEBUG(( "unsupported vote account" ));
534-
continue;
535-
}
536-
537488
// Find and update the vote reward node in the local map
538489
fd_vote_reward_t_mapnode_t vote_map_key[1];
539490
vote_map_key->elem.pubkey = *voter_acc;
@@ -548,7 +499,7 @@ calculate_stake_vote_rewards_account( fd_exec_slot_ctx_t const *
548499
if( vote_reward_node==NULL ) {
549500
vote_reward_node = fd_vote_reward_t_map_acquire( vote_reward_map_pool );
550501
vote_reward_node->elem.pubkey = *voter_acc;
551-
vote_reward_node->elem.commission = commission;
502+
vote_reward_node->elem.commission = vote_state_ele->commission;
552503
vote_reward_node->elem.vote_rewards = calculated_stake_rewards->voter_rewards;
553504
vote_reward_node->elem.needs_store = 1;
554505
fd_vote_reward_t_map_insert( vote_reward_map_pool, &vote_reward_map_root, vote_reward_node );

src/flamenco/runtime/program/fd_vote_program.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,10 +2155,9 @@ fd_vote_record_timestamp_vote_with_slot( fd_pubkey_t const * vote_acc,
21552155

21562156
// https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/state/mod.rs#L543
21572157
void
2158-
fd_vote_commission_split( fd_vote_state_versioned_t * vote_state_versioned,
2159-
ulong on,
2160-
fd_commission_split_t * result ) {
2161-
uchar commission = (uchar)fd_vote_account_commission( vote_state_versioned );
2158+
fd_vote_commission_split( uchar commission,
2159+
ulong on,
2160+
fd_commission_split_t * result ) {
21622161
uint commission_split = fd_uint_min( (uint)commission, 100 );
21632162
result->is_split = ( commission_split != 0 && commission_split != 100 );
21642163
// https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/state/mod.rs#L545

src/flamenco/runtime/program/fd_vote_program.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ fd_vote_account_commission( fd_vote_state_versioned_t const * vote_state_version
102102
}
103103

104104
void
105-
fd_vote_commission_split( fd_vote_state_versioned_t * vote_state_versioned,
106-
ulong on,
107-
fd_commission_split_t * result );
105+
fd_vote_commission_split( uchar commission,
106+
ulong on,
107+
fd_commission_split_t * result );
108108

109109
void
110110
fd_vote_store_account( fd_txn_account_t * vote_account,

0 commit comments

Comments
 (0)