Skip to content

fix: internal trace calls should not compete the semaphore - #7421

Merged
hanabi1224 merged 2 commits into
mainfrom
hm/fix-cache-prefilling-stuckness
Jul 29, 2026
Merged

fix: internal trace calls should not compete the semaphore#7421
hanabi1224 merged 2 commits into
mainfrom
hm/fix-cache-prefilling-stuckness

Conversation

@hanabi1224

@hanabi1224 hanabi1224 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary of changes

Bug fix: eth_trace_block acquires a semaphore and can block the cache prefilling. Internal calls in cache prefilling should not compete the semaphore to avoid stuckness / deadlock

Changes introduced in this pull request:

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.

Outside contributions

  • This pull request is based on an issue that a maintainer has accepted (see Before Opening a Pull Request).
  • 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

  • Performance Improvements
    • Improved tracing RPC cache warmup for validated tipsets, using block tracing again while skipping superseded states.
  • New Features
    • Added call-source context for tracing and state replay, distinguishing internal vs external requests.
  • Behavior Improvements
    • Tracing and replay now route through the appropriate execution path based on call source.
    • Trace warmup is more selective and concurrency behavior is adjusted to reduce contention.
  • Tests
    • Updated replay-related tests to include explicit call-source context.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: 1c61fd75-5e6f-42b2-9c49-22b2cb254ef0

📥 Commits

Reviewing files that changed from the base of the PR and between 6485814 and dbbf184.

📒 Files selected for processing (1)
  • src/state_manager/tests.rs
🔗 Linked repositories identified

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

  • filecoin-project/lotus (manual)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/state_manager/tests.rs

Walkthrough

Execution tracing now carries a CallSource distinguishing internal cache warmup from external RPC requests. External paths retain replay semaphore acquisition, while daemon warmup skips superseded tipsets and invokes tracing asynchronously without acquiring that semaphore.

Changes

Source-aware execution tracing

Layer / File(s) Summary
Call source contract and state propagation
src/rpc/methods/eth/types.rs, src/state_manager/execution.rs, src/rpc/methods/state.rs, src/state_manager/tests.rs, src/state_manager/utils.rs
Adds CallSource::Internal and CallSource::External, passes source context through state replay, and updates replay tests for both source variants.
RPC trace source propagation
src/rpc/methods/eth.rs
Updates block, transaction, replay-block, and debug tracing paths to pass CallSource::External through trace execution.
Source-aware replay concurrency
src/state_manager/execution.rs
Execution trace workers acquire the replay semaphore for external calls and skip it for internal calls during cache population.
Internal daemon cache warmup
src/daemon/mod.rs
Validated-tipset warmup skips superseded tipsets, passes cancellation to asynchronous tracing, and invokes eth_trace_block with CallSource::Internal, retaining warning logs on failure.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested reviewers: eclesiomelojunior

Sequence Diagram(s)

sequenceDiagram
  participant Daemon
  participant eth_trace_block
  participant StateManager
  participant ReplaySemaphore
  Daemon->>eth_trace_block: warm current tipset with CallSource::Internal
  eth_trace_block->>StateManager: execution_trace(tipset, Internal)
  StateManager->>StateManager: populate execution trace cache
  StateManager-->>eth_trace_block: trace results
  eth_trace_block-->>Daemon: cache warmup result
  Note over StateManager,ReplaySemaphore: Internal tracing skips replay semaphore acquisition
Loading
sequenceDiagram
  participant ExternalRPC
  participant eth_trace_block
  participant StateManager
  participant ReplaySemaphore
  ExternalRPC->>eth_trace_block: request trace with CallSource::External
  eth_trace_block->>StateManager: execution_trace(tipset, External)
  StateManager->>ReplaySemaphore: acquire replay permit
  ReplaySemaphore-->>StateManager: permit granted
  StateManager-->>eth_trace_block: trace results
  eth_trace_block-->>ExternalRPC: RPC response
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: internal trace calls no longer contend for the semaphore during cache prefilling.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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 hm/fix-cache-prefilling-stuckness
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch hm/fix-cache-prefilling-stuckness

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

@hanabi1224
hanabi1224 marked this pull request as ready for review July 29, 2026 11:33
@hanabi1224
hanabi1224 requested a review from a team as a code owner July 29, 2026 11:33
@hanabi1224
hanabi1224 requested review from EclesioMeloJunior and akaladarshi and removed request for a team July 29, 2026 11:33
akaladarshi
akaladarshi previously approved these changes Jul 29, 2026
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.79365% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.33%. Comparing base (c6e0744) to head (dbbf184).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/daemon/mod.rs 0.00% 23 Missing ⚠️
src/rpc/methods/eth.rs 50.00% 3 Missing and 3 partials ⚠️
src/rpc/methods/state.rs 75.00% 0 Missing and 1 partial ⚠️
src/state_manager/execution.rs 93.75% 1 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/rpc/methods/eth/types.rs 65.32% <ø> (+0.40%) ⬆️
src/state_manager/utils.rs 81.06% <100.00%> (+0.25%) ⬆️
src/rpc/methods/state.rs 44.15% <75.00%> (+0.08%) ⬆️
src/state_manager/execution.rs 37.76% <93.75%> (+3.67%) ⬆️
src/rpc/methods/eth.rs 68.43% <50.00%> (-0.02%) ⬇️
src/daemon/mod.rs 24.28% <0.00%> (-0.68%) ⬇️

... and 7 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 c6e0744...dbbf184. 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.

@hanabi1224
hanabi1224 enabled auto-merge July 29, 2026 11:55
@hanabi1224
hanabi1224 added this pull request to the merge queue Jul 29, 2026
@hanabi1224
hanabi1224 removed this pull request from the merge queue due to a manual request Jul 29, 2026
@hanabi1224
hanabi1224 force-pushed the hm/fix-cache-prefilling-stuckness branch from 4535dcc to d09f192 Compare July 29, 2026 12:30
@hanabi1224 hanabi1224 changed the title fix: disable cache prefilling for trace to avoid being blocked by semaphore fix: internal trace calls should not compete the semaphore Jul 29, 2026
@hanabi1224 hanabi1224 added the RPC requires calibnet RPC checks to run on CI label Jul 29, 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: 2

🧹 Nitpick comments (1)
src/state_manager/execution.rs (1)

25-33: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the CallSource scheduling contract.

Explain that Internal bypasses replay-permit acquisition while External is throttled; execution_trace currently has no public API documentation. As per coding guidelines, document public functions and structs with doc comments.

Also applies to: 208-222

🤖 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/state_manager/execution.rs` around lines 25 - 33, Document the public
replay function and the execution_trace API with Rust doc comments, explicitly
describing that CallSource::Internal bypasses replay-permit acquisition while
CallSource::External is throttled. Cover the same scheduling contract wherever
execution_trace is publicly exposed, including the referenced additional
section, without changing behavior.

Source: Coding guidelines

🤖 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/daemon/mod.rs`:
- Around line 453-463: Bound cache-prefill execution separately from RPC replay
concurrency: add a dedicated semaphore or queue for the detached prefill tasks
created in the validated-tipset path, and acquire it before invoking the
internal eth_trace_block warmup shown here. Keep CallSource::Internal and the
RPC replay semaphore bypass unchanged, release the permit after completion, and
ensure task creation cannot allow unbounded concurrent replays.

In `@src/state_manager/execution.rs`:
- Around line 213-219: Make in-flight trace-cache admission source-aware so
CallSource-dependent replay-permit behavior is deterministic: update the
trace-cache flow around execution_trace_inner in
src/state_manager/execution.rs:213-219 to avoid coalescing incompatible sources
while preserving sharing of completed results. Apply the same source-scoped or
decoupled in-flight policy to the block-trace cache in
src/rpc/methods/eth.rs:3618-3637, ensuring warmup and external RPC requests
cannot join futures with the other source’s admission contract.

---

Nitpick comments:
In `@src/state_manager/execution.rs`:
- Around line 25-33: Document the public replay function and the execution_trace
API with Rust doc comments, explicitly describing that CallSource::Internal
bypasses replay-permit acquisition while CallSource::External is throttled.
Cover the same scheduling contract wherever execution_trace is publicly exposed,
including the referenced additional section, without changing behavior.
🪄 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: a2511d45-cb46-4ec5-af08-d03581a483ed

📥 Commits

Reviewing files that changed from the base of the PR and between 4535dcc and d09f192.

📒 Files selected for processing (5)
  • src/daemon/mod.rs
  • src/rpc/methods/eth.rs
  • src/rpc/methods/eth/types.rs
  • src/rpc/methods/state.rs
  • src/state_manager/execution.rs
🔗 Linked repositories identified

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

  • filecoin-project/lotus (manual)

Comment thread src/daemon/mod.rs Outdated
Comment thread src/state_manager/execution.rs
@hanabi1224
hanabi1224 force-pushed the hm/fix-cache-prefilling-stuckness branch from d09f192 to 919d04e Compare July 29, 2026 12:55
@hanabi1224
hanabi1224 requested a review from akaladarshi July 29, 2026 12:57
@hanabi1224
hanabi1224 force-pushed the hm/fix-cache-prefilling-stuckness branch from 919d04e to ef094e3 Compare July 29, 2026 13:08
Comment thread src/daemon/mod.rs
@hanabi1224
hanabi1224 force-pushed the hm/fix-cache-prefilling-stuckness branch from ef094e3 to 6485814 Compare July 29, 2026 13:33
Comment thread src/state_manager/tests.rs Outdated
@hanabi1224
hanabi1224 enabled auto-merge July 29, 2026 14:18
@hanabi1224
hanabi1224 added this pull request to the merge queue Jul 29, 2026
Merged via the queue into main with commit 01d569a Jul 29, 2026
34 checks passed
@hanabi1224
hanabi1224 deleted the hm/fix-cache-prefilling-stuckness branch July 29, 2026 14:38
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.

2 participants