Skip to content

fix: eth block returns correctly filled logs bloom field#7156

Open
akaladarshi wants to merge 3 commits into
mainfrom
akaladarshi/fix-logs-bloom
Open

fix: eth block returns correctly filled logs bloom field#7156
akaladarshi wants to merge 3 commits into
mainfrom
akaladarshi/fix-logs-bloom

Conversation

@akaladarshi

@akaladarshi akaladarshi commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Summary of changes

Changes introduced in this pull request:

  • While creating the full ethereum block data, the log bloom field is correctly filed as the Ethereum yellow paper suggested.

Reference issue to close (if applicable)

Closes #7151

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.

Outside contributions

  • I have read and agree to the CONTRIBUTING document.
  • I have read and agree to the AI Policy document. I understand that failure to comply with the guidelines will lead to rejection of the pull request.

Summary by CodeRabbit

  • Bug Fixes

    • Updated Ethereum bloom so the block-level bloom is derived from the block’s logs, and receipt bloom accrual now uses the same shared logic as other bloom handling.
  • Refactor

    • Centralized Ethereum bloom accrual and block bloom computation into reusable helpers.
    • Streamlined event collection by delegating per-message event collection to a dedicated helper.
  • Tests

    • Added unit tests for bloom behavior (empty logs, multi-log composition, idempotence).
    • Refreshed API comparison and ETH block snapshot artifacts.
  • Chores

    • Updated changelog entry and API compare filter lists for unsupported methods.

@akaladarshi akaladarshi requested a review from a team as a code owner June 9, 2026 15:54
@akaladarshi akaladarshi requested review from LesnyRumcajs and sudo-shashank and removed request for a team June 9, 2026 15:54
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5f5513e2-d5d7-4ee5-b803-88fcbf4ce806

📥 Commits

Reviewing files that changed from the base of the PR and between 1e9c70e and 96b6e9c.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • scripts/tests/api_compare/filter-list
  • scripts/tests/api_compare/filter-list-gateway
  • src/rpc/methods/eth.rs
  • src/rpc/methods/eth/filter/mod.rs
  • src/tool/subcommands/api_cmd/test_snapshots.txt
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)
✅ Files skipped from review due to trivial changes (2)
  • scripts/tests/api_compare/filter-list
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/rpc/methods/eth/filter/mod.rs
  • src/rpc/methods/eth.rs

Walkthrough

Extracts reusable helpers to accrue Ethereum log address/topics into a Bloom and compute a block's logs_bloom from executed messages; integrates the helpers into block and receipt construction, adds a unit test, and extracts per-message event collection into a dedicated helper. Updates test infrastructure and changelog to reflect the corrected block bloom computation.

Changes

Block Bloom Computation and Event Collection Refactoring

Layer / File(s) Summary
Bloom computation helpers and block integration
src/rpc/methods/eth.rs
Adds accrue_eth_log and compute_block_logs_bloom helpers. Block::from_filecoin_tipset_with_full_tx calls compute_block_logs_bloom with state manager, tipset, and executed messages, then sets the resulting bloom on the Block struct.
Receipt bloom computation refactor
src/rpc/methods/eth.rs
Replaces inlined receipt log bloom accumulation with calls to the shared accrue_eth_log helper in new_eth_tx_receipt.
Bloom behavior validation
src/rpc/methods/eth.rs
Adds test_accrue_eth_log_and_block_bloom_decomposition verifying empty logs produce an all-zero bloom, OR composition across logs, and idempotence when accruing the same log twice.
Event collection refactor
src/rpc/methods/eth/filter/mod.rs
Extracts per-message event collection into collect_events_from_messages helper. EthEventHandler::collect_events now loads the executed tipset and delegates core logic to the helper.
Test infrastructure and filter updates
scripts/tests/api_compare/filter-list-gateway, src/tool/subcommands/api_cmd/test_snapshots.txt
Removes eth_getBlockByHash and eth_getBlockByNumber from gateway unsupported filter lists and updates RPC snapshot filenames to reflect corrected block bloom behavior.
Changelog
CHANGELOG.md
Adds unreleased Fixed entry documenting that block-level bloom is now computed from block logs.

Sequence Diagram

sequenceDiagram
  participant Block as Block::from_filecoin_tipset_with_full_tx
  participant ComputeBloom as compute_block_logs_bloom
  participant EventCollect as collect_events_from_messages
  participant AccrueLog as accrue_eth_log
  participant BloomResult as Block.logs_bloom
  Block->>ComputeBloom: state_manager, tipset, executed_messages
  ComputeBloom->>EventCollect: collect events from executed_messages
  EventCollect->>ComputeBloom: EthLog list
  loop per EthLog
    ComputeBloom->>AccrueLog: provide log.address + log.topics
    AccrueLog->>ComputeBloom: accumulate Bloom bits
  end
  ComputeBloom->>BloomResult: return accumulated logs_bloom
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • ChainSafe/forest#7025: Overlapping changes to receipt log handling and filter/message-CID scoping that determine which logs are included in block bloom computation.
  • ChainSafe/forest#7116: Modifies Block::from_filecoin_tipset_with_full_tx and executed-tipset loading pathways that interact with the block bloom computation changes.
  • ChainSafe/forest#6402: Changes eth_subscribe/newHeads to emit the Ethereum Block produced by Block::from_filecoin_tipset_with_full_tx, directly affected by the corrected logs_bloom value.

Suggested reviewers

  • LesnyRumcajs
  • sudo-shashank
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.36% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately describes the main fix: correctly filling the logs bloom field in Ethereum block responses, which directly addresses the core issue.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from issue #7151: block-level logsBloom is now computed from logs (not hardcoded), blocks with no logs return all-zeros bloom, and per-receipt blooms are correctly OR'd together.
Out of Scope Changes check ✅ Passed All changes are in-scope: bloom computation helpers and tests, refactored event collection for reusability, and test snapshot updates are all necessary for the fix.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch akaladarshi/fix-logs-bloom
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch akaladarshi/fix-logs-bloom

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

@akaladarshi akaladarshi added the RPC requires calibnet RPC checks to run on CI label Jun 9, 2026

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/rpc/methods/eth/filter/mod.rs (1)

392-392: ⚡ Quick win

Add context to the error propagation.

The try_from conversion lacks .context(), which violates the coding guideline to "add context with .context() when errors occur." While unlikely to fail in practice, adding context improves debuggability.

🔧 Suggested fix
-                let event_idx_base = u64::try_from(event_count)?;
+                let event_idx_base = u64::try_from(event_count)
+                    .context("event count exceeds u64::MAX")?;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/rpc/methods/eth/filter/mod.rs` at line 392, The conversion call let
event_idx_base = u64::try_from(event_count)? should propagate a contextual
error; replace the bare ? with a Context-wrapped error (e.g., call .context(...)
before ?). Update the expression referencing u64::try_from(event_count) so
failures include a clear message like "failed to convert event_count to u64"
(affecting the event_idx_base assignment) to satisfy the `.context()` guideline.

Source: Coding guidelines

src/rpc/methods/eth.rs (1)

4562-4600: ⚡ Quick win

Consider adding a test for compute_block_logs_bloom.

The current test validates accrue_eth_log behavior well (empty bloom, single log, OR composition, idempotence). However, there's no unit test for compute_block_logs_bloom itself, which handles event collection and address resolution. An integration test or unit test covering:

  • Blocks with no events → empty bloom
  • Blocks with valid EVM events → correct bloom
  • Blocks with mixed valid/invalid events → partial bloom

would increase confidence in the full bloom computation path.

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/rpc/methods/eth/filter/mod.rs`:
- Around line 358-365: Add a doc comment above the public function
collect_events_from_messages that succinctly describes its purpose (collect
events from executed messages in a tipset), its parameters (state_manager:
&StateManager, tipset: &Tipset, executed_messages: &[ExecutedMessage], spec:
Option<&impl Matcher>, skip_event: SkipEvent, collected_events: &mut
Vec<CollectedEvent>), its behavior (filters/matches events using spec, skips
events per skip_event, appends found CollectedEvent items into
collected_events), and its return value (anyhow::Result<()> indicating success
or error); make sure the doc mentions that collected_events is mutated in-place
and any notable side effects or error conditions the caller should expect.

---

Nitpick comments:
In `@src/rpc/methods/eth/filter/mod.rs`:
- Line 392: The conversion call let event_idx_base = u64::try_from(event_count)?
should propagate a contextual error; replace the bare ? with a Context-wrapped
error (e.g., call .context(...) before ?). Update the expression referencing
u64::try_from(event_count) so failures include a clear message like "failed to
convert event_count to u64" (affecting the event_idx_base assignment) to satisfy
the `.context()` guideline.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 80cc42cd-3208-4465-a098-75793490f3be

📥 Commits

Reviewing files that changed from the base of the PR and between 7bafcfb and 45541b5.

📒 Files selected for processing (2)
  • src/rpc/methods/eth.rs
  • src/rpc/methods/eth/filter/mod.rs

Comment on lines +358 to +365
pub async fn collect_events_from_messages(
state_manager: &StateManager,
tipset: &Tipset,
executed_messages: &[ExecutedMessage],
spec: Option<&impl Matcher>,
skip_event: SkipEvent,
collected_events: &mut Vec<CollectedEvent>,
) -> anyhow::Result<()> {

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.

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Add doc comment for the new public function.

The new collect_events_from_messages function is public but lacks documentation. As per coding guidelines, all public functions should have doc comments explaining their purpose, parameters, and behavior.

📝 Suggested documentation
+    /// Collects events from executed messages for a given tipset.
+    ///
+    /// This is a lower-level helper that operates on already-loaded executed messages,
+    /// enabling reuse from both RPC event collection and block bloom computation.
+    ///
+    /// # Parameters
+    /// - `state_manager`: State manager for address resolution
+    /// - `tipset`: The tipset containing the executed messages
+    /// - `executed_messages`: Pre-loaded executed messages from the tipset
+    /// - `spec`: Optional filter spec to match specific events
+    /// - `skip_event`: Strategy for handling unresolved addresses
+    /// - `collected_events`: Output buffer for matching events
     pub async fn collect_events_from_messages(
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pub async fn collect_events_from_messages(
state_manager: &StateManager,
tipset: &Tipset,
executed_messages: &[ExecutedMessage],
spec: Option<&impl Matcher>,
skip_event: SkipEvent,
collected_events: &mut Vec<CollectedEvent>,
) -> anyhow::Result<()> {
/// Collects events from executed messages for a given tipset.
///
/// This is a lower-level helper that operates on already-loaded executed messages,
/// enabling reuse from both RPC event collection and block bloom computation.
///
/// # Parameters
/// - `state_manager`: State manager for address resolution
/// - `tipset`: The tipset containing the executed messages
/// - `executed_messages`: Pre-loaded executed messages from the tipset
/// - `spec`: Optional filter spec to match specific events
/// - `skip_event`: Strategy for handling unresolved addresses
/// - `collected_events`: Output buffer for matching events
pub async fn collect_events_from_messages(
state_manager: &StateManager,
tipset: &Tipset,
executed_messages: &[ExecutedMessage],
spec: Option<&impl Matcher>,
skip_event: SkipEvent,
collected_events: &mut Vec<CollectedEvent>,
) -> anyhow::Result<()> {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/rpc/methods/eth/filter/mod.rs` around lines 358 - 365, Add a doc comment
above the public function collect_events_from_messages that succinctly describes
its purpose (collect events from executed messages in a tipset), its parameters
(state_manager: &StateManager, tipset: &Tipset, executed_messages:
&[ExecutedMessage], spec: Option<&impl Matcher>, skip_event: SkipEvent,
collected_events: &mut Vec<CollectedEvent>), its behavior (filters/matches
events using spec, skips events per skip_event, appends found CollectedEvent
items into collected_events), and its return value (anyhow::Result<()>
indicating success or error); make sure the doc mentions that collected_events
is mutated in-place and any notable side effects or error conditions the caller
should expect.

Source: Coding guidelines

@akaladarshi akaladarshi marked this pull request as draft June 10, 2026 07:20
@akaladarshi akaladarshi force-pushed the akaladarshi/fix-logs-bloom branch from d2d8078 to b0be642 Compare June 19, 2026 16:41
@akaladarshi akaladarshi force-pushed the akaladarshi/fix-logs-bloom branch from b0be642 to 96b6e9c Compare June 19, 2026 16:54
@akaladarshi akaladarshi marked this pull request as ready for review June 19, 2026 16:54
@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.22222% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.40%. Comparing base (a326b14) to head (96b6e9c).
⚠️ Report is 4 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/rpc/methods/eth.rs 63.76% 25 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/rpc/methods/eth/filter/mod.rs 89.64% <100.00%> (+0.42%) ⬆️
src/rpc/methods/eth.rs 65.63% <63.76%> (+0.81%) ⬆️

... and 13 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a326b14...96b6e9c. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

like lotus we should store the computed logs bloom so we don't re-compute it again and again.

@sudo-shashank

Copy link
Copy Markdown
Contributor

There are few more changes required and needs to be ported from the list of changes filecoin-project/lotus#13618 for both correctness and performance.

- Add a tipset_bloom table to the chain index DB for block-level ETH log blooms.
- Add a migration for existing chain index DBs.
- Compute and store tipset-level blooms while indexing actor events.
- Store empty blooms for indexed tipsets with no events.
- Rebuild/store blooms when previously reverted events are unreverted.
- Delete bloom rows on revert.
- Delete old bloom rows during chain index GC.
- Expose GetTipsetBloom on the chain indexer.
- Use indexed blooms when constructing ETH block responses for:
- eth_getBlockByHash
- eth_getBlockByNumber
- new-head subscription block payloads
- Preserve compatibility by falling back to the previous full bloom when no indexed bloom is available.
- Extend TestTxReceiptBloom to cover receipt bloom, empty block bloom, block-by-hash bloom, and block-by-number bloom.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RPC requires calibnet RPC checks to run on CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

eth: eth_getBlockBy* / newHeads return an all-ones logsBloom

2 participants