4
4
#include "../runtime/context/fd_exec_slot_ctx.h"
5
5
#include "../runtime/program/fd_stake_program.h"
6
6
#include "../runtime/sysvar/fd_sysvar_stake_history.h"
7
+ #include "fd_stake_delegations.h"
7
8
8
9
ulong
9
10
fd_stake_weights_by_node ( fd_vote_accounts_global_t const * accs ,
@@ -73,18 +74,14 @@ deserialize_and_update_vote_account( fd_exec_slot_ctx_t *
73
74
}
74
75
75
76
static void
76
- compute_stake_delegations (
77
- fd_epoch_info_t * temp_info ,
78
- ulong const epoch ,
79
- fd_stake_history_t const * history ,
80
- ulong * new_rate_activation_epoch ,
81
- fd_stake_weight_t_mapnode_t * delegation_pool ,
82
- fd_stake_weight_t_mapnode_t * delegation_root ,
83
- ulong vote_states_pool_sz ,
84
- fd_spad_t * spad ,
85
- ulong end_idx
86
- ) {
87
- fd_epoch_info_pair_t const * stake_infos = temp_info -> stake_infos ;
77
+ compute_stake_delegations ( fd_bank_t * bank ,
78
+ ulong const epoch ,
79
+ fd_stake_history_t const * history ,
80
+ ulong * new_rate_activation_epoch ,
81
+ fd_stake_weight_t_mapnode_t * delegation_pool ,
82
+ fd_stake_weight_t_mapnode_t * delegation_root ,
83
+ ulong vote_states_pool_sz ,
84
+ fd_spad_t * spad ) {
88
85
89
86
FD_SPAD_FRAME_BEGIN ( spad ) {
90
87
@@ -93,22 +90,43 @@ compute_stake_delegations(
93
90
fd_stake_weight_t_mapnode_t * temp_pool = fd_stake_weight_t_map_join ( fd_stake_weight_t_map_new ( mem , vote_states_pool_sz ) );
94
91
fd_stake_weight_t_mapnode_t * temp_root = NULL ;
95
92
93
+ fd_stake_delegations_t const * stake_delegations = fd_bank_stake_delegations_locking_query ( bank );
94
+ if ( FD_UNLIKELY ( !stake_delegations ) ) {
95
+ FD_LOG_CRIT (( "stake_delegations is NULL" ));
96
+ }
97
+ fd_stake_delegation_map_t * stake_delegation_map = fd_stake_delegations_get_map ( stake_delegations );
98
+ fd_stake_delegation_t * stake_delegation_pool = fd_stake_delegations_get_pool ( stake_delegations );
99
+
96
100
fd_stake_weight_t_mapnode_t temp ;
97
- for ( ulong i = 0UL ; i < end_idx ; i ++ ) {
98
- fd_delegation_t const * delegation = & stake_infos [i ].stake .delegation ;
99
- temp .elem .key = delegation -> voter_pubkey ;
101
+
102
+ for ( fd_stake_delegation_map_iter_t iter = fd_stake_delegation_map_iter_init ( stake_delegation_map , stake_delegation_pool );
103
+ !fd_stake_delegation_map_iter_done ( iter , stake_delegation_map , stake_delegation_pool );
104
+ iter = fd_stake_delegation_map_iter_next ( iter , stake_delegation_map , stake_delegation_pool ) ) {
105
+
106
+
107
+ fd_stake_delegation_t const * stake_delegation = fd_stake_delegation_map_iter_ele_const ( iter , stake_delegation_map , stake_delegation_pool );
108
+
109
+ temp .elem .key = stake_delegation -> vote_account ;
100
110
101
111
// Skip any delegations that are not in the delegation pool
102
112
fd_stake_weight_t_mapnode_t * delegation_entry = fd_stake_weight_t_map_find ( delegation_pool , delegation_root , & temp );
103
113
if ( FD_UNLIKELY ( delegation_entry == NULL ) ) {
104
114
continue ;
105
115
}
106
116
107
- fd_stake_history_entry_t new_entry = fd_stake_activating_and_deactivating ( delegation , epoch , history , new_rate_activation_epoch );
117
+ fd_delegation_t delegation = {
118
+ .voter_pubkey = stake_delegation -> vote_account ,
119
+ .stake = stake_delegation -> stake ,
120
+ .deactivation_epoch = stake_delegation -> deactivation_epoch ,
121
+ .activation_epoch = stake_delegation -> activation_epoch ,
122
+ .warmup_cooldown_rate = stake_delegation -> warmup_cooldown_rate ,
123
+ };
124
+
125
+ fd_stake_history_entry_t new_entry = fd_stake_activating_and_deactivating ( & delegation , epoch , history , new_rate_activation_epoch );
108
126
delegation_entry = fd_stake_weight_t_map_find ( temp_pool , temp_root , & temp );
109
127
if ( FD_UNLIKELY ( delegation_entry == NULL ) ) {
110
128
delegation_entry = fd_stake_weight_t_map_acquire ( temp_pool );
111
- delegation_entry -> elem .key = delegation -> voter_pubkey ;
129
+ delegation_entry -> elem .key = stake_delegation -> vote_account ;
112
130
delegation_entry -> elem .stake = new_entry .effective ;
113
131
fd_stake_weight_t_map_insert ( temp_pool , & temp_root , delegation_entry );
114
132
} else {
@@ -124,6 +142,8 @@ compute_stake_delegations(
124
142
output_delegation_node -> elem .stake += elem -> elem .stake ;
125
143
}
126
144
145
+ fd_bank_stake_delegations_end_locking_query ( bank );
146
+
127
147
} FD_SPAD_FRAME_END ;
128
148
129
149
}
@@ -189,16 +209,14 @@ fd_populate_vote_accounts( fd_exec_slot_ctx_t * slot_ctx,
189
209
fd_bank_vote_account_keys_end_locking_modify ( slot_ctx -> bank );
190
210
191
211
compute_stake_delegations (
192
- temp_info ,
212
+ slot_ctx -> bank ,
193
213
fd_bank_epoch_get ( slot_ctx -> bank ),
194
214
history ,
195
215
new_rate_activation_epoch ,
196
216
pool ,
197
217
root ,
198
218
vote_states_pool_sz ,
199
- runtime_spad ,
200
- temp_info -> stake_infos_len
201
- );
219
+ runtime_spad );
202
220
203
221
// Iterate over each vote account in the epoch stakes cache and populate the new vote accounts pool
204
222
/* NOTE: we use epoch_bank->next_epoch_stakes because Agave indexes their epoch stakes cache by leader schedule epoch.
@@ -308,16 +326,14 @@ fd_refresh_vote_accounts( fd_exec_slot_ctx_t * slot_ctx,
308
326
}
309
327
310
328
compute_stake_delegations (
311
- temp_info ,
329
+ slot_ctx -> bank ,
312
330
fd_bank_epoch_get ( slot_ctx -> bank ),
313
331
history ,
314
332
new_rate_activation_epoch ,
315
333
pool ,
316
334
root ,
317
335
vote_states_pool_sz ,
318
- runtime_spad ,
319
- temp_info -> stake_infos_len
320
- );
336
+ runtime_spad );
321
337
322
338
// Iterate over each vote account in the epoch stakes cache and populate the new vote accounts pool
323
339
ulong total_epoch_stake = 0UL ;
@@ -403,13 +419,11 @@ fd_refresh_vote_accounts( fd_exec_slot_ctx_t * slot_ctx,
403
419
}
404
420
405
421
static void
406
- accumulate_stake_cache_delegations (
407
- fd_stake_delegations_t * stake_delegations ,
408
- fd_stake_history_t const * history ,
409
- ulong * new_rate_activation_epoch ,
410
- fd_stake_history_entry_t * accumulator ,
411
- fd_epoch_info_t * temp_info ,
412
- ulong epoch ) {
422
+ accumulate_stake_cache_delegations ( fd_stake_delegations_t * stake_delegations ,
423
+ fd_stake_history_t const * history ,
424
+ ulong * new_rate_activation_epoch ,
425
+ fd_stake_history_entry_t * accumulator ,
426
+ ulong epoch ) {
413
427
414
428
fd_stake_delegation_t * pool = fd_stake_delegations_get_pool ( stake_delegations );
415
429
fd_stake_delegation_map_t * map = fd_stake_delegations_get_map ( stake_delegations );
@@ -423,19 +437,19 @@ accumulate_stake_cache_delegations(
423
437
iter = fd_stake_delegation_map_iter_next ( iter , map , pool ) ) {
424
438
fd_stake_delegation_t const * stake_delegation = fd_stake_delegation_map_iter_ele_const ( iter , map , pool );
425
439
426
- ulong delegation_idx = temp_info -> stake_infos_len ++ ;
427
-
428
- temp_info -> stake_infos [ delegation_idx ] .stake . credits_observed = stake_delegation -> credits_observed ;
429
- temp_info -> stake_infos [ delegation_idx ]. account = stake_delegation -> stake_account ;
430
- temp_info -> stake_infos [ delegation_idx ]. stake . delegation . voter_pubkey = stake_delegation -> vote_account ;
431
- temp_info -> stake_infos [ delegation_idx ]. stake . delegation . stake = stake_delegation -> stake ;
432
- temp_info -> stake_infos [ delegation_idx ]. stake . delegation . activation_epoch = stake_delegation -> activation_epoch ;
433
- temp_info -> stake_infos [ delegation_idx ]. stake . delegation . deactivation_epoch = stake_delegation -> deactivation_epoch ;
434
- temp_info -> stake_infos [ delegation_idx ]. stake . delegation . warmup_cooldown_rate = stake_delegation -> warmup_cooldown_rate ;
435
-
436
- fd_delegation_t * delegation = & temp_info -> stake_infos [ delegation_idx ]. stake . delegation ;
437
-
438
- fd_stake_history_entry_t new_entry = fd_stake_activating_and_deactivating ( delegation , epoch , history , new_rate_activation_epoch );
440
+ fd_delegation_t delegation = {
441
+ . voter_pubkey = stake_delegation -> vote_account ,
442
+ .stake = stake_delegation -> stake ,
443
+ . activation_epoch = stake_delegation -> activation_epoch ,
444
+ . deactivation_epoch = stake_delegation -> deactivation_epoch ,
445
+ . warmup_cooldown_rate = stake_delegation -> warmup_cooldown_rate ,
446
+ } ;
447
+
448
+ fd_stake_history_entry_t new_entry = fd_stake_activating_and_deactivating (
449
+ & delegation ,
450
+ epoch ,
451
+ history ,
452
+ new_rate_activation_epoch );
439
453
effective += new_entry .effective ;
440
454
activating += new_entry .activating ;
441
455
deactivating += new_entry .deactivating ;
@@ -456,7 +470,6 @@ fd_accumulate_stake_infos( fd_exec_slot_ctx_t const * slot_ctx,
456
470
fd_stake_history_t const * history ,
457
471
ulong * new_rate_activation_epoch ,
458
472
fd_stake_history_entry_t * accumulator ,
459
- fd_epoch_info_t * temp_info ,
460
473
fd_spad_t * runtime_spad ) {
461
474
462
475
FD_SPAD_FRAME_BEGIN ( runtime_spad ) {
@@ -468,9 +481,7 @@ fd_accumulate_stake_infos( fd_exec_slot_ctx_t const * slot_ctx,
468
481
history ,
469
482
new_rate_activation_epoch ,
470
483
accumulator ,
471
- temp_info ,
472
- epoch
473
- );
484
+ epoch );
474
485
475
486
} FD_SPAD_FRAME_END ;
476
487
}
@@ -482,6 +493,7 @@ fd_stakes_activate_epoch( fd_exec_slot_ctx_t * slot_ctx,
482
493
fd_epoch_info_t * temp_info ,
483
494
fd_spad_t * runtime_spad ) {
484
495
496
+ (void )temp_info ;
485
497
fd_stake_delegations_t * stake_delegations = fd_stake_delegations_join ( (void * )fd_bank_stake_delegations_locking_modify ( slot_ctx -> bank ) );
486
498
487
499
/* Current stake delegations: list of all current delegations in stake_delegations
@@ -492,12 +504,6 @@ fd_stakes_activate_epoch( fd_exec_slot_ctx_t * slot_ctx,
492
504
fd_stake_history_t const * history = fd_sysvar_stake_history_read ( slot_ctx -> funk , slot_ctx -> funk_txn , runtime_spad );
493
505
if ( FD_UNLIKELY ( !history ) ) FD_LOG_ERR (( "StakeHistory sysvar is missing from sysvar cache" ));
494
506
495
- ulong stake_delegations_size = fd_stake_delegations_cnt ( stake_delegations );
496
-
497
- temp_info -> stake_infos_len = 0UL ;
498
- temp_info -> stake_infos = (fd_epoch_info_pair_t * )fd_spad_alloc ( runtime_spad , FD_EPOCH_INFO_PAIR_ALIGN , sizeof (fd_epoch_info_pair_t )* stake_delegations_size );
499
- fd_memset ( temp_info -> stake_infos , 0 , sizeof (fd_epoch_info_pair_t )* stake_delegations_size );
500
-
501
507
fd_stake_history_entry_t accumulator = {
502
508
.effective = 0UL ,
503
509
.activating = 0UL ,
@@ -511,7 +517,6 @@ fd_stakes_activate_epoch( fd_exec_slot_ctx_t * slot_ctx,
511
517
history ,
512
518
new_rate_activation_epoch ,
513
519
& accumulator ,
514
- temp_info ,
515
520
runtime_spad );
516
521
517
522
/* https://github.com/anza-xyz/agave/blob/v2.1.6/runtime/src/stakes.rs#L359 */
0 commit comments