Skip to content

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

Open
kalabukdima wants to merge 3 commits into
masterfrom
hotblocks-api-head-retention
Open

Allow capping data to N blocks with API retention NET-896#77
kalabukdima wants to merge 3 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>
}

#[cfg(test)]
mod tests {

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.

All tests could be probably shrink-ed probasbly just to two. What would be more valuable to test is an actual capping behaviour.

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.

Head(u64),
// Retention is set dynamically from the portal
Api,
// Retention is set dynamically from the portal. `max_blocks`, if set, caps

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.

let's ask Claude to trim those verboose comments.

@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.

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