Skip to content

Split RPC command processing into focused helpers - #8562

Merged
Amaury Chamayou (achamayou) merged 7 commits into
mainfrom
achamayou-rpc-processing-extraction
Oct 16, 2026
Merged

Amaury Chamayou (achamayou) merged 7 commits into
mainfrom
achamayou-rpc-processing-extraction

Conversation

@achamayou

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

Copy link
Copy Markdown
Member

Motivation

RpcFrontend::process_command_inner scores 90 on readability-function-cognitive-complexity, against a threshold of 50, and carries a baseline suppression. This PR splits it so the suppression can be removed without changing behaviour.

Related to #7358. The remaining suppressions are handled in #8560 and #8561.

Implementation summary

Extract three private helpers from the per-attempt loop body, moving the statements verbatim:

  • check_backpressure: the consensus backpressure check, still run before the try.
  • redirect_or_forward: redirection-config lookup, check_redirect, and the ForwardingRequired switch.
  • commit_transaction: write-set observer setup, tx.commit, the locally-committed callback and its fallbacks, respond_on_commit population, and signature emission. It returns CommitAction::Done for SUCCESS and FAIL_NO_REPLICATE, and Retry for FAIL_CONFLICT, so the caller's loop and all seven catch clauses are unchanged.

Add frontend_test cases for local-commit callback order relative to signature emission, respond_on_commit receipt fields, standard and non-standard exceptions from the local-commit callback, and replication failure completing without retry or commit callbacks.

Measured with clang-tidy 21.1.8 and IgnoreMacros=true; the repository threshold stays at 50:

Function Before After
process_command_inner 90 44
commit_transaction - 17
redirect_or_forward - 16
check_backpressure - 4

Safety and compatibility

Internal refactor with no API, ledger-format, or mixed-version impact. A token comparison against main shows the only differences are the helper signatures, their call sites, and return becoming return CommitAction::Done. Routing and authorization order, transaction ownership, retry outcomes, receipt capture, and every error status, code, and message are unchanged. CommitAction is uint8_t to satisfy performance-enum-size.

Validation:

  • Built frontend_test and node_frontend_test and ran both; all cases pass, including the new ones.
  • scripts/ci-checks.sh passed without auto-fix.
  • CI passed on the pre-merge head, including the Debug CLANG_TIDY=ON build with the suppression removed. Required CI must pass again on the current head.

Extract backpressure, redirect/forward and commit completion blocks without changing retry control, transaction ownership or exception handling. Add regression coverage for local commit callbacks, receipt fields and replication failure. Measured cognitive complexity drops from 90 to 44; all helpers remain below 50. Ref #7358.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use uint8_t for the private Done/Retry enum and include cstdint directly, matching the existing endpoint enum convention. Fix performance-enum-size under the required clang-tidy configuration without changing values, retry semantics, or suppressions.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@achamayou
Amaury Chamayou (achamayou) marked this pull request as ready for review October 16, 2026 07:04
@achamayou
Amaury Chamayou (achamayou) requested a review from a team as a code owner October 16, 2026 07:04
Copilot AI balanced review requested due to automatic review settings October 16, 2026 07:04

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.

🟢 Approval recommended

The extraction preserves existing behavior, no unresolved findings remain, and CI succeeded for the repaired head.

0 open findings

What changed in this PR

Refactors RPC command processing into focused helpers, advancing #7358 without changing request behavior.

Changes:

  • Extracts backpressure, routing, and commit-completion logic.
  • Removes the cognitive-complexity suppression.
  • Adds regression coverage for callbacks, receipts, exceptions, and replication failure.

Custom instructions used

Applied the supplied guidance for .github/copilot-instructions.md and .github/instructions/reviewing.instructions.md; local copies were unavailable.

File Description
src/​node/​rpc/​test/​frontend_test.cpp Adds commit-completion and replication-failure regression tests.
src/​node/​rpc/​frontend.h Extracts processing helpers while preserving retry and completion behavior.

🧠 Review effort: Balanced


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

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread CHANGELOG.md Resolved
@achamayou
Amaury Chamayou (achamayou) merged commit baa9e3e into main Oct 16, 2026
12 checks passed
@achamayou
Amaury Chamayou (achamayou) deleted the achamayou-rpc-processing-extraction branch October 16, 2026 12:17
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