feat(fortuna): CLI command to debug fee estimation issues#3313
feat(fortuna): CLI command to debug fee estimation issues#3313
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| 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; |
There was a problem hiding this comment.
🟡 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 == 0While 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.
| let effective_gas_price = tx_cost / gas_limit; | |
| let effective_gas_price = if gas_limit > 0 { tx_cost / gas_limit } else { 0 }; |
Was this helpful? React with 👍 or 👎 to provide feedback.
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?