Hi Guys, I'm trying to estimate fees for my transaction using the cardano-wallet-byron REST API
But I'm getting this error
Generated an unbalanced tx! Too much left for fees : fee (raw) = 169356 : fee (dangling) = 169312 , diff = 169444
selection = inputs: - 1st 53dc6b97 (~ 1000000 @ 82d81858...f4c18d36)
outputs: - 800000 @ 82d81858...b51caf97
change: [30556]
CallStack (from HasCallStack):
error, called at src/Cardano/Wallet/Primitive/Fee.hs:330:18 in cardano-wallet-core-2020.4.7-J7ISR43lhLPDUNes6kwzqg:Cardano.Wallet.Primitive.Fee
remainingFee, called at src/Cardano/Wallet/Primitive/Fee.hs:207:22 in cardano-wallet-core-2020.4.7-J7ISR43lhLPDUNes6kwzqg:Cardano.Wallet.Primitive.Fee
| Information | - |
| --- | --- |
| Version | 2020.4.7 (git revision: cff0e391985887f60b9076aace207674bef6a2b4) |
| Platform | Ubuntu 18.04 WSL |
I have a wallet with balance 1 ADA
I send this payload into the
/payment-fees endpoint
this is my payload
{
"payments": [
{
"address": "Ae2tdPwUPEZLeGE96wfn8ro2ZsSYj8SFbaNXkfPexXV7sgJwUyLfJq3A7Nv",
"amount": {
"quantity": 800000,
"unit": "lovelace"
}
}
]
}
Return the estimated fee
{
"amount": {
"quantity": 42000000,
"unit": "lovelace"
}
}
Logs
Generated an unbalanced tx! Too much left for fees : fee (raw) = 169356 : fee (dangling) = 169312 , diff = 169444
selection = inputs: - 1st 53dc6b97 (~ 1000000 @ 82d81858...f4c18d36)
outputs: - 800000 @ 82d81858...b51caf97
change: [30556]
CallStack (from HasCallStack):
error, called at src/Cardano/Wallet/Primitive/Fee.hs:330:18 in cardano-wallet-core-2020.4.7-J7ISR43lhLPDUNes6kwzqg:Cardano.Wallet.Primitive.Fee
remainingFee, called at src/Cardano/Wallet/Primitive/Fee.hs:207:22 in cardano-wallet-core-2020.4.7-J7ISR43lhLPDUNes6kwzqg:Cardano.Wallet.Primitive.Fee
Endpoint Response
"Something went wrong"
Added a regression test capturing the example above ==> https://github.com/input-output-hk/cardano-wallet/blob/master/lib/byron/test/unit/Cardano/Wallet/Byron/TransactionSpec.hs#L135-L164
Added also a property for balancing coin selection and showing that it always eventually resolve. Passed locally with 1M cases after several round of bug and fixes ==> https://github.com/input-output-hk/cardano-wallet/blob/master/lib/byron/test/unit/Cardano/Wallet/Byron/TransactionSpec.hs#L166-L169
edit: I think its when I send a very low amount transaction
Awe crap. Yes, this is an important one.
TL; DR; We need to allow _slightly_ unbalanced transaction for cardano-node.
A bit of context:
cardano-wallet is now integrated with two nodes, the cardano-node and jormungandr. They can have different behaviors on some validations they do. J枚rmungandr is actually more strict with regards to fees and require a transaction to be _exactly balanced_. This isn't a big issue with j枚rmungandr because the underlying binary encoding is relatively simply.
cardano-node on the contrary are more lenient on the fee validation and would allow a transaction to leave more that the minimal amount of fee necessary. This is, partly, to cope with the more complex binary encoding on cardano-node where the length of the underlying data may vary based on the _value_ of its constituants (and no their type! e.g. 14 is encoded over 1 byte, but 137536 over 3 bytes ...). Our estimator is doing its best and, we do actually know what's are error margin here: up to 10 bytes per change output. We need to take this into account and make this invariant a bit more lenient, for cardano-node at least.
Awesome, I'm glad to help you guys out!
Indeed, I can reproduce with 1 ada balance and try estimate payment (or send tx) with 800000 lovelace.
LGTM.
Verified additionally on testnet for random and sequential (icarus, trezor and ledger) wallets.
In all cases transaction (and fee estimation) is successful with balance = 1 ADA and amount to be sent = 800000 lovelaces.
Most helpful comment
Indeed, I can reproduce with 1 ada balance and try estimate payment (or send tx) with 800000 lovelace.