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

Add derivation paths to coin selection change outputs #2244

Merged
merged 22 commits into from
Oct 21, 2020

Conversation

jonathanknowles
Copy link
Contributor

@jonathanknowles jonathanknowles commented Oct 15, 2020

Issue Number

#2247

Overview

This PR adjusts the API selectCoins operation so that:

  • ordinary outputs and change outputs are held in separate fields in the returned selection:

    Field Description
    outputs ordinary payments to external wallets
    change change to be returned to the wallet
  • each change output now has a derivation_path field containing the full derivation path for the change output address.

    The format of this field is identical to the format of the existing derivation_path field of each input.

Click here to see updated API description

separate-change-ouputs

Internal Changes

This PR introduces a ApiCoinSelectionChange type that includes a derivation path:

data ApiCoinSelectionChange (n :: NetworkDiscriminant) = ApiCoinSelectionChange
    { address :: !(ApiT Address, Proxy n)
    , amount :: !(Quantity "lovelace" Natural)
    , derivationPath :: NonEmpty (ApiT DerivationIndex)
    } deriving (Eq, Generic, Show)

In addition, we modify the ApiCoinSelection type so that ordinary outputs (without derivation paths) and change outputs (with derivation paths) are held in separate fields:

data ApiCoinSelection (n :: NetworkDiscriminant) = ApiCoinSelection
    { inputs :: !(NonEmpty (ApiCoinSelectionInput n))
-   , outputs :: !(NonEmpty (AddressAmount (ApiT Address, Proxy n)))
+   , outputs :: !(NonEmpty (ApiCoinSelectionOutput n))
+   , change :: ![ApiCoinSelectionChange n]
    } deriving (Eq, Generic, Show)

Testing

This PR updates the following integration tests:

  • WALLETS_COIN_SELECTION_01.
  • WALLETS_COIN_SELECTION_02.
  • SHELLEY_HW_WALLETS/HW_WALLETS_04.
  • BYRON_HW_WALLETS/HW_WALLETS_04.

@jonathanknowles jonathanknowles force-pushed the jonathanknowles/change-outputs-derivation-paths branch from e2d903e to d15c740 Compare October 15, 2020 03:58
iohk-bors bot added a commit that referenced this pull request Oct 15, 2020
@cardano-foundation cardano-foundation deleted a comment from iohk-bors bot Oct 15, 2020
iohk-bors bot added a commit that referenced this pull request Oct 15, 2020
@jonathanknowles jonathanknowles self-assigned this Oct 15, 2020
@jonathanknowles jonathanknowles added the IMPROVEMENT Mark a PR as an improvement, for auto-generated CHANGELOG label Oct 15, 2020
@paweljakubas

This comment has been minimized.

@jonathanknowles jonathanknowles force-pushed the jonathanknowles/change-outputs-derivation-paths branch from f171225 to 070ebfc Compare October 15, 2020 13:52
-- have been assigned with addresses and are included in the set of ordinary
-- outputs. We use the 'Void' type here to prevent callers from accidentally
-- passing change values into this function:
-> UnsignedTx input output Void
Copy link
Contributor

Choose a reason for hiding this comment

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

for quite a while have not seen Void :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally I wrote this by specifying change ~ Void in the list of constraints, and then specifying UnsignedTx input output change as the parameter type, as I felt that this would be more readable.

However, GHC views this as a redundant constraint. Of course, it's possible to silence the redundant constraint warning, but that would mean silencing this warning for the whole file. So I eventually switched to just writing Void inline, even though it is slightly less readable (IMO).

iohk-bors bot added a commit that referenced this pull request Oct 15, 2020
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/change-outputs-derivation-paths branch from 070ebfc to 77a335f Compare October 16, 2020 06:04
@jonathanknowles

This comment has been minimized.

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

iohk-bors bot commented Oct 16, 2020

try

Build succeeded:

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.

so far lgtm.having a way to derive change and inputs begs for some advanced testing sometime in future: we have a wallet with mnemonic1 with one utxo, and send some money to another one. We can now have a handle to output and change. We re-derive the addresses using derivation paths in cardano-addresses. And use them to create another transaction blob in cardano-transactions. Then send it using external api endpoint and see that it works in integration testing . Maybe @piotr-iohk would be interested in adding such a test sometime in the future:-)

@cardano-foundation cardano-foundation deleted a comment from iohk-bors bot Oct 16, 2020
@jonathanknowles jonathanknowles changed the title WIP: Add derivation paths to coin selection change outputs Add derivation paths to coin selection change outputs Oct 16, 2020
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/change-outputs-derivation-paths branch from 77a335f to 431b2cd Compare October 16, 2020 09:12
@cardano-foundation cardano-foundation deleted a comment from iohk-bors bot Oct 16, 2020
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/change-outputs-derivation-paths branch 7 times, most recently from d0dc17e to b991025 Compare October 19, 2020 10:30
This function is currently only used in contexts where all change outputs
have been assigned with addresses and are included in the set of ordinary
outputs. We use the 'Void' type here to prevent callers from accidentally
passing change values into this function.
Use `Void` type in function `assignMigrationAddresses` to indicate that
no change is returned.
Use this function to factor out common parts of `selectCoinsExternal`.
Before this change we were constructing payment addresses from the stake
key, which remains constant over time.

This resulted in the generation of a constant "payment address" that was
not recognizable as a valid payment address belonging to the wallet,
causing subsequent calls to `isOurs` to fail.
Update integration test `WALLETS_COIN_SELECTION_01` to check that:

- change outputs are listed within the `change` field of an `ApiCoinSelection`.
- change output derivation paths are valid.
Update integration test `WALLETS_COIN_SELECTION_02` to check that the
set of coin selection outputs is exactly the same as intially provided,
rather than being a subset.
Update integration test `SHELLEY_HW_WALLETS/HW_WALLETS_04` to make
multiple payments.

In addition, we expect that the resulting selection will have:

* an output for each of the original payments.
* at least one change output.
Update integration test `BYRON_HW_WALLETS/HW_WALLETS_04` to make
multiple payments.

In addition, we expect that the resulting selection will have:

* an output for each of the original payments.
* at least one change output.
We now expect that there are:

* no ordinary outputs.
* at least one change output.
We now expect that there are:

* no ordinary outputs.
* at least one change output.
We now expect that there are:

* no ordinary outputs.
* at least one change output.
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/change-outputs-derivation-paths branch from 5295989 to ebcfd02 Compare October 21, 2020 05:23
@jonathanknowles
Copy link
Contributor Author

bors try

iohk-bors bot added a commit that referenced this pull request Oct 21, 2020
@jonathanknowles
Copy link
Contributor Author

bors r+

iohk-bors bot added a commit that referenced this pull request Oct 21, 2020
2244: Add derivation paths to coin selection change outputs r=jonathanknowles a=jonathanknowles

# Issue Number

#2247 
  
# Overview

This PR introduces a new `ApiCoinSelectionChange` type that includes a derivation path:

```hs
data ApiCoinSelectionChange (n :: NetworkDiscriminant) = ApiCoinSelectionChange
    { address :: !(ApiT Address, Proxy n)
    , amount :: !(Quantity "lovelace" Natural)
    , derivationPath :: NonEmpty (ApiT DerivationIndex)
    } deriving (Eq, Generic, Show)
```

In addition, we modify the `ApiCoinSelection` type so that ordinary outputs (**_without_** derivation paths) and change outputs (**_with_** derivation paths) are held in separate fields:

```patch

data ApiCoinSelection (n :: NetworkDiscriminant) = ApiCoinSelection
    { inputs :: !(NonEmpty (ApiCoinSelectionInput n))
-   , outputs :: !(NonEmpty (AddressAmount (ApiT Address, Proxy n)))
+   , outputs :: !(NonEmpty (ApiCoinSelectionOutput n))
+   , change :: ![ApiCoinSelectionChange n]
    } deriving (Eq, Generic, Show)

```
# Comments

This PR updates the following integration tests:

- `WALLETS_COIN_SELECTION_01`.
- `WALLETS_COIN_SELECTION_02`.
- `SHELLEY_HW_WALLETS/HW_WALLETS_04`.
- `BYRON_HW_WALLETS/HW_WALLETS_04`.

Co-authored-by: Jonathan Knowles <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Oct 21, 2020

try

Timed out.

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Oct 21, 2020

Timed out.

#2279

@jonathanknowles
Copy link
Contributor Author

bors r+

iohk-bors bot added a commit that referenced this pull request Oct 21, 2020
2244: Add derivation paths to coin selection change outputs r=jonathanknowles a=jonathanknowles

# Issue Number

#2247 
  
# Overview

This PR introduces a new `ApiCoinSelectionChange` type that includes a derivation path:

```hs
data ApiCoinSelectionChange (n :: NetworkDiscriminant) = ApiCoinSelectionChange
    { address :: !(ApiT Address, Proxy n)
    , amount :: !(Quantity "lovelace" Natural)
    , derivationPath :: NonEmpty (ApiT DerivationIndex)
    } deriving (Eq, Generic, Show)
```

In addition, we modify the `ApiCoinSelection` type so that ordinary outputs (**_without_** derivation paths) and change outputs (**_with_** derivation paths) are held in separate fields:

```patch

data ApiCoinSelection (n :: NetworkDiscriminant) = ApiCoinSelection
    { inputs :: !(NonEmpty (ApiCoinSelectionInput n))
-   , outputs :: !(NonEmpty (AddressAmount (ApiT Address, Proxy n)))
+   , outputs :: !(NonEmpty (ApiCoinSelectionOutput n))
+   , change :: ![ApiCoinSelectionChange n]
    } deriving (Eq, Generic, Show)

```
# Comments

This PR updates the following integration tests:

- `WALLETS_COIN_SELECTION_01`.
- `WALLETS_COIN_SELECTION_02`.
- `SHELLEY_HW_WALLETS/HW_WALLETS_04`.
- `BYRON_HW_WALLETS/HW_WALLETS_04`.

2257: API data-types & specifications for arbitrary metadata signing. r=rvl a=KtorZ

# Issue Number

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

ADP-481 > ADP-508

# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

- 209781b
  📍 **define ToText/FromText instances for 'DerivationIndex'**
    I had to also move it in '...Primitive.AddressDerivation' because of otherwise circular dependencies (since this module is using the Bounded instances of 'Index', relying on the 'DerivationType' as type parameter. This is mostly extracting the text parsing that was already done in the JSON instance, and moving it as a ToText/FromText instances (and re-using it to build the JSON instances). I've however added a quick sanity text roundtrip property test in the meantime.

- c965936
  📍 **rename UTxO*ternal -> Utxo*ternal**
    We use the data-type constructor in order to generate text instances.
  However, our automatic casing function is doing pretty bad with the
  mixed cases and we end up with something like:

    - u_tx_o_external
    - u_tx_o_internal
    - mutable_account

  Instead of fixing the instance itself to work around this, I found it
  easier to just fix the type (which isn't used in many places).

- c4cbafe
  📍 **do not output back invalid input when parsing text values.**
    This is a rather bad practice; if a value failed to parse, then we have very little idea about _what_ it is and what's it's shape. It may not be even readable / printable. Instead, the error message should show valid expected options.

- fb5ab0d
  📍 **extend API and specifications to include the 'signMetadata' operation**

# 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: Jonathan Knowles <[email protected]>
Co-authored-by: KtorZ <[email protected]>
Co-authored-by: Rodney Lorrimar <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Oct 21, 2020

This PR was included in a batch that timed out, it will be automatically retried

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Oct 21, 2020

Build succeeded:

@iohk-bors iohk-bors bot merged commit f939d02 into master Oct 21, 2020
@iohk-bors iohk-bors bot deleted the jonathanknowles/change-outputs-derivation-paths branch October 21, 2020 14:30
iohk-bors bot added a commit that referenced this pull request Oct 22, 2020
2261: Update the API specification to reflect the minimum number of inputs returned by `selectCoins`. r=KtorZ a=jonathanknowles

# Issue

Related to #2244.

# Overview

This PR updates the API specification for the `selectCoins` operation, changing the minimum number of inputs from `0` to `1` in the returned coin selection.

This matches the existing `ApiCoinSelection` type, which specifies a `NonEmpty` list of `ApiCoinSelectionInput` values:

```hs
data ApiCoinSelection (n :: NetworkDiscriminant) = ApiCoinSelection
    { inputs :: !(NonEmpty (ApiCoinSelectionInput n))
    , outputs :: ![ApiCoinSelectionOutput n]
    , change :: ![ApiCoinSelectionChange n]
    , certificates :: Maybe (NonEmpty ApiCertificate)
    } deriving (Eq, Generic, Show)
```


Co-authored-by: Jonathan Knowles <[email protected]>
iohk-bors bot added a commit that referenced this pull request Oct 22, 2020
2261: Update the API specification to reflect the minimum number of inputs returned by `selectCoins`. r=KtorZ a=jonathanknowles

# Issue

Related to #2244.

# Overview

This PR updates the API specification for the `selectCoins` operation, changing the minimum number of inputs from `0` to `1` in the returned coin selection.

This matches the existing `ApiCoinSelection` type, which specifies a `NonEmpty` list of `ApiCoinSelectionInput` values:

```hs
data ApiCoinSelection (n :: NetworkDiscriminant) = ApiCoinSelection
    { inputs :: !(NonEmpty (ApiCoinSelectionInput n))
    , outputs :: ![ApiCoinSelectionOutput n]
    , change :: ![ApiCoinSelectionChange n]
    , certificates :: Maybe (NonEmpty ApiCertificate)
    } deriving (Eq, Generic, Show)
```


Co-authored-by: Jonathan Knowles <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IMPROVEMENT Mark a PR as an improvement, for auto-generated CHANGELOG
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants