Skip to content

csdb: sync the BerkeleyDB log before a quick-start checkpoint is saved - #97

Open
EnzinoBB wants to merge 1 commit into
CREDITSCOM:masterfrom
CreditsCommunity:official/bdb-log-sync
Open

EnzinoBB wants to merge 1 commit into
CREDITSCOM:masterfrom
CreditsCommunity:official/bdb-log-sync

Conversation

@EnzinoBB

@EnzinoBB EnzinoBB commented Nov 1, 2026

Copy link
Copy Markdown

Why this PR

BlockChain::applyBlockToCaches saves a quick-start checkpoint every checkpoint_every blocks (or minutes). BerkeleyDB commits run with DB_TXN_NOSYNC, so their log records can still sit in the in-process log buffer when the checkpoint is written. If the process is killed (power cut, OOM killer, SIGKILL), the checkpoint survives but the last blocks do not, and the next start fails with "startSequence > last_seq_in_db + 1". (The PR "a quick-start checkpoint ahead of the stored blocks is set aside" lets the node recover from such a checkpoint; this one avoids creating it.)

What changes

  • csdb::Database::flush() (new virtual, default no-op) and csdb::Storage::flush().
  • DatabaseBerkeleyDB::flush() writes and syncs the log (DbEnv::log_flush).
  • BlockChain::applyBlockToCaches flushes the storage before it saves a checkpoint (a failure is logged; the checkpoint is still saved, as today).

Effect on the network

None on the wire or in consensus. One log sync per checkpoint.

Tests

Built and run on 4a95aaa (GCC 13). In the fork, robustness scenarios kill nodes (SIGKILL, power cut) and check that they start again from their checkpoints.

Same change in the community fork: CreditsCommunity#47, running on mainnet community nodes.

BlockChain saves a quick-start checkpoint every checkpoint_every blocks (or minutes). BerkeleyDB
commits run with DB_TXN_NOSYNC, so their log records can still sit in the in-process log buffer
when the checkpoint is written. When the process is killed (power cut, OOM killer, SIGKILL), the
checkpoint survives but the last blocks do not, and the next start fails with
"startSequence > last_seq_in_db + 1".

- csdb::Database::flush() (default no-op) and Storage::flush()
- DatabaseBerkeleyDB::flush() writes and syncs the log (DbEnv::log_flush), once per checkpoint
- BlockChain::applyBlockToCaches flushes the storage before it saves a checkpoint

Same change in the community fork: #47.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant