Skip to content

feat(fortuna): CLI command to debug fee estimation issues#3313

Open
jayantk wants to merge 1 commit intomainfrom
fortuna_debug_gas
Open

feat(fortuna): CLI command to debug fee estimation issues#3313
jayantk wants to merge 1 commit intomainfrom
fortuna_debug_gas

Conversation

@jayantk
Copy link
Contributor

@jayantk jayantk commented Dec 18, 2025

Summary

add a CLI command for estimating how much a tx costs on an ongoing basis. You can use this + some debug statements in fee estimation to figure out why the fees are set where they are.

Rationale

this is helpful for debugging some of the monad issues

How has this been tested?

  • Current tests cover my changes
  • Added new tests
  • Manually tested the code

Open with Devin

@jayantk jayantk requested review from a team and tejasbadadare as code owners December 18, 2025 03:19
@vercel
Copy link

vercel bot commented Dec 18, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
api-reference Ready Ready Preview, Comment Dec 18, 2025 3:22am
component-library Ready Ready Preview, Comment Dec 18, 2025 3:22am
developer-hub Ready Ready Preview, Comment Dec 18, 2025 3:22am
entropy-explorer Ready Ready Preview, Comment Dec 18, 2025 3:22am
insights Ready Ready Preview, Comment Dec 18, 2025 3:22am
proposals Ready Ready Preview, Comment Dec 18, 2025 3:22am
staking Ready Ready Preview, Comment Dec 18, 2025 3:22am

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 4 additional findings in Devin Review.

Open in Devin Review

match estimate_tx_cost(middleware.clone(), chain_config.legacy_tx, gas_limit).await {
Ok(tx_cost) => {
let tx_cost_eth = tx_cost as f64 / 1e18;
let effective_gas_price = tx_cost / gas_limit;
Copy link
Contributor

Choose a reason for hiding this comment

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

🟡 Division by zero panic when gas_limit is 0

The effective_gas_price calculation at line 78 performs tx_cost / gas_limit where gas_limit is derived from chain_config.gas_limit (a u32). If gas_limit is 0, this causes a panic due to integer division by zero.

Root Cause

The gas_limit field in EthereumConfig (apps/fortuna/src/config.rs:158) is a u32 with no default value and no validation that it is non-zero. At apps/fortuna/src/command/debug_gas.rs:74, it is cast to u128 and then used as a divisor at line 78:

let gas_limit: u128 = chain_config.gas_limit as u128;
// ...
let effective_gas_price = tx_cost / gas_limit;  // panics if gas_limit == 0

While a gas_limit of 0 is an unusual configuration, there is no guard against it. Other callers of estimate_tx_cost (e.g., apps/fortuna/src/keeper/fee.rs:305-306) get gas_limit from the on-chain provider info rather than the config, so they don't have this specific issue.

Impact: The debug tool panics at runtime with a division-by-zero error if the config has gas_limit: 0.

Suggested change
let effective_gas_price = tx_cost / gas_limit;
let effective_gas_price = if gas_limit > 0 { tx_cost / gas_limit } else { 0 };
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant