Skip to content

fix: MN port validation on mainnet is broken after 6627 #6664

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

Merged
merged 3 commits into from
May 12, 2025

Conversation

UdjinM6
Copy link

@UdjinM6 UdjinM6 commented May 10, 2025

Issue being fixed or feature implemented

#6627 broke MN port validation on mainnet - develop fails with bad-protx-netinfo-port for a completely valid protx

What was done?

Implement it the way it was before https://github.com/dashpay/dash/pull/6627/files#diff-0998f8dfc4c1089e90cbaafe9607b361035b904cd103df31e3c2339a3cbf790dL1189-L1195

How Has This Been Tested?

Sync on mainnet

Breaking Changes

n/a

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@UdjinM6 UdjinM6 added this to the 23 milestone May 10, 2025
Copy link

coderabbitai bot commented May 10, 2025

Walkthrough

The validation logic for the service port in src/evo/netinfo.cpp was simplified by replacing a two-branch conditional with a single combined conditional expression that checks whether the node is on mainnet and if the service port matches the mainnet default port. The semantics remain unchanged: the service port must be the mainnet default port if and only if the node is on mainnet. In src/test/evo_netinfo_tests.cpp, the test suite was updated to use BasicTestingSetup instead of RegTestingSetup, with test vectors adjusted to use new port numbers (replacing port 8888 with 9999 and related changes). A new test case was added to verify rejection of internal addresses. No public interfaces were modified.

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 20afc99 and 2e8c7ef.

📒 Files selected for processing (2)
  • src/evo/netinfo.cpp (1 hunks)
  • src/test/evo_netinfo_tests.cpp (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/evo/netinfo.cpp
🧰 Additional context used
🪛 Cppcheck (2.10-2)
src/test/evo_netinfo_tests.cpp

[error] 14-14: There is an unknown macro here somewhere. Configuration is required. If BOOST_FIXTURE_TEST_SUITE is a macro then please configure it.

(unknownMacro)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: x86_64-apple-darwin / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_nowallet / Build depends
  • GitHub Check: arm-linux-gnueabihf / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_multiprocess / Build depends
🔇 Additional comments (5)
src/test/evo_netinfo_tests.cpp (5)

14-14: Good update to the test fixture setup.

Changing from RegTestingSetup to BasicTestingSetup is appropriate for properly testing mainnet port validation behavior, which aligns with the PR objective of fixing mainnet MN port validation.

🧰 Tools
🪛 Cppcheck (2.10-2)

[error] 14-14: There is an unknown macro here somewhere. Configuration is required. If BOOST_FIXTURE_TEST_SUITE is a macro then please configure it.

(unknownMacro)


18-18: Port number update looks good.

Updating the port from 8888 to 9999 is consistent with the port changes needed to fix the MN port validation on mainnet.


22-22: Test case correctly updated for mainnet port validation.

The test now properly checks that using a non-mainnet port (9998) on mainnet fails with BadPort status, which directly addresses the issue this PR is fixing.


24-24: Good addition of internal address rejection test.

Adding a test case to verify that internal addresses like 127.0.0.1 are rejected on mainnet improves security validation coverage.


26-36: Port number updates are consistent.

All instances of port 8888 have been correctly updated to 9999 throughout the test cases, maintaining consistency with the required changes for proper mainnet port validation.

✨ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link

@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)
src/evo/netinfo.cpp (1)

40-44: Optional: Simplify nested if/else for brevity
For a more concise style, you can combine both branches into a single condition:

-if (IsNodeOnMainnet()) {
-    if (service.GetPort() != default_port_main) {
-        return NetInfoStatus::BadPort;
-    }
-} else if (service.GetPort() == default_port_main) {
-    return NetInfoStatus::BadPort;
-}
+if ((IsNodeOnMainnet() && service.GetPort() != default_port_main) ||
+    (!IsNodeOnMainnet() && service.GetPort() == default_port_main)) {
+    return NetInfoStatus::BadPort;
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f94e3e and 20afc99.

📒 Files selected for processing (1)
  • src/evo/netinfo.cpp (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Check Potential Conflicts
src/evo/netinfo.cpp

[error] 1-1: Merge conflict detected in this file. Conflicting PR #6629 affects this file.

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: x86_64-pc-linux-gnu_multiprocess / Build depends
  • GitHub Check: x86_64-apple-darwin / Build depends
  • GitHub Check: x86_64-pc-linux-gnu / Build depends
🔇 Additional comments (2)
src/evo/netinfo.cpp (2)

1-86: Resolve merge conflicts with PR #6629
A merge conflict was detected in this file with changes from PR #6629. Please ensure that the MN port validation fix here and any other updates introduced by #6629 are correctly merged so no logic is lost or duplicated.

🧰 Tools
🪛 GitHub Actions: Check Potential Conflicts

[error] 1-1: Merge conflict detected in this file. Conflicting PR #6629 affects this file.


40-44: Correctly restored mainnet port validation logic
This change accurately reverts the port validation to its pre-#6627 state: on mainnet only the default port is accepted, and the default mainnet port is prohibited off-mainnet, preserving the intended behavior.

@UdjinM6 UdjinM6 changed the title fix: MN port validation is broken after 6627 fix: MN port validation on mainnet is broken after 6627 May 10, 2025
knst
knst previously approved these changes May 10, 2025
Copy link
Collaborator

@knst knst left a comment

Choose a reason for hiding this comment

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

LGTM 20afc99

Copy link
Collaborator

@kwvg kwvg left a comment

Choose a reason for hiding this comment

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

Consider 4b839a3 from dash#6629 for test suite changes.

@knst
Copy link
Collaborator

knst commented May 11, 2025

Consider 4b839a3 from dash#6629

This condition is a bit messy because IsNodeOnMainnet used twice in different branches and as A and !A.

if (IsNodeOnMainnet() && service.GetPort() != default_port_main) {


        // Must use mainnet port on mainnet

        return NetInfoStatus::BadPort;
    } else if (!IsNodeOnMainnet() && service.GetPort() == default_port_main) {

Consider refactoring such as: if (fbool port_is_mainnet = service.GetPort() == default_port_main; IsNodeOnMainet() == port_is_mainnet) {...}

Otherwise it's too messy

@kwvg
Copy link
Collaborator

kwvg commented May 11, 2025

@knst I don't mind retaining the condition as proposed here, was moreso interested in having the test changes from the commit incorporated to expand coverage.

Copy link
Collaborator

@kwvg kwvg left a comment

Choose a reason for hiding this comment

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

utACK 2e8c7ef

Copy link
Collaborator

@knst knst left a comment

Choose a reason for hiding this comment

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

utACK 2e8c7ef

@PastaPastaPasta PastaPastaPasta merged commit e853d0b into dashpay:develop May 12, 2025
31 of 34 checks passed
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.

4 participants