Skip to content

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

Draft
akaladarshi wants to merge 2 commits into
mainfrom
akaladarshi/fix-logs-bloom
Draft

fix: eth block returns correctly filled logs bloom field#7156
akaladarshi wants to merge 2 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

  • Refactor

    • Improved Ethereum bloom computation by centralizing bloom accrual and delegating event collection to dedicated helpers, reducing duplication and improving organization.
  • Tests

    • Added unit tests covering bloom behavior, including empty-logs, multi-log bitwise composition, and idempotence.
  • Chores

    • Updated changelog to note that block-level bloom is now computed from block logs.

@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: ff6f65f1-d858-400b-9bbf-c6c9bb84d1bf

📥 Commits

Reviewing files that changed from the base of the PR and between 45541b5 and 1e9c70e.

📒 Files selected for processing (1)
  • CHANGELOG.md
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md

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.

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, and calls the new helper from Block::from_filecoin_tipset_with_full_tx to set logs_bloom.
Receipt bloom computation refactor
src/rpc/methods/eth.rs
Replaces the 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.
Event collection refactor
src/rpc/methods/eth/filter/mod.rs
Extracts per-message collection into collect_events_from_messages; EthEventHandler::collect_events now loads ExecutedTipset and delegates to the helper.
Changelog
CHANGELOG.md
Adds an unreleased Fixed entry noting block-level bloom is 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) | ⏱️ ~20 minutes

Possibly related PRs

  • ChainSafe/forest#7025: Overlapping changes to receipt log handling and filter/message-CID scoping.
  • ChainSafe/forest#7116: Modifies Block::from_filecoin_tipset_with_full_tx and executed-tipset loading—overlaps with block bloom computation changes.
  • ChainSafe/forest#7062: Related edits to block-construction path and logs_bloom/receipt bloom handling.

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 accurately describes the main change: fixing the eth block's logs bloom field to be correctly computed instead of hardcoded to all-ones.
Linked Issues check ✅ Passed The pull request fully addresses issue #7151 by implementing bloom computation from receipts/logs, handling both empty and non-empty log cases, and ensuring block-level bloom is derived from transaction receipts.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the logs bloom computation issue; refactors in eth.rs and filter/mod.rs support the bloom fix, and CHANGELOG.md documents the fix appropriately.

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

✨ Finishing Touches
🧪 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

Warning

Review ran into problems

🔥 Problems

Linked repositories: Couldn't analyze filecoin-project/lotus - clone failed: Clone operation failed: Cloning into '/home/jailuser/git'...
warning: templates not found in /usr/share/git-core/templates
fatal: unable to access 'https://github.com/filecoin-project/lotus.git/': Failed to connect to github.com port 443 after 133888 ms: Couldn't connect to server


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

1 participant