Skip to content

Commit f37a5d2

Browse files
committed
flamenco: vote states v4
1 parent 05aef62 commit f37a5d2

33 files changed

+3037
-1427
lines changed

src/choreo/voter/fd_voter.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616

1717
#define FD_VOTER_V2 (1)
1818
#define FD_VOTER_V3 (2)
19+
#define FD_VOTER_V4 (3)
1920
FD_STATIC_ASSERT( FD_VOTER_V2==fd_vote_state_versioned_enum_v1_14_11, FD_VOTER_V2 );
20-
FD_STATIC_ASSERT( FD_VOTER_V3==fd_vote_state_versioned_enum_current, FD_VOTER_V3 );
21+
FD_STATIC_ASSERT( FD_VOTER_V3==fd_vote_state_versioned_enum_v3, FD_VOTER_V3 );
22+
FD_STATIC_ASSERT( FD_VOTER_V4==fd_vote_state_versioned_enum_v4, FD_VOTER_V4 );
2123

22-
/* fd_voter describes the layout of a vote state stored in a vote
24+
/* TODO: Update for vote state v4
25+
26+
fd_voter describes the layout of a vote state stored in a vote
2327
account. These structs are used to support zero-copy access (direct
2428
casts) of byte arrays containing the vote account data.
2529

src/flamenco/features/fd_features_generated.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,12 @@ fd_feature_id_t const ids[] = {
17271727
.name = "static_instruction_limit",
17281728
.cleaned_up = {UINT_MAX, UINT_MAX, UINT_MAX} },
17291729

1730+
{ .index = offsetof(fd_features_t, vote_state_v4)>>3,
1731+
.id = {"\xec\xfa\x3a\xf2\xab\xa3\x21\x89\x19\xf4\xc3\x4c\x05\xdf\x88\xf0\x79\x57\x48\xf1\x3e\x35\x12\x0b\x7b\x56\xaa\xae\x3f\xe9\x98\x58"},
1732+
/* Gx4XFcrVMt4HUvPzTpTSVkdDVgcDSjKhDN1RqRS6KDuZ */
1733+
.name = "vote_state_v4",
1734+
.cleaned_up = {UINT_MAX, UINT_MAX, UINT_MAX} },
1735+
17301736
{ .index = ULONG_MAX }
17311737
};
17321738
/* TODO replace this with fd_map_perfect */
@@ -1986,6 +1992,7 @@ fd_feature_id_query( ulong prefix ) {
19861992
case 0x55792888a8cf31ef: return &ids[ 250 ];
19871993
case 0xf4792febab30b80c: return &ids[ 251 ];
19881994
case 0xdab5b6a991a03e4b: return &ids[ 252 ];
1995+
case 0x8921a3abf23afaec: return &ids[ 253 ];
19891996
default: break;
19901997
}
19911998
return NULL;
@@ -2244,4 +2251,5 @@ FD_STATIC_ASSERT( offsetof( fd_features_t, enforce_fixed_fec_set
22442251
FD_STATIC_ASSERT( offsetof( fd_features_t, increase_cpi_account_info_limit )>>3==250UL, layout );
22452252
FD_STATIC_ASSERT( offsetof( fd_features_t, deprecate_rent_exemption_threshold )>>3==251UL, layout );
22462253
FD_STATIC_ASSERT( offsetof( fd_features_t, static_instruction_limit )>>3==252UL, layout );
2254+
FD_STATIC_ASSERT( offsetof( fd_features_t, vote_state_v4 )>>3==253UL, layout );
22472255
FD_STATIC_ASSERT( sizeof( fd_features_t )>>3==FD_FEATURE_ID_CNT, layout );

src/flamenco/features/fd_features_generated.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
#endif
99

1010
/* FEATURE_ID_CNT is the number of features in ids */
11-
#define FD_FEATURE_ID_CNT (253UL)
11+
#define FD_FEATURE_ID_CNT (254UL)
1212

1313
/* Feature set ID calculated from all feature names */
14-
#define FD_FEATURE_SET_ID (3650511804U)
14+
#define FD_FEATURE_SET_ID (2034823332U)
1515

1616
union fd_features {
1717
ulong f[ FD_FEATURE_ID_CNT ];
@@ -269,5 +269,6 @@ union fd_features {
269269
/* 0x55792888a8cf31ef */ ulong increase_cpi_account_info_limit;
270270
/* 0xf4792febab30b80c */ ulong deprecate_rent_exemption_threshold;
271271
/* 0xdab5b6a991a03e4b */ ulong static_instruction_limit;
272+
/* 0x8921a3abf23afaec */ ulong vote_state_v4;
272273
};
273274
};

src/flamenco/features/feature_map.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,5 +251,6 @@
251251
{"name":"enforce_fixed_fec_set","pubkey":"fixfecLZYMfkGzwq6NJA11Yw6KYztzXiK9QcL3K78in"},
252252
{"name":"increase_cpi_account_info_limit","pubkey":"H6iVbVaDZgDphcPbcZwc5LoznMPWQfnJ1AM7L1xzqvt5"},
253253
{"name":"deprecate_rent_exemption_threshold","pubkey":"rent6iVy6PDoViPBeJ6k5EJQrkj62h7DPyLbWGHwjrC"},
254-
{"name":"static_instruction_limit","pubkey":"64ixypL1HPu8WtJhNSMb9mSgfFaJvsANuRkTbHyuLfnx"}
254+
{"name":"static_instruction_limit","pubkey":"64ixypL1HPu8WtJhNSMb9mSgfFaJvsANuRkTbHyuLfnx"},
255+
{"name":"vote_state_v4","pubkey":"Gx4XFcrVMt4HUvPzTpTSVkdDVgcDSjKhDN1RqRS6KDuZ"}
255256
]

src/flamenco/genesis/fd_genesis_create.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ genesis_create( void * buf,
121121

122122
FD_SCRATCH_SCOPE_BEGIN {
123123
fd_vote_state_versioned_t vsv[1];
124-
fd_vote_state_versioned_new_disc( vsv, fd_vote_state_versioned_enum_current );
124+
fd_vote_state_versioned_new_disc( vsv, fd_vote_state_versioned_enum_v3 );
125125

126-
fd_vote_state_t * vs = &vsv->inner.current;
126+
fd_vote_state_v3_t * vs = &vsv->inner.v3;
127127
vs->node_pubkey = options->identity_pubkey;
128128
vs->authorized_withdrawer = options->identity_pubkey;
129129
vs->commission = 100;

src/flamenco/rewards/fd_rewards.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,11 @@ get_vote_credits( uchar const * account_data,
113113
case fd_vote_state_versioned_enum_v1_14_11:
114114
*credits = vsv->inner.v1_14_11.epoch_credits;
115115
break;
116-
case fd_vote_state_versioned_enum_current:
117-
*credits = vsv->inner.current.epoch_credits;
116+
case fd_vote_state_versioned_enum_v3:
117+
*credits = vsv->inner.v3.epoch_credits;
118+
break;
119+
case fd_vote_state_versioned_enum_v4:
120+
*credits = vsv->inner.v4.epoch_credits;
118121
break;
119122
default:
120123
__builtin_unreachable();

src/flamenco/runtime/fd_runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ struct fd_runtime {
9696
uchar authorized_voters_mem [ FD_AUTHORIZED_VOTERS_FOOTPRINT ] __attribute__((aligned(FD_AUTHORIZED_VOTERS_ALIGN)));
9797
uchar vote_state_landed_votes_mem[ FD_LANDED_VOTES_FOOTPRINT ] __attribute__((aligned(FD_LANDED_VOTES_ALIGN)));
9898
uchar tower_sync_landed_votes_mem[ FD_LANDED_VOTES_FOOTPRINT ] __attribute__((aligned(FD_LANDED_VOTES_ALIGN)));
99+
uchar vote_lockout_mem [ FD_VOTE_LOCKOUTS_FOOTPRINT ] __attribute__((aligned(FD_VOTE_LOCKOUTS_ALIGN)));
99100
} tower_sync;
100101

101102
struct {

src/flamenco/runtime/program/fd_stake_program.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ get_stake_status( fd_exec_instr_ctx_t const * invoke_context,
11891189

11901190
// https://github.com/anza-xyz/agave/blob/c8685ce0e1bb9b26014f1024de2cd2b8c308cbde/sdk/program/src/vote/state/mod.rs#L740
11911191
static ulong
1192-
get_credits( fd_vote_state_t const * vote_state ) {
1192+
get_credits( fd_vote_state_v3_t const * vote_state ) {
11931193

11941194
return ( deq_fd_vote_epoch_credits_t_empty( vote_state->epoch_credits )
11951195
? 0
@@ -1205,7 +1205,7 @@ redelegate_stake( fd_exec_instr_ctx_t const * ctx,
12051205
fd_stake_t * stake,
12061206
ulong stake_lamports,
12071207
fd_pubkey_t const * voter_pubkey,
1208-
fd_vote_state_t const * vote_state,
1208+
fd_vote_state_v3_t const * vote_state,
12091209
fd_sol_sysvar_clock_t const * clock,
12101210
fd_stake_history_t const * stake_history,
12111211
uint * custom_err ) {
@@ -1247,10 +1247,10 @@ redelegate_stake( fd_exec_instr_ctx_t const * ctx,
12471247

12481248
// https://github.com/anza-xyz/agave/blob/c8685ce0e1bb9b26014f1024de2cd2b8c308cbde/programs/stake/src/stake_state.rs#L202
12491249
static fd_stake_t
1250-
new_stake( ulong stake,
1251-
fd_pubkey_t const * voter_pubkey,
1252-
fd_vote_state_t const * vote_state,
1253-
ulong activation_epoch ) {
1250+
new_stake( ulong stake,
1251+
fd_pubkey_t const * voter_pubkey,
1252+
fd_vote_state_v3_t const * vote_state,
1253+
ulong activation_epoch ) {
12541254
// https://github.com/anza-xyz/agave/blob/c8685ce0e1bb9b26014f1024de2cd2b8c308cbde/programs/stake/src/stake_state.rs#L208
12551255
return ( fd_stake_t ){
12561256
.delegation = {.voter_pubkey = *voter_pubkey,
@@ -1465,7 +1465,7 @@ delegate( fd_exec_instr_ctx_t const * ctx,
14651465
ctx->runtime->stake_program.delegate.landed_votes_mem );
14661466
fd_stake_t stake = new_stake( stake_amount,
14671467
vote_pubkey,
1468-
&vote_state->inner.current,
1468+
&vote_state->inner.v3,
14691469
clock->epoch );
14701470
// https://github.com/anza-xyz/agave/blob/c8685ce0e1bb9b26014f1024de2cd2b8c308cbde/programs/stake/src/stake_state.rs#L343
14711471
fd_stake_state_v2_t new_stake_state = { .discriminant = fd_stake_state_v2_enum_stake,
@@ -1502,7 +1502,7 @@ delegate( fd_exec_instr_ctx_t const * ctx,
15021502
&stake,
15031503
stake_amount,
15041504
vote_pubkey,
1505-
&vote_state->inner.current,
1505+
&vote_state->inner.v3,
15061506
clock,
15071507
stake_history,
15081508
&ctx->txn_out->err.custom_err );
@@ -2443,7 +2443,7 @@ deactivate_delinquent( fd_exec_instr_ctx_t * ctx,
24432443
fd_vote_convert_to_current( delinquent_vote_state_versioned,
24442444
ctx->runtime->stake_program.deactivate_delinquent.delinquent_authorized_voters_mem,
24452445
ctx->runtime->stake_program.deactivate_delinquent.delinquent_landed_votes_mem );
2446-
fd_vote_state_t delinquent_vote_state = delinquent_vote_state_versioned->inner.current;
2446+
fd_vote_state_v3_t delinquent_vote_state = delinquent_vote_state_versioned->inner.v3;
24472447

24482448
/* https://github.com/anza-xyz/agave/blob/v2.1.14/programs/stake/src/stake_state.rs#L924 */
24492449
fd_guarded_borrowed_account_t reference_vote_account = {0};
@@ -2459,7 +2459,7 @@ deactivate_delinquent( fd_exec_instr_ctx_t * ctx,
24592459
fd_vote_convert_to_current( reference_vote_state_versioned,
24602460
ctx->runtime->stake_program.deactivate_delinquent.reference_authorized_voters_mem,
24612461
ctx->runtime->stake_program.deactivate_delinquent.reference_landed_votes_mem );
2462-
fd_vote_state_t reference_vote_state = reference_vote_state_versioned->inner.current;
2462+
fd_vote_state_v3_t reference_vote_state = reference_vote_state_versioned->inner.v3;
24632463

24642464
// https://github.com/anza-xyz/agave/blob/c8685ce0e1bb9b26014f1024de2cd2b8c308cbde/programs/stake/src/stake_state.rs#L933
24652465
if( !acceptable_reference_epoch_credits( reference_vote_state.epoch_credits, current_epoch ) ) {

0 commit comments

Comments
 (0)