calcMinFeeRecursive: return result at iteration limit when fee is reasonable#1120
Draft
calcMinFeeRecursive: return result at iteration limit when fee is reasonable#1120
Conversation
3 tasks
Co-authored-by: carbolymer <228866+carbolymer@users.noreply.github.com>
Contributor
Author
|
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:
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
carbolymer
reviewed
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 |
Contributor
There was a problem hiding this comment.
@copilot figure out an upper bound for the fee too!
Contributor
Author
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
calcMinFeeRecursivehits the 50-iteration limit, it unconditionally returnedFeeCalculationDidNotConverge. 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 0base 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 returnsRight txLeft FeeCalculationDidNotConvergeThe most likely scenario reaching
go 0is 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.