Skip to content

calcMinFeeRecursive: return result at iteration limit when fee is reasonable#1120

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/sub-pr-1106-again
Draft

calcMinFeeRecursive: return result at iteration limit when fee is reasonable#1120
Copilot wants to merge 3 commits intomasterfrom
copilot/sub-pr-1106-again

Conversation

Copy link
Contributor

Copilot AI commented Mar 6, 2026

When calcMinFeeRecursive hits the 50-iteration limit, it unconditionally returned FeeCalculationDidNotConverge. The result is still useful if the fee is valid — the error was too aggressive.

Definition of "reasonable fee": minFee <= txBodyFee <= 2 * minFee — the fee meets or exceeds the ledger-calculated minimum (so the transaction won't be rejected for insufficient fees) and does not exceed twice the minimum (ruling out a fee so high it likely signals a calculation error rather than ordinary oscillation).

Changes:

  • go 0 base case — instead of discarding the final transaction state and returning an error, inspects it:
    • minFee <= txBodyFee <= 2 * minFee: validates outputs against min UTxO (consistent with Case 1) and returns Right tx
    • otherwise: returns Left FeeCalculationDidNotConverge
  • Haddock — documents the full "reasonable fee" bounds at the iteration limit

The most likely scenario reaching go 0 is fee oscillation between two ledger-calculated minimum values (caused by a change output's CBOR size alternately shifting the tx byte count). In that case the two oscillating fee values differ by only a tiny fraction (a few bytes of encoding), so both bounds are easily satisfied and the result is useful to return.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: carbolymer <228866+carbolymer@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 6, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • chap.intersectmbo.org
    • Triggering command: /usr/bin/curl /usr/bin/curl REDACTED --output /tmp/transportAdapterGet4091-7 --location --write-out %{http_code} --user-agent cabal-install/3.16.1.0 (linux; x86_64) --silent --show-error --dump-header /tmp/curl-headers4091-8.txt (dns block)
    • Triggering command: /usr/bin/curl /usr/bin/curl REDACTED --output /tmp/transportAdapterGet4314-3 --location --write-out %{http_code} --user-agent cabal-install/3.16.1.0 (linux; x86_64) --silent --show-error --dump-header /tmp/curl-headers4314-4.txt (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Refine recursive minimum fee calculation based on feedback calcMinFeeRecursive: return result at iteration limit when fee is reasonable Mar 6, 2026
-- the result is still useful even though strict convergence was not confirmed.
-- Only fail when the fee would be below the ledger minimum.
go 0 unSignTx@(UnsignedTx ledgerTx) utxo' pparams' _ _ _ nExtraWitnesses'
| txBodyFee >= minFee = do
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot figure out an upper bound for the fee too!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 7a77450. The full "reasonable fee" bounds are now minFee <= txBodyFee <= 2 * minFee:

  • Lower bound (>= minFee): ensures the ledger will accept the fee.
  • Upper bound (<= 2 * minFee): rules out a fee so far above the minimum that it likely indicates a calculation error rather than ordinary oscillation.

In practice, at the iteration limit the fee was set to a prior ledger-computed minimum and will be within a tiny fraction of the current minimum (oscillation stems from a few bytes of CBOR encoding difference between iterations), so both bounds will be satisfied.

Co-authored-by: carbolymer <228866+carbolymer@users.noreply.github.com>
Base automatically changed from jordan/introduce-calculate-min-fee-recursive to master March 9, 2026 16:20
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.

3 participants