-
Notifications
You must be signed in to change notification settings - Fork 182
fix: eth_getTransactionCount to return the actual count, not parent's
#6103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughUpdates eth_getTransactionCount to derive the state from the requested tipset via an async tipset_state call and then construct the StateTree from that state root. Adjusts StateManager::tipset_state documentation to clarify return values. Adds a changelog entry describing the fix. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Client
participant E as eth_getTransactionCount (RPC)
participant SM as StateManager
participant TS as Tipset
participant ST as StateTree
C->>E: Request tx count (addr, tipset key)
E->>SM: tipset_state(TS) (async)
SM-->>E: (state_root, receipt_root)
E->>ST: construct from state_root
ST-->>E: actor state (nonce)
E-->>C: nonce
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. Comment |
818ce0f to
0f7c715
Compare
eth_getTransactionCount to return the actual count, not parenteth_getTransactionCount to return the actual count, not parent's
There was a problem hiding this 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
🧹 Nitpick comments (3)
src/state_manager/mod.rs (3)
396-406: Doc fix aligns with behavior (on-tipset state, not parent).Nice clarification. Consider explicitly stating “for tipset T (not T’s parent)” to remove any residual ambiguity for new contributors.
1690-1699: Potential type-conversion nit: prefer deref overinto()for&Cid.
state_rootis&Cid(fromparent_state()), butStateOutputValue.state_rootisCid. Usingstate_root.into()relies on aFrom<&Cid> for Cidimpl; elsewhere in this file you use*ts.parent_state()which is clearer and avoids surprising trait requirements.Apply this small tweak for consistency:
- return Some(StateOutputValue { - state_root: state_root.into(), - receipt_root, - }); + return Some(StateOutputValue { + state_root: *state_root, + receipt_root, + });
396-406: Optional: add a convenience helper to reduce repeated patterns.Given more callers (e.g., eth RPC) now need the on-tipset state, a
get_state_tree_for_tipset(&Arc<Tipset>) -> StateTree<DB>helper that internally callstipset_statewould simplify call sites and prevent future regressions toparent_state().
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
CHANGELOG.md(1 hunks)src/rpc/methods/eth.rs(1 hunks)src/state_manager/mod.rs(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: LesnyRumcajs
PR: ChainSafe/forest#5907
File: src/rpc/methods/state.rs:523-570
Timestamp: 2025-08-06T15:44:33.467Z
Learning: LesnyRumcajs prefers to rely on BufWriter's Drop implementation for automatic flushing rather than explicit flush() calls in Forest codebase.
🧬 Code graph analysis (1)
src/rpc/methods/eth.rs (2)
src/tool/subcommands/api_cmd/generate_test_snapshot.rs (1)
ctx(106-159)src/shim/state_tree.rs (1)
new_from_root(168-188)
⏰ 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). (7)
- GitHub Check: Build Ubuntu
- GitHub Check: cargo-publish-dry-run
- GitHub Check: Build MacOS
- GitHub Check: All lint checks
- GitHub Check: Build forest binaries on Linux AMD64
- GitHub Check: tests-release
- GitHub Check: tests
🔇 Additional comments (3)
CHANGELOG.md (1)
44-45: Changelog entry is clear and accurate.Good, succinct description; matches the PR objective (on-tipset nonce vs parent).
src/state_manager/mod.rs (1)
396-406: Verify eth_getTransactionCount uses tipset_state(...) instead of ts.parent_state()Check src/rpc/methods/eth.rs (EthGetTransactionCount impl — ~line 2227) and confirm the RPC builds the StateTree from tipset_state(tipset), not ts.parent_state(). To verify locally, run:
rg -nF 'eth_getTransactionCount' src/rpc/methods/eth.rs
rg -nF 'parent_state(' src/rpc/methods/eth.rs || true
rg -nF 'tipset_state(' src/rpc/methods/eth.rs || truesrc/rpc/methods/eth.rs (1)
2255-2258: LGTM! Correct fix for eth_getTransactionCount implementation.The change correctly implements returning the nonce of the requested tipset instead of its parent. According to Filecoin documentation, "The state looked up is the parent state of the tipset", but for
eth_getTransactionCount, we want the state after the tipset's messages have been executed, which is achieved by callingtipset_stateon the tipset itself and then constructing the StateTree from that result.The async call to
ctx.state_manager.tipset_state(&ts)followed byStateTree::new_from_root(ctx.store_owned(), &state_cid)correctly gets the state after the tipset execution, ensuring the transaction count reflects transactions that have been executed up to and including the requested tipset.
Is this a breaking change? Have you considered adding an |
I could add it, but the problem is that it'd be difficult to re-create if needed. So I decided not to add it at all. In general, such tests would be better suited for running on devnet, but we don't have them (yet). |
Summary of changes
Changes introduced in this pull request:
eth_getTransactionCountto return the nonce of the requested tipset and not its parent. Sadly, no bonus points for tests here.Manually tested this transaction (note the tipset https://beryx.io/fil/calibration/txs/0x7a4de7139c4748e1df0e4aa1c02f28f69d1c3a9f9646678c17979afcaf59d529)
before
after
Reference issue to close (if applicable)
Part of #5979
Other information and links
Change checklist
Summary by CodeRabbit
Bug Fixes
Documentation