Skip to content

Commit

Permalink
pool_hardening: idx_acquire and ele_acquire dont check to see if the …
Browse files Browse the repository at this point in the history
…pool is empty
  • Loading branch information
jumpsiegel committed Jun 27, 2024
1 parent bdc5822 commit 38b7ad1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/flamenco/runtime/program/fd_vote_program.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ authorized_voters_new( ulong epoch,
fd_vote_authorized_voters_t * authorized_voters /* out */ ) {
authorized_voters->pool = fd_vote_authorized_voters_pool_alloc ( valloc, FD_VOTE_AUTHORIZED_VOTERS_MIN );
authorized_voters->treap = fd_vote_authorized_voters_treap_alloc( valloc, FD_VOTE_AUTHORIZED_VOTERS_MIN );
if( 0 == fd_vote_authorized_voters_pool_free( authorized_voters->pool) ) {
FD_LOG_ERR(( "Authorized_voter pool is empty" ));
}
fd_vote_authorized_voter_t * ele =
fd_vote_authorized_voters_pool_ele_acquire( authorized_voters->pool );
ele->epoch = epoch;
Expand Down Expand Up @@ -320,6 +323,9 @@ authorized_voters_get_and_cache_authorized_voter_for_epoch( fd_vote_authorized_v
if( !res ) return NULL;
if( !existed ) {
/* insert cannot fail because !existed */
if( 0 == fd_vote_authorized_voters_pool_free( self->pool) ) {
FD_LOG_ERR(( "Authorized_voter pool is empty" ));
}
fd_vote_authorized_voter_t * ele = fd_vote_authorized_voters_pool_ele_acquire( self->pool );
ele->epoch = epoch;
memcpy( &ele->pubkey, &res->pubkey, sizeof( fd_pubkey_t ) );
Expand Down Expand Up @@ -724,6 +730,10 @@ set_new_authorized_voter( fd_vote_state_t * self,
}

// https://github.com/firedancer-io/solana/blob/da470eef4652b3b22598a1f379cacfe82bd5928d/sdk/program/src/vote/state/mod.rs#L581-L582
if( 0 == fd_vote_authorized_voters_pool_free( self->authorized_voters.pool) ) {
FD_LOG_ERR(( "Authorized_voter pool is empty" ));
}

fd_vote_authorized_voter_t * ele =
fd_vote_authorized_voters_pool_ele_acquire( self->authorized_voters.pool );
ele->epoch = target_epoch;
Expand Down
3 changes: 3 additions & 0 deletions src/flamenco/runtime/sysvar/fd_sysvar_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ fd_calculate_stake_weighted_timestamp(
if ( FD_LIKELY( treap_idx < ULONG_MAX ) ) {
pool[ treap_idx ].stake += n->elem.stake;
} else {
if( 0 == stake_ts_pool_free( pool ) ) {
FD_LOG_ERR(( "stake_ts_pool is empty" ));
}
ulong idx = stake_ts_pool_idx_acquire( pool );
pool[ idx ].timestamp = estimate;
pool[ idx ].stake = n->elem.stake;
Expand Down
4 changes: 4 additions & 0 deletions src/flamenco/runtime/sysvar/fd_sysvar_stake_history.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ fd_sysvar_stake_history_update( fd_exec_slot_ctx_t * slot_ctx,
fd_stake_history_pool_ele_release( stake_history.pool, ele );
}

if( 0 == fd_stake_history_pool_free( stake_history.pool ) ) {
FD_LOG_ERR(( "stake_history.pool is empty" ));
}

ulong idx = fd_stake_history_pool_idx_acquire( stake_history.pool );

stake_history.pool[ idx ].epoch = entry->epoch;
Expand Down

0 comments on commit 38b7ad1

Please sign in to comment.