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

Remove hard-coded dependency on txOutMax{Coin,TokenQuantity} within coin selection modules #3197

Conversation

jonathanknowles
Copy link
Contributor

@jonathanknowles jonathanknowles commented Mar 23, 2022

Issue Number

ADP-1481

Summary

This PR adjusts the internal coin selection modules so that they no longer depend on hard-coded maximum token quantity constants imported from the wallet.

Instead, these constants are now passed in to coin selection as part of SelectionConstraints.

  data SelectionConstraints ctx = SelectionConstraints
      { ...
+     , outputMaximumAdaQuantity
+        :: Coin
+     , outputMaximumTokenQuantity
+        :: TokenQuantity
      , ...
      }

There is no impact on the wallet itself, since these dependencies are injected in automatically by the Cardano.Wallet.CoinSelection module, which provides a wallet-friendly interface to coin selection.

Future Work

We intend to eventually adjust coin selection so that it does not discriminate between ada and non-ada quantities. (See https://input-output.atlassian.net/browse/ADP-1449). When that moment comes, we may want to replace these two constants with a function similar to:

 data SelectionConstraints ctx = SelectionConstraints
     { ...
-    , outputMaximumAdaQuantity
-       :: Coin
-    , outputMaximumTokenQuantity
-       :: TokenQuantity
+    , outputMaximumTokenQuantity
+        :: Asset ctx -> TokenQuantity 
     , ...
     }

Then, callers of coin selection can provide a function that meets their requirements. If the requirement is still to have different limits for ada and non-ada quantities, then this can be encoded in the function.

Or, if we can get away with a single limit for all asset types (including ada), then we can reduce this to a single constant.

@jonathanknowles jonathanknowles self-assigned this Mar 23, 2022
@jonathanknowles jonathanknowles changed the title Remove hard-coded dependency on txOutMax{Coin,TokenQuantity} from coin selection Remove hard-coded dependency on txOutMax{Coin,TokenQuantity} from Coin Selection Mar 23, 2022
@jonathanknowles jonathanknowles changed the title Remove hard-coded dependency on txOutMax{Coin,TokenQuantity} from Coin Selection Remove hard-coded dependency on txOutMax{Coin,TokenQuantity} within coin selection modules Mar 23, 2022
Copy link
Member

@Anviking Anviking left a comment

Choose a reason for hiding this comment

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

👍

@Anviking
Copy link
Member

Anviking commented Mar 23, 2022

Actually, wouldn't it be better to hard-code these inside coin-selection?

As long as coin-selection is specific to the Cardano blockchain (and as long they the two fields are not added to the PParams), there would be no need for any kind of user to provide any different value, right?

@Anviking
Copy link
Member

Ah, it seems you want to be able to vary these for testing, which seems like a good reason. But when we create the main interface for the haskell+cardano-api-dependent coin-selection library, I think we should ensure these two fields are not part of it. (This might trivially end up being the case, if we take a Cardano.ProtocolParameters as an argument rather than SelectionConstraints)

@jonathanknowles
Copy link
Contributor Author

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Mar 23, 2022

Build succeeded:

@iohk-bors iohk-bors bot merged commit ace5058 into master Mar 23, 2022
@iohk-bors iohk-bors bot deleted the jonathanknowles/move-maximum-output-quantities-to-selection-constraints branch March 23, 2022 23:55
WilliamKingNoel-Bot pushed a commit that referenced this pull request Mar 23, 2022
@jonathanknowles
Copy link
Contributor Author

Ah, it seems you want to be able to vary these for testing, which seems like a good reason. But when we create the main interface for the haskell+cardano-api-dependent coin-selection library, I think we should ensure these two fields are not part of it.

Definitely, that was also my thinking. 👍🏻

This PR is just so that the internal coin selection modules:

  • don't need to depend on hard-coded constants imported from elsewhere
  • can have tests that vary these constants (if necessary) to provide better coverage

For example, it might be nice to generate smaller values to provoke the splitting of token bundles more frequently, to check that properties still hold.

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