Skip to content

fix(mempool): add priority based eviction for pending chunk cache#1038

Merged
glottologist merged 2 commits into
masterfrom
jason/pending_chunk_cache
Dec 3, 2025
Merged

fix(mempool): add priority based eviction for pending chunk cache#1038
glottologist merged 2 commits into
masterfrom
jason/pending_chunk_cache

Conversation

@glottologist

Copy link
Copy Markdown
Contributor

Describe the changes
Before:
Pending chunks cache used LRU eviction, allowing attackers to flood the cache with single-chunk entries and evict legitimate multi-chunk uploads.

After:
Cache evicts entries with the fewest chunks first, protecting multi-chunk uploads from single-chunk flooding attacks.

Changes

New Module: pending_chunks.rs

  • Added PriorityPendingChunks struct with priority-based eviction
  • Eviction selects the entry with the minimum chunk count instead of LRU
  • Maintains per-entry LRU cache for individual chunks within each data_root

mempool_service.rs

  • Replaced LruCache<DataRoot, LruCache<...>> with PriorityPendingChunks
  • Simplified put_chunk() method signature (removed preheader_chunks_per_item parameter)
  • Updated create_state() and test mock to use new type

chunks.rs

  • Updated put_chunk() call site

Related Issue(s)
Please link to the issue(s) that will be closed with this PR.

Checklist

  • Tests have been added/updated for the changes.
  • Documentation has been updated for the changes (if applicable).
  • The code follows Rust's style guidelines.

Additional Context
Add any other context about the pull request here.

@glottologist glottologist marked this pull request as ready for review December 1, 2025 09:09
let tx_offset = chunk.tx_offset;

if let Some(chunks) = self.entries.get_mut(&data_root) {
chunks.put(tx_offset, chunk);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we add logging for evictions here?

@JesseTheRobot JesseTheRobot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, feedback is nonblocking

@glottologist glottologist merged commit cf68563 into master Dec 3, 2025
17 checks passed
@glottologist glottologist deleted the jason/pending_chunk_cache branch December 3, 2025 08:46
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