Skip to content

fix: forge script bug#6541

Merged
LesnyRumcajs merged 8 commits intomainfrom
akaladarshi/fix-forge-bug
Feb 6, 2026
Merged

fix: forge script bug#6541
LesnyRumcajs merged 8 commits intomainfrom
akaladarshi/fix-forge-bug

Conversation

@akaladarshi
Copy link
Collaborator

@akaladarshi akaladarshi commented Feb 5, 2026

Summary of changes

Changes introduced in this pull request:

  • The EVM returns the 0 value instead of error for couple of the API's if the actor/address is not found in the state tree (This behaviour was missing in forest), forge internally uses these API to create proper transactions.

    • EthGetBalance
    • EthGetCode
    • EthGetStorageAt
    • EthTransactionCount
  • Refactored some of the ETH API's to use the StateManger instead of directly accessing the state tree, so we have single point of contact with the state tree in the API's at least. This will help us in future to make the stateManager as trait with public facing API's.

Reference issue to close (if applicable)

Closes #6525

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

  • Improvements

    • Ethereum RPC methods now use a centralized state lookup for more consistent queries.
    • Balance queries converted to asynchronous calls for more reliable RPC responses.
  • Bug Fixes

    • RPC methods now return standard defaults for non-existent addresses (zero balance, zero nonce, empty code), preventing "actor not found" errors.
  • Tests

    • Expanded randomized-address tests and added snapshot variants for balance, code, storage, and transaction-count cases.

@akaladarshi akaladarshi added the RPC requires calibnet RPC checks to run on CI label Feb 5, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

Walkthrough

Refactors eth RPC state access to use a centralized state manager, converts eth_get_balance to async (and await call sites), updates actor lookup/error handling, and adds randomized eth address tests plus expanded RPC snapshot variants.

Changes

Cohort / File(s) Summary
Core RPC state & balance changes
src/rpc/methods/eth.rs
Replaced StateTree::new_from_root(...) calls with ctx.state_manager.get_state_tree(...) ? across multiple handlers; switched eth_get_balance to async and updated all call sites to .await; adjusted actor lookup and missing-actor handling.
Tests — randomized addresses & snapshots
src/tool/subcommands/api_cmd/api_compare_tests.rs, src/tool/subcommands/api_cmd/test_snapshots.txt
Added generate_eth_random_address() (libsecp256k1) and new randomized test cases; expanded snapshot entries into multiple v1/v2 and unknown-address variants.
Docs / Changelog
CHANGELOG.md
Added entry noting default behavior for non-existent addresses in eth_getBalance, eth_getTransactionCount, and eth_getCode (return defaults instead of actor-not-found errors).

Sequence Diagram(s)

sequenceDiagram
    participant RPC as RPC Handler
    participant SM as State Manager
    participant BS as Blockstore
    participant ST as StateTree

    rect rgba(220,53,69,0.5)
    Note over RPC,BS: Old flow — direct reconstruction
    RPC->>BS: StateTree::new_from_root(store, root_cid)
    BS-->>ST: reconstruct state tree
    ST-->>RPC: StateTree
    RPC->>ST: get_actor(address)
    end

    rect rgba(40,167,69,0.5)
    Note over RPC,SM: New flow — manager-mediated + async balance
    RPC->>SM: get_state_tree(root_cid)?
    SM->>BS: resolve/access state CID
    SM-->>RPC: StateTree
    RPC->>ST: get_actor(address)
    RPC->>RPC: call async eth_get_balance(...).await
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • hanabi1224
  • sudo-shashank
🚥 Pre-merge checks | ✅ 2 | ❌ 3
❌ Failed checks (1 warning, 2 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 35.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The PR title 'fix: forge script bug' is vague and generic—it uses non-descriptive terms without conveying the meaningful nature of the changes (fixing actor-not-found errors in ETH RPC methods). Clarify the title to describe the specific fix, e.g., 'fix: return default values for non-existent actors in ETH RPC methods' or 'fix: handle missing actors gracefully in eth_getBalance/Code/StorageAt/TransactionCount'.
Out of Scope Changes check ❓ Inconclusive The refactoring to use StateManager instead of direct StateTree construction is a reasonable technical improvement enabling future API enhancements, though not strictly required by the linked issue—it constitutes scope creep but is justifiable. Consider documenting why the StateManager refactoring was included beyond the linked issue requirements, or defer it to a separate PR to keep changes focused on the forge script fix.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR successfully addresses all linked issue #6525 objectives: ETH RPC methods (eth_getBalance, eth_getCode, eth_getStorageAt, eth_getTransactionCount) now return default values for non-existent addresses instead of errors, aligning with EVM semantics to fix forge script failures.

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

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch akaladarshi/fix-forge-bug

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

@akaladarshi akaladarshi marked this pull request as ready for review February 5, 2026 11:56
@akaladarshi akaladarshi requested a review from a team as a code owner February 5, 2026 11:56
@akaladarshi akaladarshi requested review from LesnyRumcajs and hanabi1224 and removed request for a team February 5, 2026 11:56
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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/tool/subcommands/api_cmd/test_snapshots.txt (1)

61-111: ⚠️ Potential issue | 🟠 Major

Fix list ordering to satisfy lint:lists.

The pipeline reports a sorting diff for this file, so the new snapshot entries appear out of order. Please re-run the list-sorting task (or apply the repo’s list-sort convention) and commit the sorted result to clear lint:lists.

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

589-590: Add error context to new state-tree lookups.

These new get_state_tree calls are a good place to attach context so failures are easier to diagnose in logs.

Suggested change (example)
-    let state_tree = ctx.state_manager.get_state_tree(&state_root)?;
+    let state_tree = ctx
+        .state_manager
+        .get_state_tree(&state_root)
+        .context("failed to load state tree for executed tipset")?;

As per coding guidelines: Use anyhow::Result<T> for most operations and add context with .context() method.

Also applies to: 1448-1449, 1703-1704, 2879-2880, 2914-2915, 3896-3897, 4050-4051

@codecov
Copy link

codecov bot commented Feb 5, 2026

Codecov Report

❌ Patch coverage is 45.16129% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.36%. Comparing base (a25c85a) to head (9036fe9).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/rpc/methods/eth.rs 45.16% 0 Missing and 17 partials ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/rpc/methods/eth.rs 69.89% <45.16%> (+0.34%) ⬆️

... and 6 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@LesnyRumcajs LesnyRumcajs left a comment

Choose a reason for hiding this comment

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

Let's have a changelog entry for this fix.

@LesnyRumcajs
Copy link
Member

Blocked by #6547. Once it's merged, please rebase.

@LesnyRumcajs LesnyRumcajs added this pull request to the merge queue Feb 6, 2026
Merged via the queue into main with commit b4f44a5 Feb 6, 2026
44 checks passed
@LesnyRumcajs LesnyRumcajs deleted the akaladarshi/fix-forge-bug branch February 6, 2026 09:16
@coderabbitai coderabbitai bot mentioned this pull request Feb 19, 2026
4 tasks
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.

Forest fails with actor not found errors on forge scripts

2 participants