Skip to content

Move node endpoint handlers out of NodeEndpoints::init_handlers - #8491

Merged
Amaury Chamayou (achamayou) merged 1 commit into
achamayou-studious-guidefrom
achamayou-supreme-guide
Oct 2, 2026
Merged

Amaury Chamayou (achamayou) merged 1 commit into
achamayou-studious-guidefrom
achamayou-supreme-guide

Conversation

@achamayou

Copy link
Copy Markdown
Member

Motivation

Part of #7358. This is layer 6 of a 7-PR stack, on top of #8489. ccf::NodeEndpoints::init_handlers() in src/node/rpc/node_frontend.h scored a cognitive complexity of 266, all of it contributed by its 24 inline [this] handler lambdas.

Implementation summary

Each handler lambda body becomes a private member function with the same name and parameter list, following #8489's member-function convention; registration keeps a thin forwarding lambda.

Generic lambdas became member function templates with the same deduced auto return type; concrete-typed ones stayed concrete; the two capture-less handlers (version, service_previous_identity) became private static member functions.

Naming rule: no clashes were found against CommonEndpointRegistry/BaseEndpointRegistry/EndpointRegistry or free functions, so all handlers kept their original names unchanged.

Complexity: init_handlers() 266 -> effectively 0 (pure forwarding calls); largest extracted function (accept) measures 38, all new functions are well under the threshold of 50.

Non-move edits, each needed because a clang-tidy check that skips lambda bodies now applies to the moved code: 20 unnamed trailing nlohmann::json&& parameters given a /*params*/ name (readability-named-parameter); 5 NOLINT(bugprone-unchecked-optional-access) added at pre-existing unchecked accesses now visible to the checker; 2 redundant trailing return; removed from get_ready_app/get_ready_gov (readability-redundant-control-flow), matching the precedent in file_serving_handlers.h.

Verified as a pure reshuffle by stripping comments/whitespace from each old lambda body and new function body and requiring exact equality after applying only the edits listed above; all handler bodies and the rest of init_handlers() match.

Tests: unit tests frontend_test and node_frontend_test pass; e2e schema_test, reconfiguration_test_suite, and nodes_test pass.

Safety and compatibility

Pure reshuffle of existing code with no behaviour change: endpoint paths, verbs, adapters, auth policies, and registration order are unchanged, so there is no runtime, API, or compatibility impact.

@achamayou
Amaury Chamayou (achamayou) requested a review from a team as a code owner October 2, 2026 07:54
Refactor ccf::NodeEndpoints::init_handlers() in src/node/rpc/node_frontend.h
following the member-function convention from #8489: each [this] handler
lambda body becomes a private member function (templated where the lambda
was generic), with a thin forwarding lambda left in place for registration.
Capture-less handlers (version, service_previous_identity) become private
static member functions. No naming clashes were found against
CommonEndpointRegistry/BaseEndpointRegistry/EndpointRegistry or free
functions, so all 32 handlers keep their original names.

Removes the NOLINTNEXTLINE(readability-function-cognitive-complexity) above
init_handlers(). Cognitive complexity drops from 266 (all contributed by the
24 inline handler lambdas) to effectively 0 for the new init_handlers(); the
largest extracted function (accept) measures 38, well under the threshold
of 50.

Non-move changes, all required because some clang-tidy checks skip lambda
bodies but apply once the code is a real named function:
- 20 unnamed trailing nlohmann::json&& parameters given a /*params*/ comment
  name (readability-named-parameter).
- 5 NOLINT(bugprone-unchecked-optional-access) added at pre-existing unchecked
  optional accesses now visible to the checker; placed as NOLINTNEXTLINE
  immediately above the flagged expression to match clang-tidy's diagnostic
  location for these multi-line statements.
- 2 redundant trailing `return;` statements removed from get_ready_app and
  get_ready_gov (readability-redundant-control-flow), matching the precedent
  set in file_serving_handlers.h.

Verified as a pure reshuffle with a script that strips comments/whitespace
from each old lambda body and new function body and requires exact equality
after applying only the explicit edit list above; all 33 units match.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@achamayou
Amaury Chamayou (achamayou) merged commit 058f585 into achamayou-studious-guide Oct 2, 2026
12 checks passed
@achamayou
Amaury Chamayou (achamayou) deleted the achamayou-supreme-guide branch October 2, 2026 20:03
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.

2 participants