Skip to content

Conversation

Teebor-Choka
Copy link
Contributor

@Teebor-Choka Teebor-Choka commented Jun 2, 2025

  • probe: Minor log improvements
  • Cleanup Pinger object
  • Remove explicit network update feedback chain to the transport layer (connection close and quality update) and remove the obsolete code
  • Improve libp2p discovery logs

Notes

This pull request simplifies the codebase by removing unused features and streamlining event handling across multiple files. It eliminates the NetworkTriggeredEvent enum and its associated logic, refactors related methods, and updates dependencies to reflect these changes. Additionally, it adjusts some configuration constants and improves documentation clarity.

Event Handling Simplifications:

  • Removed NetworkTriggeredEvent enum and its usage across files, including transport/api/src/lib.rs, transport/api/src/network_notifier.rs, transport/network/src/network.rs, and transport/p2p/src/behavior/discovery.rs. This includes eliminating associated methods like update, is_ignored, and event emitters. [1] [2] [3] [4]

Code Refactoring:

  • Refactored HoprSwarm::new and related method calls to remove unused parameters, simplifying initialization logic in transport/api/src/lib.rs. [1] [2]
  • Updated methods in transport/network/src/network.rs to use the Result type from crate::errors directly, replacing crate::errors::Result. [1] [2] [3]

Dependency and Configuration Updates:

  • Removed hopr_transport_network dependency from transport/p2p/Cargo.toml and futures-concurrency from multiple files. [1] [2]
  • Adjusted DEFAULT_MAX_FIRST_HOP_LATENCY_THRESHOLD in transport/network/src/config.rs from 100ms to 250ms for improved latency handling.

Documentation and Style Improvements:

  • Improved clarity in comments and documentation strings, such as changing "since which" to "since when" in transport/network/src/config.rs.
  • Added missing periods in method documentation for consistency in transport/network/src/network.rs.

Testing Adjustments:

  • Updated test cases in transport/network/src/network.rs to reflect the removal of NetworkTriggeredEvent, ensuring compatibility with the refactored code. [1] [2]

@Teebor-Choka Teebor-Choka added this to the 3.0.0 milestone Jun 2, 2025
@Teebor-Choka Teebor-Choka self-assigned this Jun 2, 2025
Copy link
Contributor

coderabbitai bot commented Jun 2, 2025

📝 Walkthrough
## Walkthrough

The change updates the tracing instrumentation on the `send_message` async function in `Sender<T>` to log its return value at trace level. It modifies the `Probe` struct to notify an optional `PingQueryReplier` on probe timeouts and simplifies nonce generation and pong notification. The `PingQueryReplier` struct and related ping logic were refactored to remove challenge nonce handling, simplify latency calculation, and change the notification interface to accept direct ping results. Additionally, the `NetworkTriggeredEvent` mechanism was removed across multiple crates, simplifying network event handling, peer discovery, and swarm initialization, and removing related dependencies. The default maximum first hop latency threshold was increased from 100ms to 250ms. The `process_stream_protocol` function was refactored to propagate stream opening errors explicitly. The Python SDK node class was updated to support ephemeral data directories with optional cleanup.

## Changes

| File(s)                                      | Change Summary                                                                                              |
|----------------------------------------------|-------------------------------------------------------------------------------------------------------------|
| transport/probe/src/probe.rs                  | Added trace-level return value logging to `send_message`; notify `PingQueryReplier` on probe timeout; simplified nonce generation; changed pong notification to send latency result. |
| transport/probe/src/ping.rs                   | Removed challenge nonce field and verification from `PingQueryReplier`; changed `notify` to accept ping results directly; simplified latency calculation; updated tests accordingly. |
| transport/api/src/constants.rs                | Removed constant `MAXIMUM_NETWORK_UPDATE_EVENT_QUEUE_SIZE`.                                                  |
| transport/api/src/lib.rs                      | Removed creation and passing of `NetworkTriggeredEvent` channel to `HoprSwarm::new` and `Probe::continuously_scan`. |
| transport/api/src/network_notifier.rs        | Removed `emitter` field and event emission logic from `ProbeNetworkInteractions`; simplified `on_finished` method. |
| transport/network/src/network.rs              | Removed `NetworkTriggeredEvent` enum and variants; simplified `update` method to return only `Result<()>` without events; updated tests. |
| transport/network/src/config.rs               | Increased `DEFAULT_MAX_FIRST_HOP_LATENCY_THRESHOLD` from 100ms to 250ms; improved documentation wording.     |
| transport/p2p/Cargo.toml                       | Removed dependencies `futures-concurrency` and `hopr-transport-network`.                                     |
| transport/p2p/src/behavior/discovery.rs       | Removed `NetworkTriggeredEvent` handling from discovery behavior; simplified constructor and connection logic; removed dial failure handling; changed peer multiaddress storage to vector. |
| transport/p2p/src/lib.rs                        | Removed `NetworkTriggeredEvent` parameter from `HoprNetworkBehavior::new` constructor.                       |
| transport/p2p/src/swarm.rs                      | Removed `NetworkTriggeredEvent` parameter from `build_p2p_network` and `HoprSwarm::new` constructors.       |
| transport/p2p/tests/p2p_transport_test.rs      | Removed `NetworkTriggeredEvent` channel and related fields from test setup; simplified swarm construction.   |
| transport/protocol/src/stream.rs                | Refactored `process_stream_protocol` to use explicit `Sender` and `Receiver` imports; changed cache retrieval to propagate errors explicitly with improved logging. |
| transport/protocol/Cargo.toml                    | Moved `anyhow` dependency from dev-dependencies to main dependencies.                                        |
| sdk/python/localcluster/node.py                  | Added ephemeral temporary data directory support to `Node` class with optional automatic cleanup.           |

## Possibly related PRs

- hoprnet/hoprnet#6504: Modifies the internal logic of `Network::update` to fix peer detection issues while retaining event returns; related due to changes in the same method but with different goals.

## Suggested labels

`crate:core-network`, `crate:core-transport`, `crate:core-p2p`

## Suggested reviewers

- tolbrino

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3fc69c0 and c4bd3e5.

📒 Files selected for processing (1)
  • tests/test_win_prob.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test_win_prob.py
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: tests-unit
  • GitHub Check: Build Candidate Binaries (hoprd)
  • GitHub Check: tests-unit-nightly
  • GitHub Check: Build Candidate Binaries (hopli)
  • GitHub Check: hopli / docker
  • GitHub Check: hoprd / docker
  • GitHub Check: zizmor
  • GitHub Check: Linter
  • GitHub Check: Cargo Audit
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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)

  • @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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@Teebor-Choka Teebor-Choka force-pushed the kauki/v3/logs/improve-logging branch from 384ee29 to 2b4077b Compare June 2, 2025 11:44
@Teebor-Choka Teebor-Choka marked this pull request as ready for review June 2, 2025 11:45
@Copilot Copilot AI review requested due to automatic review settings June 2, 2025 11:45
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances debug logging for the probe sender by capturing the return value of send_message alongside existing error logs.

  • Added ret(level = tracing::Level::DEBUG) to the tracing::instrument attribute.

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

🧹 Nitpick comments (1)
transport/probe/src/probe.rs (1)

52-52: Maintain consistency in level specifiers
The main instrument macro uses level = "debug" (string literal) but the ret attribute references tracing::Level::DEBUG. For a more uniform style, consider switching the ret specifier to a string literal as well:

- #[tracing::instrument(level = "debug",
-                      skip(self, path, message),
-                      fields(message=%message, nonce=%to_nonce(&message), pseudonym=%to_pseudonym(&path)),
-                      ret(level = tracing::Level::DEBUG),
-                      err(level = tracing::Level::DEBUG, Display))]
+ #[tracing::instrument(level = "debug",
+                      skip(self, path, message),
+                      fields(message=%message, nonce=%to_nonce(&message), pseudonym=%to_pseudonym(&path)),
+                      ret(level = "debug"),
+                      err(level = "debug", Display))]
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8a7df74 and 2b4077b.

📒 Files selected for processing (1)
  • transport/probe/src/probe.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: hopli / docker
  • GitHub Check: hoprd / docker
  • GitHub Check: Docs / Rust docs
  • GitHub Check: zizmor
  • GitHub Check: Build Candidate Binaries (hoprd)
  • GitHub Check: Build Candidate Binaries (hopli)
  • GitHub Check: tests-unit
  • GitHub Check: tests-unit-nightly
  • GitHub Check: Linter
  • GitHub Check: Cargo Audit
🔇 Additional comments (1)
transport/probe/src/probe.rs (1)

52-52: Great observability: return value logging added
Introducing ret(level = tracing::Level::DEBUG) will emit the successful return of send_message at debug level, giving you full visibility into both error and success paths.

@Teebor-Choka Teebor-Choka force-pushed the kauki/v3/logs/improve-logging branch 4 times, most recently from 3c082db to b96d7bf Compare June 3, 2025 09:51
@github-actions github-actions bot added the dependencies Pull requests that update a dependency file label Jun 3, 2025
@Teebor-Choka Teebor-Choka force-pushed the kauki/v3/logs/improve-logging branch from b96d7bf to 7998e64 Compare June 3, 2025 09:57
@Teebor-Choka Teebor-Choka force-pushed the kauki/v3/logs/improve-logging branch from d6f44c2 to c78dd82 Compare June 3, 2025 12:48
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.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c78dd82 and cd9e894.

📒 Files selected for processing (1)
  • transport/p2p/src/behavior/discovery.rs (5 hunks)
🧰 Additional context used
🧠 Learnings (1)
transport/p2p/src/behavior/discovery.rs (1)
Learnt from: Teebor-Choka
PR: hoprnet/hoprnet#6553
File: transport/api/src/p2p.rs:570-574
Timestamp: 2024-10-15T20:37:20.303Z
Learning: In `transport/api/src/p2p.rs`, within the `ConnectionEstablished` event handler, we follow the libp2p convention by assigning `PeerOrigin::IncomingConnection` to all peers, regardless of whether the connection was initiated by our node or by the remote peer.
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: hopli / docker
  • GitHub Check: hoprd / docker
  • GitHub Check: Docs / Rust docs
  • GitHub Check: Build Candidate Binaries (hoprd)
  • GitHub Check: Linter
  • GitHub Check: Build Candidate Binaries (hopli)
  • GitHub Check: tests-unit-nightly
  • GitHub Check: tests-smart-contracts
  • GitHub Check: tests-unit
  • GitHub Check: zizmor
  • GitHub Check: Cargo Audit
🔇 Additional comments (5)
transport/p2p/src/behavior/discovery.rs (5)

35-35: LGTM: Improved data structure for multiple addresses per peer.

The change from HashMap<PeerId, Multiaddr> to HashMap<PeerId, Vec<Multiaddr>> is a logical improvement that supports peers having multiple network addresses, which is common in distributed systems.


41-47: Simplified constructor aligns with NetworkTriggeredEvent removal.

The constructor simplification to accept only PeerDiscovery events (removing network events) is consistent with the PR objective of removing the network update feedback chain. The stream mapping is clean and efficient.


64-64: Excellent tracing instrumentation for observability.

The structured logging with appropriate fields (transport = "p2p discovery") and consistent use of debug level provides good observability for debugging connection and discovery issues. The instrumentation covers all key methods appropriately.

Also applies to: 81-87, 115-115, 152-157


98-104: Handle potential empty address vector gracefully.

The logic correctly handles cases where no addresses are found for a peer by returning an empty vector and logging a debug message. This approach prevents dial failures from causing unexpected errors while maintaining visibility through logging.


169-212: Robust event handling with improved multi-address support.

The event handling logic properly manages multiple addresses per peer:

  • Announces all addresses for allowed peers
  • Stores the complete address vector
  • Performs proactive dialing to establish connections before heartbeat mechanisms

The structured logging provides good visibility into the discovery process. The dial logic is well-reasoned to avoid heartbeat failures due to connection establishment delays.

@Teebor-Choka Teebor-Choka force-pushed the kauki/v3/logs/improve-logging branch from a06a9ae to 36b0146 Compare June 9, 2025 14:46
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

🧹 Nitpick comments (1)
sdk/python/localcluster/node.py (1)

59-59: Resource management is appropriate despite static analysis warning.

The static analysis tool suggests using 'with' for resource allocation, but this is a false positive. The TemporaryDirectory object needs to persist for the lifetime of the Node instance, making manual cleanup in the clean_up method the correct approach.

Consider adding error handling to verify the temporary directory was created successfully:

+try:
     self.temp_data_dir = tempfile.TemporaryDirectory(prefix=f"{NODE_NAME_PREFIX}_{self.id}_")
+except OSError as e:
+    raise RuntimeError(f"Failed to create temporary directory for node {self.id}: {e}")
🧰 Tools
🪛 Pylint (3.3.7)

[refactor] 59-59: Consider using 'with' for resource-allocating operations

(R1732)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 36b0146 and e834a15.

📒 Files selected for processing (1)
  • sdk/python/localcluster/node.py (5 hunks)
🧰 Additional context used
🪛 Pylint (3.3.7)
sdk/python/localcluster/node.py

[refactor] 59-59: Consider using 'with' for resource-allocating operations

(R1732)

⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: hopli / docker
  • GitHub Check: hoprd / docker
  • GitHub Check: Docs / Rust docs
  • GitHub Check: Build Candidate Binaries (hopli)
  • GitHub Check: tests-unit-nightly
  • GitHub Check: Build Candidate Binaries (hoprd)
  • GitHub Check: tests-unit
  • GitHub Check: zizmor
  • GitHub Check: Add PR labels
  • GitHub Check: Linter
  • GitHub Check: Cargo Audit
🔇 Additional comments (4)
sdk/python/localcluster/node.py (4)

4-4: LGTM: Import addition is appropriate.

The tempfile import is necessary for the new ephemeral data directory functionality.


48-48: LGTM: Constructor parameter follows good practices.

The remove_temp_data parameter with a sensible default value allows users to control the cleanup behavior while maintaining backward compatibility.


57-57: LGTM: Instance variable assignment is standard.

Proper assignment of the constructor parameter to an instance variable.


208-208:

❓ Verification inconclusive

Verify the behavioral change from persistent to ephemeral storage.

This change represents a significant shift from using persistent data directories (self.dir) to ephemeral temporary directories (self.temp_data_dir.name). Ensure that:

  1. This change is intentional and aligns with the testing session improvements mentioned in the PR
  2. Any critical node data that needs to persist between runs is handled elsewhere
  3. Tests are updated to account for this behavioral change

🏁 Script executed:

#!/bin/bash
# Description: Check for any references to persistent data directory usage that might be affected
# Expected: Identify any code that might depend on persistent data storage

echo "Searching for references to self.dir in the codebase..."
rg "self\.dir" --type py -A 3 -B 3

echo "Searching for any hardcoded data directory paths..."
rg "data.*dir" --type py -A 2 -B 2

Length of output: 6061


Confirm intentional switch from persistent (self.dir) to ephemeral (self.temp_data_dir) storage

The hoprd command now receives

    f"--data={self.temp_data_dir.name}"

instead of --data=self.dir, which means all node data is written to a temporary directory by default. This is a behavioral change that requires verification:

• sdk/python/localcluster/node.py (around line 208): --data={self.temp_data_dir.name}
• sdk/python/localcluster/node.py: other uses of self.dir still cover identity files (hoprd.id), .env loading, logs, etc.
• sdk/python/localcluster/snapshot.py: cleanup routines still reference self.dir

Please ensure:

  1. The switch to ephemeral storage is intentional and matches the PR’s testing-session goals.
  2. Any data that must survive across runs (snapshots, identities, env files) is still written to a persistent location or handled elsewhere.
  3. All relevant tests and fixtures have been updated to expect temporary directories for hoprd data.

@Teebor-Choka Teebor-Choka force-pushed the kauki/v3/logs/improve-logging branch from e834a15 to 01c11da Compare June 10, 2025 07:57
@github-actions github-actions bot added the testing Related to tests label Jun 10, 2025
@Teebor-Choka Teebor-Choka force-pushed the kauki/v3/logs/improve-logging branch from 3fc69c0 to c4bd3e5 Compare June 10, 2025 09:03
@Teebor-Choka Teebor-Choka enabled auto-merge (squash) June 10, 2025 09:04
@Teebor-Choka Teebor-Choka merged commit ea81403 into master Jun 10, 2025
32 of 33 checks passed
@Teebor-Choka Teebor-Choka deleted the kauki/v3/logs/improve-logging branch June 10, 2025 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Randomly failing winning probability smoke tests The smoke tests are not cleaning up properly
2 participants