Skip to content

Extract NodeState basic hook callbacks - #8509

Merged
Amaury Chamayou (achamayou) merged 4 commits into
mainfrom
achamayou-automatic-giggle
Oct 6, 2026
Merged

Amaury Chamayou (achamayou) merged 4 commits into
mainfrom
achamayou-automatic-giggle

Conversation

@achamayou

Copy link
Copy Markdown
Member

Motivation

The inline callbacks in NodeState::setup_basic_hooks make the registration function exceed the cognitive-complexity threshold. Extracting them removes this function's baseline suppression without changing hook behavior.

Related to #7358. This is an independent change based on main at a6fe2f2fc, not stacked on #8504, and does not resolve the remaining backlog.

Implementation summary

Move all six callback bodies into concretely typed member helpers and retain small [this] forwarding lambdas. Remove only the setup_basic_hooks complexity suppression; no other suppressions, check configuration, logging sample code, or join/recovery control flow are changed.

Actual clang-tidy 18.1.8 measurements with IgnoreMacros=true: setup_basic_hooks falls from 66 to 0, and each of its six forwarding lambdas scores 0. A threshold-zero diagnostic probe measured the positive scores below and confirmed no score above zero for the registration function or adapters; the repository threshold remains 50.

Helper Before (inline callback) After
on_secrets_local_commit 7 7
on_secrets_global_commit 12 12
on_nodes_global_commit 4 4
on_node_endorsed_certificates_local_commit 7 7
on_node_endorsed_certificates_global_commit 8 8
on_service_global_commit 3 3

Every helper and retained lambda independently remains below the threshold.

Safety and compatibility

This is a mechanical internal refactor with no API, ledger format, mixed-version, or intended behavior changes. Callback bodies are token-identical apart from whitespace, and hook registration order, map names, wrapper types, captures, and all code outside the extracted region are unchanged. Typed write sets remain synchronously borrowed, and map hooks return the same null consensus hooks. Ledger secret filtering/decryption/version handling, recovery restrictions and transitions, commit/rollback timing, certificate locking/renewal, deferred frontend opening, retirement notification, and exception/logging behavior are preserved.

Validation:

  • Configured Debug with CLANG_TIDY=ON and clang-tidy 18.1.8. The affected CMakeFiles/ccf.dir/src/enclave/main.cpp.o passed the full configured checks.
  • Built kv_test, ledger_test, ledger_secrets_test, encryptor_test, logging, logging_cose_only, logging_cose_only_allow_join_dual, and js_generic with the full configured tidy checks.
  • All eight existing regressions passed through build-tidy/tests.sh: kv_test, ledger_test, ledger_secrets_test, encryptor_test, recovery_test, recovery_test_suite (rekey/recovery and membership/recovery interleavings), governance_test (including node/service certificate renewal), and nodes_test.
  • scripts/ci-checks.sh passed without auto-fix, including C++ formatting, ASCII, and all other local repository checks. Token/registration comparisons and git diff --check also passed.

Environment note: the initial broader build with the AUTO-selected std::stacktrace backend on this Clang 21 host failed on the pre-existing src/tasks/worker.cpp:83 bugprone-empty-catch diagnostic. Reconfiguring the same build intentionally with the supported backend passed configuration, the full selected build, and all selected tests without modifying baseline code or disabling checks:

cmake -S . -B build-tidy -GNinja -DCMAKE_BUILD_TYPE=Debug -DCLANG_TIDY=ON -DCCF_STACKTRACE_BACKEND=LIBBACKTRACE

There are no remaining local validation blockers; required CI still needs to pass before merge.

Move the six setup_basic_hooks callbacks into typed member helpers and retain small binding lambdas without changing hook semantics. Remove only the registration function's cognitive-complexity suppression.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

Copilot review overview

🟢 Approval recommended

The mechanical extraction preserves callback types, order, captures, return behavior, and existing validation coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Extracts six NodeState hook callbacks into private helpers to reduce cognitive complexity without changing behavior.

Changes:

  • Adds concretely typed callback helpers.
  • Retains hook order and forwarding semantics while removing the suppression.

Custom instructions used: .github/copilot-instructions.md, .github/instructions/reviewing.instructions.md, .github/skills/testing/SKILL.md

File Description
src/​node/​node_state.h Extracts hook implementations and simplifies registration.

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

@achamayou
Amaury Chamayou (achamayou) merged commit 1688a7f into main Oct 6, 2026
12 checks passed
@achamayou
Amaury Chamayou (achamayou) deleted the achamayou-automatic-giggle branch October 6, 2026 14:55
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