Skip to content

Commit

Permalink
flamenco: fix fd_stake_history_ele_query_const
Browse files Browse the repository at this point in the history
  • Loading branch information
kbhargava-jump committed Dec 31, 2024
1 parent c2eeaef commit 70b6d86
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/flamenco/runtime/program/fd_stake_program.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,19 +445,24 @@ typedef fd_stake_history_entry_t fd_stake_activation_status_t;
fd_stake_history_entry_t const *
fd_stake_history_ele_query_const( fd_stake_history_t const * history,
ulong epoch ) {
if( 0 == history->fd_stake_history_len )
if( 0 == history->fd_stake_history_len ) {
return NULL;
}

if( epoch > history->fd_stake_history[0].epoch )
if( epoch > history->fd_stake_history[0].epoch ) {
return NULL;
}

ulong off = (history->fd_stake_history[0].epoch - epoch);
if( off >= history->fd_stake_history_len )
if( off >= history->fd_stake_history_len ) {
return NULL;
}

ulong e = (off + history->fd_stake_history_offset) & (history->fd_stake_history_size - 1);

FD_TEST(history->fd_stake_history[e].epoch == epoch);
if ( history->fd_stake_history[e].epoch != epoch ) {
return NULL;
}

return &history->fd_stake_history[e];
}
Expand Down

0 comments on commit 70b6d86

Please sign in to comment.