Skip to content

Commit 4113945

Browse files
committed
tower: fixes
1 parent d2f7e0a commit 4113945

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

src/choreo/tower/fd_tower.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,9 @@ switch_check( fd_tower_t const * tower,
236236
/* Iterate over all the leaves of all forks */
237237
fd_tower_leaf_t * leaf = fd_tower_leaves_dlist_iter_ele( iter, forks->tower_leaves_dlist, forks->tower_leaves_pool );
238238
ulong candidate_slot = leaf->slot;
239+
ulong lca = fd_forks_lowest_common_ancestor( forks, candidate_slot, last_vote_slot );
239240

240-
if( fd_forks_is_slot_descendant( forks, fd_forks_lowest_common_ancestor( forks, candidate_slot, last_vote_slot ), switch_slot ) ) {
241+
if( lca != ULONG_MAX && fd_forks_is_slot_descendant( forks, lca, switch_slot ) ) {
241242

242243
/* This candidate slot may be considered for the switch proof, if
243244
it passes the following conditions:
@@ -811,6 +812,9 @@ fd_tower_verify( fd_tower_t const * tower ) {
811812
void
812813
fd_tower_print( fd_tower_t const * tower, ulong root ) {
813814
FD_LOG_NOTICE( ( "\n\n[Tower]" ) );
815+
816+
if( FD_UNLIKELY( fd_tower_empty( tower ) ) ) return;
817+
814818
ulong max_slot = 0;
815819

816820
/* Determine spacing. */

src/choreo/tower/fd_tower_forks.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ fd_forks_lowest_common_ancestor( fd_forks_t * forks,
108108
if( fork1->slot > fork2->slot ) fork1 = fd_tower_forks_query( forks->tower_forks, fork1->parent_slot, NULL );
109109
else fork2 = fd_tower_forks_query( forks->tower_forks, fork2->parent_slot, NULL );
110110
}
111-
FD_LOG_CRIT(( "invalid forks" ));
111+
/* If we reach here, then one of the slots is on a minority fork who's
112+
ancestor that connected it to the main fork has been pruned (i.e.)
113+
we have a dangling leaf right now! There is no LCA in this case. */
114+
return ULONG_MAX;
112115
}
113116

114117
fd_hash_t const *

src/choreo/voter/fd_voter.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,14 @@ fd_voter_root_slot( uchar const * vote_account_data ) {
7979
fd_voter_t const * voter = (fd_voter_t const *)fd_type_pun_const( vote_account_data );
8080
ulong cnt = voter->votes_cnt;
8181
switch( voter->kind ) {
82-
case FD_VOTER_V3: { uchar root_option = fd_uchar_load_1_fast( (uchar *)&voter->votes_v3[cnt] ); return root_option ? fd_ulong_load_8_fast( (uchar *)&voter->votes_v3[cnt] ) : ULONG_MAX; }
83-
case FD_VOTER_V2: { uchar root_option = fd_uchar_load_1_fast( (uchar *)&voter->votes_v2[cnt] ); return root_option ? fd_ulong_load_8_fast( (uchar *)&voter->votes_v2[cnt] ) : ULONG_MAX; }
82+
case FD_VOTER_V3: {
83+
uchar root_option = fd_uchar_load_1_fast( (uchar const *)&voter->votes_v3[cnt] );
84+
return root_option ? fd_ulong_load_8_fast( (uchar const *)&voter->votes_v3[cnt] + 1UL ) : ULONG_MAX;
85+
}
86+
case FD_VOTER_V2: {
87+
uchar root_option = fd_uchar_load_1_fast( (uchar const *)&voter->votes_v2[cnt] );
88+
return root_option ? fd_ulong_load_8_fast( (uchar const *)&voter->votes_v2[cnt] + 1UL ) : ULONG_MAX;
89+
}
8490
default: FD_LOG_CRIT(( "unhandled kind %u", voter->kind ));
8591
}
8692
}

src/discof/tower/fd_tower_tile.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ scratch_align( void ) {
153153
FD_FN_PURE static inline ulong
154154
scratch_footprint( FD_PARAM_UNUSED fd_topo_tile_t const * tile ) {
155155
ulong slot_max = tile->tower.max_live_slots;
156-
int lg_slot_max = fd_ulong_find_msb( fd_ulong_pow2_up( slot_max ) ) + 1;
157156
FD_LOG_DEBUG(( "hfork footprint %lu", fd_hfork_footprint( slot_max, FD_VOTER_MAX ) ));
158157
ulong l = FD_LAYOUT_INIT;
159158
l = FD_LAYOUT_APPEND( l, alignof(ctx_t), sizeof(ctx_t) );
@@ -163,10 +162,8 @@ scratch_footprint( FD_PARAM_UNUSED fd_topo_tile_t const * tile ) {
163162
l = FD_LAYOUT_APPEND( l, fd_tower_align(), fd_tower_footprint() );
164163
l = FD_LAYOUT_APPEND( l, fd_tower_accts_align(), fd_tower_accts_footprint( FD_VOTER_MAX ) );
165164
l = FD_LAYOUT_APPEND( l, fd_forks_align(), fd_forks_footprint( slot_max, FD_VOTER_MAX ) );
166-
l = FD_LAYOUT_APPEND( l, fd_tower_align(), fd_tower_footprint() );
167-
l = FD_LAYOUT_APPEND( l, fd_epoch_stakes_align(), fd_epoch_stakes_footprint( slot_max ) );
168-
l = FD_LAYOUT_APPEND( l, fd_tower_forks_align(), fd_tower_forks_footprint( lg_slot_max ) );
169165
l = FD_LAYOUT_APPEND( l, fd_tower_align(), fd_tower_footprint() ); /* ctx->tower_spare */
166+
l = FD_LAYOUT_APPEND( l, fd_epoch_stakes_align(), fd_epoch_stakes_footprint( slot_max ) );
170167
l = FD_LAYOUT_APPEND( l, notif_align(), notif_footprint( slot_max ) );
171168
return FD_LAYOUT_FINI( l, scratch_align() );
172169
}
@@ -474,7 +471,12 @@ replay_slot_completed( ctx_t * ctx,
474471
/* Query our on-chain vote acct and reconcile with our local tower. */
475472

476473
int found = query_vote_state_from_accdb( ctx->accdb, &xid, ctx->vote_account, ctx->our_vote_acct );
477-
if( FD_LIKELY( found ) ) fd_tower_reconcile( ctx->tower, ctx->root_slot, ctx->our_vote_acct );
474+
if( FD_LIKELY( found ) ) {
475+
fd_tower_reconcile( ctx->tower, ctx->root_slot, ctx->our_vote_acct );
476+
/* Sanity check that most recent vote in tower exists in tower forks */
477+
fd_tower_vote_t const * last_vote = fd_tower_peek_tail_const( ctx->tower );
478+
FD_TEST( !last_vote || fd_forks_query( ctx->forks, last_vote->slot ) );
479+
}
478480

479481
/* Insert the vote acct addrs and stakes from the bank into accts. */
480482

0 commit comments

Comments
 (0)