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 the SelectionStrategy type. #3161

Merged
merged 9 commits into from
Mar 4, 2022
Merged

Conversation

jonathanknowles
Copy link
Member

@jonathanknowles jonathanknowles commented Mar 4, 2022

Issue Number

ADP-1499

Summary

This PR is intended to be a pure refactoring, with no changes to behaviour. It adds the SelectionStrategy type to the coin selection library, which will eventually be defined as:

data SelectionStrategy
    = SelectionStrategyMinimal
    | SelectionStrategyOptimal

This PR adds only the SelectionStrategyOptimal constructor: this strategy corresponds to the existing behaviour of coin selection.

A future PR will add the SelectionStrategyMinimal constructor, along with appropriate test coverage.

Explanation

These two strategies are intended to correspond to the following behaviours:

  • Specifying the optimal strategy (currently the default) should cause the coin selection algorithm to attempt to select around twice the minimum possible amount of each asset from the available UTxO set, making it possible to generate change outputs that are roughly the same sizes and shapes as the user-specified outputs.

  • Specifying the minimal strategy should cause the coin selection algorithm to select just enough of each asset from the available UTxO set to meet the minimum amount. When the minimum amount of each asset is satisfied, coin selection should terminate. This strategy, if used frequently, may sacrifice the long-term health of the wallet’s UTxO distribution, as it’s likely to produce a greater concentration of dust values. Therefore, it should only be used as a fallback: i.e., if using the optimal strategy produces a selection that is too large.

Fixes:

  - Use 4-space indents everywhere instead of other indent widths.
  - Coalesce lines that don't need to be wrapped.
  - Shorten excessively-long lines to fit within the 80 column limit
    (where practical).
…onLens`.

To begin with, we give this type just a single constructor:

`SelectionStrategyOptimal`.
Additionally, adjust `runSelection` to pass the value of this field
through to inner functions.
Additionally, adjust `performSelection` to pass the value of this field
through to inner functions.
…straints`.

Additionally, adjust `toBalanceConstraintsParams` to pass the value of
this field through to inner functions.
…raints`.

Additionally, adjust `toInternalSelectionConstraints` to pass the value of
this field through to inner functions.
Additionally, adjust `selectAssets` to pass the value of this field
through to inner functions.
@jonathanknowles jonathanknowles self-assigned this Mar 4, 2022
@jonathanknowles jonathanknowles marked this pull request as ready for review March 4, 2022 06:45
@Anviking
Copy link
Member

Anviking commented Mar 4, 2022

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Mar 4, 2022

Build succeeded:

@iohk-bors iohk-bors bot merged commit bedd151 into master Mar 4, 2022
@iohk-bors iohk-bors bot deleted the jonathanknowles/selection-strategy branch March 4, 2022 14:22
WilliamKingNoel-Bot pushed a commit that referenced this pull request Mar 4, 2022
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