Skip to content

Commit 85c7e5e

Browse files
authored
fix: Ensure we always have a minimum number of connected peers (#2462)
## Why is this change needed? In case the db didn't already have sufficient peers we wouldn't connect to enough peers because the autodial was disabled. ## Merge Checklist _Choose all relevant options below by adding an `x` now or at any time before submitting for review_ - [x] PR title adheres to the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) standard - [x] PR has a [changeset](https://github.com/farcasterxyz/hub-monorepo/blob/main/CONTRIBUTING.md#35-adding-changesets) - [x] PR has been tagged with a change label(s) (i.e. documentation, feature, bugfix, or chore) - [ ] PR includes [documentation](https://github.com/farcasterxyz/hub-monorepo/blob/main/CONTRIBUTING.md#32-writing-docs) if necessary. <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on enhancing the peer-to-peer connection management in the `hubble` application by ensuring a minimum number of connected peers and adding functionality to manage denied peers. ### Detailed summary - Updated `minConnections` from `0` to `7` in `connectionManager` for better connection stability. - Introduced `addDeniedPeer(peerId: string)` method in `connectionFilter.ts` to manage denied peers. - Added logic to prevent autodial reconnections for denied peers in `removePeerFromAddressBook`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 6bbfcca commit 85c7e5e

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

.changeset/silent-crews-explain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@farcaster/hubble": patch
3+
---
4+
5+
fix: Ensure we always have a minimum number of connected peers

apps/hubble/src/network/p2p/connectionFilter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export class ConnectionFilter implements ConnectionGater {
3333
this.deniedPeers = addrs;
3434
}
3535

36+
addDeniedPeer(peerId: string) {
37+
this.deniedPeers.push(peerId);
38+
}
39+
3640
denyDialPeer = async (peerId: PeerId): Promise<boolean> => {
3741
const deny = this.shouldDeny(peerId.toString());
3842
if (deny) {

apps/hubble/src/network/p2p/gossipNodeWorker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ export class LibP2PNode {
244244
...(peerId && { peerId }),
245245
connectionGater: this._connectionGater,
246246
connectionManager: {
247-
minConnections: 0,
247+
// Set between the default DLo and DHi values. So we always have some connections, and not just the bootstrap peers.
248+
// This is also helpful in case the node starts with a clean db, since the only explicit connections are to bootstrap peers and db peers.
249+
minConnections: 7,
248250
},
249251
addresses: {
250252
listen: [listenMultiAddrStr],
@@ -423,6 +425,8 @@ export class LibP2PNode {
423425
/** Removes the peer from the address book and hangs up on them */
424426
async removePeerFromAddressBook(peerId: PeerId) {
425427
if (this._node) {
428+
// Add to the connection gater so the autodial doesn't reconnect. Not persisted on restart.
429+
this._connectionGater?.addDeniedPeer(peerId.toString());
426430
const hangupResult = await ResultAsync.fromPromise(
427431
this._node.hangUp(peerId),
428432
(error) => new HubError("unavailable", error as Error),

0 commit comments

Comments
 (0)