Skip to content

feat: better block cache for block bodies#1145

Merged
antouhou merged 4 commits into
masterfrom
feat-block-cache
Feb 16, 2026
Merged

feat: better block cache for block bodies#1145
antouhou merged 4 commits into
masterfrom
feat-block-cache

Conversation

@antouhou

@antouhou antouhou commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

Describe the changes
This PR improves the block body pipeline to use stored block bodies instead of assembling them as much as possible

Related Issue(s)

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

Summary by CodeRabbit

  • New Features
    • Added read access to full sealed blocks for faster retrieval when available.
  • Refactor
    • Introduced a small "recently processed" cache to retain successfully processed blocks for quick reuse.
    • Block lookup now checks cache and stored sealed blocks before attempting expensive reconstruction, improving efficiency and reducing work.
  • Tests
    • Updated tests to verify recently processed behavior and correct handling of failed vs successful blocks.

@coderabbitai

coderabbitai Bot commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Adds a sealed-block accessor to BlockTree, introduces a small recently-processed SealedBlock LRU cache in the block pool and updates removal semantics to record successful processing, and changes gossip data retrieval to check block pool → block tree → mempool reconstruction when assembling block bodies.

Changes

Cohort / File(s) Summary
BlockTree API Extension
crates/domain/src/models/block_tree.rs
Added pub fn get_sealed_block(&self, block_hash: &BlockHash) -> Option<Arc<SealedBlock>> to return a full sealed block by hash.
Block Pool Caching & Removal Flow
crates/p2p/src/block_pool.rs
Added RECENTLY_PROCESSED_CACHE_SIZE and recently_processed: LruCache<BlockHash, Arc<SealedBlock>>; changed remove_block signatures to accept BlockRemovalReason and store successfully processed blocks into the new cache; added get_recently_processed() accessors; updated tests to reflect new behavior.
Gossip Data Retrieval
crates/p2p/src/gossip_data_handler.rs
get_block_body signature updated to accept &BlockTreeReadGuard; lookup sequence reworked to check block pool cache, then BlockTree::get_sealed_block, and only then attempt expensive reconstruction via mempool; call sites updated accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant Peer as Peer/Requestor
    participant Gossip as GossipHandler
    participant Pool as BlockPool
    participant Tree as BlockTree
    participant Mempool as Mempool

    Peer->>Gossip: GET_DATA(block_hash)
    Gossip->>Pool: get_cached_block_body(block_hash)
    alt found in recently_processed / pool cache
        Pool-->>Gossip: Arc<BlockBody>
        Gossip-->>Peer: block body
    else not in pool
        Gossip->>Tree: get_sealed_block(block_hash)
        alt found in BlockTree
            Tree-->>Gossip: Arc<SealedBlock> (body)
            Gossip-->>Peer: block body
        else not in BlockTree
            Gossip->>Mempool: reconstruct body from header / mempool DB
            alt reconstruction success
                Mempool-->>Gossip: Arc<BlockBody>
                Gossip-->>Peer: block body
            else failure
                Mempool-->>Gossip: None / error
                Gossip-->>Peer: None / error
            end
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • DanMacDonald
  • glottologist
  • JesseTheRobot
🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 52.17% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: better block cache for block bodies' accurately summarizes the main change: adding improved caching mechanisms for block bodies across multiple files.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into master

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-block-cache

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

# Conflicts:
#	crates/p2p/src/block_pool.rs

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

lgtm

@antouhou antouhou merged commit 86739c1 into master Feb 16, 2026
25 of 26 checks passed
@antouhou antouhou deleted the feat-block-cache branch February 16, 2026 18:40
@coderabbitai coderabbitai Bot mentioned this pull request May 13, 2026
3 tasks
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