-
Notifications
You must be signed in to change notification settings - Fork 43
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
chore: refactor peer-exchange according to nwaku 0.15.0 #1193
Conversation
size-limit report 📦
|
@@ -18,19 +18,17 @@ import { Nwaku } from "../src/nwaku.js"; | |||
describe("Peer Exchange", () => { | |||
let waku: LightNode; | |||
|
|||
before(async function () { | |||
afterEach(async function () { | |||
!!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e)); |
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.
async/await
can be used to prettify code
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.
How would it look like? You'd need to add a try/catch block which would make this more verbose than necessary, no?
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.
something like
afterEach(async () => {
try {
await waku?.stop();
} catch (err) {
console.log("Waku failed to stop", e);
}
});
It depends on perception what is verbose for this case.
const enrs = await Promise.all( | ||
decoded.peerInfos.map( | ||
(peerInfo) => peerInfo.enr && ENR.decode(peerInfo.enr) | ||
) | ||
); | ||
|
||
const peerInfos = enrs.map((enr) => { | ||
return { | ||
ENR: enr, | ||
}; | ||
}); |
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.
could probably merge both maps to avoid traversing the array twice
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.
we need to wait for the promise resolution first before converting it into an array again
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.
const peerInfos = await Promise.all(
decoded.peerInfos.map(
(peerInfo) => {
if (!peerInfo.enr) return;
const enr = await ENR.decode(peerInfo.enr);
return { ENR: enr }
}
)
);
Probably need to use a typeguard:
export function isDefined<T>(msg: T | undefined): msg is T {
return !!msg;
}
Or use this lib: https://twitter.com/mattpocockuk/status/1627686864579600385?s=20
for (const _peerInfo of peerInfos) { | ||
const { ENR } = _peerInfo; | ||
if (!ENR) { | ||
log("no ENR"); |
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.
We can see that this should not be possible from the code in waku_peer_exchange.ts
I don't think this log line is useful.
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 of the protobuf definitions and typescript interpretations, it interprets that the fields might be optional which makes it necessary for us to handle that scenario without a forbidden assertion
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.
Should be sorted with #1196
@@ -18,19 +18,17 @@ import { Nwaku } from "../src/nwaku.js"; | |||
describe("Peer Exchange", () => { | |||
let waku: LightNode; | |||
|
|||
before(async function () { | |||
afterEach(async function () { | |||
!!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e)); |
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.
How would it look like? You'd need to add a try/catch block which would make this more verbose than necessary, no?
Will aim to merge this for now with the comments addressed in the interest of time as this PR also unblocks #1186. Please feel free to tag me again in case we want to address some of the remaining open conversations. |
@fryorcraken are you aware why the px test with go-waku is failing with a timeout error, while it succeeds for node & nwaku? how can i run go-waku testing locally to reproduce the same? |
I don't know if @richard-ramos has aligned go-waku's behaviour just yet.
Just set some env vars (modify as needed).
|
go-waku's peer exchange implementation is not compatible with nwaku. I'll look at it this week |
69ba3b8
to
eb885c5
Compare
eb885c5
to
55cc8f9
Compare
Hey @richard-ramos, is there an update yet? 😅 |
Update CI to use go-waku 0.5.2 and see how it goes. |
Merging this PR for now. Tracking the breaking go-waku CI test here: waku-org/go-waku#491 |
Problem
Peer Exchange is supposed to be a request-response protocol (https://rfc.vac.dev/spec/34/) but due to a bug in the earlier versions of nwaku, it would asynchronously send a callback on a different stream. To adapt to this, js-waku would have an event listener open.
With nwaku 0.15.0, this is addressed and peer-exchange works as the originally designed request-response protocol.
Solution
js-waku's peer exchange implementation now removes the event listener on the registrar, and use the response received in the request to dispatch the ENRs.
Notes