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

Modify coin selection algorithm to support minting and burning #2725

Merged
merged 40 commits into from
Jul 8, 2021

Commits on Jul 6, 2021

  1. Modify coin selection to support minting and burning

    - Modifies "performSelection" to account for minted and burnt tokens. On a
      superficial level, mints provide extra tokens to use, where burns increase the
      amount of tokens we need to select.
    - Modifies the "makeChange" algorithm to account for minted and burnt tokens.
      When tokens are minted they are added to the largest change bundle. When
      tokens are burnt they are removed from the smallest change bundles until the
      burn has been satisfied. See the code for more detailed commentary.
    - Adds property tests that ensure the "addMintChange" and "removeBurnChange"
      family of functions:
      - maintain number of change bundles,
      - maintain partial ascending ordering of change bundles
      - modify the total value of the change bundle by their respective mint/burn
        amounts.
    - Adds a few unit tests to ensure the change generation occurs as we expect it
      to.
    - Adds some debugging information to the coin selection tests to make debugging
      in the presence of minting and burning easier.
    sevanspowell authored and jonathanknowles committed Jul 6, 2021
    Configuration menu
    Copy the full SHA
    1ce4c75 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    3818c7e View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    ff7a2a6 View commit details
    Browse the repository at this point in the history
  4. Fix errors in commentary

    sevanspowell authored and jonathanknowles committed Jul 6, 2021
    Configuration menu
    Copy the full SHA
    3854bc6 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    4f09d5d View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    9bb91f7 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    66edfcb View commit details
    Browse the repository at this point in the history
  8. Refactor removeBurnValueFromChangeMaps

    - Refactor removeBurnValueFromChangeMaps to make use of the
      "TokenQuantity.difference" and "TokenMap.adjustQuantity" functions, reducing
      the complexity of the implementation (thanks @jonathanknowles).
    sevanspowell authored and jonathanknowles committed Jul 6, 2021
    Configuration menu
    Copy the full SHA
    5093d30 View commit details
    Browse the repository at this point in the history
  9. Simplify TokenMap.difference with new TokenQuantity.difference func

    - Use the new TokenQuantity.difference function to simplify the
      TokenMap.difference implementation (thanks @jonathanknowles).
    sevanspowell authored and jonathanknowles committed Jul 6, 2021
    Configuration menu
    Copy the full SHA
    e6d6d27 View commit details
    Browse the repository at this point in the history
  10. Further refactor "removeBurnValueFromChangeMaps"

    - Further refactor "removeBurnValueFromChangeMaps" to split out the concepts of
      "subtracting a value from a list of values" and "using that new list to modify
      the quantities of an existing token map". Thanks @jonathanknowles.
    sevanspowell authored and jonathanknowles committed Jul 6, 2021
    Configuration menu
    Copy the full SHA
    ecde5a9 View commit details
    Browse the repository at this point in the history
  11. Styling

    sevanspowell authored and jonathanknowles committed Jul 6, 2021
    Configuration menu
    Copy the full SHA
    52503e6 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    5ed7da6 View commit details
    Browse the repository at this point in the history
  13. Fix indentation, use monoid operator

    Co-authored-by: Jonathan Knowles <[email protected]>
    sevanspowell and jonathanknowles committed Jul 6, 2021
    Configuration menu
    Copy the full SHA
    e646a26 View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    ebd57d3 View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    810ee61 View commit details
    Browse the repository at this point in the history
  16. Use scanl and treat generated qtys as diffs to get asc partial order

    - Thanks to @jonathanknowles for this great suggestion.
    sevanspowell authored and jonathanknowles committed Jul 6, 2021
    Configuration menu
    Copy the full SHA
    1f9a363 View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    7890bd7 View commit details
    Browse the repository at this point in the history
  18. Configuration menu
    Copy the full SHA
    93109fd View commit details
    Browse the repository at this point in the history

Commits on Jul 8, 2021

  1. Configuration menu
    Copy the full SHA
    0ef7c04 View commit details
    Browse the repository at this point in the history
  2. Minimize the responsibility of makeChangeForNonUserSpecifiedOutputs.

    This change moves the following responsibilities out of the
    `makeChangeForNonUserSpecifiedOutputs` function:
    
        - the removing of burned values
        - the addition of minted values
    
    This reduces the complexity of property and unit tests that test this
    function.
    
    The following functions are still checked by relevant properties:
    
        - `addMintValuesToChangeMaps`
        - `removeBurnValuesFromChangeMaps`
    
    Further changes will add unit tests to act as documentation and sanity
    checks for the above functions.
    jonathanknowles committed Jul 8, 2021
    Configuration menu
    Copy the full SHA
    44a6a89 View commit details
    Browse the repository at this point in the history
  3. Improve documentation for minting and burning.

    This commit clarifies documentation and adds explanatory examples for
    several functions and fields relating to minting and burning.
    jonathanknowles committed Jul 8, 2021
    Configuration menu
    Copy the full SHA
    16ad726 View commit details
    Browse the repository at this point in the history
  4. Make missingOutputAssets resilient to changes in `OutputsInsufficie…

    …ntError`.
    
    We replace positional arguments with named arguments. (These arguments
    are all the same type, so can easily be switched.)
    jonathanknowles committed Jul 8, 2021
    Configuration menu
    Copy the full SHA
    c1f46e6 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    47ad1e2 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    a941675 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    4657ea6 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    35ec8b9 View commit details
    Browse the repository at this point in the history
  9. Simplify folds in {addMint,removeBurn}values{To,From}ChangeMaps.

    We remove the nested function composition in favour of simple function
    composition.
    jonathanknowles committed Jul 8, 2021
    Configuration menu
    Copy the full SHA
    a44880e View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    36e4cce View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    902b75c View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    93c8948 View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    28ba0a7 View commit details
    Browse the repository at this point in the history
  14. Introduce minimal API change to support minting and burning error.

    This error should currently never be thrown, as we do not currently
    provide a method for the user to mint or burn tokens through the API.
    
    Nevertheless, our test suite requires that we document the error in our
    API specification.
    jonathanknowles committed Jul 8, 2021
    Configuration menu
    Copy the full SHA
    5a10b15 View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    18be06b View commit details
    Browse the repository at this point in the history
  16. Add the TokenMap.intersection function.

    This function will be used to verify coverage in coin selection
    properties.
    jonathanknowles committed Jul 8, 2021
    Configuration menu
    Copy the full SHA
    4b38d41 View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    b02cb1a View commit details
    Browse the repository at this point in the history
  18. Enhance the generators for minted and burned assets in `genSelectionC…

    …riteria`.
    
    In particular, we add coverage for the case where some minted values are
    not spent or burned, so we can trigger the `OutputsInsufficient` error.
    jonathanknowles committed Jul 8, 2021
    Configuration menu
    Copy the full SHA
    5b58f1b View commit details
    Browse the repository at this point in the history
  19. Fix erroneous assertion in onOutputsInsufficient.

    This assertion should have been negated.
    
    The error was only revealed once we had deliberately tweaked the
    generator to generate selection criteria with some minted values
    that are not spent or burned.
    jonathanknowles committed Jul 8, 2021
    Configuration menu
    Copy the full SHA
    4d22d58 View commit details
    Browse the repository at this point in the history
  20. Configuration menu
    Copy the full SHA
    8eb87a8 View commit details
    Browse the repository at this point in the history
  21. Configuration menu
    Copy the full SHA
    96b6a75 View commit details
    Browse the repository at this point in the history
  22. Add missing coverage for prop_makeChange.

    In the `genAssetsToMintAndBurn` subgenerator for `genMakeChangeData`, we
    deliberately create the possibliity of a non-empty intersection between
    the sets of assets to mint and assets to burn.
    jonathanknowles committed Jul 8, 2021
    Configuration menu
    Copy the full SHA
    378d35f View commit details
    Browse the repository at this point in the history