Skip to content

feat: sparse block header storage for wallet scanner#7744

Open
0xPepeSilvia wants to merge 1 commit intotari-project:developmentfrom
0xPepeSilvia:feat/sparse-block-header-storage-7738
Open

feat: sparse block header storage for wallet scanner#7744
0xPepeSilvia wants to merge 1 commit intotari-project:developmentfrom
0xPepeSilvia:feat/sparse-block-header-storage-7738

Conversation

@0xPepeSilvia
Copy link
Copy Markdown

Summary

  • Replace the fixed 720-block scanned header cache with a sparse storage schedule that retains checkpoint headers much further back in the chain
  • Schedule: all blocks within 720 of tip, every 100th from 720-10k, every 1000th from 10k-100k, every 5000th before 100k
  • Blocks with recovered outputs are always preserved regardless of depth
  • Reduces the chance of having to rescan from wallet birthday after deep reorgs

Closes #7738

Test plan

  • Wallet scanning completes successfully and stores headers per the sparse schedule
  • After scanning past 720 blocks, older checkpoint headers are retained at the correct intervals
  • Blocks containing recovered outputs are never pruned
  • Wallet can determine scan start point using sparse checkpoints after reorg

🤖 Generated with Claude Code

Replace the fixed 720-block cache with a sparse storage schedule that
keeps progressively fewer block headers as they age. This reduces the
chance of having to rescan from the wallet birthday after a reorg,
since the wallet now retains checkpoint headers much further back.

Sparse schedule:
- tip - 720 to tip: all blocks (unchanged)
- tip - 10,000 to tip - 720: every 100th block
- tip - 100,000 to tip - 10,000: every 1,000th block
- genesis to tip - 100,000: every 5,000th block

Blocks containing recovered outputs are always preserved regardless
of the schedule.

Closes tari-project#7738

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@0xPepeSilvia 0xPepeSilvia requested a review from a team as a code owner April 9, 2026 21:38
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements a sparse storage schedule for scanned blocks in the wallet database, replacing the previous simple pruning mechanism. The new logic preserves all blocks within the last 720 heights and maintains progressively sparser checkpoints for older blocks. A significant issue was identified where the mechanism to protect blocks with recovered outputs from pruning is currently non-functional, as the 'num_outputs' field is not yet populated or tracked in the underlying data structures.

Comment on lines +121 to +125
if let Some(outputs) = block.num_outputs {
if outputs > 0 {
continue;
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The logic to preserve blocks with recovered outputs (num_outputs > 0) is currently non-functional because the num_outputs field is never populated. The ScannedBlock domain model (defined in service.rs) does not include this field, and the From<ScannedBlock> for ScannedBlockSql implementation explicitly sets it to None. Consequently, all blocks will be pruned according to the sparse schedule regardless of whether they contain recovered outputs, which contradicts the PR description. The ScannedBlock struct and the scanner task need to be updated to track and store the number of recovered outputs per block.

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.

Let the wallet save more scanned block headers by spare headers beyond a day

1 participant