Skip to content
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

Fix remaining fee calculation #1578

Merged
merged 6 commits into from
Apr 16, 2020
Merged

Conversation

KtorZ
Copy link
Member

@KtorZ KtorZ commented Apr 16, 2020

Issue Number

#1561

Overview

  • 938a3a0
    📍 add regression test triggering the unbalanced invariant
    currently fails as expected with:

    Generated an unbalanced tx! Too much left for fees : fee (raw) = 164282 : fee (dangling) = 167722 , diff = 200000
    selection = inputs: - 1st 30 (~ 1000000 @ 66616b65...72657373)
    outputs: - 800000 @ 66616b65...72657373
    change: []
    
    CallStack (from HasCallStack):
      error, called at src/Cardano/Wallet/Primitive/Fee.hs:330:18 in cardano-wallet-core-2020.4.7-Be8Kf2A2Kpl7z2pVyjHPdZ:Cardano.Wallet.Primitive.Fee
      remainingFee, called at src/Cardano/Wallet/Primitive/Fee.hs:207:22 in cardano-wallet-core-2020.4.7-Be8Kf2A2Kpl7z2pVyjHPdZ:Cardano.Wallet.Primitive.Fee
    
  • 1041fac
    📍 refactor: merge 'remainingFee' and 'rebalanceChangeOutput'
    The former actually makes assumption based on the output of the later. Testing these
    function in isolation makes little sense. Grouping them into one function makes it
    easier to understand the surrounding context and what is happening.

Further refactoring is needed in order to now fix the issue with dangling fee

  • 1758a30
    📍 use dustThreshold instead of 'Coin 0'
    They should actually have the same semantic within this context.

  • 7194126
    📍 fix remaining fee calculation

  • a17462c
    📍 fix unit test now correctly divying fee across change outputs

  • 1534124
    📍 property test fee balancing
    And allow transaction to be unbalanced if the node allows it

Comments

  currently fails as expected with:

  ```
  Generated an unbalanced tx! Too much left for fees : fee (raw) = 164282 : fee (dangling) = 167722 , diff = 200000
  selection = inputs: - 1st 30 (~ 1000000 @ 66616b65...72657373)
  outputs: - 800000 @ 66616b65...72657373
  change: []

  CallStack (from HasCallStack):
    error, called at src/Cardano/Wallet/Primitive/Fee.hs:330:18 in cardano-wallet-core-2020.4.7-Be8Kf2A2Kpl7z2pVyjHPdZ:Cardano.Wallet.Primitive.Fee
    remainingFee, called at src/Cardano/Wallet/Primitive/Fee.hs:207:22 in cardano-wallet-core-2020.4.7-Be8Kf2A2Kpl7z2pVyjHPdZ:Cardano.Wallet.Primitive.Fee
  ```
The former actually makes assumption based on the output of the later. Testing these
function in isolation makes little sense. Grouping them into one function makes it
easier to understand the surrounding context and what is happening.

Further refactoring is needed in order to now fix the issue with dangling fee
They should actually have the same semantic within this context.
@KtorZ KtorZ self-assigned this Apr 16, 2020
@KtorZ
Copy link
Member Author

KtorZ commented Apr 16, 2020

bors try

iohk-bors bot added a commit that referenced this pull request Apr 16, 2020
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Apr 16, 2020

try

Build failed

-- The new requested fee after adding the output.
δ_dangling = φ_original -- by construction of the change output

extraChng = Coin (δ_original - φ_original)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

@paweljakubas paweljakubas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks fine

@KtorZ
Copy link
Member Author

KtorZ commented Apr 16, 2020

bors r+

iohk-bors bot added a commit that referenced this pull request Apr 16, 2020
1578: Fix remaining fee calculation r=KtorZ a=KtorZ

# Issue Number

<!-- Put here a reference to the issue this PR relates to and which requirements it tackles -->

#1561 

# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->
- 938a3a0
  📍 **add regression test triggering the unbalanced invariant**
    currently fails as expected with:

  ```
  Generated an unbalanced tx! Too much left for fees : fee (raw) = 164282 : fee (dangling) = 167722 , diff = 200000
  selection = inputs: - 1st 30 (~ 1000000 @ 66616b65...72657373)
  outputs: - 800000 @ 66616b65...72657373
  change: []

  CallStack (from HasCallStack):
    error, called at src/Cardano/Wallet/Primitive/Fee.hs:330:18 in cardano-wallet-core-2020.4.7-Be8Kf2A2Kpl7z2pVyjHPdZ:Cardano.Wallet.Primitive.Fee
    remainingFee, called at src/Cardano/Wallet/Primitive/Fee.hs:207:22 in cardano-wallet-core-2020.4.7-Be8Kf2A2Kpl7z2pVyjHPdZ:Cardano.Wallet.Primitive.Fee
  ```

- 1041fac
  📍 **refactor: merge 'remainingFee' and 'rebalanceChangeOutput'**
  The former actually makes assumption based on the output of the later. Testing these
function in isolation makes little sense. Grouping them into one function makes it
easier to understand the surrounding context and what is happening.

Further refactoring is needed in order to now fix the issue with dangling fee

- 1758a30
  📍 **use dustThreshold instead of 'Coin 0'**
  They should actually have the same semantic within this context.

- 7194126
  📍 **fix remaining fee calculation**
  
- a17462c
  📍 **fix unit test now correctly divying fee across change outputs**
  
- 1534124
  📍 **property test fee balancing**
  And allow transaction to be unbalanced if the node allows it


# 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: KtorZ <matthias.benkort@gmail.com>
And allow transaction to be unbalanced if the node allows it
@KtorZ KtorZ force-pushed the KtorZ/1561/remaining-fee-calculation branch from 1534124 to 5c88126 Compare April 16, 2020 18:40
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Apr 16, 2020

Canceled

@KtorZ
Copy link
Member Author

KtorZ commented Apr 16, 2020

bors r+

iohk-bors bot added a commit that referenced this pull request Apr 16, 2020
1578: Fix remaining fee calculation r=KtorZ a=KtorZ

# Issue Number

<!-- Put here a reference to the issue this PR relates to and which requirements it tackles -->

#1561 

# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->
- 938a3a0
  📍 **add regression test triggering the unbalanced invariant**
    currently fails as expected with:

  ```
  Generated an unbalanced tx! Too much left for fees : fee (raw) = 164282 : fee (dangling) = 167722 , diff = 200000
  selection = inputs: - 1st 30 (~ 1000000 @ 66616b65...72657373)
  outputs: - 800000 @ 66616b65...72657373
  change: []

  CallStack (from HasCallStack):
    error, called at src/Cardano/Wallet/Primitive/Fee.hs:330:18 in cardano-wallet-core-2020.4.7-Be8Kf2A2Kpl7z2pVyjHPdZ:Cardano.Wallet.Primitive.Fee
    remainingFee, called at src/Cardano/Wallet/Primitive/Fee.hs:207:22 in cardano-wallet-core-2020.4.7-Be8Kf2A2Kpl7z2pVyjHPdZ:Cardano.Wallet.Primitive.Fee
  ```

- 1041fac
  📍 **refactor: merge 'remainingFee' and 'rebalanceChangeOutput'**
  The former actually makes assumption based on the output of the later. Testing these
function in isolation makes little sense. Grouping them into one function makes it
easier to understand the surrounding context and what is happening.

Further refactoring is needed in order to now fix the issue with dangling fee

- 1758a30
  📍 **use dustThreshold instead of 'Coin 0'**
  They should actually have the same semantic within this context.

- 7194126
  📍 **fix remaining fee calculation**
  
- a17462c
  📍 **fix unit test now correctly divying fee across change outputs**
  
- 1534124
  📍 **property test fee balancing**
  And allow transaction to be unbalanced if the node allows it


# 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: KtorZ <matthias.benkort@gmail.com>
@@ -161,7 +167,7 @@ spec = do
}) (Right $ FeeOutput
{ csInps = [20,20,20]
, csOuts = [14,18,19]
, csChngs = [6]
, csChngs = [4,1,1]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: To be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants