-
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
Random input selection impl #140
Conversation
pure res | ||
|
||
|
||
-- Selecting coins to cover at least the specified value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how I understand how this algorithm operates
withIx m' ix = Just (Map.elemAt ix m', Map.deleteAt ix m') | ||
|
||
|
||
instance MonadRandom m => MonadRandom (ExceptT e m) where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need this unfortunately
720a1dc
to
b5de826
Compare
b5de826
to
c672899
Compare
}) | ||
|
||
describe "Coin selection properties : Random algorithm" $ do | ||
xit "forall (UTxO, NonEmpty TxOut), \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it stucks when random
is called, probably because of wrong impl of MonadRandom instance of Identity at the end of this file
<*> vectorOf n arbitrary | ||
return $ UTxO $ Map.fromList utxo | ||
|
||
instance MonadRandom Identity where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is probably wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it makes sense to me that this will loop forever. On the right side you are calling the same getRandomBytes
defined in the instance MonadRandom Identity
, with the same params.
Looking at https://www.stackage.org/haddock/lts-13.15/cryptonite-0.25/Crypto-Random-Types.html what I believe you should have aimed for is to use one of two implementations of class DRG
(from the same module) for implementation of MonadRandom Identity
as you would like to use some deterministic pseudo random generator in this pure code.
I can have a closer look later and experiment if this doesn't give any clue (hope its the right one)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @akegalj for the comment. Indeed, random monad within random algo needs more effects power than the monad within largestFirst. there is a need of more effects to enable randomness - be in IO or have initial seed/generator.
$ NE.sortBy (flip $ comparing coin) txOutputs | ||
let n = maximumNumberOfInputs opt | ||
|
||
let moneyRequested = sum $ (getCoin . coin) <$> txOutputsSorted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think parens can be dropped here
sum $ getCoin . coin <$> txOutputsSorted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
<*> vectorOf n arbitrary | ||
return $ UTxO $ Map.fromList utxo | ||
|
||
instance MonadRandom Identity where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it makes sense to me that this will loop forever. On the right side you are calling the same getRandomBytes
defined in the instance MonadRandom Identity
, with the same params.
Looking at https://www.stackage.org/haddock/lts-13.15/cryptonite-0.25/Crypto-Random-Types.html what I believe you should have aimed for is to use one of two implementations of class DRG
(from the same module) for implementation of MonadRandom Identity
as you would like to use some deterministic pseudo random generator in this pure code.
I can have a closer look later and experiment if this doesn't give any clue (hope its the right one)
cd287bd
to
939f3f6
Compare
resigned from using |
fc03426
to
328976e
Compare
-- step.) | ||
-- | ||
-- 2. Randomly select outputs from the UTxO, considering for each output if that | ||
-- output is animprovement. If it is, add it to the transaction, and keep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
animprovement -> an improvement
targetAim <- | ||
if isValidCoin (Coin $ 2*v) then Just (Coin $ 2*v) else Nothing | ||
targetMax <- | ||
if isValidCoin (Coin $ 3*v) then Just (Coin $ 3*v) else Nothing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are not afraid of situation that for instance targetMax will exceed upperBound of what Coin can have???
Add NotEnoughMoney and UtxoNotEnoughFragmented errors
Don't use Identity with MonadRandom Fix maxNumberOfInput in propertyFragmentation Hush hlint
We don't need these various targets to be 'Coin', some may actually not be; in the end, we will select several coins, so it's not impossible that the sum of their value will overflow the max coin value. In the rare case this would happen, we can simply fallback to splitting the output into two change coins.
I found calling the latter 'atLeast' quite confusing with the 'largestFirst' algorithm.
fd04299
to
a5bddd3
Compare
Issue Number
#92
Overview
Comments