Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove PubSub based PeerDiscovery #1530

Merged
merged 6 commits into from
Oct 19, 2023

Conversation

sagar-a16z
Copy link
Contributor

@sagar-a16z sagar-a16z commented Oct 18, 2023

Motivation

Hubble instances were running out of Memory due to excessive duplicated traffic on Gossip.

Change Summary

Revoved PubSub based PeerDiscovery in favor of the existing ContactInfos being shared. This reduces amount of network traffic by over 10x while still allowing nodes to be discovered.

The way ContactInfos are added to the Peer Store's AddressBook suffices as a discovery mechism inside of libp2p.

Merge Checklist

Choose all relevant options below by adding an x now or at any time before submitting for review

Additional Context

The only outstanding consideration with this change is that now, Hubs only publish their own ContactInfos once every 4 hours, or on every new Connection. This means that a new Hub might not see the rest of the network immediately. We could reduce the 4 hour interval to something more reasonable once we test this change out.


PR-Codex overview

This PR focuses on adding a timestamp field to the ContactInfoContent message in the gossip.ts file.

Detailed summary

  • Added timestamp field to ContactInfoContent message in gossip.ts

The following files were skipped due to too many changes: apps/hubble/src/network/p2p/gossipNode.ts, apps/hubble/src/network/p2p/gossipNodeWorker.ts, apps/hubble/src/hubble.ts

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@changeset-bot
Copy link

changeset-bot bot commented Oct 18, 2023

🦋 Changeset detected

Latest commit: b933b45

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@farcaster/hub-nodejs Minor
@farcaster/hub-web Minor
@farcaster/core Minor
@farcaster/hubble Minor
@farcaster/replicator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Oct 18, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hub-monorepo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 18, 2023 6:13pm

@socket-security
Copy link

Removed dependencies detected. Learn more about Socket for GitHub ↗︎

🚮 Removed packages: @libp2p/[email protected]

@codecov
Copy link

codecov bot commented Oct 18, 2023

Codecov Report

Attention: 33 lines in your changes are missing coverage. Please review.

Files Coverage Δ
apps/hubble/src/network/p2p/gossipNode.ts 84.86% <100.00%> (-2.29%) ⬇️
apps/hubble/src/network/p2p/protocol.ts 50.00% <100.00%> (-33.34%) ⬇️
apps/hubble/src/hubble.ts 53.32% <56.52%> (+0.38%) ⬆️
apps/hubble/src/network/p2p/gossipNodeWorker.ts 24.16% <8.00%> (-0.41%) ⬇️

... and 2 files with indirect coverage changes

📢 Thoughts on this report? Let us know!.

@@ -1003,6 +1039,12 @@ export class Hub implements HubInterface {
log.error({ error: syncResult.error, peerId }, "Failed to sync with new peer");
}
}

// if the contact info doesn't include a timestamp, consider it invalid but allow the peer to stay in the address book
// TODO remove this once all peers are updated past 1.6.4
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just calling this out as a workaround to still accept peer contacts but to not forward them if they don't include a timestamp.

@@ -212,7 +220,7 @@ export class LibP2PNode {
}
}
}
return msgIdFnStrictSign(message);
return msgIdFnStrictNoSign(message);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the NoSign version? Performance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is misleading. I've pulled this function in from libp2p. The NoSign MsgId just hashes the Message.data field. The Signed MsgId function from earlier instead uses a Key + randomly generated Seq number as the MsgId.

So tldr; This just uses a sha256 hash of the Gossip Message.

@sanjayprabhu sanjayprabhu merged commit 153da45 into farcasterxyz:main Oct 19, 2023
7 of 8 checks passed
@sagar-a16z sagar-a16z deleted the hubble_oom branch October 19, 2023 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants