Skip to content

refactor: default to relay=false in P2P handshake#536

Open
xdustinface wants to merge 1 commit intov0.42-devfrom
refactor/relay-false
Open

refactor: default to relay=false in P2P handshake#536
xdustinface wants to merge 1 commit intov0.42-devfrom
refactor/relay-false

Conversation

@xdustinface
Copy link
Collaborator

@xdustinface xdustinface commented Mar 14, 2026

Just always default to false. The new coming mempool implementation will enable it on demand.

Summary by CodeRabbit

  • Refactor

    • Simplified network handshake and peer manager initialization by removing an internal mempool configuration, reducing connection setup complexity.
    • Handshake relay behavior is now fixed (no mempool-driven variation), producing more predictable peer negotiation.
  • Tests

    • Updated handshake tests to align with the simplified initialization and relay behavior.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 14, 2026

📝 Walkthrough

Walkthrough

Removed the MempoolStrategy dependency from handshake and peer network management. HandshakeManager::new now takes (Network, Option) and build_version_message() sets relay = false. PeerNetworkManager dropped its mempool_strategy field and related uses. Tests updated to the new HandshakeManager signature.

Changes

Cohort / File(s) Summary
Handshake & Network manager
dash-spv/src/network/handshake.rs, dash-spv/src/network/manager.rs
Removed MempoolStrategy field and parameter from HandshakeManager and PeerNetworkManager; updated constructor signatures, initialization, and clone logic; build_version_message() now sets relay = false.
Tests
dash-spv/tests/handshake_test.rs, dash-spv/tests/test_handshake_logic.rs
Removed MempoolStrategy imports/usages and updated calls to HandshakeManager::new(...) to the simplified signature (Network, Option).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibbled out a needless plan,
Tidied paws and changed my span.
Handshakes lean, relays turned low,
I hop lighter where clean code grows. 🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: defaulting relay to false in the P2P handshake, which is the primary purpose of removing MempoolStrategy and hardcoding relay behavior.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/relay-false
📝 Coding Plan
  • Generate coding plan for human review comments

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Mar 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.82%. Comparing base (b946271) to head (f819a4d).

Additional details and impacted files
@@              Coverage Diff              @@
##           v0.42-dev     #536      +/-   ##
=============================================
- Coverage      66.89%   66.82%   -0.07%     
=============================================
  Files            313      313              
  Lines          64753    64746       -7     
=============================================
- Hits           43317    43269      -48     
- Misses         21436    21477      +41     
Flag Coverage Δ *Carryforward flag
core 75.02% <ø> (ø)
dash-network 75.00% <ø> (ø) Carriedforward from b946271
dash-network-ffi 34.76% <ø> (ø) Carriedforward from b946271
dash-spv 68.28% <ø> (+0.01%) ⬆️ Carriedforward from b946271
dash-spv-ffi 34.76% <ø> (ø) Carriedforward from b946271
dashcore 75.00% <ø> (ø) Carriedforward from b946271
dashcore-private 75.00% <ø> (ø) Carriedforward from b946271
dashcore-rpc 19.92% <ø> (ø) Carriedforward from b946271
dashcore-rpc-json 19.92% <ø> (ø) Carriedforward from b946271
dashcore_hashes 75.00% <ø> (ø) Carriedforward from b946271
ffi 37.16% <ø> (+0.56%) ⬆️
key-wallet 65.64% <ø> (ø) Carriedforward from b946271
key-wallet-ffi 34.76% <ø> (ø) Carriedforward from b946271
key-wallet-manager 65.64% <ø> (ø) Carriedforward from b946271
rpc 19.92% <ø> (ø)
spv 81.00% <100.00%> (-0.09%) ⬇️
wallet 65.67% <ø> (ø)

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
dash-spv/src/network/handshake.rs 78.75% <100.00%> (+0.22%) ⬆️
dash-spv/src/network/manager.rs 58.09% <100.00%> (-0.09%) ⬇️

... and 14 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
dash-spv/src/network/handshake.rs (1)

47-58: ⚠️ Potential issue | 🟠 Major

Hardcoded relay=false removes runtime policy and risks mempool regression.

HandshakeManager no longer accepts any relay policy and build_version_message() always sends relay: false. That can break expected mempool behavior for configs that still enable tracking.

Proposed fix (make relay explicit and configurable)
 pub struct HandshakeManager {
     _network: Network,
@@
     user_agent: Option<String>,
+    relay: bool,
 }
@@
-    pub fn new(network: Network, user_agent: Option<String>) -> Self {
+    pub fn new(network: Network, user_agent: Option<String>, relay: bool) -> Self {
         Self {
             _network: network,
@@
             version_sent: false,
             user_agent,
+            relay,
         }
     }
@@
-            relay: false, // SPV client enables this on demand
+            relay: self.relay,

Then pass a policy from PeerNetworkManager (for example derived from ClientConfig::enable_mempool_tracking / mempool_strategy) instead of dropping it.

Also applies to: 288-288

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dash-spv/src/network/handshake.rs` around lines 47 - 58, The handshake
currently hardcodes relay=false in build_version_message; update
HandshakeManager to store an explicit relay policy and thread it through
construction and message building: add a field (e.g., relay: bool or
relay_policy enum) to the HandshakeManager struct, change HandshakeManager::new
to accept a relay parameter (derived upstream from
PeerNetworkManager/ClientConfig::enable_mempool_tracking or mempool_strategy)
and set that field, and update build_version_message() to use self.relay instead
of the hardcoded false; also ensure the same fix is applied to the other
constructor/usage mentioned around the second occurrence (line ~288) so all
instantiations pass the configured policy.
dash-spv/tests/handshake_test.rs (1)

10-43: ⚠️ Potential issue | 🟠 Major

Network integration test currently allows false positives.

If the connection fails, this test logs and exits without failing, so handshake regressions can pass CI unnoticed. Since this requires a live node, mark it #[ignore] and fail when explicitly run.

Proposed fix
 #[tokio::test]
+#[ignore = "requires a Dash Core node at 127.0.0.1:9999"]
 async fn test_handshake_with_mainnet_peer() {
@@
-        Err(e) => {
-            println!("✗ Handshake failed with peer {}: {}", peer_addr, e);
-            // For CI/testing environments where the peer might not be available,
-            // we'll make this a warning rather than a failure
-            println!("Note: This test requires a Dash Core node running at 127.0.0.1:9999");
-            println!("Error details: {}", e);
-        }
+        Err(e) => {
+            panic!("Handshake failed with peer {}: {}", peer_addr, e);
+        }
     }
 }
As per coding guidelines, "Mark network-dependent or long-running tests with `#[ignore]` attribute; run with `-- --ignored`."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dash-spv/tests/handshake_test.rs` around lines 10 - 43, Mark the
network-dependent async test function test_handshake_with_mainnet_peer with both
#[tokio::test] and #[ignore] so it only runs when explicitly requested, and
change the Err(e) branch (where Peer::connect fails) from printing/warning to
failing the test (panic! or assert!) so the test will surface regressions when
run; keep the rest of the logic using Peer::connect and
HandshakeManager::perform_handshake unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@dash-spv/src/network/handshake.rs`:
- Around line 47-58: The handshake currently hardcodes relay=false in
build_version_message; update HandshakeManager to store an explicit relay policy
and thread it through construction and message building: add a field (e.g.,
relay: bool or relay_policy enum) to the HandshakeManager struct, change
HandshakeManager::new to accept a relay parameter (derived upstream from
PeerNetworkManager/ClientConfig::enable_mempool_tracking or mempool_strategy)
and set that field, and update build_version_message() to use self.relay instead
of the hardcoded false; also ensure the same fix is applied to the other
constructor/usage mentioned around the second occurrence (line ~288) so all
instantiations pass the configured policy.

In `@dash-spv/tests/handshake_test.rs`:
- Around line 10-43: Mark the network-dependent async test function
test_handshake_with_mainnet_peer with both #[tokio::test] and #[ignore] so it
only runs when explicitly requested, and change the Err(e) branch (where
Peer::connect fails) from printing/warning to failing the test (panic! or
assert!) so the test will surface regressions when run; keep the rest of the
logic using Peer::connect and HandshakeManager::perform_handshake unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a33f8cfc-774f-4918-9cf5-941b11b3773c

📥 Commits

Reviewing files that changed from the base of the PR and between b946271 and 38df8b7.

📒 Files selected for processing (4)
  • dash-spv/src/network/handshake.rs
  • dash-spv/src/network/manager.rs
  • dash-spv/tests/handshake_test.rs
  • dash-spv/tests/test_handshake_logic.rs

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
dash-spv/tests/test_handshake_logic.rs (1)

8-15: ⚠️ Potential issue | 🟡 Minor

Add a regression test for the new relay default.

This update only follows the constructor signature change; it still does not assert the behavior changed by the PR. Please add coverage that the emitted VERSION message defaults relay to false so this cannot regress silently. Best placed as a #[cfg(test)] unit test next to build_version_message().

As per coding guidelines, "Write unit tests for new functionality in Rust code" and "Place unit tests alongside code with #[cfg(test)] attribute".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dash-spv/tests/test_handshake_logic.rs` around lines 8 - 15, Add a unit test
(#[cfg(test)]) next to build_version_message() that constructs a Version message
via build_version_message() (or the public API that emits the VERSION message
from HandshakeManager) and asserts that the emitted message's relay field
defaults to false; reference build_version_message() and
HandshakeManager::build_version_message (or the function used to produce the
VERSION message) and check the Version object's relay boolean (e.g.,
version_msg.relay == false) to prevent regressions.
dash-spv/src/network/handshake.rs (1)

47-58: ⚠️ Potential issue | 🟠 Major

Don't turn a default flip into a hardcoded behavior.

Removing the strategy from HandshakeManager::new and hardcoding relay: false makes the handshake path unable to express any opt-in at all. In the manager flow shown at dash-spv/src/network/manager.rs:256-266, every outbound handshake now sends the same relay setting, so the distinction from MempoolStrategy::{FetchAll, BloomFilter} in dash-spv/src/client/config.rs:14-19 is gone at handshake time. Please keep new() defaulting to false, but preserve an explicit override on HandshakeManager so full-tx relay can still be enabled when needed.

🔧 Suggested shape
 pub struct HandshakeManager {
     _network: Network,
     state: HandshakeState,
     our_version: u32,
     peer_version: Option<u32>,
     peer_services: Option<ServiceFlags>,
     version_received: bool,
     verack_received: bool,
     version_sent: bool,
+    relay: bool,
     user_agent: Option<String>,
 }
 
 impl HandshakeManager {
     pub fn new(network: Network, user_agent: Option<String>) -> Self {
-        Self {
+        Self::with_relay(network, false, user_agent)
+    }
+
+    pub fn with_relay(network: Network, relay: bool, user_agent: Option<String>) -> Self {
+        Self {
             _network: network,
             state: HandshakeState::Init,
             our_version: constants::PROTOCOL_VERSION,
             peer_version: None,
             peer_services: None,
             version_received: false,
             verack_received: false,
             version_sent: false,
+            relay,
             user_agent,
         }
     }
 }
 
 ...
-            relay: false,
+            relay: self.relay,

Also applies to: 287-288

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dash-spv/src/network/handshake.rs` around lines 47 - 58, Handshake::new
currently drops the relay option and hardcodes relay behavior; restore a default
relay: false in the Handshake struct initialization inside Handshake::new, and
preserve a way for HandshakeManager to explicitly override it when
constructing/starting a handshake. Concretely: add relay: false back into the
returned Self in Handshake::new (ensuring the Handshake struct still has a relay
field), and update HandshakeManager (the code that creates the Handshake) to set
handshake.relay (or pass the relay value into the Handshake constructor) based
on the client config/mempool strategy (MempoolStrategy::{FetchAll, BloomFilter})
so full-tx relay can still be enabled when required.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@dash-spv/src/network/handshake.rs`:
- Around line 47-58: Handshake::new currently drops the relay option and
hardcodes relay behavior; restore a default relay: false in the Handshake struct
initialization inside Handshake::new, and preserve a way for HandshakeManager to
explicitly override it when constructing/starting a handshake. Concretely: add
relay: false back into the returned Self in Handshake::new (ensuring the
Handshake struct still has a relay field), and update HandshakeManager (the code
that creates the Handshake) to set handshake.relay (or pass the relay value into
the Handshake constructor) based on the client config/mempool strategy
(MempoolStrategy::{FetchAll, BloomFilter}) so full-tx relay can still be enabled
when required.

In `@dash-spv/tests/test_handshake_logic.rs`:
- Around line 8-15: Add a unit test (#[cfg(test)]) next to
build_version_message() that constructs a Version message via
build_version_message() (or the public API that emits the VERSION message from
HandshakeManager) and asserts that the emitted message's relay field defaults to
false; reference build_version_message() and
HandshakeManager::build_version_message (or the function used to produce the
VERSION message) and check the Version object's relay boolean (e.g.,
version_msg.relay == false) to prevent regressions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: afe7ba6a-bb24-4b57-a5b0-09c1e11d8849

📥 Commits

Reviewing files that changed from the base of the PR and between 38df8b7 and 72c757c.

📒 Files selected for processing (4)
  • dash-spv/src/network/handshake.rs
  • dash-spv/src/network/manager.rs
  • dash-spv/tests/handshake_test.rs
  • dash-spv/tests/test_handshake_logic.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • dash-spv/src/network/manager.rs

Just always default to `false`. The new coming mempool implementation will enable it on demand.
@xdustinface xdustinface force-pushed the refactor/relay-false branch from 72c757c to f819a4d Compare March 14, 2026 18:06
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.

🧹 Nitpick comments (1)
dash-spv/tests/handshake_test.rs (1)

19-20: Consider simpler string conversion.

Using .parse().unwrap() to convert &str to String is unusual. A more idiomatic approach would be:

✨ Suggested simplification
-            let mut handshake_manager =
-                HandshakeManager::new(Network::Mainnet, Some("handshake_test".parse().unwrap()));
+            let mut handshake_manager =
+                HandshakeManager::new(Network::Mainnet, Some("handshake_test".to_string()));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dash-spv/tests/handshake_test.rs` around lines 19 - 20, The test uses an odd
`.parse().unwrap()` to convert a string slice when constructing the
HandshakeManager: replace the `Some("handshake_test".parse().unwrap())` argument
with a straightforward String conversion (e.g.,
`Some("handshake_test".to_string())` or `Some(String::from("handshake_test"))`)
when calling `HandshakeManager::new(Network::Mainnet, ...)` to make the code
idiomatic and clearer.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@dash-spv/tests/handshake_test.rs`:
- Around line 19-20: The test uses an odd `.parse().unwrap()` to convert a
string slice when constructing the HandshakeManager: replace the
`Some("handshake_test".parse().unwrap())` argument with a straightforward String
conversion (e.g., `Some("handshake_test".to_string())` or
`Some(String::from("handshake_test"))`) when calling
`HandshakeManager::new(Network::Mainnet, ...)` to make the code idiomatic and
clearer.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 804d2b34-ba94-413f-ad35-b03e2b5bd299

📥 Commits

Reviewing files that changed from the base of the PR and between 72c757c and f819a4d.

📒 Files selected for processing (4)
  • dash-spv/src/network/handshake.rs
  • dash-spv/src/network/manager.rs
  • dash-spv/tests/handshake_test.rs
  • dash-spv/tests/test_handshake_logic.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • dash-spv/src/network/manager.rs

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.

1 participant