{"record":{"id":"24169ddc4e81cbd0","repo":"nautechsystems/nautilus_trader","slug":"derived-max-fee-per-gas-max-fee-wei-exceeds-ceil","errorCode":null,"errorMessage":"Derived max fee per gas {max_fee} wei exceeds ceiling {max_fee_per_gas_wei} wei","messagePattern":"Derived max fee per gas (.+?) wei exceeds ceiling (.+?) wei","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/execution/transaction.rs","lineNumber":368,"sourceCode":"///\n/// # Errors\n///\n/// Returns an error if the derived max fee exceeds `max_fee_per_gas_wei` or the arithmetic\n/// overflows.\npub fn derive_fees(\n    base_fee_per_gas_wei: u128,\n    priority_fee_per_gas_wei: u128,\n    base_fee_buffer_bps: u32,\n    max_fee_per_gas_wei: u128,\n) -> anyhow::Result<(u128, u128)> {\n    let max_fee = compute_max_fee(\n        base_fee_per_gas_wei,\n        priority_fee_per_gas_wei,\n        base_fee_buffer_bps,\n    )?;\n\n    if max_fee > max_fee_per_gas_wei {\n        anyhow::bail!(\n            \"Derived max fee per gas {max_fee} wei exceeds ceiling {max_fee_per_gas_wei} wei\"\n        );\n    }\n\n    Ok((max_fee, priority_fee_per_gas_wei))\n}\n\n/// Computes the EIP-1559 max fee per gas: the base fee with `base_fee_buffer_bps` applied\n/// plus the priority fee, without applying any ceiling.\n///\n/// # Errors\n///\n/// Returns an error if the arithmetic overflows.\npub fn compute_max_fee(\n    base_fee_per_gas_wei: u128,\n    priority_fee_per_gas_wei: u128,\n    base_fee_buffer_bps: u32,\n) -> anyhow::Result<u128> {","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/execution/transaction.rs#L350-L386","documentation":"derive_fees computes a max fee per gas from a buffered base fee plus a priority fee and enforces a configured ceiling max_fee_per_gas_wei. It bails when the derived max fee exceeds that ceiling, so callers never sign a transaction whose fee cap exceeds policy. The priority fee is returned unchanged alongside.","triggerScenarios":"Calling derive_fees (or prepare_and_sign_with_anchors) when base_fee_per_gas_wei plus its base_fee_buffer_bps buffer plus priority_fee_per_gas_wei exceeds max_fee_per_gas_wei — e.g. a network base-fee spike or a ceiling configured below current chain fees.","commonSituations":"Volatile base fee during congestion exceeding a static configured ceiling; max_fee_per_gas configured too low for current network conditions; base-fee buffer bps set too aggressively; stale fee data cached from a calmer period.","solutions":["Raise the max_fee_per_gas_wei ceiling to accommodate current network base fee plus buffer and priority fee.","Reduce base_fee_buffer_bps or the priority fee so the derived max fee fits under the ceiling.","Refresh base fee data from the latest block — a stale/spiked base_fee_per_gas_wei input may be the cause.","If the ceiling is a hard policy limit, delay or skip the transaction until base fee falls rather than raising the ceiling."],"exampleFix":"// before\nlet (max_fee, tip) = derive_fees(50_000_000_000, 2_000_000_000, 2000, 40_000_000_000)?; // derived > 40 gwei ceiling\n// after\nlet (max_fee, tip) = derive_fees(50_000_000_000, 2_000_000_000, 2000, 75_000_000_000)?; // ceiling raised","handlingStrategy":"validation","validationCode":"fn fees_within_ceiling(base_fee: u128, tip: u128, bps: u32, ceiling: u128) -> bool {\n    let max_fee = base_fee * (10_000 + bps as u128) / 10_000 + tip;\n    max_fee <= ceiling\n}\n// verify config before calling derive_fees","typeGuard":null,"tryCatchPattern":"match derive_fees(base_fee, tip, bps, ceiling) {\n    Err(e) if e.to_string().contains(\"exceeds ceiling\") => /* defer tx or raise ceiling per policy */,\n    Err(e) => return Err(e),\n    Ok((max_fee, tip)) => (max_fee, tip),\n}","preventionTips":["Derive fee ceilings from live network conditions with headroom, not hardcoded values","Refresh base fee from the latest block before each signing","Treat ceiling breaches as a signal to delay, not to clamp fees below estimate","Alert when sustained base-fee levels approach the configured ceiling"],"tags":["rust","gas-fees","eip-1559","configuration"],"backgroundTag":"value-out-of-range","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}