Skip to content

Conversation

QYuQianchen
Copy link
Contributor

Make localcluster nodes allowed for each other
Include check of network registry entries for peer discovery (announce)
Closes #7215 #7196

@Copilot Copilot AI review requested due to automatic review settings June 23, 2025 12:30
@QYuQianchen QYuQianchen self-assigned this Jun 23, 2025
Copy link
Contributor

coderabbitai bot commented Jun 23, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (2)
  • master
  • release/.*

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

The changes update contract addresses in configuration files, revise peer discovery logic by adding an allowed flag to announcement events, simplify network registry checks, and enhance logging for peer allowance decisions. A new method for deregistering nodes from the network registry is introduced, and redundant node registration logic is removed from the cluster bringup process.

Changes

File(s) Change Summary
ethereum/contracts/contracts-addresses.json, scripts/protocol-config-anvil.json Updated contract addresses for "anvil-localhost" and "anvil-localhost2" networks.
hopr/hopr-lib/src/lib.rs, transport/api/src/lib.rs, transport/protocol/src/lib.rs, transport/p2p/src/behavior/discovery.rs, transport/p2p/tests/p2p_transport_test.rs Added allowed boolean parameter to PeerDiscovery::Announce event; integrated network registry allowance checks; enhanced peer allowance logging; simplified peer announcement handling.
sdk/python/localcluster/cluster.py Added remove_nodes_to_network_registry method to deregister nodes via CLI.
sdk/python/localcluster/main_process.py Removed automatic node registration to network registry during bringup.

Sequence Diagram(s)

sequenceDiagram
    participant ChainEvent as ChainEventType::Announcement
    participant DB as Database
    participant EventPipeline as chain_events_to_transport_events
    participant P2P as PeerDiscovery Handler

    ChainEvent->>EventPipeline: Announcement(address, ...)
    EventPipeline->>DB: Check if address is allowed
    DB-->>EventPipeline: allowed (bool)
    EventPipeline->>P2P: PeerDiscovery::Announce(peer_id, multiaddrs, allowed)
    P2P->>P2P: If allowed, add peer to allowed_peers
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure node eligibility is correctly determined after database resync (#7215)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Suggested labels

bug, crate:core-p2p, crate:core-protocol, crate:hoprd-api, testing

Suggested reviewers

  • NumberFour8

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.

@QYuQianchen QYuQianchen added this to the 3.0.0 milestone Jun 23, 2025
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 peer discovery by incorporating network registry status into announcements and updates related handling across various components. Key changes include:

  • Updating the PeerDiscovery::Announce variant to include an allowed flag.
  • Adding additional debug logging to trace connection handling in the p2p discovery behavior.
  • Adjusting API, SDK, and lib code to support the new flag and deprecating redundant network registry node addition.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
transport/protocol/src/lib.rs Updated the PeerDiscovery::Announce variant signature.
transport/p2p/src/behavior/discovery.rs Added debug logging for inbound/outbound connection handling and allowed peer insertion.
transport/api/src/lib.rs Adjusted matching and event sending for the new PeerDiscovery::Announce variant.
sdk/python/localcluster/main_process.py Removed unnecessary network registry node addition and sleep delay.
sdk/python/localcluster/cluster.py Introduced a new function to remove nodes from the network registry.
hopr/hopr-lib/src/lib.rs Updated ChainEventType::Announcement handling and streamlined channel event propagation.
ethereum/contracts/contracts-addresses.json Adjusted addresses for network registry and other related contracts.
Comments suppressed due to low confidence (1)

sdk/python/localcluster/cluster.py:130

  • [nitpick] The function name 'remove_nodes_to_network_registry' can be misleading; it may be clearer if renamed to 'remove_nodes_from_network_registry' to better reflect its purpose.
    def remove_nodes_to_network_registry(self):

@QYuQianchen QYuQianchen changed the title Include Network Registry status in peer discovery announce fix: Include Network Registry status in peer discovery announce Jun 23, 2025
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: 2

♻️ Duplicate comments (1)
transport/p2p/src/behavior/discovery.rs (1)

74-77: Improve log message clarity for connection decisions.

While the current trace messages are more descriptive than before, they could still be clearer about the actual decision being made (connection allowed vs denied).

Consider this improvement:

-            trace!(%peer, "Discovery::handle_established_inbound_connection in allowed_peers");
+            trace!(%peer, "Discovery::handle_established_inbound_connection: Connection allowed");
-            trace!(%peer, "Discovery::handle_established_inbound_connection NOT in allowed_peers");
+            trace!(%peer, "Discovery::handle_established_inbound_connection: Connection denied");
🧹 Nitpick comments (3)
transport/protocol/src/lib.rs (1)

126-133: Document the breaking change and the boolean parameter's purpose.

The addition of a boolean parameter to PeerDiscovery::Announce is a breaking change that affects all consumers of this enum. Consider adding documentation to clarify:

  1. The purpose of the boolean parameter (represents network registry allowance status)
  2. The breaking nature of this change in the changelog or migration guide

Add documentation to the enum variant:

 pub enum PeerDiscovery {
     Allow(PeerId),
     Ban(PeerId),
+    /// Announce a peer with their multiaddresses and network registry allowance status.
+    /// The boolean parameter indicates whether the peer is allowed by the network registry.
     Announce(PeerId, Vec<Multiaddr>, bool),
 }
hopr/hopr-lib/src/lib.rs (1)

234-240: Consider logging database errors during network registry check.

While the implementation correctly checks the network registry, using .unwrap_or(false) silently ignores potential database errors. Consider logging these errors for better observability.

                ChainEventType::Announcement{peer, address, multiaddresses} => {
                    let allowed = db
                        .is_allowed_in_network_registry(None, &address)
                        .await
-                        .unwrap_or(false);
+                        .unwrap_or_else(|e| {
+                            error!(error = %e, %address, "Failed to check network registry status");
+                            false
+                        });
                    Some(PeerDiscovery::Announce(peer, multiaddresses, allowed))
                }
transport/p2p/src/behavior/discovery.rs (1)

100-100: Apply consistent log message clarity improvements.

Similar to the inbound connection handler, these trace messages could be clearer about the connection decision.

Apply consistent messaging:

-                trace!(%peer, "Discovery::handle_pending_outbound_connection in allowed_peers");
+                trace!(%peer, "Discovery::handle_pending_outbound_connection: Connection allowed");
-                trace!(%peer, "Discovery::handle_pending_outbound_connection NOT in allowed_peers");
+                trace!(%peer, "Discovery::handle_pending_outbound_connection: Connection denied");

Also applies to: 110-110

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e899040 and 216a9dc.

📒 Files selected for processing (7)
  • ethereum/contracts/contracts-addresses.json (1 hunks)
  • hopr/hopr-lib/src/lib.rs (4 hunks)
  • sdk/python/localcluster/cluster.py (1 hunks)
  • sdk/python/localcluster/main_process.py (0 hunks)
  • transport/api/src/lib.rs (3 hunks)
  • transport/p2p/src/behavior/discovery.rs (7 hunks)
  • transport/protocol/src/lib.rs (1 hunks)
💤 Files with no reviewable changes (1)
  • sdk/python/localcluster/main_process.py
🧰 Additional context used
🧠 Learnings (1)
hopr/hopr-lib/src/lib.rs (1)
Learnt from: Teebor-Choka
PR: hoprnet/hoprnet#6313
File: hopr/hopr-lib/src/lib.rs:0-0
Timestamp: 2024-07-28T07:26:06.634Z
Learning: The types `IndexerTransportEvent`, `Network`, `PeerEligibility`, and `PeerOrigin` in the `hopr/hopr-lib/src/lib.rs` file are internal to the transport mechanism and do not require public documentation.
🪛 Gitleaks (8.26.0)
ethereum/contracts/contracts-addresses.json

13-13: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


29-29: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Build Candidate Binaries (hoprd)
  • GitHub Check: tests-unit-nightly
  • GitHub Check: tests-unit
  • GitHub Check: hoprd / docker
  • GitHub Check: zizmor
  • GitHub Check: Linter
🔇 Additional comments (7)
ethereum/contracts/contracts-addresses.json (1)

1-100: LGTM!

Contract address updates for local test networks look correct. All addresses follow the proper Ethereum address format.

sdk/python/localcluster/cluster.py (1)

131-160: Implementation looks good!

The method correctly implements node deregistration following the same pattern as the registration method.

transport/api/src/lib.rs (1)

319-340: Excellent simplification of the peer announcement logic!

The refactoring to use the pre-computed allowed flag eliminates redundant database lookups and complex conversions. This improves both performance and code clarity.

hopr/hopr-lib/src/lib.rs (2)

35-35: Good cleanup of unused import.

Removing the unused SinkExt import improves code cleanliness.


676-693: Clean simplification of the indexer event pipeline.

The changes correctly simplify the event forwarding by:

  1. Using an immutable binding since cloning is no longer needed
  2. Directly forwarding to the sender without unnecessary cloning

The removal of the peer synchronization logic aligns with the new approach where network registry checks are integrated into the event processing pipeline.

transport/p2p/src/behavior/discovery.rs (2)

17-17: LGTM: Import addition for trace logging.

The addition of trace to the tracing imports is necessary for the new trace logging statements.


202-202: LGTM: Announce event signature updated with allowed flag.

The addition of the allowed parameter to PeerDiscovery::Announce aligns with the broader network registry integration mentioned in the PR objectives.

@Teebor-Choka Teebor-Choka changed the title fix: Include Network Registry status in peer discovery announce fix(hopr-lib): Include Network Registry status in peer discovery announce Jun 23, 2025
@github-actions github-actions bot added the toolchain Developer and product happiness label Jun 23, 2025
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 (2)
transport/p2p/tests/p2p_transport_test.rs (1)

131-142: Consider adding test coverage for the new allowed parameter.

While the current changes correctly update the test for the new API, the test only covers the allowed=true scenario. Consider adding a separate test case to verify the behavior when allowed=false to ensure complete coverage of the new network registry functionality.

Do you want me to help create an additional test case that covers the allowed=false scenario?

scripts/protocol-config-anvil.json (1)

27-36: Reduce duplication in network definitions.

Both anvil-localhost and anvil-localhost2 share identical address blocks. To simplify maintenance and avoid drift, consider extracting a shared base configuration (e.g., via JSON merge/extend or a script) and referencing it for both networks.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 216a9dc and 038d266.

📒 Files selected for processing (3)
  • scripts/protocol-config-anvil.json (2 hunks)
  • transport/api/src/lib.rs (3 hunks)
  • transport/p2p/tests/p2p_transport_test.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • transport/api/src/lib.rs
🧰 Additional context used
🪛 Gitleaks (8.26.0)
scripts/protocol-config-anvil.json

13-13: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


35-35: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: hoprd / docker
  • GitHub Check: hopli / docker
  • GitHub Check: Docs / Rust docs
  • GitHub Check: Linter
  • GitHub Check: Build Candidate Binaries (hopli)
  • GitHub Check: zizmor
  • GitHub Check: tests-unit-nightly
  • GitHub Check: Build Candidate Binaries (hoprd)
  • GitHub Check: tests-unit
  • GitHub Check: Cargo Audit
🔇 Additional comments (3)
transport/p2p/tests/p2p_transport_test.rs (2)

132-132: LGTM: Test correctly updated for new API signature.

The addition of the true parameter aligns with the updated PeerDiscovery::Announce event signature that now includes an allowed boolean flag. Using true is appropriate for this throughput test scenario.


138-138: LGTM: Consistent API signature update.

This change mirrors the previous announcement call, maintaining consistency in the test while adapting to the new event signature.

scripts/protocol-config-anvil.json (1)

5-14: Validate updated EIP-55 checksummed addresses and cross-file consistency.

The new contract addresses for anvil-localhost (announcements, network_registry, ticket_price_oracle, token, winning_probability_oracle) must exactly match those in ethereum/contracts/contracts-addresses.json and comply with EIP-55 checksums. Consider adding a CI step or running the following script to verify:

#!/usr/bin/env bash
# Compare addresses between protocol-config-anvil.json and contracts-addresses.json
jq -S '.networks["anvil-localhost"].addresses' scripts/protocol-config-anvil.json > /tmp/config.json
jq -S '.["anvil-localhost"].addresses' ethereum/contracts/contracts-addresses.json > /tmp/addresses.json
diff -u /tmp/addresses.json /tmp/config.json || echo "Address mismatch detected"

@Teebor-Choka
Copy link
Contributor

Pls rebase on #7255

@QYuQianchen QYuQianchen force-pushed the q/add-nr-in-peer-discovery-announce branch from e3641cf to 335af7f Compare June 23, 2025 13:49
@Teebor-Choka Teebor-Choka changed the base branch from master to kauki/v3/logs/improve-logging-and-code-quality June 23, 2025 13:51
@Teebor-Choka Teebor-Choka merged commit 5de9589 into kauki/v3/logs/improve-logging-and-code-quality Jun 24, 2025
25 checks passed
@Teebor-Choka Teebor-Choka deleted the q/add-nr-in-peer-discovery-announce branch June 24, 2025 07:32
QYuQianchen added a commit that referenced this pull request Jun 26, 2025
…unce (#7264)

Co-authored-by: Tibor Csóka <csokat@gmail.com>
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.

core-team-rotsee node 2 is not identified as eligible for the network
2 participants