Skip to content

fix(blocksync): preserve in-flight finalization during handover - #1488

Merged
lklimek merged 4 commits into
v1.8-devfrom
fix/1485
Sep 21, 2026
Merged

lklimek merged 4 commits into
v1.8-devfrom
fix/1485

Conversation

@lklimek

@lklimek lklimek commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR: Prevent a syncing node from crashing as it catches up and switches to consensus.

User story

As a node operator, I want my node to finish syncing without a restart so it can join consensus reliably.

Scenario

A node reaches the network tip while its application is still finishing the last block. The switch to consensus must wait for that work without interrupting it or getting stuck reporting a peer error.

Detailed discussion

Issue being fixed or feature implemented

Fixes #1485. Synchronizer shutdown canceled the context shared with an in-flight FinalizeBlock, triggering the committed-block panic.

What was done?

  • Keep only block application on the parent node context. Fetching, result receives, and peer-error delivery use the synchronizer's cancelable child context.
  • Stop the worker pool and wait for the result consumer to exit before handover reads the final state.
  • Retain consumerDone: the applier's mutex waits for one Apply, but cannot prevent a received block from starting application after a state snapshot. Worker-pool shutdown and BaseService.Wait do not independently join this consumer.
  • Preserve node-shutdown cancellation for application work.

How Has This Been Tested?

  • Regression coverage holds the consumer both inside finalization and before entering Apply, checking shutdown ordering, final state, and parent cancellation.
  • A full P2P error channel checks that handover cancels blocked error delivery while leaving the parent context live; the test fails without the context-scope fix.
  • Mutation check: removing the consumer completion wait makes both application handover tests fail in all five repetitions.
  • Full internal/blocksync package passed with -race -tags deadlock -count=1 (9.233s), using BLS 1.3.6 headers matching the locally built native library.
  • Handover tests passed 10 repetitions with the race detector after the final test fix (7.879s); the consumer-result assertion was also verified in the preceding run.
  • Skipping application of the received block causes an immediate test failure with cleanup, rather than a global timeout (mutation-checked).
  • Astra and Daybreak reviewed the full PR: no remaining production findings; the test failure-path hang identified during review is fixed.
  • Repository-configured lint scoped to internal/blocksync: 0 issues. gofmt and git diff --check passed.

Breaking Changes

None.

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 (not needed for this internal fix)

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Co-authored by Claudius the Magnificent AI Agent

Keep application work on the node context and wait for the result
consumer to exit before handing its final state to consensus.

Fixes #1485.

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

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

coderabbitai Bot commented Sep 21, 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: a96d8b6b-4d54-4514-acc5-186c560c7089

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 21, 2026 •

Copy link
Copy Markdown

⚠️ DEGRADED — Final review complete — no blockers (commit 7d18433) · triage: low · stand-in models (primary models out of quota)

@lklimek
lklimek marked this pull request as ready for review September 21, 2026 08:16
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

PR Hygiene

State: ready-to-merge · commit 7d184333775265324a9dd80dc17f72b2c3fd963f

  • All policy requirements are satisfied

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.

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

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Sep 21, 2026
Keep the parent context only for applying received blocks. Cancel result
receives and peer-error delivery with the synchronizer so a blocked P2P
send cannot prevent consumer shutdown.

Cover a full peer-error channel and a consumer paused before Apply.
Strengthen stop ordering checks; removing the consumer join fails both
handover tests in five repeated mutation-test runs.

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

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
Check finalization without blocking after the consumer has been joined.
A missing application must fail the regression test and run cleanup,
not hang until the global test timeout.

Verified with a skipped-application mutation before and after the fix.

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

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

@lklimek lklimek left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

LGTM

@lklimek

lklimek commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

/self-reviewed

@lklimek
lklimek enabled auto-merge (squash) September 21, 2026 10:16

@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 — 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.

Handover fix is correct: consumer I/O uses the cancelable child context while FinalizeBlock keeps the parent node context, and OnStop joins the consumer before consensus reads state. The unbounded-wait concern describes the intended safety-over-liveness tradeoff, not a defect, and shutdown cancellation is preserved.

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); 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: low by muse-spark-1.3-contributor (standing in for gpt-6-astra) (effort low) — Small contained context-scoping and shutdown-ordering fix in synchronizer.go with extensive tests and no change to consensus rules, crypto, or serialization logic.
  • 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 100% left, weekly 100% left; passed over gemini-3.8-flash-high (lane failed)
  • 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 medium); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6-astra) — tenderdash-consensus-security (completed, effort medium); agent phase2-reviewer

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Sep 21, 2026
@lklimek

lklimek commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

/self-reviewed

@github-actions github-actions Bot added ready-to-merge and removed waiting-self-review Waiting for the author to post /self-reviewed labels Sep 21, 2026
@lklimek
lklimek merged commit 00647eb into v1.8-dev Sep 21, 2026
23 checks passed
@lklimek
lklimek deleted the fix/1485 branch September 21, 2026 12:23
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.

2 participants