Skip to content

Commit 8830672

Browse files
gui: support FD_GUI_MAX_PEER_CNT many peers
When there are no peers and we try to add `FD_GUI_MAX_PEER_CNT` peers, `gui->gossip.peer_cnt` would previously be stuck at `FD_GUI_MAX_PEER_CNT-1` due to the saturating arithmetic. The effect is that ALL `FD_GUI_MAX_PEER_CNT` peers of the input `msg` would be _copied_ into the `peers` array, but the last peer would be effectively ignored since the `gui->gossip.peer_cnt` would not reflect its addition. The value of `gui->gossip.peer_cnt` is now allowed to go up to `FD_GUI_MAX_PEER_CNT`, so that all `FD_GUI_MAX_PEER_CNT` peers can be added when starting from zero peers. The testing and bail-out when `gui->gossip.peer_cnt` is the maximum is unnecessary, due to the removal logic which ensures that the peer count can never exceed the maximum.
1 parent 0cff989 commit 8830672

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/disco/gui/fd_gui.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -862,10 +862,10 @@ fd_gui_poll( fd_gui_t * gui, long now ) {
862862
static void
863863
fd_gui_handle_gossip_update( fd_gui_t * gui,
864864
uchar const * msg ) {
865-
if( FD_UNLIKELY( gui->gossip.peer_cnt == FD_GUI_MAX_PEER_CNT ) ) {
866-
FD_LOG_DEBUG(("gossip peer cnt exceeds 40200 %lu, ignoring additional entries", gui->gossip.peer_cnt ));
867-
return;
868-
}
865+
/* `gui->gossip.peer_cnt` is guaranteed to be in [0, FD_GUI_MAX_PEER_CNT], because
866+
`peer_cnt` is FD_TEST-ed to be less than or equal FD_GUI_MAX_PEER_CNT.
867+
For every new peer that is added an existing peer will be removed or was still free.
868+
And adding a new peer is done at most `peer_cnt` times. */
869869
ulong const * header = (ulong const *)fd_type_pun_const( msg );
870870
ulong peer_cnt = header[ 0 ];
871871

@@ -933,7 +933,7 @@ fd_gui_handle_gossip_update( fd_gui_t * gui,
933933
gui->gossip.peers[ gui->gossip.peer_cnt ].sockets[ j ].port = *(ushort const *)(data+i*(58UL+12UL*6UL)+58UL+j*6UL+4UL);
934934
}
935935

936-
gui->gossip.peer_cnt = fd_ulong_min( gui->gossip.peer_cnt+1UL, FD_GUI_MAX_PEER_CNT-1UL );
936+
gui->gossip.peer_cnt++;
937937
} else {
938938
int peer_updated = gui->gossip.peers[ found_idx ].shred_version!=*(ushort const *)(data+i*(58UL+12UL*6UL)+40UL) ||
939939
// gui->gossip.peers[ found_idx ].wallclock!=*(ulong const *)(data+i*(58UL+12UL*6UL)+32UL) ||
@@ -990,10 +990,8 @@ fd_gui_handle_gossip_update( fd_gui_t * gui,
990990
static void
991991
fd_gui_handle_vote_account_update( fd_gui_t * gui,
992992
uchar const * msg ) {
993-
if( FD_UNLIKELY( gui->vote_account.vote_account_cnt==FD_GUI_MAX_PEER_CNT ) ) {
994-
FD_LOG_DEBUG(("vote account cnt exceeds 40200 %lu, ignoring additional entries", gui->vote_account.vote_account_cnt ));
995-
return;
996-
}
993+
/* See fd_gui_handle_gossip_update for why `gui->vote_account.vote_account_cnt`
994+
is guaranteed to be in [0, FD_GUI_MAX_PEER_CNT]. */
997995
ulong const * header = (ulong const *)fd_type_pun_const( msg );
998996
ulong peer_cnt = header[ 0 ];
999997

@@ -1051,7 +1049,7 @@ fd_gui_handle_vote_account_update( fd_gui_t * gui,
10511049
gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].commission = *(data+i*112UL+96UL);
10521050
gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].delinquent = *(data+i*112UL+97UL);
10531051

1054-
gui->vote_account.vote_account_cnt = fd_ulong_min( gui->vote_account.vote_account_cnt+1UL, FD_GUI_MAX_PEER_CNT-1UL );
1052+
gui->vote_account.vote_account_cnt++;
10551053
} else {
10561054
int peer_updated =
10571055
memcmp( gui->vote_account.vote_accounts[ found_idx ].pubkey->uc, data+i*112UL+32UL, 32UL ) ||

0 commit comments

Comments
 (0)