Skip to content

Commit e8f1a7d

Browse files
patch
1 parent f359809 commit e8f1a7d

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

src/flamenco/runtime/program/fd_vote_program.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,10 +2043,7 @@ process_tower_sync( fd_borrowed_account_t * vote_account,
20432043
FD_LOG_CRIT(( "vote_states is NULL" ));
20442044
}
20452045
fd_vote_state_ele_t * vote_state_ele = fd_vote_states_query( vote_states, vote_account->acct->pubkey );
2046-
if( !vote_state_ele ) {
2047-
FD_LOG_CRIT(( "vote_state_ele is NULL" ));
2048-
}
2049-
if( FD_LIKELY( lockout && bank_hash_cmp ) ) {
2046+
if( FD_LIKELY( lockout && bank_hash_cmp && vote_state_ele ) ) {
20502047
fd_bank_hash_cmp_lock( bank_hash_cmp );
20512048
fd_bank_hash_cmp_insert(
20522049
bank_hash_cmp,

src/flamenco/runtime/sysvar/fd_sysvar_clock.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ estimate_timestamp( fd_bank_t * bank ) {
123123
/* TODO: actually take the stake-weighted median. For now, just use a node. */
124124
fd_vote_states_t const * vote_states = fd_bank_vote_states_locking_query( bank );
125125

126+
if( !fd_vote_states_cnt( vote_states ) ) {
127+
fd_bank_vote_states_end_locking_query( bank );
128+
return timestamp_from_genesis( bank );
129+
}
130+
126131
fd_vote_state_ele_t * vote_state_pool = fd_vote_states_get_pool( vote_states );
127132
fd_vote_state_map_t * vote_state_map = fd_vote_states_get_map( vote_states );
128133

@@ -134,10 +139,10 @@ estimate_timestamp( fd_bank_t * bank ) {
134139
ulong slots = fd_bank_slot_get( bank ) - vote_state->last_vote_slot;
135140
uint128 ns_correction = fd_bank_ns_per_slot_get( bank ) * slots;
136141

137-
fd_bank_vote_states_end_locking_query( bank );
138142
return vote_state->last_vote_timestamp + (long)(ns_correction / NS_IN_S);
139143
}
140144

145+
fd_bank_vote_states_end_locking_query( bank );
141146
FD_LOG_CRIT(( "unreachable" ));
142147
}
143148

src/flamenco/runtime/tests/harness/fd_block_harness.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
static void
77
fd_runtime_fuzz_block_refresh_vote_accounts( fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_pool,
88
fd_vote_accounts_pair_global_t_mapnode_t * vote_accounts_root,
9+
fd_vote_states_t * vote_states,
910
fd_stake_delegations_t * stake_delegations ) {
1011
fd_stake_delegation_map_t * map = fd_stake_delegations_get_map( stake_delegations );
1112
fd_stake_delegation_t * pool = fd_stake_delegations_get_pool( stake_delegations );
@@ -25,6 +26,10 @@ fd_runtime_fuzz_block_refresh_vote_accounts( fd_vote_accounts_pair_global_t_mapn
2526
if( FD_LIKELY( found_node ) ) {
2627
found_node->elem.stake += stake;
2728
}
29+
fd_vote_state_ele_t * vote_state = fd_vote_states_query( vote_states, voter_pubkey );
30+
ulong vote_stake = vote_state->stake;
31+
fd_vote_states_update_stake( vote_states, voter_pubkey, vote_stake + stake );
32+
2833
}
2934
}
3035

@@ -282,21 +287,20 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner,
282287
stake_delegations = fd_stake_delegations_join( fd_stake_delegations_new( stake_delegations, FD_RUNTIME_MAX_STAKE_ACCOUNTS ) );
283288

284289
/* Load in all accounts with > 0 lamports provided in the context. The input expects unique account pubkeys. */
290+
vote_states = fd_bank_vote_states_locking_modify( slot_ctx->bank );
285291
for( ushort i=0; i<test_ctx->acct_states_count; i++ ) {
286292
FD_TXN_ACCOUNT_DECL(acc);
287293
fd_runtime_fuzz_load_account( acc, funk, funk_txn, &test_ctx->acct_states[i], 1 );
288294

289295
/* Update vote accounts cache for epoch T */
290296
fd_pubkey_t pubkey;
291297
memcpy( &pubkey, test_ctx->acct_states[i].address, sizeof(fd_pubkey_t) );
292-
vote_states = fd_bank_vote_states_locking_modify( slot_ctx->bank );
293298
fd_runtime_fuzz_block_register_vote_account( slot_ctx,
294299
vote_states,
295300
vote_accounts_pool,
296301
&vote_accounts_root,
297302
&pubkey,
298303
runner->spad );
299-
fd_bank_vote_states_end_locking_modify( slot_ctx->bank );
300304

301305
/* Update the stake delegations cache for epoch T */
302306
fd_runtime_fuzz_block_register_stake_delegation( slot_ctx,
@@ -307,14 +311,14 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner,
307311
/* Refresh vote accounts to calculate stake delegations */
308312
fd_runtime_fuzz_block_refresh_vote_accounts( vote_accounts_pool,
309313
vote_accounts_root,
314+
vote_states,
310315
stake_delegations );
316+
fd_bank_vote_states_end_locking_modify( slot_ctx->bank );
317+
311318

312319
fd_vote_accounts_vote_accounts_pool_update( curr_stakes, vote_accounts_pool );
313320
fd_vote_accounts_vote_accounts_root_update( curr_stakes, vote_accounts_root );
314321

315-
// fd_vote_accounts_stake_delegations_pool_update( curr_stakes, stake_delegations_pool );
316-
// fd_vote_accounts_stake_delegations_root_update( curr_stakes, stake_delegations_root );
317-
318322
fd_bank_curr_epoch_stakes_end_locking_modify( slot_ctx->bank );
319323
fd_bank_stake_delegations_end_locking_modify( slot_ctx->bank );
320324

src/flamenco/runtime/tests/harness/fd_instr_harness.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ fd_runtime_fuzz_instr_ctx_create( fd_runtime_fuzz_runner_t * runner,
5959
return 0;
6060
}
6161

62+
/* Setup vote states dummy account */
63+
fd_vote_states_t * vote_states = fd_vote_states_join( fd_vote_states_new( fd_bank_vote_states_locking_modify( slot_ctx->bank ), 10000UL ) );
64+
if( FD_UNLIKELY( !vote_states ) ) {
65+
return 0;
66+
}
67+
fd_bank_vote_states_end_locking_modify( slot_ctx->bank );
68+
6269
/* Set up epoch context. Defaults obtained from GenesisConfig::Default() */
6370

6471
fd_rent_t * rent_bm = fd_bank_rent_modify( slot_ctx->bank );

src/flamenco/runtime/tests/harness/fd_txn_harness.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner,
140140
fd_sysvar_last_restart_slot_init( slot_ctx );
141141
}
142142

143+
/* Setup vote states dummy account */
144+
fd_vote_states_t * vote_states = fd_vote_states_join( fd_vote_states_new( fd_bank_vote_states_locking_modify( slot_ctx->bank ), 10000UL ) );
145+
if( FD_UNLIKELY( !vote_states ) ) {
146+
return NULL;
147+
}
148+
fd_bank_vote_states_end_locking_modify( slot_ctx->bank );
149+
143150
/* Provide a default clock if not present */
144151
fd_sol_sysvar_clock_t clock_[1];
145152
fd_sol_sysvar_clock_t const * clock = fd_sysvar_clock_read( funk, funk_txn, clock_ );

0 commit comments

Comments
 (0)