Repository navigation
Move file serving handlers out of init_file_serving_handlers - #8488
Merged
Merged
Conversation
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>
Max (maxtropets)
approved these changes
Oct 2, 2026
# Conflicts: # src/node/gov/handlers/acks.h
Contributor
There was a problem hiding this comment.
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
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, andget_ledger_chunkhandler bodies intoccf::node::detailfunctions. - Left thin forwarding lambdas in
init_file_serving_handlersfor 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.
Amaury Chamayou (achamayou)
enabled auto-merge (squash)
October 2, 2026 17:26
Copilot started reviewing on behalf of
Amaury Chamayou (achamayou)
October 2, 2026 17:31
View session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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_handlersinsrc/node/rpc/file_serving_handlers.hscored 66, entirely from its 4 inline handler lambdas (find_snapshot,find_chunk,get_snapshot,get_ledger_chunk).Implementation summary
ccf::node::detailnamespace, 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_handlerscomplexity: 66 -> 0 (new functions: 16, 17, 3, 3, all well under the threshold of 50).return;statements infind_chunk/get_snapshot/get_ledger_chunk, newly flagged byreadability-redundant-control-flowonce this code left lambda scope (that check, likebugprone-unchecked-optional-access, skips lambda bodies).frontend_testandnode_frontend_test(all pass), plus theschema_teste2e 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.