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

feat!: set peer-exchange with default bootstrap #1469

Merged
merged 75 commits into from
Sep 7, 2023
Merged

Conversation

danisharora099
Copy link
Collaborator

@danisharora099 danisharora099 commented Aug 11, 2023

This PR addresses #1429 (comment):

  • sets peer-exchange with the default bootstrap flag
  • adds a configurable method to be able to fetch bootstrap peers and number of peers according to the protocol:
    • sets up redundant usage with LP while adding functionality that we can extend on (getPeers()) to directly use multiple nodes for other protocols

Notes:

  • the tests are added but skip as our current infrastructure does not support stubbing standalone functions

TODO:

@github-actions
Copy link

github-actions bot commented Aug 11, 2023

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
Waku core 28.73 KB (+0.2% 🔺) 575 ms (+0.2% 🔺) 511 ms (+218.84% 🔺) 1.1 s
Waku Simple Light Node 309.61 KB (+0.44% 🔺) 6.2 s (+0.44% 🔺) 1.7 s (+101.07% 🔺) 7.9 s
ECIES encryption 28.68 KB (0%) 574 ms (0%) 451 ms (+44.79% 🔺) 1.1 s
Symmetric encryption 28.68 KB (0%) 574 ms (0%) 313 ms (-5.79% 🔽) 887 ms
DNS discovery 118.59 KB (0%) 2.4 s (0%) 795 ms (+34.21% 🔺) 3.2 s
Privacy preserving protocols 122.61 KB (+0.01% 🔺) 2.5 s (+0.01% 🔺) 784 ms (+37.94% 🔺) 3.3 s
Light protocols 28.95 KB (+0.9% 🔺) 579 ms (+0.9% 🔺) 379 ms (-1.51% 🔽) 958 ms
History retrieval protocols 28.08 KB (+0.57% 🔺) 562 ms (+0.57% 🔺) 354 ms (+15.53% 🔺) 915 ms
Deterministic Message Hashing 5.64 KB (0%) 113 ms (0%) 128 ms (+10% 🔺) 241 ms

packages/core/src/lib/base_protocol.ts Outdated Show resolved Hide resolved
packages/core/src/lib/base_protocol.ts Outdated Show resolved Hide resolved
packages/interfaces/src/protocols.ts Outdated Show resolved Hide resolved
packages/core/src/lib/light_push/index.ts Outdated Show resolved Hide resolved
@danisharora099 danisharora099 changed the title feat: set peer-exchange with default bootstrap feat!: set peer-exchange with default bootstrap Sep 5, 2023
packages/core/src/lib/base_protocol.ts Outdated Show resolved Hide resolved
packages/core/src/lib/light_push/index.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@weboko weboko left a comment

Choose a reason for hiding this comment

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

still some comments to address but looks neat

log("Failed to decode push reply", err);
error = SendError.DECODE_FAILED;
log("Failed to send waku light push request", err);
error = SendError.GENERIC_FAIL;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why it's GENERIC_FAIL now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

because there's another try-catch block for decoding attempt (line 134)

this try-catch block is purely for the pipe() operation

const _pubSubTopic =
pubSubTopic ?? this.options.pubSubTopic ?? DefaultPubSubTopic;

const peer = await this.getPeer(peerId);
const peer = (
await this.getPeers({
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

uses the new API but only uses one peer for filter
with #1463, we can use multiple peers to subscribe to the message


const peer = await this.getPeer(options?.peerId);
const peer = (
await this.getPeers({
Copy link
Collaborator Author

@danisharora099 danisharora099 Sep 5, 2023

Choose a reason for hiding this comment

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

uses the new API is above with Filter but fetches one peers -- extendable to using multiple peers for the Store protocol

/**
* @param components - libp2p components
*/
constructor(components: Libp2pComponents) {
super(PeerExchangeCodec, components);
this.multicodec = PeerExchangeCodec;
Copy link
Collaborator Author

@danisharora099 danisharora099 Sep 5, 2023

Choose a reason for hiding this comment

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

this is already set/accessible with this.multicodec as we initialise BaseProtocol with super()

Copy link
Collaborator

@fryorcraken fryorcraken left a comment

Choose a reason for hiding this comment

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

A number of software engineer principles that would make sense to follow:

  • single-responsibility principle in regards to the filterPeers function
  • tests are close to the code they test (filterPeers is in @waku/utils but the test are in @waku/core
  • relevant/minimal scope: keep the scope of variables and functions minimal: filterPeers is in @waku/utils but only used by @waku/core

Approving because business logic looks correct but refactoring is needed to keep code maintainable.

tags: new Map<string, Tag>([[Tags.BOOTSTRAP, { value: 100 }]])
},
{
id: peer3,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd include non-boostrap peers in this test to ensure they don't get filtered out.

* @param maxBootstrapPeers - The maximum number of bootstrap peers to retrieve.
* @returns A Promise that resolves to an array of peers based on the specified criteria.
*/
export async function filterPeers(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this function in a different package? is it used by another other package but @waku/core?

Copy link
Collaborator Author

@danisharora099 danisharora099 Sep 7, 2023

Choose a reason for hiding this comment

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

it is not - fair point. wanted it to be similar to other standalone functions we use for base_protocol that stay in @waku/utils like selectPeerForProtocol.
personally inclining to have these standalone functions not in the root of core as it's a helper function; perhaps this issue is part of a potential larger proposal to move helpers into a subdir within the same package to increase readability?

Screenshot 2023-09-07 at 12 55 16 PM

Copy link
Collaborator

Choose a reason for hiding this comment

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

move helpers into a subdir within the same package to increase readability?

Sounds good

Copy link
Collaborator Author

@danisharora099 danisharora099 Sep 15, 2023

Choose a reason for hiding this comment

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

move helpers into a subdir within the same package to increase readability?

Sounds good

tracking here: #1570

import type { Tag } from "@libp2p/interface/peer-store";
import { createSecp256k1PeerId } from "@libp2p/peer-id-factory";
import { Tags } from "@waku/interfaces";
import { filterPeers } from "@waku/utils";
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test file only tests filterPeers which is in a different package.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

renamed this to be a filterPeers spec test instead

@danisharora099
Copy link
Collaborator Author

A number of software engineer principles that would make sense to follow:

  • single-responsibility principle in regards to the filterPeers function
  • tests are close to the code they test (filterPeers is in @waku/utils but the test are in @waku/core
  • relevant/minimal scope: keep the scope of variables and functions minimal: filterPeers is in @waku/utils but only used by @waku/core

Approving because business logic looks correct but refactoring is needed to keep code maintainable.

Thanks for the feedback!!
I have addressed the comments. Please let me know if there's anything else that you think needs to be addressed re this PR and I can followup!

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.

3 participants