Conversation
Summary of ChangesHello @wemeetagain, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request undertakes a significant upgrade of the project's networking layer by integrating Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request is a significant but necessary upgrade of libp2p and related dependencies to v3. The changes correctly adapt the codebase to the new stream and gossipsub APIs, simplify timeout handling by removing the TTFB mechanism, and improve multiaddr parsing for better compatibility. The refactoring from inheritance to composition for Eth2Gossipsub is well-executed. Overall, the changes are well-aligned with the stated motivation. I've identified a couple of areas where the code for constructing bind addresses could be simplified for better readability and robustness.
| const bindAddrs = (workerData.bindAddrs.ip4 && workerData.bindAddrs.ip6 | ||
| ? { | ||
| ip4: multiaddr(workerData.bindAddrs.ip4), | ||
| ip6: multiaddr(workerData.bindAddrs.ip6), | ||
| } | ||
| : workerData.bindAddrs.ip4 | ||
| ? { | ||
| ip4: multiaddr(workerData.bindAddrs.ip4), | ||
| } | ||
| : { | ||
| ip6: multiaddr(workerData.bindAddrs.ip6), | ||
| }) as Parameters<(typeof Discv5)["create"]>[0]["bindAddrs"]; |
There was a problem hiding this comment.
The logic for constructing bindAddrs using nested ternary operators is complex and hard to read. It also has a potential bug: if both workerData.bindAddrs.ip4 and workerData.bindAddrs.ip6 are falsy, it will attempt to call multiaddr(undefined), which would cause a runtime error. A refactor using if statements would be clearer, more maintainable, and safer.
const bindAddrs: Parameters<(typeof Discv5)["create"]>[0]["bindAddrs"] = {};
if (workerData.bindAddrs.ip4) {
bindAddrs.ip4 = multiaddr(workerData.bindAddrs.ip4);
}
if (workerData.bindAddrs.ip6) {
bindAddrs.ip6 = multiaddr(workerData.bindAddrs.ip6);
}| const bindAddrsConfig = (bindAddrs.ip4 && bindAddrs.ip6 | ||
| ? { | ||
| ip4: multiaddr(bindAddrs.ip4), | ||
| ip6: multiaddr(bindAddrs.ip6), | ||
| } | ||
| : bindAddrs.ip4 | ||
| ? { | ||
| ip4: multiaddr(bindAddrs.ip4), | ||
| } | ||
| : { | ||
| ip6: multiaddr(bindAddrs.ip6), | ||
| }) as Parameters<(typeof Discv5)["create"]>[0]["bindAddrs"]; |
There was a problem hiding this comment.
The construction of bindAddrsConfig is difficult to follow due to the nested ternary operators. This complexity can be reduced for better readability and maintainability. Additionally, if both bindAddrs.ip4 and bindAddrs.ip6 are falsy, this logic would lead to a runtime error by calling multiaddr(undefined). I recommend refactoring this to use simple if statements, which is both safer and easier to understand.
const bindAddrsConfig: Parameters<(typeof Discv5)["create"]>[0]["bindAddrs"] = {};
if (bindAddrs.ip4) {
bindAddrsConfig.ip4 = multiaddr(bindAddrs.ip4);
}
if (bindAddrs.ip6) {
bindAddrsConfig.ip6 = multiaddr(bindAddrs.ip6);
}There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 34abe5716d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| try { | ||
| restartRespTimeout(); | ||
| // Note: libp2p.stop() will close all connections, so not necessary to abort this pipe on parent stop | ||
| yield* pipe( | ||
| abortableSource(stream.source as AsyncIterable<Uint8ArrayList>, [ | ||
| { | ||
| signal: ttfbTimeoutController.signal, | ||
| getError: () => new RequestError({code: RequestErrorCode.TTFB_TIMEOUT}), | ||
| }, | ||
| abortableSource(stream as AsyncIterable<Uint8ArrayList>, [ |
There was a problem hiding this comment.
Start RESP timeout after first byte to avoid false timeouts
The RESP timeout is armed before any response bytes are read (restartRespTimeout() is called immediately), and it is only reset in onResponseChunk after a full chunk has been decoded. This means the first chunk’s budget includes any initial delay plus transfer time, so large/slow responses can hit RESP_TIMEOUT even while data is still streaming. If a peer takes a few seconds to send the first byte and then streams a large byRange response, this can now time out prematurely. Consider starting the timeout when the first header byte arrives (or resetting on each chunk boundary as soon as it begins) to preserve the per‑chunk timeout semantics.
Useful? React with 👍 / 👎.
Performance Report🚀🚀 Significant benchmark improvement detected
Full benchmark results
|
Motivation
Description
source/sinkwith libp2p v3MessageStreamsemantics (send,onDrain,close, async-iteration) and adapt request/response encoders/decoders accordingly (packages/reqresp/src/*).MockLibP2pStream,arrToSource, event helpers) to implement the v3 message stream interface and event handling; update unit/e2e tests that exercised stream APIs and encode/decode behavior (multiple test files underpackages/reqresp/testandpackages/beacon-node/test).@libp2p/gossipsubtypes and service instance usage, update gossipsub adapter to the service factory and instance APIs, and adjust topic/message types and scoring imports; fix multiaddr parsing and direct-peer handling to usegetComponents()(several files underpackages/beacon-node/src/network/*).typesto package.json for beacon-node/validator), update datastore/level API call signatures and other libp2p v3 type changes across the repo (multiple package.json and ts code changes).Testing
pnpm installand rebuilt updated packages where needed usingpnpm --filter <pkg> buildfor affected packages (notably@lodestar/reqresp,@lodestar/beacon-node,@lodestar/state-transition,@lodestar/fork-choice,@lodestar/api,@lodestar/db,@lodestar/validator); builds completed for the modified targets.pnpm check-types(recursive workspace run) and iterated fixes until the checker completed successfully for the workspace.Codex Task