Skip to content

feat(rpc): internal method Forest.BaseFeeByHeight for troubleshooting#7103

Merged
hanabi1224 merged 1 commit into
mainfrom
hm/BaseFeeByHeight
May 25, 2026
Merged

feat(rpc): internal method Forest.BaseFeeByHeight for troubleshooting#7103
hanabi1224 merged 1 commit into
mainfrom
hm/BaseFeeByHeight

Conversation

@hanabi1224
Copy link
Copy Markdown
Contributor

@hanabi1224 hanabi1224 commented May 25, 2026

Summary of changes

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

  • 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

  • New Features

    • Added a new RPC, Forest.BaseFeeByHeight — fetch the upcoming base fee for a given chain height; resolves missing tipsets as needed.
  • Refactor

    • Centralized base-fee computation into a shared helper and updated existing RPCs to use it, reducing duplication and improving consistency and error reporting.

Review Change Stack

@hanabi1224 hanabi1224 added the RPC requires calibnet RPC checks to run on CI label May 25, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 25, 2026

Walkthrough

Extracts EthBaseFee::get_base_fee used by Filecoin.EthBaseFee and adds Forest.BaseFeeByHeight RPC that resolves a tipset at a given epoch and returns its upcoming base fee; registers the new RPC and updates ignored API snapshots.

Changes

Base-fee RPC refactoring and new height-indexed method

Layer / File(s) Summary
Base-fee helper extraction
src/rpc/methods/eth.rs
New internal EthBaseFee::get_base_fee(ctx, ts) reads Smoke and FireHorse epochs from chain config, delegates to compute_base_fee for the tipset, and adds contextual error messages.
RPC handler and new method implementation
src/rpc/methods/eth.rs, src/rpc/mod.rs, src/tool/subcommands/api_cmd/test_snapshots_ignored.txt
Filecoin.EthBaseFee now calls get_base_fee for the current heaviest tipset; new Forest.BaseFeeByHeight RPC accepts a ChainEpoch, resolves the tipset at that height (ResolveNullTipset::TakeOlder), returns the upcoming base fee via get_base_fee; BaseFeeByHeight registered in for_each_rpc_method!; API snapshot ignore list updated.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • ChainSafe/forest#7056: Updates RPC API comparison tests and snapshots for Filecoin.EthBaseFee, which exercise the refactored handler.
  • ChainSafe/forest#7028: Prior Filecoin.EthBaseFee implementation work that this refactor builds on.
  • ChainSafe/forest#6702: Changes related to adding a height parameter to compute_base_fee for FIP-0115 support referenced by this PR.

Suggested reviewers

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

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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: adding a new internal RPC method Forest.BaseFeeByHeight for troubleshooting purposes, which aligns with the changeset's primary objective.
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.

✏️ 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 hm/BaseFeeByHeight
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch hm/BaseFeeByHeight

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

@hanabi1224 hanabi1224 marked this pull request as ready for review May 25, 2026 13:20
@hanabi1224 hanabi1224 requested a review from a team as a code owner May 25, 2026 13:20
@hanabi1224 hanabi1224 requested review from LesnyRumcajs and akaladarshi and removed request for a team May 25, 2026 13:20
Copy link
Copy Markdown
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.

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

896-900: ⚡ Quick win

Add context to tipset lookup failures.

load_required_tipset_by_height currently bubbles raw errors; adding context here will make RPC troubleshooting much easier for bad/unsupported heights.

Suggested patch
-        let ts = ctx.chain_index().load_required_tipset_by_height(
-            height,
-            ctx.chain_store().heaviest_tipset(),
-            ResolveNullTipset::TakeOlder,
-        )?;
+        let ts = ctx
+            .chain_index()
+            .load_required_tipset_by_height(
+                height,
+                ctx.chain_store().heaviest_tipset(),
+                ResolveNullTipset::TakeOlder,
+            )
+            .with_context(|| format!("failed to load tipset at height {height}"))?;

As per coding guidelines, "Use anyhow::Result<T> for most operations and add context with .context() when errors occur".

🤖 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.rs` around lines 896 - 900, The call to
ctx.chain_index().load_required_tipset_by_height(...) should add contextual
error information instead of bubbling raw errors; update the expression that
produces ts (the call to load_required_tipset_by_height on ctx.chain_index with
ResolveNullTipset::TakeOlder and the height variable) to attach .context(...)
(from anyhow::Context) with a clear message such as "failed to load tipset at
height {height}" so RPC callers get meaningful diagnostics, and ensure the
surrounding function returns anyhow::Result to propagate the contextualized
error.
🤖 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.

Nitpick comments:
In `@src/rpc/methods/eth.rs`:
- Around line 896-900: The call to
ctx.chain_index().load_required_tipset_by_height(...) should add contextual
error information instead of bubbling raw errors; update the expression that
produces ts (the call to load_required_tipset_by_height on ctx.chain_index with
ResolveNullTipset::TakeOlder and the height variable) to attach .context(...)
(from anyhow::Context) with a clear message such as "failed to load tipset at
height {height}" so RPC callers get meaningful diagnostics, and ensure the
surrounding function returns anyhow::Result to propagate the contextualized
error.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5fea6f5b-181f-48bc-8a4e-4a2a8f4238d7

📥 Commits

Reviewing files that changed from the base of the PR and between 476c64e and ae20044.

⛔ Files ignored due to path filters (3)
  • src/rpc/snapshots/forest__rpc__tests__rpc__v0.snap is excluded by !**/*.snap
  • src/rpc/snapshots/forest__rpc__tests__rpc__v1.snap is excluded by !**/*.snap
  • src/rpc/snapshots/forest__rpc__tests__rpc__v2.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • src/rpc/methods/eth.rs
  • src/rpc/mod.rs

@hanabi1224 hanabi1224 force-pushed the hm/BaseFeeByHeight branch from ae20044 to ef891dc Compare May 25, 2026 13:31
Copy link
Copy Markdown
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.

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

896-901: ⚡ Quick win

Add context to height-based tipset resolution errors.

load_required_tipset_by_height(...) currently bubbles errors without height context. Add .with_context(...) so troubleshooting failures are actionable.

Suggested patch
-        let ts = ctx.chain_index().load_required_tipset_by_height(
-            height,
-            ctx.chain_store().heaviest_tipset(),
-            ResolveNullTipset::TakeOlder,
-        )?;
+        let ts = ctx
+            .chain_index()
+            .load_required_tipset_by_height(
+                height,
+                ctx.chain_store().heaviest_tipset(),
+                ResolveNullTipset::TakeOlder,
+            )
+            .with_context(|| format!("failed to resolve tipset for height {height}"))?;

As per coding guidelines: **/*.rs: Use anyhow::Result<T> for most operations and add context with .context() when errors occur.

🤖 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.rs` around lines 896 - 901, The call to
load_required_tipset_by_height in eth.rs
(ctx.chain_index().load_required_tipset_by_height(...)) can return errors with
no height context; update that invocation to add an anyhow context (using
.context(...)) that includes the requested height so the error message shows
which height failed, and propagate the updated Result into the subsequent
EthBaseFee::get_base_fee(&ctx, &ts)? call; e.g., add .context(format!("loading
tipset at height {}", height)) to the load_required_tipset_by_height call to
provide actionable debug information.
🤖 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.

Nitpick comments:
In `@src/rpc/methods/eth.rs`:
- Around line 896-901: The call to load_required_tipset_by_height in eth.rs
(ctx.chain_index().load_required_tipset_by_height(...)) can return errors with
no height context; update that invocation to add an anyhow context (using
.context(...)) that includes the requested height so the error message shows
which height failed, and propagate the updated Result into the subsequent
EthBaseFee::get_base_fee(&ctx, &ts)? call; e.g., add .context(format!("loading
tipset at height {}", height)) to the load_required_tipset_by_height call to
provide actionable debug information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4c393b0a-54b6-432b-801b-dc33ce32b170

📥 Commits

Reviewing files that changed from the base of the PR and between ae20044 and ef891dc.

⛔ Files ignored due to path filters (3)
  • src/rpc/snapshots/forest__rpc__tests__rpc__v0.snap is excluded by !**/*.snap
  • src/rpc/snapshots/forest__rpc__tests__rpc__v1.snap is excluded by !**/*.snap
  • src/rpc/snapshots/forest__rpc__tests__rpc__v2.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • src/rpc/methods/eth.rs
  • src/rpc/mod.rs

@codecov
Copy link
Copy Markdown

codecov Bot commented May 25, 2026

Codecov Report

❌ Patch coverage is 44.00000% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.19%. Comparing base (476c64e) to head (2089aad).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/rpc/methods/eth.rs 44.00% 11 Missing and 3 partials ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/rpc/mod.rs 88.08% <ø> (ø)
src/rpc/methods/eth.rs 65.40% <44.00%> (-0.29%) ⬇️

... and 14 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 476c64e...2089aad. 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 force-pushed the hm/BaseFeeByHeight branch from ef891dc to 2089aad Compare May 25, 2026 13:56
Copy link
Copy Markdown
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: 1

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

851-851: ⚡ Quick win

Make helper error context method-agnostic.

Line 851 hardcodes eth_baseFee in a shared helper, so Forest.BaseFeeByHeight failures will be mislabeled.

Suggested patch
-        compute_base_fee(ctx.db(), ts, smoke_height, firehorse_height)
-            .context("failed to compute base fee for eth_baseFee")
+        compute_base_fee(ctx.db(), ts, smoke_height, firehorse_height)
+            .context("failed to compute base fee")
🤖 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.rs` at line 851, The helper in src/rpc/methods/eth.rs
currently hardcodes the string "eth_baseFee" in its .context call, causing other
callers like Forest.BaseFeeByHeight to be mislabeled; change the helper to be
method-agnostic by removing the hardcoded name and either (A) accept a
method_name parameter and use it in the context (e.g., format!("failed to
compute base fee for {}", method_name)) or (B) use a generic context like
"failed to compute base fee", then update callers (eth_baseFee and
Forest.BaseFeeByHeight) to pass the appropriate label if you choose option A.
Ensure the .context invocation is updated accordingly so errors reflect the
correct RPC method.
🤖 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.rs`:
- Around line 896-900: Forest.BaseFeeByHeight must reject requests for future
epochs instead of relying on ResolveNullTipset::TakeOlder; before calling
ctx.chain_index().load_required_tipset_by_height, obtain the current head epoch
from the chain head (via ctx.chain_store().heaviest_tipset().epoch() or
equivalent) and if the requested height is greater than that epoch return an
error (appropriate RPC/error variant) immediately; then call
load_required_tipset_by_height for valid heights (or switch ResolveNullTipset to
a non-fallback mode like Fail) so you never silently return an older tipset base
fee.

---

Nitpick comments:
In `@src/rpc/methods/eth.rs`:
- Line 851: The helper in src/rpc/methods/eth.rs currently hardcodes the string
"eth_baseFee" in its .context call, causing other callers like
Forest.BaseFeeByHeight to be mislabeled; change the helper to be method-agnostic
by removing the hardcoded name and either (A) accept a method_name parameter and
use it in the context (e.g., format!("failed to compute base fee for {}",
method_name)) or (B) use a generic context like "failed to compute base fee",
then update callers (eth_baseFee and Forest.BaseFeeByHeight) to pass the
appropriate label if you choose option A. Ensure the .context invocation is
updated accordingly so errors reflect the correct RPC method.
🪄 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: 594a49e3-5aac-4b0b-9813-f0e515f77bf3

📥 Commits

Reviewing files that changed from the base of the PR and between ef891dc and 2089aad.

⛔ Files ignored due to path filters (3)
  • src/rpc/snapshots/forest__rpc__tests__rpc__v0.snap is excluded by !**/*.snap
  • src/rpc/snapshots/forest__rpc__tests__rpc__v1.snap is excluded by !**/*.snap
  • src/rpc/snapshots/forest__rpc__tests__rpc__v2.snap is excluded by !**/*.snap
📒 Files selected for processing (3)
  • src/rpc/methods/eth.rs
  • src/rpc/mod.rs
  • src/tool/subcommands/api_cmd/test_snapshots_ignored.txt
✅ Files skipped from review due to trivial changes (1)
  • src/tool/subcommands/api_cmd/test_snapshots_ignored.txt

Comment thread src/rpc/methods/eth.rs
@hanabi1224 hanabi1224 enabled auto-merge May 25, 2026 14:12
@hanabi1224 hanabi1224 added this pull request to the merge queue May 25, 2026
Merged via the queue into main with commit 934b8ad May 25, 2026
34 checks passed
@hanabi1224 hanabi1224 deleted the hm/BaseFeeByHeight branch May 25, 2026 14:41
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