Skip to content

Commit 9884872

Browse files
committed
fix(tower): lockout check
1 parent 9c4df8e commit 9884872

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/choreo/tower/fd_tower.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,16 @@ simulate_vote( fd_tower_t const * tower, ulong slot ) {
9191
int
9292
fd_tower_lockout_check( fd_tower_t const * tower,
9393
fd_ghost_t const * ghost,
94-
ulong switch_slot,
95-
fd_hash_t const * hash_id ) {
94+
ulong slot,
95+
fd_hash_t const * block_id ) {
9696
#if FD_TOWER_USE_HANDHOLDING
9797
FD_TEST( !fd_tower_votes_empty( tower ) ); /* caller error */
9898
#endif
9999

100100
/* Simulate a vote to pop off all the votes that have been expired at
101101
the top of the tower. */
102102

103-
ulong cnt = simulate_vote( tower, switch_slot );
103+
ulong cnt = simulate_vote( tower, slot );
104104

105105
/* By definition, all votes in the tower must be for the same fork, so
106106
check if the previous vote (ie. the last vote in the tower) is on
@@ -115,18 +115,19 @@ fd_tower_lockout_check( fd_tower_t const * tower,
115115
fd_tower_vote_t const * vote = fd_tower_votes_peek_index_const( tower, cnt - 1 );
116116
fd_ghost_ele_t const * root = fd_ghost_root_const( ghost );
117117

118-
int lockout_check = vote->slot < root->slot ||
119-
fd_ghost_is_ancestor( ghost, fd_ghost_hash( ghost, vote->slot ), hash_id );
120-
FD_LOG_NOTICE(( "[fd_tower_lockout_check] ok? %d. top: (slot: %lu, conf: %lu). switch: %lu.", lockout_check, vote->slot, vote->conf, switch_slot ));
118+
int lockout_check = slot <= vote->slot ||
119+
vote->slot < root->slot ||
120+
fd_ghost_is_ancestor( ghost, fd_ghost_hash( ghost, vote->slot ), block_id );
121+
FD_LOG_NOTICE(( "[fd_tower_lockout_check] ok? %d. top: (slot: %lu, conf: %lu). switch: %lu.", lockout_check, vote->slot, vote->conf, slot ));
121122
return lockout_check;
122123
}
123124

124125
int
125126
fd_tower_switch_check( fd_tower_t const * tower,
126127
fd_epoch_t const * epoch,
127128
fd_ghost_t const * ghost,
128-
ulong switch_slot,
129-
fd_hash_t const * switch_hash_id ) {
129+
ulong slot,
130+
fd_hash_t const * block_id ) {
130131
#if FD_TOWER_USE_HANDHOLDING
131132
FD_TEST( !fd_tower_votes_empty( tower ) ); /* caller error */
132133
#endif
@@ -169,12 +170,12 @@ fd_tower_switch_check( fd_tower_t const * tower,
169170
*/
170171

171172
#if FD_TOWER_USE_HANDHOLDING
172-
FD_TEST( !fd_ghost_is_ancestor( ghost, fd_ghost_hash( ghost, vote->slot ), switch_hash_id ) );
173+
FD_TEST( !fd_ghost_is_ancestor( ghost, fd_ghost_hash( ghost, vote->slot ), block_id ) );
173174
#endif
174175
fd_hash_t const * vote_block_id = fd_ghost_hash( ghost, vote->slot );
175176
fd_ghost_hash_map_t const * maph = fd_ghost_hash_map_const( ghost );
176177
fd_ghost_ele_t const * pool = fd_ghost_pool_const( ghost );
177-
fd_ghost_ele_t const * gca = fd_ghost_gca( ghost, vote_block_id, switch_hash_id );
178+
fd_ghost_ele_t const * gca = fd_ghost_gca( ghost, vote_block_id, block_id );
178179
ulong gca_idx = fd_ghost_hash_map_idx_query_const( maph, &gca->key, ULONG_MAX, pool );
179180

180181
/* gca_child is our latest_vote slot's ancestor that is also a direct
@@ -196,7 +197,7 @@ fd_tower_switch_check( fd_tower_t const * tower,
196197
}
197198

198199
double switch_pct = (double)switch_stake / (double)epoch->total_stake;
199-
FD_LOG_DEBUG(( "[%s] ok? %d. top: %lu. switch: %lu. switch stake: %.0lf%%.", __func__, switch_pct > SWITCH_PCT, fd_tower_votes_peek_tail_const( tower )->slot, switch_slot, switch_pct * 100.0 ));
200+
FD_LOG_DEBUG(( "[%s] ok? %d. top: %lu. switch: %lu. switch stake: %.0lf%%.", __func__, switch_pct > SWITCH_PCT, fd_tower_votes_peek_tail_const( tower )->slot, slot, switch_pct * 100.0 ));
200201
return switch_pct > SWITCH_PCT;
201202
}
202203

src/choreo/tower/fd_tower.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ void *
517517
fd_tower_delete( void * tower );
518518

519519
/* fd_tower_lockout_check checks if we are locked out from voting for
520-
`slot`. Returns 1 if we can vote for `slot` without violating
520+
the `slot`. Returns 1 if we can vote for `slot` without violating
521521
lockout, 0 otherwise. Assumes tower is non-empty.
522522
523523
After voting for a slot n, we are locked out for 2^k slots, where k

0 commit comments

Comments
 (0)