-
Notifications
You must be signed in to change notification settings - Fork 42
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
Conversation
size-limit report 📦
|
There was a problem hiding this 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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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({ |
There was a problem hiding this comment.
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({ |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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()
There was a problem hiding this 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, |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
4a9e241
to
c90f88b
Compare
Thanks for the feedback!! |
This PR addresses #1429 (comment):
getPeers()
) to directly use multiple nodes for other protocolsNotes:
the tests are added butskip
as our current infrastructure does not support stubbing standalone functionstests to be un-skipped once test suite lacks mocking capabilities for standalone functions #1523 is doneTODO:
useproxyquire
/rewire
or alternatives to stub standalone functionsexplored; unfeasible