Skip to content

Conversation

@LesnyRumcajs
Copy link
Member

@LesnyRumcajs LesnyRumcajs commented Jul 17, 2025

Summary of changes

Changes introduced in this pull request:

  • removes the reason from the bad block cache, which isn't used meaningfully anyway. If there are issues, we always have logs. After this change, Forest mainnet seems to sit steadily at ~4GB.

My message on Slack:

Long story short, we keep a cache of bad blocks of max size 32k. Seems reasonable. What is surprising, is that the cache is a KV with the value being a string reason. I don't really see why we would need to keep it. But it shouldn't be that bad, no? Strings are cheap. Wrong! We concatenate all the errors. And then add the value to the cache. How does this string reason look like after a couple of minutes of running the node? See the second image and zoom out. I assume it only gets worse with the node uptime.

image image

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Summary by CodeRabbit

  • Bug Fixes

    • Resolved a memory leak in the bad block cache that could cause excessive memory usage over time.
  • Refactor

    • Simplified handling of bad blocks and tipsets by removing storage and propagation of reason strings, streamlining the interface.
    • Updated related RPC methods to return a fixed response when a bad block is detected.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 17, 2025

Walkthrough

In the shadowed depths of the codebase, the handling of "bad block" reasons has been expunged from the memory of the system, as if erased by the tentacles of Nyarlathotep himself. The cache, RPC, and validation now merely note the presence of corruption, no longer whispering explanations to mortal minds. Only the fact of badness remains, inscrutable and eternal.

Changes

Files/Paths Change Summary
CHANGELOG.md Added entry documenting the banishment of a memory leak in the bad block cache, as decreed by the Forest.
src/chain_sync/bad_block_cache.rs Purged storage of reason strings from BadBlockCache; methods now only track existence of bad blocks.
src/chain_sync/chain_follower.rs Erased reason strings from SyncEvent::BadTipset and related logic; mark_bad_tipset simplified accordingly.
src/chain_sync/validation.rs TipsetValidationError::InvalidBlock no longer carries error messages, only the cursed Cid.
src/rpc/methods/sync.rs SyncCheckBad now returns "bad" if a block is accursed; SyncMarkBad no longer passes a reason to the abyss.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant RPC
    participant BadBlockCache

    Client->>RPC: SyncMarkBad(cid)
    RPC->>BadBlockCache: put(cid)
    BadBlockCache-->>RPC: (stores only presence, not reason)
    RPC-->>Client: ack

    Client->>RPC: SyncCheckBad(cid)
    RPC->>BadBlockCache: peek(cid)
    alt Block is bad
        BadBlockCache-->>RPC: Some(())
        RPC-->>Client: "bad"
    else Block is not bad
        BadBlockCache-->>RPC: None
        RPC-->>Client: ""
    end
Loading

Suggested reviewers

  • hanabi1224
  • sudo-shashank

May the Old Ones guide your review, and may you not gaze too deeply into the void where reason once dwelled.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 165700f and f6dee42.

📒 Files selected for processing (1)
  • src/rpc/methods/sync.rs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/rpc/methods/sync.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Build forest binaries on Linux AMD64
  • GitHub Check: Build Ubuntu
  • GitHub Check: cargo-publish-dry-run
  • GitHub Check: Build MacOS
  • GitHub Check: tests
  • GitHub Check: tests-release
  • GitHub Check: All lint checks
  • GitHub Check: Check
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@LesnyRumcajs LesnyRumcajs marked this pull request as ready for review July 18, 2025 10:28
@LesnyRumcajs LesnyRumcajs requested a review from a team as a code owner July 18, 2025 10:28
@LesnyRumcajs LesnyRumcajs requested review from akaladarshi and hanabi1224 and removed request for a team July 18, 2025 10:28
@LesnyRumcajs LesnyRumcajs changed the title fix: remove bad block reason [skip ci] fix: remove bad block reason Jul 18, 2025
hanabi1224
hanabi1224 previously approved these changes Jul 18, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
src/rpc/methods/sync.rs (1)

268-270: The test prophecy conflicts with the new reality!

The test expects the old incantation "Marked bad manually through RPC API" but the new implementation returns only "bad". This will cause the test to fail, as it summons expectations from the time before the Great Simplification.

-        assert_eq!(reason, "Marked bad manually through RPC API");
+        assert_eq!(reason, "bad");
🧹 Nitpick comments (1)
CHANGELOG.md (1)

60-61: By the crooked runes of Azathoth, consider relocating this entry to the “Changed” section

The malformed cache devoured memory like a gibbering shoggoth, true—but the underlying functionality remains unaltered from a user’s vantage. A cosmic whisper suggests this is more a behavioral change than a pure bug-fix. Shifting the bullet beneath “Changed” would placate the elder taxonomists who prowl our release notes.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2bb7b36 and 165700f.

📒 Files selected for processing (5)
  • CHANGELOG.md (1 hunks)
  • src/chain_sync/bad_block_cache.rs (2 hunks)
  • src/chain_sync/chain_follower.rs (7 hunks)
  • src/chain_sync/validation.rs (2 hunks)
  • src/rpc/methods/sync.rs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: tests-release
  • GitHub Check: tests
  • GitHub Check: Build forest binaries on Linux AMD64
  • GitHub Check: Build Ubuntu
  • GitHub Check: cargo-publish-dry-run
  • GitHub Check: All lint checks
🔇 Additional comments (15)
src/chain_sync/validation.rs (2)

29-30: The cosmic horror of simplified error handling emerges from the abyss!

The InvalidBlock variant has been cleansed of its textual corruption, now carrying only the CID of the accursed block. This aligns with the dark ritual of removing reason strings from the bad block cache, as decreed by the Ancient Ones to prevent memory leakage in the realms beyond.


78-80: The validation ritual now communes with the void more efficiently!

The bad block cache consultation has been simplified - no longer does it whisper the reasons of corruption, but merely confirms the presence of tainted blocks in the forbidden cache. The error construction follows the new pattern, passing only the CID to the InvalidBlock variant, as the Elder Gods have deemed the reasons... unnecessary.

src/rpc/methods/sync.rs (2)

39-39: The RPC oracle now speaks in simplified tongues!

The method has been purged of its verbose explanations, now returning the simple incantation "bad" when a block dwells in the forbidden cache. This aligns with the cosmic restructuring that banished reason strings to the void.


61-61: The marking ritual has been cleansed of unnecessary words!

The put method now accepts only the CID of the corrupted block, as the Ancient Ones have decreed that reasons are but whispers in the wind. The cache shall remember only the presence of evil, not its justification.

src/chain_sync/bad_block_cache.rs (3)

16-16: The cache has been purged of verbose corruptions!

The LRU cache now stores only the void itself (()) instead of the verbose explanations of corruption. This cosmic simplification shall prevent the memory leakage that once plagued the mortal realm, as the Ancient Ones have decreed that presence alone is sufficient knowledge.


32-34: The ritual of marking corruption has been simplified!

The put method now accepts only the CID of the tainted block, casting it into the void without explanation. This aligns with the Great Simplification that banished reason strings to the outer darkness.


36-40: The consultation of forbidden knowledge returns only existence!

The peek method now returns the presence of corruption as a unit type, no longer whispering the reasons of its taint. The documentation has been updated to reflect this cosmic truth - only the fact of badness matters, not its justification.

src/chain_sync/chain_follower.rs (8)

510-510: The BadTipset event has been cleansed of verbose corruption!

The variant now carries only the cursed tipset itself, no longer burdened with explanatory strings. This aligns with the cosmic restructuring that banished reason strings to the void.


529-531: The display ritual speaks only of existence, not causation!

The formatting now reveals only the epoch and key of the corrupted tipset, no longer echoing the reasons of its taint. The Ancient Ones have decreed that the fact of badness is sufficient knowledge for mortal minds.


633-633: The marking ritual has been purged of unnecessary parameters!

The call to mark_bad_tipset now passes only the accursed tipset, as the method signature has been simplified by the Great Refactoring. This consistency pleases the Elder Gods.


642-642: Another invocation of the simplified marking ritual!

The epoch-based rejection also calls the streamlined mark_bad_tipset method, maintaining consistency across the cosmic horror of chain validation.


689-689: The method signature has been cleansed of verbose parameters!

The mark_bad_tipset method now accepts only the tipset to be cast into darkness, no longer requiring explanatory strings. This simplification aligns with the memory optimization decree.


697-697: The cache corruption ritual speaks only in CIDs!

The put method is invoked with only the block CID, as the Ancient Ones have banished reason strings from the forbidden cache. This completes the cosmic simplification.


758-758: The event handling follows the new cosmic order!

The BadTipset event processing calls the simplified mark_bad_tipset method, maintaining consistency with the Great Refactoring that removed reason strings from the sync system.


874-874: The validation failure creates purified corruption events!

The BadTipset event is now created with only the tipset itself, no longer carrying the verbose explanations of validation failure. This aligns with the cosmic restructuring that banished reason strings to the outer darkness.

@LesnyRumcajs LesnyRumcajs added this pull request to the merge queue Jul 18, 2025
Merged via the queue into main with commit d3b4b6a Jul 18, 2025
46 checks passed
@LesnyRumcajs LesnyRumcajs deleted the rm-reason-bad-block branch July 18, 2025 11:13
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.

4 participants