[Bug] Ledger checkpoint can contain a block tree that is ahead of its RocksDB data

Open
#4,607 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
backend, database

Research direction

Read node/rest/src/routes.rs's db_backup handler and node/src/node.rs's automatic checkpoint task, then trace how the ledger backup and block tree cache are written. The issue describes a race between those two steps; inspect the block store locking and checkpoint APIs to determine how to make both snapshots consistent. Done means a checkpoint's tree and RocksDB data describe the same height and the reported restart failure is covered.

Written by the indexing model from the issue text.

Description

bug storage

🐛 Bug Report

A ledger checkpoint can contain a block_tree file that is ahead of its RocksDB data. A node that restarts from this checkpoint fails to load the ledger.

The checkpoint is written in two steps:

  1. ledger.backup_database(path) takes a RocksDB checkpoint.
  2. ledger.cache_block_tree() writes the in-memory block tree. The file is then copied into the checkpoint.

Nothing stops a block from being committed between step 1 and step 2. If a block is committed there, the RocksDB checkpoint ends at height H and the cached tree contains height H + 1.

Affected call sites:

  • node/rest/src/routes.rs, db_backup handler (POST /{network}/db_backup).
  • node/src/node.rs, automatic checkpoint task. Open PR #4583 moves this task to a blocking thread but keeps the two separate steps.

Steps to Reproduce

The devnet CI job (.ci/test_db_backup.sh) hits this as a flake. Example: https://github.com/aleo-labs-protocol/snarkOS/actions/runs/41003086250/job/123892952148 (PR #4606 changes only Cargo.lock).

Timeline for validator-3:

time (s) event
14.569655 db_backup request received. RocksDB checkpoint taken at height 4.
14.569704 atomic speculate (height 5, round 10) starts.
14.587979 Cached the current block tree (tree includes block 5).
14.588518 Advanced to block 5 at round 10.

Validators 0–2 served the request 30–80 ms before block 5 and did not hit the race.

After the rollback, validator-3 restarts from checkpoint_3_0 and exits:

Failed to start node — Failed to initialize the ledger — Failed to load ledger (run 'snarkos clean' and try again)

Block 5 exists in tree but not in storage;perhaps you used a wrong block tree cache file at '.../checkpoint_3_0/block_tree'?

Expected Behavior

The RocksDB checkpoint and its block_tree file describe the same height. A node can always restart from a checkpoint it wrote.

Possible fixes

  • Take the RocksDB checkpoint and the tree snapshot as one consistent step. BlockStore::insert holds the block-tree write lock while it writes storage. If the backup holds the tree lock across both steps, no block can be committed between them. This likely needs a snarkVM API, for example a BlockStore method that does both under one lock.
  • Or take the tree snapshot first, then the RocksDB checkpoint. On load, trim the cached tree down to the stored height instead of failing. This needs a snarkVM change to the load path.

Related: #4227 (same mismatch type, seen after a restart).

Your Environment

  • snarkOS staging at 22c4a97a3 (base of PR #4606).
  • snarkVM rev 9796eb19 (pinned in Cargo.toml).
  • CI: GitHub Actions devnet job.
Dominant language
Rust
Stars
4.5k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ProvableHQ/snarkOS

All issues in ProvableHQ/snarkOS

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.