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: Make random bytes deterministic within the test test_restored_packages_retry fixes lightningdevkit#2827 #2833

Closed
wants to merge 5 commits into from

Conversation

Harsh1s
Copy link

@Harsh1s Harsh1s commented Jan 17, 2024

I've tried to do as the issue wanted but I'm not sure if this is enough since this is my first PR on the org. Please feel free to suggest changes and would really appreciate some guidance as I am really interested in contributing to this org.

Copy link

coderabbitai bot commented Jan 17, 2024

Walkthrough

The recent modification implements a mechanism to create predictable randomness within a specific test in the Rust-Lightning project. This is done to stabilize the test_restored_packages_retry test, which had shown fragility due to its reliance on random bytes that could change with each execution.

Changes

File Path Change Summary
.../src/ln/monitor_tests.rs Introduced a loop for consistent test randomness in do_test_restored_packages_retry.

Related issues

Poem

In the code's woven burrow, a test did fret,
For random bytes danced in a chaotic set.
🐇 With a loop, now tame, they march in line,
Ensuring that each test will run just fine. ✨


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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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

@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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a175958 and 600f3a0.
Files selected for processing (1)
  • lightning/src/ln/monitor_tests.rs (1 hunks)
Additional comments: 2
lightning/src/ln/monitor_tests.rs (2)
  • 1985-1988: The implementation of the loop to override random bytes appears to be correct, ensuring deterministic behavior for the get-random calls. However, it's important to ensure that this deterministic behavior is only enabled during testing and does not affect production code paths.
Verification successful

The occurrences of override_random_bytes are found only within test files and a test utility file (test_utils.rs). This confirms that the override is used exclusively for testing purposes and does not affect production code paths.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the override is only set in test code and not in production code.
rg --type rust 'override_random_bytes' -- 'src/**/*.rs'

Length of output: 107



Script:

#!/bin/bash
# Search for occurrences of 'override_random_bytes' across all Rust files in the repository.
rg --type rust 'override_random_bytes'

Length of output: 1096

* 1988-1988: Ensure that the deterministic random bytes set by the override are being utilized correctly in the subsequent calls within the test. This is crucial for maintaining the integrity of the test's deterministic behavior.

@valentinewallace
Copy link
Contributor

So when I add a call to get_secure_random_bytes on startup, the test still fails.

To fix #2827, you'll need to actually check out a different git commit of LDK linked in the issue and regenerate the hardcoded monitor bytes in the test :)

@Harsh1s
Copy link
Author

Harsh1s commented Jan 20, 2024

So when I add a call to get_secure_random_bytes on startup, the test still fails.

To fix #2827, you'll need to actually check out a different git commit of LDK linked in the issue and regenerate the hardcoded monitor bytes in the test :)

Okay, thanks for the guidance and patience. I'll learn more and get to work again!

@codecov-commenter
Copy link

codecov-commenter commented May 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.83%. Comparing base (bd3cc00) to head (c1bc2b7).
Report is 729 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2833      +/-   ##
==========================================
+ Coverage   89.17%   89.83%   +0.66%     
==========================================
  Files         118      117       -1     
  Lines       97986    96179    -1807     
  Branches    97986    96179    -1807     
==========================================
- Hits        87376    86404     -972     
+ Misses       8419     7211    -1208     
- Partials     2191     2564     +373     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TheBlueMatt
Copy link
Collaborator

Hey @Harsh1s do you still intend to work on this?

@TheBlueMatt
Copy link
Collaborator

Closing as abandoned.

@TheBlueMatt TheBlueMatt closed this Sep 9, 2024
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.

4 participants