Skip to content
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

Validate grpc port info in GRPCServer ctor #4728

Merged
merged 11 commits into from
Feb 7, 2024
Merged

Conversation

ckeshava
Copy link
Collaborator

@ckeshava ckeshava commented Sep 25, 2023

High Level Overview of Change

Fix #4015, #4557: GRPCServer and ServerHandler are created during the construction of Application instance. Do not validate GRPC IP/Port/Protocol information in ServerHandler. Instead, pass the responsibility of grpc port information validation to GRPCServer constructor. This ensures that configuration file can specify the port_grpc section.

Context of Change

Based on suggestions from @ximinez , I implemented this code change. @cjcobb23 suggests an alternative solution to the same issue #4015

I welcome any other suggestions too. I felt this is a clean way to handle this problem without breaking backwards compatibility.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking change that only restructures code)
  • Tests (You added tests for code that already exists, or your new feature included in this PR)
  • Documentation Updates
  • Release

This pertains to renaming of variables inside the codebase. It should suffice to test it through the existing unit tests.

…ormation in ServerHandler. Pass the responsibility of grpc port information validation to GRPCServer constructor. Both GRPCServer and ServerHandler are created during the construction of Application instance.

Introduce a constant (SECTION_PORT_GRPC) for port_grpc configuration section

Replace all usages of "port_grpc" raw string with a constant

Created macros for "port_ws", "port_rpc" and "port_peer" for unit test files.
Removed unused imports in some files
Copy link
Collaborator

@ximinez ximinez left a comment

Choose a reason for hiding this comment

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

This is only a partial review after taking a quick glance

src/ripple/app/main/GRPCServer.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@ximinez ximinez left a comment

Choose a reason for hiding this comment

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

One minor suggestion. Also, please merge in the latest develop branch.

@@ -101,6 +101,8 @@ struct ConfigSection
#define SECTION_SWEEP_INTERVAL "sweep_interval"
#define SECTION_NETWORK_ID "network_id"

#define SECTION_PORT_GRPC "port_grpc"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Most of the definitions in this list are alphabetical. Could you move this one to slot in alphabetically with the bulk of them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The last 6 #defines are not in alphabetical order, I've fixed them too

@intelliot intelliot requested a review from mDuo13 October 15, 2023 02:14
@intelliot intelliot added this to the 2.0 milestone Oct 16, 2023
@intelliot intelliot modified the milestones: 2.0, 2024 release Oct 17, 2023
@intelliot
Copy link
Collaborator

This is being held until 2.1.0 (so should be merged in ~Jan 2024)

@intelliot intelliot added the Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required. label Dec 6, 2023
@intelliot
Copy link
Collaborator

@ckeshava confirmed this is ready from his perspective; adding Passed label.

@codecov-commenter
Copy link

codecov-commenter commented Feb 1, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (1e96a1d) 61.50% compared to head (f7dd7b8) 61.49%.

Files Patch % Lines
src/ripple/rpc/impl/ServerHandler.cpp 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4728      +/-   ##
===========================================
- Coverage    61.50%   61.49%   -0.01%     
===========================================
  Files          797      797              
  Lines        70131    70131              
  Branches     36244    36245       +1     
===========================================
- Hits         43136    43130       -6     
- Misses       19755    19759       +4     
- Partials      7240     7242       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@intelliot intelliot added the Perf impact not expected Change is not expected to improve nor harm performance. label Feb 1, 2024
@intelliot
Copy link
Collaborator

@ckeshava @legleux - did you confirm that this PR, as-is, fully fixes the issue reported in #4557 (comment)?

Specifically:

  1. All ports removed and isolated down to grpc_port - node stop
  2. Isolated down to grpc_port and add protocol - node stop
  3. grpc_port removed from server block - successful boot

In all of those cases, with this PR, the node will successfully boot with a correctly configured grpc_port, right?

@intelliot
Copy link
Collaborator

intelliot commented Feb 1, 2024

Suggested commit message:

See updated message below.

@legleux
Copy link
Collaborator

legleux commented Feb 3, 2024

The commit message should not have [port_grpc] but just port_grpc in the [server] block.

👍 With this PR, rippled no longer stops with

Application:ERR Missing 'protocol' in [port_grpc]

when port_grpc appears in the [server] block which was a cause of confusion.

However, port_grpc can be omitted and it appears the server starts so the behavior is not consistent with the other [server] options, i.e. if you omit port_rpc from [server] yet leave the config, the rpc server does not appear to be running.

Here's output from startup completely omitting grpc_port in [server] showing it (at least logging) that it's starting, which was the previous behavior. The previous behavior prevented startup if the field was present.

2024-Feb-03 01:10:04.559472985 UTC Server:NFO Opened 'port_rpc' (ip=0.0.0.0:51234, admin nets:127.0.0.1/32, 10.30.97.0/32, 10.30.97.162/32, http)
2024-Feb-03 01:10:04.559508247 UTC Server:NFO Opened 'port_peer' (ip=0.0.0.0:51235, peer)
2024-Feb-03 01:10:04.559537538 UTC Server:NFO Opened 'port_ws_admin_local' (ip=127.0.0.1:6006, admin nets:127.0.0.1/32, ws)
   ...
2024-Feb-03 01:10:04.583550265 UTC gRPC Server:NFO Starting gRPC server at 127.0.0.1:50051

@intelliot
Copy link
Collaborator

Thanks. I think that's ok - in fact it's probably what we want, as the change should be 100% backward-compatible with any existing working cfg.

@intelliot
Copy link
Collaborator

Suggested commit message (updated):

feat: allow `port_grpc` to be specified in `[server]` stanza (#4728)

Prior to this commit, `port_grpc` could not be added to the [server]
stanza. Instead of validating gRPC IP/Port/Protocol information in
ServerHandler, validate grpc port info in GRPCServer constructor. This
should not break backwards compatibility.

gRPC-related config info must be in a section (stanza) called
[port_gprc].

* Close #4015 - That was an alternate solution. It was decided that with
  relaxed validation, it is not necessary to rename port_grpc.
* Fix #4557

@intelliot intelliot merged commit 6d3c21e into XRPLF:develop Feb 7, 2024
17 checks passed
@ckeshava
Copy link
Collaborator Author

ckeshava commented Feb 7, 2024

@legleux Thanks for verifying the output of this PR! I was not able to look into this one for the past few days

sophiax851 pushed a commit to sophiax851/rippled that referenced this pull request Jun 12, 2024
)

Prior to this commit, `port_grpc` could not be added to the [server]
stanza. Instead of validating gRPC IP/Port/Protocol information in
ServerHandler, validate grpc port info in GRPCServer constructor. This
should not break backwards compatibility.

gRPC-related config info must be in a section (stanza) called
[port_gprc].

* Close XRPLF#4015 - That was an alternate solution. It was decided that with
  relaxed validation, it is not necessary to rename port_grpc.
* Fix XRPLF#4557
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required. Perf impact not expected Change is not expected to improve nor harm performance. Testable Will Need Documentation
Projects
Status: 🚢 Released in 2.2.0
Development

Successfully merging this pull request may close these issues.

Rename the port_grpc section to avoid confusion
5 participants