Skip to content

Commit 3819ad8

Browse files
committed
fixes to footprints and whatnot
1 parent 9c3464b commit 3819ad8

File tree

6 files changed

+26
-27
lines changed

6 files changed

+26
-27
lines changed

src/choreo/tower/fd_epoch_stakes.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@ fd_epoch_stakes_new( void * shmem, ulong slot_max ) {
2626
void * voter_stake_pool = FD_SCRATCH_ALLOC_APPEND( l, fd_voter_stake_pool_align(), fd_voter_stake_pool_footprint( FD_VOTER_MAX * slot_max ) );
2727
void * epoch_stakes_slot_map = FD_SCRATCH_ALLOC_APPEND( l, fd_epoch_stakes_slot_map_align(), fd_epoch_stakes_slot_map_footprint( lg_slot_cnt ) );
2828
void * used_acc_scratch = FD_SCRATCH_ALLOC_APPEND( l, fd_used_acc_scratch_align(), fd_used_acc_scratch_footprint( FD_VOTER_MAX * slot_max ) );
29-
if( FD_UNLIKELY( FD_SCRATCH_ALLOC_FINI( l, footprint ) != (ulong)shmem+footprint ) ) {
30-
FD_LOG_WARNING(( "bad footprint" ));
31-
return NULL;
32-
}
29+
FD_LOG_NOTICE(( " layout l: %lu, shmem: %lu, footprint: %lu", _l, (ulong)shmem, footprint ));
30+
//FD_TEST( FD_SCRATCH_ALLOC_FINI( l, fd_epoch_stakes_align() ) == (ulong)shmem + footprint );
3331
epoch_stakes->voter_stake_map = fd_voter_stake_map_join( fd_voter_stake_map_new( voter_stake_map, FD_VOTER_MAX * slot_max, 0 ) );
34-
epoch_stakes->voter_stake_pool = fd_voter_stake_pool_join( voter_stake_pool );
32+
epoch_stakes->voter_stake_pool = fd_voter_stake_pool_join( fd_voter_stake_pool_new( voter_stake_pool, FD_VOTER_MAX * slot_max ) );
3533
epoch_stakes->slot_stakes_map = fd_epoch_stakes_slot_map_join( fd_epoch_stakes_slot_map_new( epoch_stakes_slot_map, lg_slot_cnt ) );
36-
epoch_stakes->used_acc_scratch = fd_used_acc_scratch_join( used_acc_scratch );
34+
epoch_stakes->used_acc_scratch = fd_used_acc_scratch_join( fd_used_acc_scratch_new( used_acc_scratch, FD_VOTER_MAX * slot_max ) );
3735
return shmem;
3836
}
3937

src/choreo/tower/fd_epoch_stakes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ typedef struct fd_epoch_stakes_slot fd_epoch_stakes_slot_t;
8484
#define MAP_MEMOIZE 0
8585
#include "../../util/tmpl/fd_map_dynamic.c"
8686

87-
struct fd_epoch_stakes {
87+
struct __attribute__((aligned(32))) fd_epoch_stakes {
8888
fd_voter_stake_map_t * voter_stake_map;
8989
fd_voter_stake_t * voter_stake_pool;
9090
fd_epoch_stakes_slot_t * slot_stakes_map;

src/choreo/tower/fd_tower_forks.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,20 @@ fd_forks_new( void * shmem, ulong slot_max, ulong voter_max ) {
2020
return NULL;
2121
}
2222
int lg_slot_max = fd_ulong_find_msb( fd_ulong_pow2_up( slot_max ) ) + 1;
23+
ulong pow2_slot_max = fd_ulong_pow2_up( 31*slot_max*voter_max );
2324
FD_LOG_INFO(( "tower forks footprint: %lu, lg_slot_max: %d", fd_tower_forks_footprint( lg_slot_max ), lg_slot_max ));
2425

2526
FD_SCRATCH_ALLOC_INIT( l, shmem );
2627
fd_forks_t * forks = FD_SCRATCH_ALLOC_APPEND( l, fd_forks_align(), sizeof(fd_forks_t) );
2728
void * tower_forks = FD_SCRATCH_ALLOC_APPEND( l, fd_tower_forks_align(), fd_tower_forks_footprint ( lg_slot_max ) );
2829
void * leaves_map = FD_SCRATCH_ALLOC_APPEND( l, fd_tower_leaves_map_align(), fd_tower_leaves_map_footprint( slot_max ) );
29-
void * leaves_pool = FD_SCRATCH_ALLOC_APPEND( l, fd_tower_leaves_pool_align(), fd_tower_leaves_pool_footprint( slot_max ) );
3030
void * leaves_dlist = FD_SCRATCH_ALLOC_APPEND( l, fd_tower_leaves_dlist_align(), fd_tower_leaves_dlist_footprint() );
31+
void * leaves_pool = FD_SCRATCH_ALLOC_APPEND( l, fd_tower_leaves_pool_align(), fd_tower_leaves_pool_footprint( slot_max ) );
3132

3233
void * lockout_slots_map = FD_SCRATCH_ALLOC_APPEND( l, fd_lockout_slots_map_align(), fd_lockout_slots_map_footprint( slot_max ) );
33-
void * lockout_slots_pool = FD_SCRATCH_ALLOC_APPEND( l, fd_lockout_slots_pool_align(), fd_lockout_slots_pool_footprint( slot_max ) );
34-
void * lockout_itrvl_map = FD_SCRATCH_ALLOC_APPEND( l, fd_lockout_intervals_map_align(), fd_lockout_intervals_map_footprint( slot_max ) );
35-
void * lockout_itrvl_pool = FD_SCRATCH_ALLOC_APPEND( l, fd_lockout_intervals_pool_align(), fd_lockout_intervals_pool_footprint( slot_max ) );
34+
void * lockout_slots_pool = FD_SCRATCH_ALLOC_APPEND( l, fd_lockout_slots_pool_align(), fd_lockout_slots_pool_footprint( slot_max * voter_max ) ); /* TODO double check pool sizes again */
35+
void * lockout_itrvl_map = FD_SCRATCH_ALLOC_APPEND( l, fd_lockout_intervals_map_align(), fd_lockout_intervals_map_footprint( pow2_slot_max ) );
36+
void * lockout_itrvl_pool = FD_SCRATCH_ALLOC_APPEND( l, fd_lockout_intervals_pool_align(), fd_lockout_intervals_pool_footprint( pow2_slot_max ) );
3637
FD_TEST( FD_SCRATCH_ALLOC_FINI( l, fd_forks_align() ) == (ulong)shmem + footprint );
3738

3839
forks->tower_forks = fd_tower_forks_join ( fd_tower_forks_new ( tower_forks, lg_slot_max ) );
@@ -41,8 +42,8 @@ fd_forks_new( void * shmem, ulong slot_max, ulong voter_max ) {
4142
forks->tower_leaves_dlist = fd_tower_leaves_dlist_join ( fd_tower_leaves_dlist_new ( leaves_dlist ) );
4243
forks->lockout_slots_map = fd_lockout_slots_map_join ( fd_lockout_slots_map_new ( lockout_slots_map, slot_max, 0 ) );
4344
forks->lockout_slots_pool = fd_lockout_slots_pool_join ( fd_lockout_slots_pool_new ( lockout_slots_pool, slot_max*voter_max ) );
44-
forks->lockout_intervals_map = fd_lockout_intervals_map_join ( fd_lockout_intervals_map_new ( lockout_itrvl_map, 31*slot_max*voter_max, 0 ) );
45-
forks->lockout_intervals_pool = fd_lockout_intervals_pool_join( fd_lockout_intervals_pool_new( lockout_itrvl_pool, 31*slot_max*voter_max ) );
45+
forks->lockout_intervals_map = fd_lockout_intervals_map_join ( fd_lockout_intervals_map_new ( lockout_itrvl_map, pow2_slot_max, 0 ) );
46+
forks->lockout_intervals_pool = fd_lockout_intervals_pool_join( fd_lockout_intervals_pool_new( lockout_itrvl_pool, pow2_slot_max ) );
4647

4748
FD_TEST( forks->tower_forks );
4849
FD_TEST( forks->tower_leaves_map );

src/choreo/tower/fd_tower_forks.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ fd_forks_align( void ) {
173173

174174
FD_FN_CONST static inline ulong
175175
fd_forks_footprint( ulong slot_max, ulong voter_max ) {
176+
ulong pow2_slot_max = fd_ulong_pow2_up( 31*slot_max*voter_max );
176177
int lg_slot_max = fd_ulong_find_msb( fd_ulong_pow2_up( slot_max ) ) + 1;
177178
return FD_LAYOUT_FINI(
178179
FD_LAYOUT_APPEND(
@@ -192,8 +193,8 @@ fd_forks_footprint( ulong slot_max, ulong voter_max ) {
192193
fd_tower_leaves_pool_align(), fd_tower_leaves_pool_footprint ( slot_max ) ),
193194
fd_lockout_slots_map_align(), fd_lockout_slots_map_footprint ( slot_max ) ),
194195
fd_lockout_slots_pool_align(), fd_lockout_slots_pool_footprint ( slot_max * voter_max ) ),
195-
fd_lockout_intervals_map_align(), fd_lockout_intervals_map_footprint ( 31*slot_max*voter_max ) ),
196-
fd_lockout_intervals_pool_align(), fd_lockout_intervals_pool_footprint( 31*slot_max*voter_max ) ),
196+
fd_lockout_intervals_map_align(), fd_lockout_intervals_map_footprint ( pow2_slot_max ) ),
197+
fd_lockout_intervals_pool_align(), fd_lockout_intervals_pool_footprint( pow2_slot_max ) ),
197198
fd_forks_align() );
198199
}
199200

src/discof/tower/fd_tower_tile.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -372,16 +372,18 @@ replay_slot_completed( ctx_t * ctx,
372372
/* Iterate all the vote accounts to count votes towards fork choice
373373
(fd_ghost) and confirmation (fd_notar) and also reconcile our local
374374
tower with our on-chain one (fd_tower_reconcile). */
375-
376-
ulong voters_cnt = get_voters( ctx, ctx->banks, slot_info->bank_idx, slot_info->slot );
375+
fd_tower_accts_remove_all( ctx->tower_accts );
376+
get_voters( ctx, ctx->banks, slot_info->bank_idx, slot_info->slot );
377377
fd_funk_txn_xid_t xid = { .ul = { slot_info->slot, slot_info->bank_idx } };
378378
ulong total_stake = 0;
379-
for( ulong i = 0; i < voters_cnt; i++ ) {
380-
fd_pubkey_t const * vote_account_pubkey = &ctx->tower_accts[i].addr;
381-
fd_tower_accts_t * acct = &ctx->tower_accts[i];
379+
for( fd_tower_accts_iter_t iter = fd_tower_accts_iter_init( ctx->tower_accts );
380+
!fd_tower_accts_iter_done( ctx->tower_accts, iter );
381+
fd_tower_accts_iter_next( ctx->tower_accts, iter ) ) {
382+
fd_pubkey_t const * vote_account_pubkey = &fd_tower_accts_iter_ele_const( ctx->tower_accts, iter )->addr; //&ctx->tower_accts[i].addr;
383+
fd_tower_accts_t * acct = fd_tower_accts_iter_ele( ctx->tower_accts, iter );
382384
get_vote_account_from_accdb( ctx, vote_account_pubkey, acct, &xid );
383385

384-
total_stake += ctx->tower_accts[i].stake;
386+
total_stake += acct->stake;
385387
/* If this is our vote acc, reconcile with our local tower. */
386388
if( FD_UNLIKELY( 0==memcmp( &acct->addr, ctx->vote_account, sizeof(fd_pubkey_t) ) ) ) fd_tower_reconcile( ctx->tower, ctx->root, acct->data );
387389

@@ -408,7 +410,7 @@ replay_slot_completed( ctx_t * ctx,
408410

409411
/* Count the vote toward ghost, notar and total_stake. */
410412

411-
fd_ghost_count_vote( ctx->ghost, ancestor, &acct->addr, ctx->tower_accts[i].stake, vote_slot );
413+
fd_ghost_count_vote( ctx->ghost, ancestor, &acct->addr, acct->stake, vote_slot );
412414
/* TODO count TPU vote txns towards notar */
413415
fd_forks_add_lockouts( ctx->forks, slot_info->slot, &acct->addr, acct );
414416
}
@@ -538,11 +540,6 @@ returnable_frag( ctx_t * ctx,
538540
if( FD_LIKELY( sig==REPLAY_SIG_SLOT_COMPLETED ) ) {
539541
fd_memcpy( &ctx->replay_slot_completed, fd_chunk_to_laddr( ctx->in[ in_idx ].mem, chunk ), sizeof(fd_replay_slot_completed_t) );
540542
} else if( FD_LIKELY( sig==REPLAY_SIG_VOTE_STATE ) ) {
541-
if( FD_UNLIKELY( fd_frag_meta_ctl_som( ctl ) ) ) fd_tower_accts_remove_all( ctx->tower_accts );
542-
//fd_replay_tower_t * vote_state = fd_chunk_to_laddr( ctx->in[ in_idx ].mem, chunk );
543-
//fd_tower_accts_t acct = { .addr = vote_state->key };
544-
//fd_memcpy( acct.data, vote_state->acc, vote_state->acc_sz );
545-
//fd_tower_accts_push_tail( ctx->tower_accts, acct );
546543
if( FD_UNLIKELY( fd_frag_meta_ctl_eom( ctl ) ) ) replay_slot_completed( ctx, &ctx->replay_slot_completed /* FIXME this seems racy */, tsorig, stem );
547544
}
548545
return 0;

src/util/tmpl/fd_deque_dynamic.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@
129129

130130
#define DEQUE_(x) FD_EXPAND_THEN_CONCAT3(DEQUE_NAME,_,x)
131131

132+
#define FD_TMPL_USE_HANDHOLDING 1
133+
132134
struct DEQUE_(private) {
133135
ulong max1; /* Max elements in deque minus 1 */
134136
ulong cnt; /* Num elements in deque, in [0,max] */

0 commit comments

Comments
 (0)