Skip to content

fix: prevent sync handover and restart failures - #1500

Merged
lklimek merged 7 commits into
v1.8-devfrom
fix/blocksync-switch-height
Sep 23, 2026
Merged

lklimek merged 7 commits into
v1.8-devfrom
fix/blocksync-switch-height

Conversation

@lklimek

@lklimek lklimek commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR: Resume block downloads after a restored snapshot, acquire RPC addresses before starting services, and retain complete application state across interrupted writes.

User story

As a node operator, I want snapshot recovery to fetch only missing blocks and a failed RPC bind to leave the node safe to start again after freeing the port.

Scenario

After restoring a snapshot at height 100, a node should request height 101. Previously it requested height 1, or stalled against peers with pruned history. When an RPC address is occupied, startup should fail before the application and reactors start; previously retrying startup reinitialized state while those services were already running. Restarting the e2e application during persistence must retain the last complete state rather than report height zero.

Detailed discussion

Issue being fixed or feature implemented

SwitchToBlockSync updated the application height but left request generation and metrics at their original height. CI also exposed the RPC startup retry race in #1494: startup overwrote NodeInfo while reactors registered channels and reran the handshake against live consensus.

The rotate e2e failure additionally exposed kvstore persistence truncating state.json before serialization. A restart interrupted during FinalizeBlock then loaded an empty file, reported application height 0, and could not replay from the retained block-store base.

What was done?

  • Align application, request generation and metrics at LastBlockHeight + 1; clear stale retry heights before starting synchronization.

  • Preserve the generator and peer store under their respective locks and use synchronized applier state updates.

  • Initialize blocksync before consensus can write blocks when starting without synchronization; when syncing, initialize waiting consensus before the sync handover can occur.

  • Separate RPC listener acquisition from serving: bind every address before starting services, then serve requests after node initialization.

  • Close partially acquired listeners on bind failure and release reserved listeners if later startup fails. An occupied port therefore fails without starting the application or reactors, allowing a normal startup retry.

  • Cover full-history and pruned peers, custom initial heights with stale retries, failed binds before service startup, and listener cleanup after both partial binds and later startup failures.

  • Persist kvstore state using the existing atomicfile.Tx helper, publishing only successfully serialized state and propagating close/rename errors. Failed writes preserve the prior state; memory storage follows the same replacement contract.

How Has This Been Tested?

  • Confirmed blocksync regression tests fail before the fix: request 1 instead of 101, or no request reaches the pruned peer.

  • Confirmed the strengthened startup retry test fails before listener acquisition is moved ahead of service startup.

  • Passed 10 repetitions of the focused startup retry and listener-cleanup tests with -race -tags=deadlock.

  • Passed full affected packages: go test -race -tags=deadlock -p 1 ./node ./internal/rpc/core ./internal/blocksync -count=1.

  • Passed golangci-lint v2.13.2 for all three packages with --new-from-rev=origin/v1.8-dev: zero issues.

  • Formatting and git diff --check passed.

  • Native BLS uses a compatible local build of the repository-pinned revision.

  • Added regression tests that reopen the application during empty/partial writes and after failure. Both fail before atomic persistence and pass after the fix.

  • Passed go test -race -tags=deadlock -p 1 ./abci/example/kvstore ./test/e2e/app -count=1 and targeted lint.

  • Passed the full local rotate.toml e2e scenario, including validator06 restarting after state sync and all final assertions. Both CI e2e scenarios (rotate and dashcore) passed on c0e27ac87.

  • Reproduced the exact state-0/store-1 startup failure on a fresh single-validator node with default consensus settings, no RPC listener and no retry. The regression test pauses the first ABCI FinalizeBlock and yields startup after consensus launches; it fails with the previous service order and passes with the fix, without asserting service ordering.

  • Passed ten full node package repetitions with -race -tags=deadlock, followed by the full package with the behavioral regression test, and targeted lint. CI tests (04) passed on f286d4e74.

Breaking Changes

RPC/ABCI wire formats and configuration are unchanged. The internal RPC startup API accepts prebound listeners. The example kvstore StoreFactory helper replaces Writer() with a transactional Write(func(io.Writer) error) operation.

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 required for these internal bug fixes)

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Co-authored by Claudius the Magnificent AI Agent

PR Hygiene · 209f3c6

  • Bots — thepastaclaw ✓
  • Self-review — posted; again after any push
  • Within your 5 open PRs
  • Build green
  • Approvals — you own every area touched; none needed

When every box is checked the PR Hygiene check passes and this can merge.

Align block application, request generation and sync metrics with the
snapshot height before starting the synchronizer. Clear stale retries
without replacing the generator used by concurrent peer updates.

Cover full-history and pruned peers, plus a non-default initial height
with a stale retry, through SwitchToBlockSync's first block request.

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

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

coderabbitai Bot commented Sep 22, 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: 3f0a22a1-453f-491b-9c8c-14587e3d049e

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

Copy link
Copy Markdown

⚠️ DEGRADED — Final review complete — no blockers (commit 209f3c6) · triage: normal · Phase 2 only (queue backlog) · stand-in models (primary models out of quota)

Retain initialized services when RPC binding fails so startup retries do
not overwrite NodeInfo or rerun the handshake against live consensus.
Preserve the validator context when retrying RPC setup, and assert that
channels registered by running services survive the retry.

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

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
@lklimek lklimek changed the title fix(blocksync): reset fetch height after state sync fix: correct blocksync handover and node startup retries Sep 22, 2026
Separate RPC address acquisition from request serving. Reserve every
configured address before starting the application or reactors, close
partial acquisitions on bind failure, and release listeners if later
startup fails. Serve RPC only after node initialization completes.

Remove the persistent startup-phase flag and RPC-only retry path.
Test that failed binds leave services unstarted, partially bound ports
are released, and later application failures release reserved listeners.

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

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
@lklimek lklimek changed the title fix: correct blocksync handover and node startup retries fix: correct blocksync handover and RPC startup ordering Sep 22, 2026
@lklimek
lklimek marked this pull request as ready for review September 22, 2026 12:44
@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Sep 22, 2026

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

/self-reviewed

Stage application state separately and publish it only after serialization
and close succeed. Interrupted or failed writes retain the previous state
instead of leaving an empty state.json that restarts report as height zero.

Use the existing atomicfile transaction helper for file storage, and apply
the same replacement contract to memory storage. Cover restart reads before
any bytes and during a partial write, plus preservation after failure.

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

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
@lklimek lklimek changed the title fix: correct blocksync handover and RPC startup ordering fix: prevent sync handover and restart failures Sep 22, 2026
Keep consensus ready for sync handover when waiting for synchronization,
but initialize blocksync before consensus can commit in direct-start mode.
Guard this startup dependency in the RPC retry regression test.

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

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
Exercise a fresh node with default consensus settings and a paused ABCI
FinalizeBlock response. Yield startup after consensus launches so the
real block-store/state-store write interval is observable. Assert startup
success instead of imposing a particular reactor order on the retry test.

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

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
@lklimek
lklimek enabled auto-merge (squash) September 22, 2026 18:37
@lklimek

lklimek commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator Author

/self-reviewed

@github-actions

Copy link
Copy Markdown

@thepastaclaw review

No review for 209f3c66 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-skipped.

@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 2 only (queue backlog)

⚠️ 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.

Verified the blocksync handover realignment, RPC listener pre-binding with cleanup, service ordering, and kvstore atomic persistence against the diff; each fix narrows a prior race or crash window and the added regression tests match the described behavior. No in-scope defects found.

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (standing in for gpt-6-astra) (agent: phase2-reviewer, role: general); reviewer 2: 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) — Large multi-area fix across blocksync handover, node startup ordering, and kvstore persistence, but none changes consensus rules, crypto, funds, peer deserialization, or migrations.
  • Phase 1 reviewers: not run (skipped for throughput: 30 PRs queued, above the 10 limit)
  • 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

@github-actions

Copy link
Copy Markdown

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@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 23, 2026
@lklimek

lklimek commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator Author

/self-reviewed

@github-actions

Copy link
Copy Markdown

Policy satisfied — this can merge.
Full checklist in the description.

@github-actions github-actions Bot removed the waiting-self-review Waiting for the author to post /self-reviewed label Sep 23, 2026
@lklimek
lklimek merged commit be7e73c into v1.8-dev Sep 23, 2026
22 checks passed
@lklimek
lklimek deleted the fix/blocksync-switch-height branch September 23, 2026 05:29
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