-
Notifications
You must be signed in to change notification settings - Fork 97
fix(hopr-lib): Include Network Registry status in peer discovery announce #7264
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
fix(hopr-lib): Include Network Registry status in peer discovery announce #7264
Conversation
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (2)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 WalkthroughWalkthroughThe changes update contract addresses in configuration files, revise peer discovery logic by adding an Changes
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
Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes found. Suggested labels
Suggested reviewers
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
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.
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):
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
♻️ 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:
- The purpose of the boolean parameter (represents network registry allowance status)
- 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
📒 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:
- Using an immutable binding since cloning is no longer needed
- 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 toPeerDiscovery::Announce
aligns with the broader network registry integration mentioned in the PR objectives.
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
🧹 Nitpick comments (2)
transport/p2p/tests/p2p_transport_test.rs (1)
131-142
: Consider adding test coverage for the newallowed
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 whenallowed=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
andanvil-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
📒 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 updatedPeerDiscovery::Announce
event signature that now includes anallowed
boolean flag. Usingtrue
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 inethereum/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"
Pls rebase on #7255 |
…ub.com:hoprnet/hoprnet into kauki/v3/logs/improve-logging-and-code-quality
e3641cf
to
335af7f
Compare
5de9589
into
kauki/v3/logs/improve-logging-and-code-quality
…unce (#7264) Co-authored-by: Tibor Csóka <csokat@gmail.com>
Make localcluster nodes allowed for each other
Include check of network registry entries for peer discovery (announce)
Closes #7215 #7196