-
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
Handle too small outputs/changes #1916
Handle too small outputs/changes #1916
Conversation
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.
LGTM
lib/core/src/Cardano/Wallet.hs
Outdated
guardSelect | ||
:: Coin | ||
-> NonEmpty TxOut | ||
-> Either ErrTxOutTooSmall () | ||
guardSelect minUtxoValue txouts = do | ||
let invalidTxOuts = | ||
filter (\(TxOut _ out) -> out < minUtxoValue) $ NE.toList txouts | ||
let getVals = map (\(TxOut _ (Coin c)) -> c) | ||
unless (L.null invalidTxOuts) $ | ||
Left (ErrTxOutTooSmall (getCoin minUtxoValue) (getVals invalidTxOuts) ) |
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.
Maybe this might be easier to call? -- the ExceptT is built in.
guardSelect | |
:: Coin | |
-> NonEmpty TxOut | |
-> Either ErrTxOutTooSmall () | |
guardSelect minUtxoValue txouts = do | |
let invalidTxOuts = | |
filter (\(TxOut _ out) -> out < minUtxoValue) $ NE.toList txouts | |
let getVals = map (\(TxOut _ (Coin c)) -> c) | |
unless (L.null invalidTxOuts) $ | |
Left (ErrTxOutTooSmall (getCoin minUtxoValue) (getVals invalidTxOuts) ) | |
guardSelect | |
:: Coin | |
-> NonEmpty TxOut | |
-> ExceptT m ErrSelectForPayment () | |
guardSelect minUtxoValue txouts | |
| outputsAreAllBigEnough = pure () | |
| otherwise = throwE $ ErrSelectForPayment $ ErrTxOutTooSmall (getCoin minUtxoValue) (getVals invalidTxOuts) | |
where | |
outputsAreAllBigEnough = not (L.null invalidTxOuts) | |
invalidTxOuts = filter (\(TxOut _ out) -> out < minUtxoValue) $ NE.toList txouts | |
getVals = map (\(TxOut _ (Coin c)) -> c) |
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.
probably. here I just wanted to be aligned with other guards and more fit to the style already existent. But I will add property to guardSelect in coming commit
Testing on shelley_testnet on this branch, found 1 issue: wallet with balance 11 ADA with two utxos (10 ADA and 1 ADA). trying to make tx from such wallet for 10ADA results with an error:
Steps to reproduce:
this 👆 error |
@piotr-iohk I hope this change will help 87dc401 now we are checking after fee adjustement, looking at coin selection |
Tested on shelley, icarus and byron wallets on shelley testnet with minimumUtxoValue = 1 ada.
wallet balance = big arbitrary balance
wallet balance 11 ada (utxo1 = 10ada, utxo2 = 1ada)
The second scenario may be quite misleading for wallet owner, as he has balance = 11ada and cannot send 10ada, because the change of the transaction is below 1 ada. The information about the change is in the error message. Not sure if we can do more... |
I'd suggest also adding unit test for that. |
bors r+ |
1916: Handle too small outputs/changes r=paweljakubas a=paweljakubas # Issue Number <!-- Put here a reference to the issue this PR relates to and which requirements it tackles --> #1914 # Overview <!-- Detail in a few bullet points the work accomplished in this PR --> - [x] I have added the error handling situation when any `TxOut` is smaller than `minimumUTxOvalue` - [x] I have added `guardSelect` and used in `selectCoinsForPayment` - [x] I have also make sure it is in `estimateFeeForPayment` # Comments <!-- Additional comments or screenshots to attach if any --> <!-- Don't forget to: ✓ Self-review your changes to make sure nothing unexpected slipped through ✓ Assign yourself to the PR ✓ Assign one or several reviewer(s) ✓ Once created, link this PR to its corresponding ticket ✓ Assign the PR to a corresponding milestone ✓ Acknowledge any changes required to the Wiki --> Co-authored-by: Pawel Jakubas <[email protected]>
Build failed |
ba8b836
to
29d8a9d
Compare
bors try |
tryBuild failed |
3e921cf
to
6ea2d92
Compare
bors try |
tryBuild failed |
bors try |
tryBuild failed |
6ea2d92
to
73eb89a
Compare
bors try |
tryBuild succeeded |
73eb89a
to
5d1666a
Compare
bors r+ |
Build succeeded |
ErrUTxOTooSmall minUtxoValue invalidUTxO -> | ||
apiError err403 UtxoTooSmall $ mconcat | ||
[ "I'm unable to construct the given transaction as some " | ||
, "outputs or changes are too small! Each output and change is " |
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.
small note: we shouldn't be talking about change here because there's nothing users can do about change. We are actually generating them and, having changes that are too small here would mean that we messed up. Yet, for outputs, this error looks totally legit indeed.
Issue Number
#1914
Overview
TxOut
is smaller thanminimumUTxOvalue
guardSelect
and used inselectCoinsForPayment
estimateFeeForPayment
Comments