Skip to content

fix(rpc): bound asynchronous transaction broadcasts - #1478

Merged
lklimek merged 4 commits into
v1.8-devfrom
fix/bound-broadcast-tx-async
Sep 21, 2026
Merged

lklimek merged 4 commits into
v1.8-devfrom
fix/bound-broadcast-tx-async

Conversation

@lklimek

@lklimek lklimek commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

TL;DR: Nodes now cap unfinished asynchronous transaction submissions and reject excess requests immediately instead of accumulating work without limit.

User story

As a node operator, I want asynchronous transaction submissions to consume bounded resources, to achieve predictable node availability under heavy or hostile RPC traffic.

Scenario

Base flow

Clients submit transactions through broadcast_tx_async while application validation is slow or blocked.

Actual behavior

Every request starts detached work, so unfinished CheckTx calls and goroutines can grow without bound.

Expected behavior

The node accepts at most the configured number of unfinished asynchronous broadcasts and returns JSON-RPC -32004 immediately when capacity is full.

Detailed discussion

Issue being fixed or feature implemented

broadcast_tx_async used a background context and created one goroutine per request without admission control. Connection and batch limits did not bound work retained after the RPC response.

What was done?

  • Added rpc.max-concurrent-broadcast-tx-async, with a default of 100; zero selects that finite default and negative values are invalid.
  • Acquired capacity before starting work and reused the existing Too many requests response when saturated.
  • Kept accepted work independent of the client request while tying it to node shutdown and the existing broadcast timeout.
  • Held capacity until CheckTx actually returns and copied transaction bytes before returning to local callers.
  • Initialized and stopped admission for nodes with and without a network RPC listener.
  • Updated the generated TOML template and OpenAPI description.

Transport-level retention of already-sent socket ABCI requests after a positive caller timeout remains outside this change. The default zero timeout used by Tenderdash and Dashmate keeps each admitted request counted until it finishes.

How Has This Been Tested?

Regression tests first reproduced admission beyond the default limit and acceptance of an already-canceled request. Focused tests then covered default and custom limits, concurrent and batched callers, cancellation, slot release, timeout behavior, shutdown races, HTTP error mapping, configuration rendering, and node lifecycle without a listener.

go test -race -tags=deadlock -p 1 ./internal/rpc/core ./config ./node -run 'TestBroadcastTxAsync|TestAsyncBroadcastConfiguration|TestRPCConfigValidateBasic|TestNodeAsyncBroadcastLifecycleWithoutListener|TestNodeStartStop' -count=1

The focused golangci-lint v2.13.2 run reported zero issues, and git diff --check passed.

Breaking Changes

None. Successful responses and timeout semantics remain unchanged. Saturated callers can now receive the existing Too many requests error.

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Co-authored by Claudius the Magnificent AI Agent

Limit unfinished async broadcasts per node with fail-fast admission and
reuse the existing too-many-requests response. Tie accepted work to node
shutdown while preserving request independence and configured timeouts.

Add regression coverage for limits, cancellation, slot release, races,
HTTP batches, and local-only node lifecycle.

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

Co-Authored-By: Claude gpt-6-astra <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository: dashpay/tenderdash/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 2d3a5649-c540-45c1-bc7d-6a6de187a610

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@thepastaclaw

thepastaclaw commented Sep 16, 2026 •

Copy link
Copy Markdown

⚠️ DEGRADED — Final review complete — 1 blocking finding(s) (commit 1894361) · triage: normal · stand-in models (primary models out of quota)

@lklimek
lklimek marked this pull request as ready for review September 17, 2026 06:42
@lklimek
lklimek requested a review from shumkov as a code owner September 17, 2026 06:42
@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

PR Hygiene

State: waiting-bots · commit 18943616fc1394cda4cf66e878613ab729af146c

  • Bot changes request remains outstanding

Self-review is an author attestation that you have read the diff:
/self-reviewed — covers everything pushed so far; post it again after a new push.
/skip-bots — proceed without the bots that have not reported; anyone with write access may, and the report says who did.

This check passes when the policy is satisfied; the repository decides whether merging requires it.

@github-actions

Copy link
Copy Markdown

@thepastaclaw review

No review for f946fa83 yet, so PR Hygiene is asking once. If nothing arrives, the requirement is dropped for this commit and the pull request is labelled bot-review-missed.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Final validation — Phase 2 only (queue backlog)

The reported admission-capacity race is not present. BroadcastTx invokes Mempool.CheckTx synchronously and only consumes the callback result after that call returns; therefore the deferred release and shutdown idle signal occur after the complete CheckTx invocation, including post-callback mempool work.

Review provenance

Source: reviewer 1: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6-astra (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: normal by gpt-6-astra (effort low) — The change adds nontrivial RPC admission control with concurrency, cancellation, timeout, and node-lifecycle interactions across several files, but does not change consensus, funds handling, cryptography, peer-facing deserialization, or storage migrations.
  • Phase 1 reviewers: not run (skipped for throughput: 21 PRs queued, above the 10 limit)
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort high); agent phase2-reviewer, gpt-6-astra — tenderdash-consensus-security (completed, effort high); agent phase2-reviewer
Out-of-scope follow-up suggestions (1)

These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.

  • Bound socket ABCI requests retained after caller timeout — The socket client adds sent requests to reqSent but removes them only when a response arrives. A positive broadcast timeout can therefore release the RPC admission slot while the socket request remains retained if the application consumes the request without responding, allowing repeated submissions to accumulate transport state. This behavior predates this PR and is explicitly outside its admission-control scope.
    • Follow-up: Track separately in a follow-up issue or PR with bounded outstanding socket requests while preserving FIFO response matching.

@github-actions github-actions Bot added the waiting-self-review Waiting for the author to post /self-reviewed label Sep 20, 2026
Replace the active counter and idle channel with the existing x/sync
weighted semaphore. Cancel admission before acquiring all slots to drain
accepted calls, then release the slots for repeated shutdown callers.

Cover concurrent shutdown, timeout retries, and idle shutdown with an
already-canceled context.

Co-Authored-By: Codex <[email protected]>

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Sep 21, 2026
@lklimek
lklimek enabled auto-merge (squash) September 21, 2026 10:15

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ DEGRADED — Re-review — Final validation — Phase 1 + Phase 2

⚠️ DEGRADED review. The primary review models were unavailable (gpt-6-astra unavailable: All credentials for model gpt-6-astra are cooling down (last error: usage_limit_reached: The usage limit has been reache), so this review ran on stand-in models: gpt-5.6-luna → muse-spark-1.3-contributor, gpt-5.6-sol → muse-spark-1.3-contributor, gpt-5.6-terra → muse-spark-1.3-contributor, gpt-6-astra → muse-spark-1.3-contributor. Both review phases and the independent verifiers still ran, but on weaker models, with Phase 1 capped at high effort. Treat the verdict as provisional; a full-strength re-review will run on the next push once the primary models are back.

This change correctly bounds async broadcasts, but StopAsyncBroadcasts never resets admission state, so a node Start retried after a failed OnStart can never succeed. The bound, cancellation, and shutdown-drain logic otherwise check out.

🔴 1 blocking

Review provenance

Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: glm-5.3-flash (agent: phase1-reviewer, role: tenderdash-consensus-security); reviewer 3: muse-spark-1.3-contributor (standing in for gpt-6-astra) (agent: phase2-reviewer, role: general); reviewer 4: muse-spark-1.3-contributor (standing in for gpt-6-astra) (agent: phase2-reviewer, role: tenderdash-consensus-security); reviewer 5: muse-spark-1.3-contributor (standing in for gpt-6-astra) (agent: phase2-reviewer, role: general); reviewer 6: muse-spark-1.3-contributor (standing in for gpt-6-astra) (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: muse-spark-1.3-contributor (standing in for gpt-6-astra) (agent: astra-verifier, role: final-verifier)

  • Degraded mode: gpt-6-astra unavailable: All credentials for model gpt-6-astra are cooling down (last error: usage_limit_reached: The usage limit has been reache (detected by probe, since 2026-09-20T20:45:34Z); stand-ins gpt-5.6-luna → muse-spark-1.3-contributor, gpt-5.6-sol → muse-spark-1.3-contributor, gpt-5.6-terra → muse-spark-1.3-contributor, gpt-6-astra → muse-spark-1.3-contributor; Phase 1 effort capped at high
  • Triage: normal by muse-spark-1.3-contributor (standing in for gpt-6-astra) (effort low) — Adds bounded admission control for async broadcasts across config, node, and RPC with new concurrency logic, but does not change consensus, funds, crypto, peer deserialization, or migrations.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer, glm-5.3-flash — tenderdash-consensus-security (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 98% left, weekly 99% left; passed over gemini-3.8-flash-high (lane failed)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: muse-spark-1.3-contributor (standing in for gpt-6-astra) — final-verifier; agent astra-verifier
  • Phase 2 reviewers: muse-spark-1.3-contributor (standing in for gpt-6-astra) — general (completed, effort high); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6-astra) — tenderdash-consensus-security (completed, effort high); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6-astra) — general (completed, effort high); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6-astra) — tenderdash-consensus-security (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `internal/rpc/core/async_broadcast.go`:
- [BLOCKING] internal/rpc/core/async_broadcast.go:22-63: StopAsyncBroadcasts never resets state, blocking node Start retry
  StopAsyncBroadcasts cancels the admission context and drains the semaphore but leaves the started state set, while StartAsyncBroadcasts refuses to run whenever that state is set. The BaseService contract (libs/service/service.go) explicitly allows calling Start again after OnStart fails, and node OnStart has exactly that path: if the RPC listener fails to start after admission started, it stops admission and returns the error, so a retry (e.g. after a transient listen-address conflict) fails with a misleading "async broadcasts already started" instead of starting cleanly. The fix must reset the started marker only after the full drain succeeds (jobs are still outstanding when drain fails, so Start must keep refusing), and it must keep the canceled admission context so post-stop calls still fail with context.Canceled as the existing shutdown and node-lifecycle tests require — hence Start should key "already started" off a.cancel, not a.ctx.
Out-of-scope follow-up suggestions (1)

These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.

  • Positive timeout-broadcast-tx weakens the async bound at the ABCI transport layer — With the default zero timeout each admitted slot is held until CheckTx returns, so the semaphore strictly bounds outstanding work. With a positive rpc.timeout-broadcast-tx the slot is released on caller timeout while an already-sent socket ABCI CheckTx request may still be processed app-side (disclosed in the PR description). This is outside this change's scope and requires non-default operator config.
    • Follow-up: File a separate issue to propagate cancellation into the socket ABCI client on caller timeout or document that a positive timeout-broadcast-tx trades strictness of the bound for responsiveness.

Comment thread internal/rpc/core/async_broadcast.go Resolved
@lklimek
lklimek disabled auto-merge September 21, 2026 14:21
@lklimek
lklimek merged commit 13634db into v1.8-dev Sep 21, 2026
25 of 27 checks passed
@lklimek
lklimek deleted the fix/bound-broadcast-tx-async branch September 21, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-bots Waiting for the review bots to report on this head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants