Cardano-wallet: Transactions with minimal amount leave too many fee

Created on 9 Dec 2019  路  11Comments  路  Source: input-output-hk/cardano-wallet

Context

| Information | - |
| --- | --- |
| Version | 07c0ff4eb |
| Platform | All |
| Installation | N/A |

Steps to Reproduce

  1. Have a wallet with exactly the right amount to pay for delegation fee (i.e. enough to pay for a certificate, constant fee and a single input).
  2. Make a transaction

Expected behavior

  1. The transaction is accepted and the wallet has a balance of 0

Actual behavior

  1. The transaction is rejected by the server and it requires an additional amount which matches the fee for an extra input/output.

Resolution

  • Adjusted fee calculation to better handle edge-case ==> #1145
  • Use fee estimator instead of hard-coded fee in the integration tests ==> #1145

QA

See comments below.

All 11 comments

I see that delegation fee is still shown incorrectly. Looking at our own integration tests fees config:

fees: 
  certificate: 42
  coefficient: 1
  constant: 14

so, if I understand correctly, the fee for delegation fee should be 42 + 14 = 56. (if paid from one utxo)

Delegation fee endpoint shows = 58
Delegating to stake pool takes fee = 58

The same goes for transactions.
Tx fee (for single utxo tx) is calculated = 17 (instead of 16).

That is for both, making tx and tx fee.

So... tests do not catch that, Perhaps it would be better to have fee in the integration tests being part of hardcoded TestData rather than calculated by feeEstimator?

Refering to this -> https://github.com/input-output-hk/cardano-wallet/pull/1145/commits/3eee4a23f77ca8e99600c62717b5f8c122b5119d

@piotr-iohk you're forgetting the coefficient part. 1 means that each input or output cost 1. So, in the case of a standard delegation that requires only one UTxO, it'll typically cost 58 because it requires one input (the UTxO) and one change output!

Only if your input is exactly of the right amount (i.e. 57 coins) will you be able to pay 57, because no change output is needed. 56 will never be possible however because you always need an input.

We have integration tests testing for these edge-cases (sorry, I see the QA section on this ticket is empty :| ... ), let me find that back for you.

So,

  1. https://github.com/input-output-hk/cardano-wallet/blob/master/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/StakePools.hs#L345-L356

We are creating a wallet with a single UTxO that is exactly 57 coins (constant fee + certificate fee + coefficient fee for a single input). This is enough to create a delegation certificate. Perhaps it would be good to add an extra assertion on the resulting transaction to show that it actually has no outputs!

  1. https://github.com/input-output-hk/cardano-wallet/blob/master/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/StakePools.hs#L358-L366

Here's an example where we have a wallet that has 56 coins (the minimal fee - 1) and, it's not able to join.

  1. https://github.com/input-output-hk/cardano-wallet/blob/master/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/StakePools.hs#L368-L375

The assertion in this one might seem a bit counter-intuitive. The wallet is empty and the server returns that it can't create a delegation certificate, because it is missing 56 lovelace! Why 56 and not 57 ? Because of the way the algorithm works. We only require additional inputs _when needed_ and at this stage, we know that the wallet hasn't even enough to cover for the flat fees (constant + certificate) and we haven't selected a single input yet! Ultimately, we could catch that edge-case and return a more meaningful error like "your wallet is empty"

OK, so is this correct then?

fees: 
  certificate: 42
  coefficient: 1
  constant: 14

delegation_fee = constant + certificate + (coefficient * (inputs + outputs))
tx_fee = constant + (coefficient * (inputs + outputs))

Ultimately, we could catch that edge-case and return a more meaningful error like "your wallet is empty"

I'd be in favor of this idea. :)

OK, so is this correct then?

Yes!

lgtm :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vicepool picture vicepool  路  7Comments

gitloverr picture gitloverr  路  6Comments

paweljakubas picture paweljakubas  路  6Comments

Anviking picture Anviking  路  8Comments

KtorZ picture KtorZ  路  11Comments