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

(BootAPI) Keep boot host alive #1811

Merged
merged 4 commits into from
Jul 15, 2024
Merged

Conversation

nick-bisonai
Copy link
Collaborator

Description

Instead of generating new libp2p host every time the check happens, use single host for repeated checks

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist before requesting a review

  • I have performed a self-review of my code.
  • If it is a core feature, I have added thorough tests.

Deployment

  • Should publish npm package
  • Should publish Docker image

@nick-bisonai nick-bisonai self-assigned this Jul 15, 2024
@nick-bisonai nick-bisonai requested a review from a team as a code owner July 15, 2024 08:29
Copy link
Contributor

coderabbitai bot commented Jul 15, 2024

Walkthrough

Walkthrough

The recent changes introduce a dependency on github.com/libp2p/go-libp2p/core/host across the boot package. A significant refactor involves creating a libp2p host instance outside the RefreshJob function and passing it as an argument, streamlining host management. Error handling around host retrieval has been enhanced, especially within the controller's sync function. Additionally, the test setup now initializes and cleans up the host correctly, ensuring consistent test environments.

Changes

File Path Change Summary
node/pkg/boot/boot.go Introduced github.com/libp2p/go-libp2p/core/host, refactored RefreshJob to accept host as parameter
node/pkg/boot/peer/controller.go Improved error handling for host retrieval from Fiber context in sync function
node/pkg/boot/tests/main_test.go Added host field in TestItems, created and assigned bootHost, added host cleanup logic
node/pkg/boot/utils/utils.go Modified Setup function to accept host parameter, added middleware to store host in context

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FiberContext
    participant Controller as Controller (sync)
    participant Host as libp2p Host
    participant Boot as Boot (RefreshJob)
    
    User->>FiberContext: Initiate sync
    FiberContext->>Controller: Call sync function
    Controller->>FiberContext: Retrieve host
    FiberContext-->>Controller: Return host or error
    Controller->>Boot: Call RefreshJob with host
    Boot->>Host: Perform refresh operations with provided host
    Boot-->>Controller: Return result
    Controller-->>User: Send response
Loading

Poem

In the land of code, where packets flow,
A new host joins, with libp2p's glow. ✨
As errors fade, and tests align,
Our code now dances, in perfect time. ⏰
With each new refactor, we stand tall,
A rabbit’s work, cherished by all. 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 04ecbbf and 6446098.

Files selected for processing (2)
  • node/pkg/boot/boot.go (5 hunks)
  • node/pkg/boot/tests/peer_test.go (2 hunks)
Additional comments not posted (5)
node/pkg/boot/boot.go (3)

17-17: Import statement for host approved.

The addition of github.com/libp2p/go-libp2p/core/host is necessary for the new host.Host parameter in the RefreshJob function.


81-81: Changes in RefreshJob function approved.

Accepting a host.Host parameter improves modularity and testability by decoupling host creation from the job logic.


43-48: Centralized host creation in Run function approved.

Creating the libp2p host outside of RefreshJob improves efficiency and modularity.

Ensure that all calls to RefreshJob match the new signature.

Also applies to: 54-54

Verification successful

Function calls to RefreshJob match the new signature.

The updates to the RefreshJob function signature have been correctly reflected throughout the codebase.

  • node/pkg/boot/boot.go
  • node/pkg/boot/tests/peer_test.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `RefreshJob` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go -A 5 $'RefreshJob'

Length of output: 1482

node/pkg/boot/tests/peer_test.go (2)

106-112: Changes in TestRefresh function approved.

Creating a libp2p host and passing it to RefreshJob ensures the test accommodates the new host.Host parameter, maintaining consistency with the updated function.


126-126: Changes in TestRefresh function for closed host approved.

Calling RefreshJob again after closing the host ensures the function handles the scenario where the host is closed, improving the robustness of the test.

Copy link
Contributor

@Intizar-T Intizar-T left a comment

Choose a reason for hiding this comment

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

lgtm!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6446098 and f76efa2.

Files selected for processing (2)
  • node/pkg/boot/boot.go (5 hunks)
  • node/pkg/boot/peer/controller.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • node/pkg/boot/boot.go
Additional comments not posted (1)
node/pkg/boot/peer/controller.go (1)

34-37: Ensure host is correctly retrieved from context.

The code retrieves the host from Fiber context and checks if it was successful. This is a good practice for error handling. Ensure that the context is correctly set with the host elsewhere in the codebase.

node/pkg/boot/peer/controller.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f76efa2 and 5f4baa3.

Files selected for processing (3)
  • .github/workflows/boot-api.test.yaml (1 hunks)
  • node/pkg/boot/boot.go (5 hunks)
  • node/pkg/boot/peer/controller.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • .github/workflows/boot-api.test.yaml
Files skipped from review as they are similar to previous changes (2)
  • node/pkg/boot/boot.go
  • node/pkg/boot/peer/controller.go

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5f4baa3 and 1697531.

Files selected for processing (4)
  • node/pkg/boot/boot.go (6 hunks)
  • node/pkg/boot/peer/controller.go (2 hunks)
  • node/pkg/boot/tests/main_test.go (3 hunks)
  • node/pkg/boot/utils/utils.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • node/pkg/boot/boot.go
  • node/pkg/boot/peer/controller.go
Additional comments not posted (5)
node/pkg/boot/tests/main_test.go (4)

11-19: LGTM!

The addition of the host field to the TestItems struct is appropriate for the new functionality.


29-34: LGTM!

The creation of bootHost and its assignment to testItems.host are necessary for the new functionality.


35-35: LGTM!

Passing the bootHost to the utils.Setup function is necessary for the new functionality.


73-73: LGTM!

Including a call to testItems.host.Close() in the bootCleanup function is necessary for proper resource management.

node/pkg/boot/utils/utils.go (1)

Line range hint 20-45:
LGTM!

The changes to the Setup function to accept a host.Host parameter and store the host information in the context are necessary for the new functionality.

@nick-bisonai nick-bisonai merged commit 9b09599 into master Jul 15, 2024
2 checks passed
@nick-bisonai nick-bisonai deleted the feat/boot-api-long-live-host branch July 15, 2024 09:37
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