22#include "../accdb/fd_accdb_pipe.h"
33#include "../runtime/program/fd_stake_program.h"
44
5- #define POOL_NAME fd_stake_delegation_pool
6- #define POOL_T fd_stake_delegation_t
7- #define POOL_NEXT next_
5+ #define POOL_NAME fd_stake_delegation_pool
6+ #define POOL_T fd_stake_delegation_t
7+ #define POOL_NEXT next_
8+ #define POOL_IDX_T uint
89#include "../../util/tmpl/fd_pool.c"
910
1011#define MAP_NAME fd_stake_delegation_map
1415#define MAP_KEY_EQ (k0 ,k1 ) (fd_pubkey_eq( k0, k1 ))
1516#define MAP_KEY_HASH (key ,seed ) (fd_funk_rec_key_hash1( key->uc, seed ))
1617#define MAP_NEXT next_
18+ #define MAP_IDX_T uint
1719#include "../../util/tmpl/fd_map_chain.c"
1820
21+ static inline uchar
22+ fd_stake_delegations_warmup_cooldown_rate_enum ( double warmup_cooldown_rate ) {
23+ if ( FD_LIKELY ( warmup_cooldown_rate == FD_STAKE_DELEGATIONS_WARMUP_COOLDOWN_RATE_025 ) ) {
24+ return FD_STAKE_DELEGATIONS_WARMUP_COOLDOWN_RATE_ENUM_025 ;
25+ } else if ( FD_LIKELY ( warmup_cooldown_rate == FD_STAKE_DELEGATIONS_WARMUP_COOLDOWN_RATE_009 ) ) {
26+ return FD_STAKE_DELEGATIONS_WARMUP_COOLDOWN_RATE_ENUM_009 ;
27+ } else {
28+ FD_LOG_CRIT (( "Invalid warmup cooldown rate %f" , warmup_cooldown_rate ));
29+ }
30+ }
31+
1932static inline fd_stake_delegation_t *
2033fd_stake_delegations_get_pool ( fd_stake_delegations_t const * stake_delegations ) {
2134 return fd_stake_delegation_pool_join ( (uchar * )stake_delegations + stake_delegations -> pool_offset_ );
@@ -227,10 +240,10 @@ fd_stake_delegations_update( fd_stake_delegations_t * stake_delegations,
227240 ulong idx = fd_stake_delegation_map_idx_query_const (
228241 stake_delegation_map ,
229242 stake_account ,
230- ULONG_MAX ,
243+ UINT_MAX ,
231244 stake_delegation_pool );
232245
233- if ( idx != ULONG_MAX ) {
246+ if ( idx != UINT_MAX ) {
234247
235248 fd_stake_delegation_t * stake_delegation = fd_stake_delegation_pool_ele ( stake_delegation_pool , idx );
236249 if ( FD_UNLIKELY ( !stake_delegation ) ) {
@@ -239,10 +252,10 @@ fd_stake_delegations_update( fd_stake_delegations_t * stake_delegations,
239252
240253 stake_delegation -> vote_account = * vote_account ;
241254 stake_delegation -> stake = stake ;
242- stake_delegation -> activation_epoch = activation_epoch ;
243- stake_delegation -> deactivation_epoch = deactivation_epoch ;
255+ stake_delegation -> activation_epoch = ( ushort ) fd_ulong_min ( activation_epoch , USHORT_MAX ) ;
256+ stake_delegation -> deactivation_epoch = ( ushort ) fd_ulong_min ( deactivation_epoch , USHORT_MAX ) ;
244257 stake_delegation -> credits_observed = credits_observed ;
245- stake_delegation -> warmup_cooldown_rate = warmup_cooldown_rate ;
258+ stake_delegation -> warmup_cooldown_rate = fd_stake_delegations_warmup_cooldown_rate_enum ( warmup_cooldown_rate ) ;
246259 stake_delegation -> is_tombstone = 0 ;
247260 return ;
248261 }
@@ -257,10 +270,10 @@ fd_stake_delegations_update( fd_stake_delegations_t * stake_delegations,
257270 stake_delegation -> stake_account = * stake_account ;
258271 stake_delegation -> vote_account = * vote_account ;
259272 stake_delegation -> stake = stake ;
260- stake_delegation -> activation_epoch = activation_epoch ;
261- stake_delegation -> deactivation_epoch = deactivation_epoch ;
273+ stake_delegation -> activation_epoch = ( ushort ) fd_ulong_min ( activation_epoch , USHORT_MAX ) ;
274+ stake_delegation -> deactivation_epoch = ( ushort ) fd_ulong_min ( deactivation_epoch , USHORT_MAX ) ;
262275 stake_delegation -> credits_observed = credits_observed ;
263- stake_delegation -> warmup_cooldown_rate = warmup_cooldown_rate ;
276+ stake_delegation -> warmup_cooldown_rate = fd_stake_delegations_warmup_cooldown_rate_enum ( warmup_cooldown_rate ) ;
264277 stake_delegation -> is_tombstone = 0 ;
265278
266279 if ( FD_UNLIKELY ( !fd_stake_delegation_map_ele_insert (
@@ -287,15 +300,15 @@ fd_stake_delegations_remove( fd_stake_delegations_t * stake_delegations,
287300 ulong delegation_idx = fd_stake_delegation_map_idx_query (
288301 stake_delegation_map ,
289302 stake_account ,
290- ULONG_MAX ,
303+ UINT_MAX ,
291304 stake_delegation_pool );
292305
293306 if ( stake_delegations -> leave_tombstones_ == 1 ) {
294307 /* If we are configured to leave tombstones, we need to either
295308 update the entry's is_tombstone flag or insert a new entry. */
296309
297310 fd_stake_delegation_t * stake_delegation = NULL ;
298- if ( delegation_idx != ULONG_MAX ) {
311+ if ( delegation_idx != UINT_MAX ) {
299312 /* The delegation was found, update the is_tombstone flag. */
300313 stake_delegation = fd_stake_delegation_pool_ele ( stake_delegation_pool , delegation_idx );
301314 } else {
@@ -310,7 +323,7 @@ fd_stake_delegations_remove( fd_stake_delegations_t * stake_delegations,
310323 } else {
311324 /* If we are not configured to leave tombstones, we need to remove
312325 the entry from the map and release it from the pool. */
313- if ( FD_UNLIKELY ( delegation_idx == ULONG_MAX ) ) {
326+ if ( FD_UNLIKELY ( delegation_idx == UINT_MAX ) ) {
314327 /* The delegation was not found, nothing to do. */
315328 return ;
316329 }
@@ -322,12 +335,12 @@ fd_stake_delegations_remove( fd_stake_delegations_t * stake_delegations,
322335 FD_LOG_CRIT (( "unable to retrieve stake delegation" ));
323336 }
324337
325- ulong idx = fd_stake_delegation_map_idx_remove ( stake_delegation_map , stake_account , ULONG_MAX , stake_delegation_pool );
326- if ( FD_UNLIKELY ( idx == ULONG_MAX ) ) {
338+ ulong idx = fd_stake_delegation_map_idx_remove ( stake_delegation_map , stake_account , UINT_MAX , stake_delegation_pool );
339+ if ( FD_UNLIKELY ( idx == UINT_MAX ) ) {
327340 FD_LOG_CRIT (( "unable to remove stake delegation" ));
328341 }
329342
330- stake_delegation -> next_ = fd_stake_delegation_pool_idx_null ( stake_delegation_pool ) ;
343+ stake_delegation -> next_ = UINT_MAX ;
331344
332345 fd_stake_delegation_pool_idx_release ( stake_delegation_pool , delegation_idx );
333346 }
@@ -385,7 +398,7 @@ fd_stake_delegations_refresh( fd_stake_delegations_t * stake_delegations,
385398 continue ; /* ok */
386399
387400 remove :
388- fd_stake_delegation_map_idx_remove ( map , address , ULONG_MAX , pool );
401+ fd_stake_delegation_map_idx_remove ( map , address , UINT_MAX , pool );
389402 fd_stake_delegation_pool_ele_release ( pool , delegation );
390403 }
391404 }
0 commit comments