Skip to content

Move file serving handlers out of init_file_serving_handlers - #8488

Merged
Amaury Chamayou (achamayou) merged 6 commits into
mainfrom
achamayou-curly-tribble
Oct 2, 2026
Merged

Amaury Chamayou (achamayou) merged 6 commits into
mainfrom
achamayou-curly-tribble

Conversation

@achamayou

@achamayou Amaury Chamayou (achamayou) commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Motivation

Part of #7358 (clang-tidy readability-function-cognitive-complexity). This is layer 4 of the stack on top of #8487; ccf::node::init_file_serving_handlers in src/node/rpc/file_serving_handlers.h scored 66, entirely from its 4 inline handler lambdas (find_snapshot, find_chunk, get_snapshot, get_ledger_chunk).

Implementation summary

  • Moved each lambda's body into a named function in a new ccf::node::detail namespace, following the convention from Move gov ack handlers out of init_ack_handlers #8484, with thin forwarding lambdas left for registration (unchanged apart from the handler argument).
  • init_file_serving_handlers complexity: 66 -> 0 (new functions: 16, 17, 3, 3, all well under the threshold of 50).
  • Non-move edit: removed 3 pre-existing trailing return; statements in find_chunk/get_snapshot/get_ledger_chunk, newly flagged by readability-redundant-control-flow once this code left lambda scope (that check, like bugprone-unchecked-optional-access, skips lambda bodies).
  • Verified mechanically that all 4 handler bodies match the originals except for those 3 return removals, and the rest of the file is unchanged.
  • Built and ran frontend_test and node_frontend_test (all pass), plus the schema_test e2e test filtered to the snapshot/ledger-chunk groups, exercising Range/partial-content requests on both endpoints (pass).

Safety and compatibility

Pure refactor: endpoint paths, verbs, auth, and registration are unchanged, so there is no behaviour, API, or consensus/KV impact.

Move the three endpoint handler bodies (get_state_digest,
update_state_digest, ack_state_digest) out of the lambdas in
init_ack_handlers() into named function templates in a nested detail
namespace, registered via thin forwarding lambdas. This removes all
the cognitive complexity from init_ack_handlers() (now 0), which
previously inherited it from its inline lambda bodies (up to 69
combined, mostly from ack_state_digest at ~34 standalone), letting the
readability-function-cognitive-complexity NOLINTNEXTLINE be dropped.

Pure reshuffle: handler bodies are token-identical to the former
lambda bodies (captures become explicit parameters where needed,
e.g. ShareManager& for ack_state_digest); registration call sites,
paths, verbs, adapters, auth policies, and install() chains are
unchanged.

Part of #7358. Layer 1 of a stack of refactors applying this same
pattern to the other init_*_handlers functions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Extract each of the 13 endpoint handler lambdas in
init_service_state_handlers() into named functions in a detail
namespace, following the convention established for init_ack_handlers()
in acks.h. The registration function keeps thin forwarding lambdas,
so each handler's cognitive complexity is measured on its own instead
of being rolled up into one large function.

Pure reshuffle: handler bodies and endpoint registration (paths,
verbs, adapters, auth policies, chained set_* calls, install() calls,
registration order) are unchanged.

Removes the NOLINTNEXTLINE(readability-function-cognitive-complexity)
suppression, since the registration function's own complexity is now
effectively 0.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move the seven endpoint handler bodies (create_proposal,
withdraw_proposal, get_proposal, list_proposals, get_actions,
submit_ballot, get_ballot) out of the lambdas in
init_proposals_handlers() into named functions in a nested detail
namespace, registered via thin forwarding lambdas. This removes all
the cognitive complexity from init_proposals_handlers() (now 0),
which previously inherited it from its inline lambda bodies (127
combined, mostly from create_proposal at 29 and submit_ballot at 23
standalone), letting the readability-function-cognitive-complexity
NOLINTNEXTLINE be dropped.

submit_ballot is not templated on Ctx, unlike the other six: its
original lambda took a concrete ccf::endpoints::EndpointContext&, so
its body relies on non-dependent name lookup that a template
parameter would turn into dependent names requiring '.template'
disambiguators.

Pure reshuffle: handler bodies are token-identical to the former
lambda bodies (captures become explicit parameters where needed,
e.g. NetworkState& and AbstractNodeContext& for create_proposal and
submit_ballot); registration call sites, paths, verbs, adapters, auth
policies, and install() chains are unchanged.

Part of #7358. Layer 3 of a stack of refactors applying this same
pattern to the other init_*_handlers functions, on top of #8486.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
init_file_serving_handlers() in file_serving_handlers.h had a cognitive
complexity of 66, entirely from its 4 inline handler lambdas
(find_snapshot, find_chunk, get_snapshot, get_ledger_chunk). Move each
lambda's body into a named function in a ccf::node::detail namespace,
keeping thin forwarding lambdas in init_file_serving_handlers() for
registration. Remove the now-unneeded NOLINTNEXTLINE.

fill_range_response_from_file() is untouched; its own complexity is
handled separately.

Moving find_chunk, get_snapshot and get_ledger_chunk out of their
lambdas exposed 3 pre-existing trailing `return;` statements as
flagged by readability-function-cognitive-complexity's sibling check
readability-redundant-control-flow (which, like
bugprone-unchecked-optional-access, does not look inside lambda
bodies). These are removed as a minimal, behaviour-preserving fix.

Part of #7358

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Base automatically changed from achamayou-glowing-robot to main October 2, 2026 16:48
Copilot AI balanced review requested due to automatic review settings October 2, 2026 16:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

Refactors init_file_serving_handlers by moving the four inline handler lambdas into named functions under ccf::node::detail, reducing cognitive complexity while keeping endpoint registration behavior unchanged.

Changes:

  • Extracted find_snapshot, find_chunk, get_snapshot, and get_ledger_chunk handler bodies into ccf::node::detail functions.
  • Left thin forwarding lambdas in init_file_serving_handlers for endpoint registration.
  • Removed redundant trailing return; statements in moved handler bodies.
File Description
src/​node/​rpc/​file_serving_handlers.h Moves handler implementations into ccf::node::detail and keeps registration code as forwarding lambdas to reduce cognitive complexity.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/node/rpc/file_serving_handlers.h
Comment thread src/node/rpc/file_serving_handlers.h
@achamayou
Amaury Chamayou (achamayou) merged commit aba5689 into main Oct 2, 2026
13 checks passed
@achamayou
Amaury Chamayou (achamayou) deleted the achamayou-curly-tribble branch October 2, 2026 17:41
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.

3 participants