Skip to content

Commit e559618

Browse files
committed
Improve the algorithm to find low commits
Signed-off-by: Sasha Bogicevic <[email protected]>
1 parent 95aa81f commit e559618

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

hydra-node/src/Hydra/Chain/Direct/Handlers.hs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,19 @@ mkChain tracer queryTimeHandle wallet ctx LocalChainState{getLatest} submitTx =
209209
rejectLowDeposits :: PParams LedgerEra -> UTxO.UTxO -> Either (PostTxError Tx) ()
210210
rejectLowDeposits pparams utxo = do
211211
let insAndOuts = UTxO.toList utxo
212-
let providedValues = UTxO.totalLovelace . uncurry UTxO.singleton <$> insAndOuts
213-
let minimumValue = List.maximum $ (\(_, o) -> calculateMinimumUTxO shelleyBasedEra pparams $ fromCtxUTxOTxOut o) <$> insAndOuts
214-
case List.find (< minimumValue) providedValues of
215-
Nothing -> Right ()
216-
Just providedValue ->
217-
Left (DepositTooLow{providedValue, minimumValue} :: PostTxError Tx)
212+
let providedValues = (\(i, o) -> (i, UTxO.totalLovelace $ UTxO.singleton i o)) <$> insAndOuts
213+
let minimumValues = (\(i, o) -> (i, calculateMinimumUTxO shelleyBasedEra pparams $ fromCtxUTxOTxOut o)) <$> insAndOuts
214+
let results =
215+
( \(i, minVal) ->
216+
case List.find (\(ix, providedVal) -> i == ix && providedVal < minVal) providedValues of
217+
Nothing -> Right ()
218+
Just (_, tooLowValue) ->
219+
Left (DepositTooLow{providedValue = tooLowValue, minimumValue = minVal} :: PostTxError Tx)
220+
)
221+
<$> minimumValues
222+
case lefts results of
223+
[] -> pure ()
224+
(e : _) -> Left e
218225

219226
-- | Balance and sign the given partial transaction.
220227
finalizeTx ::

hydra-node/test/Hydra/API/HTTPServerSpec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ apiServerSpec = do
472472
case result of
473473
Left DepositTooLow{providedValue, minimumValue} ->
474474
property $
475-
minimumValue > providedValue
475+
minimumValue >= providedValue
476476
& counterexample ("Minimum value: " <> show minimumValue <> " Provided value: " <> show providedValue)
477477
_ -> property True
478478

0 commit comments

Comments
 (0)