Skip to content

chain: keep the timeout-vote journal across a snapshot import too - #265

Closed
On1x wants to merge 1 commit into
fix/timeout-vote-journal-reindex-restorefrom
fix/timeout-vote-journal-snapshot-restore
Closed

On1x wants to merge 1 commit into
fix/timeout-vote-journal-reindex-restorefrom
fix/timeout-vote-journal-snapshot-restore

Conversation

@On1x

@On1x On1x commented Nov 8, 2026

Copy link
Copy Markdown
Member

Stacked on #264 (base is its branch; retarget to master once it lands).

The production image ships plugin = snapshot, snapshot-every-n-blocks = 2400 and sync-snapshot-from-trusted-peer, and auto-recovery takes the newest snapshot before trying a block-log replay. So on a production node a restart under a stall goes through open_from_snapshot(), not through reindex() — and that path truncated the cache on purpose (chain state was wiped, starting with an empty cache). The reindex fix alone would not have helped the nodes it was written for: the same stall would still empty the journal through the other door.

Keeping the cache there is safe because nothing from the file is trusted by itself: the vote digest binds the chain id (block_timeout_digest(get_chain_id(), ...)), and every line is replayed through push_timeout_vote, which re-checks schedule membership, the signing key, the signature and both edges of the one-hour window. Votes of another chain are refused, not replayed.

Change:

  • open_from_snapshot() marks the cache pending instead of truncating it.
  • do_snapshot_load() calls database::resume_timeout_vote_journal() once the state is final (snapshot loaded, dlt_block_log replayed on top).
  • resume_* is the same helper reindex() uses now, so one place decides what a kept cache means.

Verification:

  • Wiring suite now reads plugins/chain/plugin.cpp, pins the snapshot branch (no truncate, pending set) and the resume call; three new mutations (snapshot-truncates-cache, snapshot-never-restores, snapshot-load-never-resumes) — 18 mutations, every one red.
  • tests/chain/test_timeout_vote_journal.py: PASS.
  • single-TU -fsyntax-only: database.cpp rc=0, plugin.cpp rc=0.

Live acceptance after #264's image: same stand with a snapshot present, so the restart takes the snapshot door.

🤖 Generated with Claude Code

The production image ships 'plugin = snapshot', snapshot-every-n-blocks = 2400
and sync-snapshot-from-trusted-peer, and auto-recovery takes the newest
snapshot BEFORE trying a block-log replay. So on a production node the restart
under a stall goes through open_from_snapshot(), not through reindex() -- and
that path truncated the cache on purpose ('chain state was wiped, starting with
an empty cache'). The reindex fix alone therefore would not have helped the
nodes it was written for: the same stall would still empty the journal through
the other door.

Keeping the cache there is safe because nothing from the file is trusted by
itself: the vote digest binds the chain id (block_timeout_digest(get_chain_id(),
...)), and every line is replayed through push_timeout_vote, which re-checks
schedule membership, the signing key, the signature and both edges of the
one-hour window. Votes of another chain are refused, not replayed.

So: open_from_snapshot() marks the cache pending instead of truncating, and
do_snapshot_load() calls database::resume_timeout_vote_journal() once the state
is final (snapshot loaded, dlt_block_log replayed on top). resume_* is the same
helper reindex() now uses, so there is one place that decides what a kept cache
means.

Test: the wiring suite reads plugins/chain/plugin.cpp as well, pins the
snapshot branch (no truncate, pending set) and the resume call, and gains three
mutations -- snapshot-truncates-cache, snapshot-never-restores,
snapshot-load-never-resumes. 18 mutations, every one red. single-TU
-fsyntax-only rc=0 for database.cpp and plugin.cpp.
@On1x On1x added the testnet21-stand Build the 21-validator testnet image for the QC bench label Nov 8, 2026
@On1x
On1x deleted the branch fix/timeout-vote-journal-reindex-restore November 8, 2026 17:58
@On1x On1x closed this Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testnet21-stand Build the 21-validator testnet image for the QC bench

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant