Skip to content

Move gov proposal handlers out of init_proposals_handlers - #8487

Merged
Amaury Chamayou (achamayou) merged 5 commits into
mainfrom
achamayou-glowing-robot
Oct 2, 2026
Merged

Amaury Chamayou (achamayou) merged 5 commits into
mainfrom
achamayou-glowing-robot

Conversation

@achamayou

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

Copy link
Copy Markdown
Member

Motivation

Part of #7358. Layer 3 of the stack on top of #8486: init_proposals_handlers in src/node/gov/handlers/proposals.h scored a cognitive complexity of 127, all of it from its 7 inline endpoint handler lambdas.

Implementation summary

Moves each handler lambda body into a named function in ccf::gov::endpoints::detail, registered via a thin forwarding lambda, following the convention set in #8484.
init_proposals_handlers drops from 127 to 0; the largest extracted handler, create_proposal, is 29 - all 7 new functions are well under the threshold of 50.
submit_ballot keeps its concrete ccf::endpoints::EndpointContext& instead of being templated like the other six, because templating it turns some non-dependent name lookups into dependent ones and introduces new clang-tidy errors.
Verified as a pure reshuffle: handler bodies and registration blocks are token/byte-identical before and after, modulo the capture-to-parameter changes, and clang-tidy findings in untouched code are unchanged.
Tests: frontend_test, node_frontend_test, and governance_test all pass.

Safety and compatibility

No behaviour change: endpoint paths, verbs, adapters, auth policies, and registration order are unchanged, so this is a no-op refactor with no compatibility 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>
Base automatically changed from achamayou-urban-barnacle to main October 2, 2026 16:29
Copilot AI balanced review requested due to automatic review settings October 2, 2026 16:35
@achamayou
Amaury Chamayou (achamayou) merged commit 341b91f into main Oct 2, 2026
13 checks passed
@achamayou
Amaury Chamayou (achamayou) deleted the achamayou-glowing-robot branch October 2, 2026 16:48

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: 2 Medium severity

Open (2)
What changed in this PR

Refactors init_proposals_handlers by extracting the inline endpoint handler lambdas into named functions, reducing cognitive complexity while preserving behavior.

Changes:

  • Moved each endpoint handler body from inline lambdas into ccf::gov::endpoints::detail functions.
  • Replaced large inline lambdas with thin forwarding lambdas during endpoint registration.
  • Kept submit_ballot non-templated to avoid dependent-name lookup/clang-tidy issues.
File Description
src/​node/​gov/​handlers/​proposals.h Extracts proposal/ballot endpoint handler bodies into detail helpers while keeping endpoint registrations unchanged.

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

Ctx& ctx,
ApiVersion api_version,
ccf::AbstractNodeContext& node_context,
ccf::NetworkState& network)
ccf::endpoints::EndpointContext& ctx,
ApiVersion api_version,
ccf::AbstractNodeContext& node_context,
ccf::NetworkState& network)
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