-
Notifications
You must be signed in to change notification settings - Fork 98
Fix nulls in peer endpoint #6553
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
Conversation
📝 Walkthrough📝 WalkthroughWalkthroughThe changes in this pull request involve modifications to the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 2
🧹 Outside diff range comments (1)
db/api/src/peers.rs (1)
Line range hint
1-824
: Consider enhancing error handling and documentationWhile the changes look good, here are some suggestions to further improve the overall quality of the code:
Error Handling: The current implementation uses a mix of
Result
andOption
types for error handling. Consider standardizing error handling across the module, possibly by defining custom error types that encompass all possible error scenarios.Documentation: Although the code is well-structured, adding more inline documentation, especially for public functions and structs, would improve maintainability. Consider adding doc comments that explain the purpose, parameters, and return values of key functions.
Consistency: Ensure that the handling of edge cases (like the NaN check we just added for
backoff
) is consistent across all floating-point fields in thePeerStatus
struct.Would you like me to provide examples of how to implement these suggestions?
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
📒 Files selected for processing (3)
- db/api/src/peers.rs (1 hunks)
- transport/api/src/lib.rs (1 hunks)
- transport/api/src/p2p.rs (3 hunks)
🧰 Additional context used
🔇 Additional comments (2)
transport/api/src/lib.rs (1)
599-609
: Improved error handling and logging innetwork_observed_multiaddresses
The changes to this method significantly improve its robustness and debuggability:
- It now handles the case when a peer is not found in the network storage, returning an empty vector instead of potentially panicking.
- Error cases are now logged, which will help with debugging issues in production.
- The function maintains its original signature, ensuring backwards compatibility.
These changes align well with best practices for error handling and logging in Rust.
db/api/src/peers.rs (1)
449-452
: LGTM! Improved handling of NaN values for backoff.This change enhances the robustness of the
PeerStatus
struct by properly handling potential NaN (Not a Number) values in thebackoff
field. By defaulting to 1.0 when a NaN value is encountered, we prevent propagation of invalid floating-point values into the application logic. This is particularly important for thebackoff
field, as it directly affects the behavior of peer interactions.To ensure this change doesn't introduce any regressions, let's verify the usage of the
backoff
field:✅ Verification successful
Verification Complete: No Impact Outside
peers.rs
The change to handle NaN values in the
backoff
field ofPeerStatus
withindb/api/src/peers.rs
is localized and does not affect other parts of the codebase. All usages ofbackoff
outside this file, particularly in vendor and unrelated modules, remain unaffected by this modification.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for any direct usage of the backoff field that might be affected by this change # Search for usage of backoff field in the codebase rg --type rust 'backoff'Length of output: 27835
Co-authored-by: Tibor <9529609+Teebor-Choka@users.noreply.github.com>
Co-authored-by: Tibor <9529609+Teebor-Choka@users.noreply.github.com>
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.
Actionable comments posted: 0
🧹 Outside diff range comments (1)
transport/api/src/lib.rs (1)
Verify NaN handling implementation
The search results indicate that
f64::NAN
handling for thebackoff
property intransport/api/src/lib.rs
is not implemented. To ensure the PR meets its objective of handlingf64::NAN
values forbackoff
, please implement the necessary NaN checks within thebackoff
logic or confirm if it's handled in another relevant file.🔗 Analysis chain
Line range hint
1-609
: Verify NaN handling implementationWhile these changes improve error handling, they don't directly address the handling of
f64::NAN
values for thebackoff
property mentioned in the PR objectives. Could you please confirm if the NaN handling is implemented in another file or if there are additional changes planned to address this specific issue?To check for NaN handling implementation, we can search for relevant code:
Line range hint
1-609
: Verify NaN handling implementationThe initial search included vendored dependencies, which returned numerous
f64::NAN
usages unrelated to our codebase. To accurately verify the implementation off64::NAN
handling in our project, please run the following script to search forf64::NAN
,f64::is_nan()
, and.is_nan()
exclusively within our codebase, excluding thevendor/
directory:
Line range hint
1-609
: Verify NaN handling for thebackoff
propertyIt appears that
f64::NAN
handling specific to thebackoff
property is not present in the main codebase. To ensure thatbackoff
correctly handlesf64::NAN
as per the PR objectives, please execute the following script to search for thebackoff
property and verify its handling off64::NAN
:🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for NaN handling in Rust files rg --type rust 'f64::NAN|f64::is_nan\(\)|\.is_nan\(\)'Length of output: 30763
Script:
#!/bin/bash # Search for NaN handling in Rust files within the main codebase, excluding vendored dependencies rg --type rust 'f64::NAN|f64::is_nan\(\)|\.is_nan\(\)' --glob '!vendor/**'Length of output: 158
Script:
#!/bin/bash # Search for the 'backoff' property and its handling of f64::NAN in Rust files, excluding vendored dependencies rg --type rust 'backoff|f64::NAN|f64::is_nan\(\)|\.is_nan\(\)' --glob '!vendor/**'Length of output: 6476
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
📒 Files selected for processing (1)
- transport/api/src/lib.rs (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
transport/api/src/lib.rs (1)
599-609
: Improved error handling and logging innetwork_observed_multiaddresses
The changes in this method significantly improve error handling and logging. The new implementation uses a
match
statement to handle different scenarios when retrieving peer information, which is more robust than the previous approach.Improvements:
- Better error handling by explicitly managing the
Ok(Some(_))
,Ok(None)
, andErr(_)
cases.- Enhanced logging with appropriate log levels (trace for not found, error for retrieval failure).
- Consistent return of an empty vector when peer information is unavailable or an error occurs.
These changes align well with the PR objectives of improving error handling and logging in the
Network
module.
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.
Actionable comments posted: 1
🧹 Outside diff range comments (2)
transport/network/src/config.rs (2)
Line range hint
91-95
: Consider reviewing commented-out validationThere's a commented-out validation check for the relationship between
quality_bad_threshold
andquality_offline_threshold
. It might be worth revisiting this to determine if it should be implemented or removed entirely.If this validation is still relevant, consider uncommenting and implementing it. If not, it may be cleaner to remove the commented code.
Line range hint
176-179
: Clarifybackoff_max
function implementationThe
backoff_max
function calculates a value based on the ratio of two durations. While functionally correct, this implementation might be confusing for future maintainers.Consider adding a comment explaining the rationale behind this calculation or refactoring it to use more self-explanatory constants or functions.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
📒 Files selected for processing (2)
- transport/api/src/lib.rs (1 hunks)
- transport/network/src/config.rs (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
transport/network/src/config.rs (1)
17-17
: Improved documentation clarityThe update to the documentation comment for the
NetworkConfig
struct is a positive change. By using the fully qualified pathcrate::network::Network
instead of the genericNetwork
, it provides more precise context and improves code navigation.This change aligns with Rust documentation best practices and will help developers better understand the relationship between
NetworkConfig
and theNetwork
object.
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.
Close #6535 and close #6340
Network