-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement distributeSurplus
and use in balanceTransaction
#3223
Conversation
lib/core/src/Cardano/Wallet.hs
Outdated
:: TxFeeAndChange | ||
-> TxFeeAndChange | ||
guardReasonableExcessFee fc@(TxFeeAndChange feeToBurn _) | ||
| feeToBurn > minAda <> minAda = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think technically this could be problematic on a network where the fee increase derived from coin-value-encoding is greater than 2*minAda — e.g. if minAda is tiny or 0...
Maybe we can add feePerByte * 16
to the right hand side… (or keep the static 20 ada one 🤷♂️ if it gets too complicated)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up just dropping guardReasonableExcessFee
completely. I think it's more trouble than it's worth.
3.050000,ErrBalanceTxSelectAssets (ErrSelectAssetsSelectionError (SelectionCollateralErrorOf (SelectionCollateralError {largestCombinationAvailable = fromList [(WalletUTxO {txIn = TxIn {inputId = Hash "00000000000000000000000000000000", inputIx = 0}, address = Address "`\177\229\224\251t\200l\128\USdhA\224|\219B\223\139\130\239<\228\229|\181A.w"},Coin 3050000)], minimumSelectionAmount = Coin 3050246}))) | ||
3.100000,0.612226,0.612050 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we see that
- 528 more lovelace is needed to succeed (at least inferred from the error message)
- When we are succeeding, fees are no longer 176 lovelace higher than needed
a285cec
to
ab82b9d
Compare
1e70528
to
dec9f1a
Compare
6995119
to
3e941e2
Compare
bors try |
tryBuild failed:
Probably the value just needs to be adjusted. |
3e941e2
to
8248eca
Compare
bors try |
tryBuild failed: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Anviking
I have some suggestions, but I think this PR can be merged as is!
I'll open a second PR with the suggestions.
Thanks for making this PR!
bors r+ |
3223: Implement `distributeSurplus` and use in `balanceTransaction` r=Anviking a=Anviking - [x] Factors out fee-minimisation logic such that it can be made more sophisticated and tested separately from `balanceTransaction` - [x] Fee- and change-related padding before fee-minimisation is _increased_. - [x] The padding _after_ fee-minimisation is (in most cases) _removed_ (see goldens; we are no longer overpaying the fee with 176 lovelace) - [x] The fee minimisation is more robust, and should work regardless of ProtocolParameters, whether a 5 ada fee is required, or a 21 lovelace one. - <s>[ ] Implement `guardReasonableExcessFee` based on `2 * minUTxOValue`, rather than using the hard-coded limit of 20 ada. </s> - <s>[ ] Extra: adjust error types (could be moved to separate PR)</s> - [x] Look over comments & polish etc ### Comments - Depends on #3215 <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number ADP-1514 <!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles. Note: Jira issues of the form ADP- will be auto-linked. --> Co-authored-by: Johannes Lund <johannes.lund@iohk.io>
Build failed:
|
bors r+ |
3223: Implement `distributeSurplus` and use in `balanceTransaction` r=Anviking a=Anviking - [x] Factors out fee-minimisation logic such that it can be made more sophisticated and tested separately from `balanceTransaction` - [x] Fee- and change-related padding before fee-minimisation is _increased_. - [x] The padding _after_ fee-minimisation is (in most cases) _removed_ (see goldens; we are no longer overpaying the fee with 176 lovelace) - [x] The fee minimisation is more robust, and should work regardless of ProtocolParameters, whether a 5 ada fee is required, or a 21 lovelace one. - <s>[ ] Implement `guardReasonableExcessFee` based on `2 * minUTxOValue`, rather than using the hard-coded limit of 20 ada. </s> - <s>[ ] Extra: adjust error types (could be moved to separate PR)</s> - [x] Look over comments & polish etc ### Comments - Depends on #3215 <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number ADP-1514 <!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles. Note: Jira issues of the form ADP- will be auto-linked. --> Co-authored-by: Johannes Lund <johannes.lund@iohk.io>
Build failed: |
- Factors out fee-minimisation logic such that it can be made more sophisticated and tested separately from balanceTransaction - Fee- and change-related padding before fee-minimisation is increased. - The padding after fee-minimisation is (in most cases) removed (see goldens; we are no longer overpaying the fee with 176 lovelace) - The fee minimisation is more robust, and should work regardless of ProtocolParameters, whether a 5 ada fee is required, or a 21 lovelace one. I ended up dropping the sanity check that any burned fee was less than 20 ada. I considered replacing the hard-coded limit with the following: ``` -- Increasing the fee by much should only happen if coin-selection is unable -- to construct a change output respecting the minUTxOValue. guardReasonableExcessFee :: TxFeeAndChange -> TxFeeAndChange guardReasonableExcessFee fc@(TxFeeAndChange feeToBurn _) | feeToBurn > limit = error $ unwords [ "final redundant safety check in balanceTransaction:" , "burning more than 2 * minUTxOValue in fees is unreasonable" ] | otherwise = fc where -- We let 2*minAda be the limit rather than just minAda to account -- for overestimations in coin-selection etc. Precision doesn't -- matter here. limit = minAda <> minAda <> Coin (ceiling $ 16 * perByteFee) -- NOTE: The change output we've failed to create would only have -- contained ada, so passing 'TokenMap.empty' should be reasonable. minAda = txOutputMinimumAdaQuantity (view #constraints tl pp) TokenMap.empty LinearFee LinearFunction {slope = perByteFee} = view (#txParameters . #getFeePolicy) pp ``` but decided it was too complex to be worth it.
8248eca
to
1f69c03
Compare
bors r+ |
3223: Implement `distributeSurplus` and use in `balanceTransaction` r=Anviking a=Anviking - [x] Factors out fee-minimisation logic such that it can be made more sophisticated and tested separately from `balanceTransaction` - [x] Fee- and change-related padding before fee-minimisation is _increased_. - [x] The padding _after_ fee-minimisation is (in most cases) _removed_ (see goldens; we are no longer overpaying the fee with 176 lovelace) - [x] The fee minimisation is more robust, and should work regardless of ProtocolParameters, whether a 5 ada fee is required, or a 21 lovelace one. - <s>[ ] Implement `guardReasonableExcessFee` based on `2 * minUTxOValue`, rather than using the hard-coded limit of 20 ada. </s> - <s>[ ] Extra: adjust error types (could be moved to separate PR)</s> - [x] Look over comments & polish etc ### Comments - Depends on #3215 <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number ADP-1514 <!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles. Note: Jira issues of the form ADP- will be auto-linked. --> Co-authored-by: Johannes Lund <johannes.lund@iohk.io>
Build failed: |
bors r+ |
3223: Implement `distributeSurplus` and use in `balanceTransaction` r=Anviking a=Anviking - [x] Factors out fee-minimisation logic such that it can be made more sophisticated and tested separately from `balanceTransaction` - [x] Fee- and change-related padding before fee-minimisation is _increased_. - [x] The padding _after_ fee-minimisation is (in most cases) _removed_ (see goldens; we are no longer overpaying the fee with 176 lovelace) - [x] The fee minimisation is more robust, and should work regardless of ProtocolParameters, whether a 5 ada fee is required, or a 21 lovelace one. - <s>[ ] Implement `guardReasonableExcessFee` based on `2 * minUTxOValue`, rather than using the hard-coded limit of 20 ada. </s> - <s>[ ] Extra: adjust error types (could be moved to separate PR)</s> - [x] Look over comments & polish etc ### Comments - Depends on #3215 <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number ADP-1514 <!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles. Note: Jira issues of the form ADP- will be auto-linked. --> Co-authored-by: Johannes Lund <johannes.lund@iohk.io>
Build failed: |
|
bors r+ |
3223: Implement `distributeSurplus` and use in `balanceTransaction` r=Anviking a=Anviking - [x] Factors out fee-minimisation logic such that it can be made more sophisticated and tested separately from `balanceTransaction` - [x] Fee- and change-related padding before fee-minimisation is _increased_. - [x] The padding _after_ fee-minimisation is (in most cases) _removed_ (see goldens; we are no longer overpaying the fee with 176 lovelace) - [x] The fee minimisation is more robust, and should work regardless of ProtocolParameters, whether a 5 ada fee is required, or a 21 lovelace one. - <s>[ ] Implement `guardReasonableExcessFee` based on `2 * minUTxOValue`, rather than using the hard-coded limit of 20 ada. </s> - <s>[ ] Extra: adjust error types (could be moved to separate PR)</s> - [x] Look over comments & polish etc ### Comments - Depends on #3215 <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number ADP-1514 <!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles. Note: Jira issues of the form ADP- will be auto-linked. --> Co-authored-by: Johannes Lund <johannes.lund@iohk.io>
bors r+ |
Already running a review |
This PR was included in a batch that successfully built, but then failed to merge into master (it was a non-fast-forward update). It will be automatically retried. |
3223: Implement `distributeSurplus` and use in `balanceTransaction` r=Anviking a=Anviking - [x] Factors out fee-minimisation logic such that it can be made more sophisticated and tested separately from `balanceTransaction` - [x] Fee- and change-related padding before fee-minimisation is _increased_. - [x] The padding _after_ fee-minimisation is (in most cases) _removed_ (see goldens; we are no longer overpaying the fee with 176 lovelace) - [x] The fee minimisation is more robust, and should work regardless of ProtocolParameters, whether a 5 ada fee is required, or a 21 lovelace one. - <s>[ ] Implement `guardReasonableExcessFee` based on `2 * minUTxOValue`, rather than using the hard-coded limit of 20 ada. </s> - <s>[ ] Extra: adjust error types (could be moved to separate PR)</s> - [x] Look over comments & polish etc ### Comments - Depends on #3215 <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number ADP-1514 <!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles. Note: Jira issues of the form ADP- will be auto-linked. --> Co-authored-by: Johannes Lund <johannes.lund@iohk.io>
This PR was included in a batch that successfully built, but then failed to merge into master. It will not be retried. Additional information: {"message":"At least 1 approving review is required by reviewers with write access.","documentation_url":"https://docs.github.com/articles/about-protected-branches"} |
balanceTransaction
[ ] ImplementguardReasonableExcessFee
based on2 * minUTxOValue
, rather than using the hard-coded limit of 20 ada.[ ] Extra: adjust error types (could be moved to separate PR)Comments
sizeOfCoin
andcostOfIncreasingCoin
#3215Issue Number
ADP-1514