Skip to content

Commit 4b661ed

Browse files
committed
tower: fixes
1 parent d2f7e0a commit 4b661ed

File tree

4 files changed

+37
-28
lines changed

4 files changed

+37
-28
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ 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: { 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] + 1UL ) : 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] + 1UL ) : ULONG_MAX; }
8484
default: FD_LOG_CRIT(( "unhandled kind %u", voter->kind ));
8585
}
8686
}

src/discof/tower/fd_tower_tile.c

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,18 @@ 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;
159-
l = FD_LAYOUT_APPEND( l, alignof(ctx_t), sizeof(ctx_t) );
160-
l = FD_LAYOUT_APPEND( l, fd_ghost_align(), fd_ghost_footprint( 2*slot_max, FD_VOTER_MAX ) );
161-
l = FD_LAYOUT_APPEND( l, fd_hfork_align(), fd_hfork_footprint( slot_max, FD_VOTER_MAX ) );
162-
l = FD_LAYOUT_APPEND( l, fd_notar_align(), fd_notar_footprint( tile->tower.max_vote_lookahead ) );
163-
l = FD_LAYOUT_APPEND( l, fd_tower_align(), fd_tower_footprint() );
164-
l = FD_LAYOUT_APPEND( l, fd_tower_accts_align(), fd_tower_accts_footprint( FD_VOTER_MAX ) );
165-
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 ) );
169-
l = FD_LAYOUT_APPEND( l, fd_tower_align(), fd_tower_footprint() ); /* ctx->tower_spare */
170-
l = FD_LAYOUT_APPEND( l, notif_align(), notif_footprint( slot_max ) );
158+
l = FD_LAYOUT_APPEND( l, alignof(ctx_t), sizeof(ctx_t) );
159+
l = FD_LAYOUT_APPEND( l, fd_ghost_align(), fd_ghost_footprint( 2*slot_max, FD_VOTER_MAX ) );
160+
l = FD_LAYOUT_APPEND( l, fd_hfork_align(), fd_hfork_footprint( slot_max, FD_VOTER_MAX ) );
161+
l = FD_LAYOUT_APPEND( l, fd_notar_align(), fd_notar_footprint( tile->tower.max_vote_lookahead ) );
162+
l = FD_LAYOUT_APPEND( l, fd_tower_align(), fd_tower_footprint() );
163+
l = FD_LAYOUT_APPEND( l, fd_tower_accts_align(), fd_tower_accts_footprint( FD_VOTER_MAX ) );
164+
l = FD_LAYOUT_APPEND( l, fd_forks_align(), fd_forks_footprint( slot_max, FD_VOTER_MAX ) );
165+
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 ) );
167+
l = FD_LAYOUT_APPEND( l, notif_align(), notif_footprint( slot_max ) );
171168
return FD_LAYOUT_FINI( l, scratch_align() );
172169
}
173170

@@ -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

@@ -782,19 +784,19 @@ unprivileged_init( fd_topo_t * topo,
782784
void * accts = FD_SCRATCH_ALLOC_APPEND( l, fd_tower_accts_align(), fd_tower_accts_footprint( FD_VOTER_MAX ) );
783785
void * forks = FD_SCRATCH_ALLOC_APPEND( l, fd_forks_align(), fd_forks_footprint( slot_max, FD_VOTER_MAX ) );
784786
void * spare = FD_SCRATCH_ALLOC_APPEND( l, fd_tower_align(), fd_tower_footprint() );
785-
void * stake = FD_SCRATCH_ALLOC_APPEND( l, fd_epoch_stakes_align(), fd_epoch_stakes_footprint( slot_max ) );
787+
void * stake = FD_SCRATCH_ALLOC_APPEND( l, fd_epoch_stakes_align(), fd_epoch_stakes_footprint( slot_max ) );
786788
void * notif = FD_SCRATCH_ALLOC_APPEND( l, notif_align(), notif_footprint( slot_max ) );
787789
FD_SCRATCH_ALLOC_FINI( l, scratch_align() );
788790

789-
ctx->ghost = fd_ghost_join ( fd_ghost_new ( ghost, 2*slot_max, FD_VOTER_MAX, 42UL ) ); /* FIXME seed */
790-
ctx->hfork = fd_hfork_join ( fd_hfork_new ( hfork, slot_max, FD_VOTER_MAX, ctx->seed, tile->tower.hard_fork_fatal ) );
791-
ctx->notar = fd_notar_join ( fd_notar_new ( notar, tile->tower.max_vote_lookahead ) );
792-
ctx->tower = fd_tower_join ( fd_tower_new ( tower ) );
793-
ctx->tower_accts = fd_tower_accts_join( fd_tower_accts_new( accts, FD_VOTER_MAX ) );
794-
ctx->forks = fd_forks_join ( fd_forks_new ( forks, slot_max, FD_VOTER_MAX ) );
795-
ctx->tower_spare = fd_tower_join ( fd_tower_new ( spare ) );
796-
ctx->slot_stakes = fd_epoch_stakes_join( fd_epoch_stakes_new( stake, slot_max ) );
797-
ctx->notif = notif_join ( notif_new ( notif, slot_max ) );
791+
ctx->ghost = fd_ghost_join ( fd_ghost_new ( ghost, 2*slot_max, FD_VOTER_MAX, 42UL ) ); /* FIXME seed */
792+
ctx->hfork = fd_hfork_join ( fd_hfork_new ( hfork, slot_max, FD_VOTER_MAX, ctx->seed, tile->tower.hard_fork_fatal ) );
793+
ctx->notar = fd_notar_join ( fd_notar_new ( notar, tile->tower.max_vote_lookahead ) );
794+
ctx->tower = fd_tower_join ( fd_tower_new ( tower ) );
795+
ctx->tower_accts = fd_tower_accts_join ( fd_tower_accts_new ( accts, FD_VOTER_MAX ) );
796+
ctx->forks = fd_forks_join ( fd_forks_new ( forks, slot_max, FD_VOTER_MAX ) );
797+
ctx->tower_spare = fd_tower_join ( fd_tower_new ( spare ) );
798+
ctx->slot_stakes = fd_epoch_stakes_join( fd_epoch_stakes_new( stake, slot_max ) );
799+
ctx->notif = notif_join ( notif_new ( notif, slot_max ) );
798800
FD_TEST( ctx->ghost );
799801
FD_TEST( ctx->hfork );
800802
FD_TEST( ctx->notar );

0 commit comments

Comments
 (0)