Skip to content

Allow capping data to N blocks with API retention NET-896#77

Merged
kalabukdima merged 4 commits into
masterfrom
hotblocks-api-head-retention
Jul 17, 2026
Merged

Allow capping data to N blocks with API retention NET-896#77
kalabukdima merged 4 commits into
masterfrom
hotblocks-api-head-retention

Conversation

@kalabukdima

Copy link
Copy Markdown
Contributor

Goal

If the archival data got stuck, the storage grows until running out of disk space leading to unpleasant consequences.

We can't reliably prevent it from happening. But we can sacrifice older blocks to keep serving the real-time data. Much less users will be affected by a gap than by a stale head.

Config changes

# bare — uncapped, exactly as before (backward compatible)
retention_strategy: Api

# nested — with the cap
retention_strategy:
  Api:
    max_blocks: 100000

Add an optional `max_blocks` to the Api config that trims the tail to
keep at most `max_blocks` from the head.
@kalabukdima
kalabukdima requested a review from define-null June 24, 2026 08:56
@mo4islona
mo4islona marked this pull request as ready for review June 24, 2026 10:13
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread crates/hotblocks/src/dataset_config.rs
data_sources: Vec<ReqwestDataClient>,
// Static safety cap on retained blocks for Api-controlled datasets: even
// if the portal stops advancing the floor, the tail is trimmed to keep at
// most this many blocks behind the tip. `None` means grow indefinitely.

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.

I think it would be valuable to mention that it's not a hard limit, but rather soft limit, as it may happen that the first chunk has accumulated a lot of blocks, which would go above the max_blocks limit. And example: max_blocks = 100K, first chunk has [0..150K], when the trigger fires at 250K, we get window 0..250K which is 2.5x times larger than the expected max_blocks limit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Mentioned, but I don't think it's related to this PR directly. The same happens with API retention — once set to block N, it usually keeps a couple of blocks below N.

Comment thread crates/hotblocks/src/dataset_config.rs Outdated

@define-null define-null left a comment

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.

Approving this PR, as max_blocks seems to be a best_effort thing, but in my view it will be hard to reason about with this soft limit approach.

- Document that `max_blocks` is a soft limit
- Extract `trim_floor` and cover the capping rule with tests
- Simplify the comments
@kalabukdima
kalabukdima force-pushed the hotblocks-api-head-retention branch from 9aa609f to 0676fde Compare July 17, 2026 07:55
@kalabukdima
kalabukdima merged commit 1d471b3 into master Jul 17, 2026
3 checks passed
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.

2 participants