Skip to content

fix(blocks): clamp tail chunk to reorg buffer max instead of dropping it#255

Open
AuburyEssentian wants to merge 1 commit intoparadigmxyz:mainfrom
AuburyEssentian:fix/reorg-buffer-tail-clip
Open

fix(blocks): clamp tail chunk to reorg buffer max instead of dropping it#255
AuburyEssentian wants to merge 1 commit intoparadigmxyz:mainfrom
AuburyEssentian:fix/reorg-buffer-tail-clip

Conversation

@AuburyEssentian
Copy link
Copy Markdown

Problem

Fixes #193.

When --reorg-buffer N is set, apply_reorg_buffer used filter_map to drop any chunk whose max_value() exceeded latest_block - N. This silently discarded the partial tail chunk — e.g. if the last full chunk boundary was block 20,029,999 but the reorg-safe ceiling was 20,030,779, the 780-block tail chunk Range(20030000, 20030787) was dropped entirely rather than trimmed to Range(20030000, 20030779).

The result: cryo with --reorg-buffer always rounds the max collected block down to the last full chunk boundary, losing up to chunk_size - 1 blocks.

Fix

Replace the filter_map predicate with a clamp_chunk_to_max helper that:

  • For Range(start, end) chunks: returns Some(Range(start, end.min(max_allowed))) if start <= max_allowed, else None.
  • For Numbers(ns) chunks: filters out block numbers > max_allowed, returning None only if the entire list is beyond the buffer.

This preserves every safe block in the tail chunk rather than discarding it.

Before / After

# Before (reorg-buffer 8, latest = 20030787)
blocks: n=30,000 min=20,000,000 max=20,029,999  ← tail chunk silently dropped

# After
blocks: n=30,779 min=20,000,000 max=20,030,779  ← tail chunk clamped correctly

When --reorg-buffer N is set, apply_reorg_buffer previously filtered out
any chunk whose max block exceeded latest_block - N. This silently dropped
the partial tail chunk (e.g. blocks 20030000-20030787 when only up to
20029999 is safe), causing cryo to never collect those trailing blocks.

Fix: replace the filter_map that drops whole chunks with clamp_chunk_to_max,
which truncates Range chunks to max_allowed and filters Numbers vectors,
preserving all safe blocks within a chunk.

Fixes paradigmxyz#193
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.

Setting re-org buffer clamps the max block to the last full chunk boundary

1 participant