-
Notifications
You must be signed in to change notification settings - Fork 217
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
Allow callers of selectAssets
to specify seed for random selection.
#3014
Allow callers of selectAssets
to specify seed for random selection.
#3014
Conversation
aef175c
to
5f6802c
Compare
5f6802c
to
b7ebcad
Compare
Looks good 🙂 I think my one niggle is that selectAssets is parameterised by the generator twice, once with the MonadRandom constraint, and again with the randomSeed in SelectAssetsParams . From the outside perspective it's unclear what generator is used in what circumstance.
That is to say, selectAssets is already parameterised by a seed (actually a generator, but equivalent), and so there is no need to change the API to selectAssets. We just need to get the seed in from the HTTP API to the call to selectAssets (where necessary):
(I'm simplifying the code a bit there) |
I've heavily investigated this option (my suggestion), but it was hampered by compiler errors caused by our prevalent use of typeclasses (in the form of "capabilities") and generic-lens. |
This module provides functions and types that extend those provided by the `Control.Monad.Random` module hierarchy.
This module provides functions and types that extend functionality provided by the `aeson` package.
This change replaces the use of the `Identity` type with the `NonRandom` type in contexts that require non-randomness. As a result, we can remove the orphan instance of `MonadRandom` for `Identity`.
This will allow the `selectAssets` function to manipulate the state of the random number generator associated with the `MonadRandom` context, allowing it to read and write the seed used for random number generation.
This will allow callers of `selectAssets` to optionally specify a seed value, to be used by the random number generator when performing random selection.
With this change, we can run coin selection with a random number generator seeded with a seed specified by the caller. If no seed is specified by the caller, then we use the `MonadRandom` context to provide us with a seed.
This class is no longer necessary, now that we are using `evalRand` within `selectAssets`.
This function creates a new `StdGenSeed` from within a random monadic context.
b7ebcad
to
39ea80f
Compare
Thanks for investigating this @sevanspowell. I completely agree with your sentiments here. Perhaps we can view this PR as a starting point, and merge it as-is, but continue to improve on this incrementally with future PRs, if/when we figure out a better way to achieve what we want. To make things clearer for now, I've added some commentary to |
Issue Number
ADP-1257
Summary
This PR makes it possible for callers of
selectAssets
to specify a seed for random selection.Ultimately, it will be possible to specify a seed through the API, but this PR does not make any changes to the API. That part is left to future PRs.
Details
This PR adds the following field to
SelectAssetParams
:data SelectAssetsParams s result = SelectAssetsParams { outputs :: [TxOut] , pendingTxs :: Set Tx + , randomSeed :: Maybe StdGenSeed , txContext :: TransactionCtx , utxoAvailableForCollateral :: UTxO , utxoAvailableForInputs :: UTxOSelection , wallet :: Wallet s }
Additionally, this PR:
StdGenSeed
, which is interconvertible withStdGen
, but provides a representation that is more convenient for construction and serialization.StdGenSeed
.