Skip to content

Commit 5c3e4be

Browse files
committed
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 6d8a2f1 commit 5c3e4be

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
@@ -867,10 +867,10 @@ fd_gui_poll( fd_gui_t * gui, long now ) {
867867
static void
868868
fd_gui_handle_gossip_update( fd_gui_t * gui,
869869
uchar const * msg ) {
870-
if( FD_UNLIKELY( gui->gossip.peer_cnt == FD_GUI_MAX_PEER_CNT ) ) {
871-
FD_LOG_DEBUG(("gossip peer cnt exceeds 40200 %lu, ignoring additional entries", gui->gossip.peer_cnt ));
872-
return;
873-
}
870+
/* `gui->gossip.peer_cnt` is guaranteed to be in [0, FD_GUI_MAX_PEER_CNT], because
871+
`peer_cnt` is FD_TEST-ed to be less than or equal FD_GUI_MAX_PEER_CNT.
872+
For every new peer that is added an existing peer will be removed or was still free.
873+
And adding a new peer is done at most `peer_cnt` times. */
874874
ulong const * header = (ulong const *)fd_type_pun_const( msg );
875875
ulong peer_cnt = header[ 0 ];
876876

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

941-
gui->gossip.peer_cnt = fd_ulong_min( gui->gossip.peer_cnt+1UL, FD_GUI_MAX_PEER_CNT-1UL );
941+
gui->gossip.peer_cnt++;
942942
} else {
943943
int peer_updated = gui->gossip.peers[ found_idx ].shred_version!=*(ushort const *)(data+i*(58UL+12UL*6UL)+40UL) ||
944944
// gui->gossip.peers[ found_idx ].wallclock!=*(ulong const *)(data+i*(58UL+12UL*6UL)+32UL) ||
@@ -995,10 +995,8 @@ fd_gui_handle_gossip_update( fd_gui_t * gui,
995995
static void
996996
fd_gui_handle_vote_account_update( fd_gui_t * gui,
997997
uchar const * msg ) {
998-
if( FD_UNLIKELY( gui->vote_account.vote_account_cnt==FD_GUI_MAX_PEER_CNT ) ) {
999-
FD_LOG_DEBUG(("vote account cnt exceeds 40200 %lu, ignoring additional entries", gui->vote_account.vote_account_cnt ));
1000-
return;
1001-
}
998+
/* See fd_gui_handle_gossip_update for why `gui->vote_account.vote_account_cnt`
999+
is guaranteed to be in [0, FD_GUI_MAX_PEER_CNT]. */
10021000
ulong const * header = (ulong const *)fd_type_pun_const( msg );
10031001
ulong peer_cnt = header[ 0 ];
10041002

@@ -1056,7 +1054,7 @@ fd_gui_handle_vote_account_update( fd_gui_t * gui,
10561054
gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].commission = *(data+i*112UL+96UL);
10571055
gui->vote_account.vote_accounts[ gui->vote_account.vote_account_cnt ].delinquent = *(data+i*112UL+97UL);
10581056

1059-
gui->vote_account.vote_account_cnt = fd_ulong_min( gui->vote_account.vote_account_cnt+1UL, FD_GUI_MAX_PEER_CNT-1UL );
1057+
gui->vote_account.vote_account_cnt++;
10601058
} else {
10611059
int peer_updated =
10621060
memcmp( gui->vote_account.vote_accounts[ found_idx ].pubkey->uc, data+i*112UL+32UL, 32UL ) ||

0 commit comments

Comments
 (0)