Skip to content

Commit c7adf7b

Browse files
two-heartlidatong
authored andcommitted
tower: fix fd_tower_verify
make tower_verify behave like defined in the header comment. Added size check and fixed wrong monotonicity check # Conflicts: # src/choreo/tower/fd_tower.c
1 parent 76b790d commit c7adf7b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/choreo/tower/fd_tower.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -787,13 +787,18 @@ fd_tower_to_vote_txn( fd_tower_t const * tower,
787787

788788
int
789789
fd_tower_verify( fd_tower_t const * tower ) {
790+
if( FD_UNLIKELY( fd_tower_cnt( tower )>=FD_TOWER_VOTE_MAX ) ) {
791+
FD_LOG_WARNING(( "[%s] invariant violation: cnt %lu >= FD_TOWER_VOTE_MAX %lu", __func__, fd_tower_cnt( tower ), (ulong)FD_TOWER_VOTE_MAX ));
792+
return -1;
793+
}
794+
790795
fd_tower_t const * prev = NULL;
791796
for( fd_tower_iter_t iter = fd_tower_iter_init( tower );
792-
!fd_tower_iter_done( tower, iter );
793-
iter = fd_tower_iter_next( tower, iter ) ) {
797+
!fd_tower_iter_done( tower, iter );
798+
iter = fd_tower_iter_next( tower, iter ) ) {
794799
fd_tower_t const * vote = fd_tower_iter_ele_const( tower, iter );
795-
if( FD_LIKELY( prev && !( vote->slot < prev->slot && vote->conf < prev->conf ) ) ) {
796-
FD_LOG_WARNING(( "[%s] invariant violation: vote %lu %lu. prev %lu %lu", __func__, vote->slot, vote->conf, prev->slot, prev->conf ));
800+
if( FD_UNLIKELY( prev && ( vote->slot < prev->slot || vote->conf < prev->conf ) ) ) {
801+
FD_LOG_WARNING(( "[%s] invariant violation: vote (slot:%lu conf:%lu) prev (slot:%lu conf:%lu)", __func__, vote->slot, vote->conf, prev->slot, prev->conf ));
797802
return -1;
798803
}
799804
prev = vote;

0 commit comments

Comments
 (0)