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

Provide integrated coin selection module #2859

Merged
merged 24 commits into from
Aug 30, 2021

Conversation

jonathanknowles
Copy link
Contributor

@jonathanknowles jonathanknowles commented Aug 29, 2021

Issue Numbers

Overview

This PR is intended to be a pure refactoring, with no behavioural changes.

It provides a basis for future work, including:

  • adjusting coin selection and fee estimation to handle collateral inputs (ADP-1037).
  • adjusting coin selection and fee estimation to handle pre-existing inputs (ADP-1070).

Details

This PR makes the following changes:

  • Adds a top-level CoinSelection module with a performSelection function. This function currently just delegates to the ordinary input selection algorithm, but will eventually provide the machinery to co-ordinate both ordinary input selection (CoinSelection.Balance) and collateral input selection (CoinSelection.Collateral).

  • Adjusts Wallet.selectAssets to use the top-level CoinSelection.performSelection function.

  • Moves the prepareOutputs function (preparing user-specified outputs) out of the TransactionLayer and into the top-level CoinSelection module. (Arguably this should never have been in the transaction layer, as it is only relevant to coin selection.)

  • Creates a SelectionConstraints type, which groups together all constraint functions (functions that are dependent on protocol parameters) relevant to coin selection into a single place:

    data SelectionConstraints = SelectionConstraints
        { assessTokenBundleSize
            :: TokenBundleSizeAssessor
        , computeMinimumAdaQuantity
            :: TokenMap -> Coin
        , computeMinimumCost
            :: SelectionSkeleton -> Coin
        , computeSelectionLimit
            :: [TxOut] -> SelectionLimit
        , maximumCollateralInputCount
            :: Word16
        }

@jonathanknowles jonathanknowles self-assigned this Aug 29, 2021
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/integrated-coin-selection branch 2 times, most recently from eea5926 to 64f1bf7 Compare August 30, 2021 01:30
Use `Integrated.performSelection` from `Cardano.Wallet`.
Use this type within `Cardano.Wallet` when calling `performSelection`.
Use this type within `Cardano.Wallet` when calling `performSelection`.
This value is passed in, only to be returned without any modification.
…ter.

This is consistent with the name of the protocol parameter in our API.
This refers to a transaction context, rather than a transaction.
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/integrated-coin-selection branch from 64f1bf7 to eaf3fdb Compare August 30, 2021 01:31
@jonathanknowles jonathanknowles changed the title Provide integrated coin selection layer Provide integrated coin selection module Aug 30, 2021
@jonathanknowles jonathanknowles marked this pull request as ready for review August 30, 2021 03:04
This commit makes some minor tweaks to names:

  - module `CoinSelection.Integrated`     -> `CoinSelection`
  - module `CoinSelection.Balanced`       -> `CoinSelection.Balance`
  - type   `CoinSelection.SelectionData`  -> `CoinSelection.SelectionParams`
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/integrated-coin-selection branch from eaf3fdb to d64662d Compare August 30, 2021 05:10
@jonathanknowles jonathanknowles force-pushed the jonathanknowles/integrated-coin-selection branch from d64662d to 20f3c18 Compare August 30, 2021 05:12
@jonathanknowles
Copy link
Contributor Author

bors r+

iohk-bors bot added a commit that referenced this pull request Aug 30, 2021
2859: Provide integrated coin selection module r=jonathanknowles a=jonathanknowles

## Issue Numbers

- ADP-1037
- ADP-1070

## Overview

This PR is intended to be a **_pure refactoring_**, with no behavioural changes.

It provides a **basis for future work**, including:
- adjusting coin selection and fee estimation to handle collateral inputs (ADP-1037).
- adjusting coin selection and fee estimation to handle pre-existing inputs (ADP-1070).

## Details

This PR makes the following changes:

- Adds a top-level `CoinSelection` module with a `performSelection` function. This function currently just _delegates_ to the ordinary input selection algorithm, but will eventually provide the machinery to co-ordinate **_both_** ordinary input selection (`CoinSelection.Balance`) **_and_** collateral input selection (`CoinSelection.Collateral`).

- Adjusts `Wallet.selectAssets` to use the top-level `CoinSelection.performSelection` function.

- Moves the `prepareOutputs` function (preparing user-specified outputs) **_out of_** the `TransactionLayer` and **_into_** the top-level `CoinSelection` module. (Arguably this should never have been in the transaction layer, as it is only relevant to coin selection.)

- Creates a `SelectionConstraints` type, which groups together all constraint functions (functions that are dependent on protocol parameters) relevant to coin selection into a single place:
  ```hs
  data SelectionConstraints = SelectionConstraints
      { assessTokenBundleSize
          :: TokenBundleSizeAssessor
      , computeMinimumAdaQuantity
          :: TokenMap -> Coin
      , computeMinimumCost
          :: SelectionSkeleton -> Coin
      , computeSelectionLimit
          :: [TxOut] -> SelectionLimit
      , maximumCollateralInputCount
          :: Word16
      }
  ```




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

iohk-bors bot commented Aug 30, 2021

Build failed:

#2861

@jonathanknowles
Copy link
Contributor Author

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Aug 30, 2021

Build succeeded:

@iohk-bors iohk-bors bot merged commit 4325bf2 into master Aug 30, 2021
@iohk-bors iohk-bors bot deleted the jonathanknowles/integrated-coin-selection branch August 30, 2021 09:16
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.

2 participants