From df195073d7bc7d349a973d0b22286f87ef8449cf Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 18 Apr 2024 04:26:34 +0000 Subject: [PATCH 01/18] Move `adjustedPartialTx` to `where` clause and add type signature. --- .../lib/internal/Internal/Cardano/Write/Tx/Balance.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs index 54a47bbdc60..c2096943c37 100644 --- a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs +++ b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs @@ -531,9 +531,7 @@ balanceTransaction s partialTx = do - let adjustedPartialTx = flip (over #tx) partialTx $ - assignMinimalAdaQuantitiesToOutputsWithoutAda pp - balanceWith strategy = + let balanceWith strategy = balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment pp timeTranslation @@ -549,6 +547,10 @@ balanceTransaction then balanceWith SelectionStrategyMinimal else throwE e where + adjustedPartialTx :: PartialTx era + adjustedPartialTx = flip (over #tx) partialTx $ + assignMinimalAdaQuantitiesToOutputsWithoutAda pp + -- Determines whether or not the minimal selection strategy is worth trying. -- This depends upon the way in which the optimal selection strategy failed. minimalStrategyIsWorthTrying :: ErrBalanceTx era -> Bool From 3d60b8617163901a757a802fb5b46ab095b235ac Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 18 Apr 2024 04:28:48 +0000 Subject: [PATCH 02/18] Move `balanceWith` to `where` clause and add type signature. --- .../Internal/Cardano/Write/Tx/Balance.hs | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs index c2096943c37..e8bfba6d571 100644 --- a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs +++ b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs @@ -531,16 +531,6 @@ balanceTransaction s partialTx = do - let balanceWith strategy = - balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment - pp - timeTranslation - utxoAssumptions - utxo - genChange - s - strategy - adjustedPartialTx balanceWith SelectionStrategyOptimal `catchE` \e -> if minimalStrategyIsWorthTrying e @@ -551,6 +541,20 @@ balanceTransaction adjustedPartialTx = flip (over #tx) partialTx $ assignMinimalAdaQuantitiesToOutputsWithoutAda pp + balanceWith + :: SelectionStrategy + -> ExceptT (ErrBalanceTx era) m (Tx era, changeState) + balanceWith strategy = + balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment + pp + timeTranslation + utxoAssumptions + utxo + genChange + s + strategy + adjustedPartialTx + -- Determines whether or not the minimal selection strategy is worth trying. -- This depends upon the way in which the optimal selection strategy failed. minimalStrategyIsWorthTrying :: ErrBalanceTx era -> Bool From 257a151605d20609fea861a023797259eee5391b Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 18 Apr 2024 04:29:08 +0000 Subject: [PATCH 03/18] Move `guardExistingCollateral` out of inner helper function. --- .../Internal/Cardano/Write/Tx/Balance.hs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs index e8bfba6d571..656592f63d6 100644 --- a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs +++ b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs @@ -531,6 +531,7 @@ balanceTransaction s partialTx = do + guardExistingCollateral balanceWith SelectionStrategyOptimal `catchE` \e -> if minimalStrategyIsWorthTrying e @@ -555,6 +556,16 @@ balanceTransaction strategy adjustedPartialTx + guardExistingCollateral :: ExceptT (ErrBalanceTx era) m () + guardExistingCollateral = do + -- Coin selection does not support pre-defining collateral. In Sep 2021 + -- consensus was that we /could/ allow for it with just a day's work or + -- so, but that the need for it was unclear enough that it was not in + -- any way a priority. + let collIns = partialTx ^. #tx . bodyTxL . collateralInputsTxBodyL + unless (null collIns) $ + throwE ErrBalanceTxExistingCollateral + -- Determines whether or not the minimal selection strategy is worth trying. -- This depends upon the way in which the optimal selection strategy failed. minimalStrategyIsWorthTrying :: ErrBalanceTx era -> Bool @@ -647,7 +658,6 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment selectionStrategy partialTx@PartialTx {extraUTxO, redeemers, timelockKeyWitnessCounts} = do - guardExistingCollateral guardExistingTotalCollateral guardExistingReturnCollateral guardUTxOConsistency @@ -904,16 +914,6 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment left ErrBalanceTxAssignRedeemers $ assignScriptRedeemers pp timeTranslation combinedUTxO redeemers tx' - guardExistingCollateral :: ExceptT (ErrBalanceTx era) m () - guardExistingCollateral = do - -- Coin selection does not support pre-defining collateral. In Sep 2021 - -- consensus was that we /could/ allow for it with just a day's work or - -- so, but that the need for it was unclear enough that it was not in - -- any way a priority. - let collIns = partialTx ^. #tx . bodyTxL . collateralInputsTxBodyL - unless (null collIns) $ - throwE ErrBalanceTxExistingCollateral - guardExistingTotalCollateral :: ExceptT (ErrBalanceTx era) m () guardExistingTotalCollateral = do let totColl = partialTx ^. #tx . bodyTxL . totalCollateralTxBodyL From d35e1cdae3080e0f31d78cf7afa75d29ea0a9505 Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 18 Apr 2024 05:15:06 +0000 Subject: [PATCH 04/18] Move `guardExistingTotalCollateral` out of inner helper function. --- .../Internal/Cardano/Write/Tx/Balance.hs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs index 656592f63d6..877a37a7538 100644 --- a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs +++ b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs @@ -532,6 +532,7 @@ balanceTransaction partialTx = do guardExistingCollateral + guardExistingTotalCollateral balanceWith SelectionStrategyOptimal `catchE` \e -> if minimalStrategyIsWorthTrying e @@ -566,6 +567,13 @@ balanceTransaction unless (null collIns) $ throwE ErrBalanceTxExistingCollateral + guardExistingTotalCollateral :: ExceptT (ErrBalanceTx era) m () + guardExistingTotalCollateral = do + let totColl = partialTx ^. #tx . bodyTxL . totalCollateralTxBodyL + case totColl of + SNothing -> return () + SJust _ -> throwE ErrBalanceTxExistingTotalCollateral + -- Determines whether or not the minimal selection strategy is worth trying. -- This depends upon the way in which the optimal selection strategy failed. minimalStrategyIsWorthTrying :: ErrBalanceTx era -> Bool @@ -658,7 +666,6 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment selectionStrategy partialTx@PartialTx {extraUTxO, redeemers, timelockKeyWitnessCounts} = do - guardExistingTotalCollateral guardExistingReturnCollateral guardUTxOConsistency @@ -914,13 +921,6 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment left ErrBalanceTxAssignRedeemers $ assignScriptRedeemers pp timeTranslation combinedUTxO redeemers tx' - guardExistingTotalCollateral :: ExceptT (ErrBalanceTx era) m () - guardExistingTotalCollateral = do - let totColl = partialTx ^. #tx . bodyTxL . totalCollateralTxBodyL - case totColl of - SNothing -> return () - SJust _ -> throwE ErrBalanceTxExistingTotalCollateral - guardExistingReturnCollateral :: ExceptT (ErrBalanceTx era) m () guardExistingReturnCollateral = do let collRet = partialTx ^. #tx . bodyTxL . collateralReturnTxBodyL From 6f52b24eb6fe0ce0c6a31c17d47326623fd01f6e Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 18 Apr 2024 05:16:15 +0000 Subject: [PATCH 05/18] Move `guardExistingReturnCollateral` out of inner helper function. --- .../Internal/Cardano/Write/Tx/Balance.hs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs index 877a37a7538..d9386bd8697 100644 --- a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs +++ b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs @@ -532,6 +532,7 @@ balanceTransaction partialTx = do guardExistingCollateral + guardExistingReturnCollateral guardExistingTotalCollateral balanceWith SelectionStrategyOptimal `catchE` \e -> @@ -567,6 +568,13 @@ balanceTransaction unless (null collIns) $ throwE ErrBalanceTxExistingCollateral + guardExistingReturnCollateral :: ExceptT (ErrBalanceTx era) m () + guardExistingReturnCollateral = do + let collRet = partialTx ^. #tx . bodyTxL . collateralReturnTxBodyL + case collRet of + SNothing -> return () + SJust _ -> throwE ErrBalanceTxExistingReturnCollateral + guardExistingTotalCollateral :: ExceptT (ErrBalanceTx era) m () guardExistingTotalCollateral = do let totColl = partialTx ^. #tx . bodyTxL . totalCollateralTxBodyL @@ -666,7 +674,6 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment selectionStrategy partialTx@PartialTx {extraUTxO, redeemers, timelockKeyWitnessCounts} = do - guardExistingReturnCollateral guardUTxOConsistency (balance0, minfee0, _) <- balanceAfterSettingMinFee (partialTx ^. #tx) @@ -921,13 +928,6 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment left ErrBalanceTxAssignRedeemers $ assignScriptRedeemers pp timeTranslation combinedUTxO redeemers tx' - guardExistingReturnCollateral :: ExceptT (ErrBalanceTx era) m () - guardExistingReturnCollateral = do - let collRet = partialTx ^. #tx . bodyTxL . collateralReturnTxBodyL - case collRet of - SNothing -> return () - SJust _ -> throwE ErrBalanceTxExistingReturnCollateral - -- | Select assets to cover the specified balance and fee. -- -- If the transaction contains redeemers, the function will also ensure the From 291aa722a67761a56629ff56565895564ca89083 Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 18 Apr 2024 05:28:12 +0000 Subject: [PATCH 06/18] Move `guardUTxOConsistency` out of inner helper function. --- .../Internal/Cardano/Write/Tx/Balance.hs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs index d9386bd8697..153e0cca047 100644 --- a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs +++ b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs @@ -526,14 +526,15 @@ balanceTransaction pp timeTranslation utxoAssumptions - utxo + utxo@UTxOIndex {availableUTxO} genChange s - partialTx + partialTx@PartialTx {extraUTxO} = do guardExistingCollateral guardExistingReturnCollateral guardExistingTotalCollateral + guardUTxOConsistency balanceWith SelectionStrategyOptimal `catchE` \e -> if minimalStrategyIsWorthTrying e @@ -582,6 +583,21 @@ balanceTransaction SNothing -> return () SJust _ -> throwE ErrBalanceTxExistingTotalCollateral + -- | Ensures that the given UTxO sets are consistent with one another. + -- + -- They are not consistent iff an input can be looked up in both UTxO sets + -- with different @Address@, or @TokenBundle@ values. + -- + guardUTxOConsistency :: ExceptT (ErrBalanceTx era) m () + guardUTxOConsistency = + case NE.nonEmpty (F.toList (conflicts extraUTxO availableUTxO)) of + Just cs -> throwE $ ErrBalanceTxInputResolutionConflicts cs + Nothing -> return () + where + conflicts :: UTxO era -> UTxO era -> Map TxIn (TxOut era, TxOut era) + conflicts = Map.conflictsWith ((/=) `on` toWalletTxOut era) `on` unUTxO + era = recentEra @era + -- Determines whether or not the minimal selection strategy is worth trying. -- This depends upon the way in which the optimal selection strategy failed. minimalStrategyIsWorthTrying :: ErrBalanceTx era -> Bool @@ -674,8 +690,6 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment selectionStrategy partialTx@PartialTx {extraUTxO, redeemers, timelockKeyWitnessCounts} = do - guardUTxOConsistency - (balance0, minfee0, _) <- balanceAfterSettingMinFee (partialTx ^. #tx) (extraInputs, extraCollateral', extraOutputs, s') <- do @@ -893,20 +907,6 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment minfee' = Convert.toLedgerCoin minfee return (balance, minfee', witCount) - -- | Ensures that the given UTxO sets are consistent with one another. - -- - -- They are not consistent iff an input can be looked up in both UTxO sets - -- with different @Address@, or @TokenBundle@ values. - -- - guardUTxOConsistency :: ExceptT (ErrBalanceTx era) m () - guardUTxOConsistency = - case NE.nonEmpty (F.toList (conflicts extraUTxO availableUTxO)) of - Just cs -> throwE $ ErrBalanceTxInputResolutionConflicts cs - Nothing -> return () - where - conflicts :: UTxO era -> UTxO era -> Map TxIn (TxOut era, TxOut era) - conflicts = Map.conflictsWith ((/=) `on` toWalletTxOut era) `on` unUTxO - combinedUTxO :: UTxO era combinedUTxO = mconcat -- The @CardanoApi.UTxO@ can contain strictly more information than From 706f4792bb8d29df87507dfc3718ede6c5043064 Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 18 Apr 2024 05:41:14 +0000 Subject: [PATCH 07/18] Unpack `PartialTx` argument to `balanceTx` inner helper function. --- .../Internal/Cardano/Write/Tx/Balance.hs | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs index 153e0cca047..d82e830a508 100644 --- a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs +++ b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs @@ -529,7 +529,7 @@ balanceTransaction utxo@UTxOIndex {availableUTxO} genChange s - partialTx@PartialTx {extraUTxO} + partialTx@PartialTx {extraUTxO, redeemers, timelockKeyWitnessCounts} = do guardExistingCollateral guardExistingReturnCollateral @@ -554,10 +554,13 @@ balanceTransaction timeTranslation utxoAssumptions utxo + extraUTxO genChange s strategy - adjustedPartialTx + redeemers + timelockKeyWitnessCounts + (view #tx adjustedPartialTx) guardExistingCollateral :: ExceptT (ErrBalanceTx era) m () guardExistingCollateral = do @@ -675,22 +678,29 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment -> TimeTranslation -> UTxOAssumptions -> UTxOIndex era + -> UTxO era + -- ^ The set of UTxOs that were provided by the `PartialTx`. -> ChangeAddressGen changeState -> changeState -> SelectionStrategy - -> PartialTx era + -> [Redeemer] + -> TimelockKeyWitnessCounts + -> Tx era -> ExceptT (ErrBalanceTx era) m (Tx era, changeState) balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment pp timeTranslation utxoAssumptions UTxOIndex {availableUTxO, availableUTxOIndex} + extraUTxO genChange s selectionStrategy - partialTx@PartialTx {extraUTxO, redeemers, timelockKeyWitnessCounts} + redeemers + timelockKeyWitnessCounts + partialTx = do - (balance0, minfee0, _) <- balanceAfterSettingMinFee (partialTx ^. #tx) + (balance0, minfee0, _) <- balanceAfterSettingMinFee partialTx (extraInputs, extraCollateral', extraOutputs, s') <- do @@ -731,7 +741,7 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment let mSel = selectAssets pp utxoAssumptions - (F.toList $ partialTx ^. #tx . bodyTxL . outputsTxBodyL) + (F.toList $ partialTx ^. bodyTxL . outputsTxBodyL) redeemers utxoSelection balance0 @@ -863,7 +873,7 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment where txIns :: [TxIn] txIns = - Set.toList $ partialTx ^. #tx . bodyTxL . inputsTxBodyL + Set.toList $ partialTx ^. bodyTxL . inputsTxBodyL guardTxSize :: KeyWitnessCounts @@ -924,7 +934,7 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment -> ExceptT (ErrBalanceTx era) m (Tx era) assembleTransaction update = ExceptT . pure $ do tx' <- left updateTxErrorToBalanceTxError - $ updateTx (partialTx ^. #tx) update + $ updateTx partialTx update left ErrBalanceTxAssignRedeemers $ assignScriptRedeemers pp timeTranslation combinedUTxO redeemers tx' From eb59c3f9d851f71c2142bdeef756b1c836973a1a Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 18 Apr 2024 05:51:15 +0000 Subject: [PATCH 08/18] Simplify type and definition of `adjustedPartialTx`. --- .../lib/internal/Internal/Cardano/Write/Tx/Balance.hs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs index d82e830a508..ff42024a9cc 100644 --- a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs +++ b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs @@ -529,7 +529,7 @@ balanceTransaction utxo@UTxOIndex {availableUTxO} genChange s - partialTx@PartialTx {extraUTxO, redeemers, timelockKeyWitnessCounts} + partialTx@PartialTx {extraUTxO, tx, redeemers, timelockKeyWitnessCounts} = do guardExistingCollateral guardExistingReturnCollateral @@ -541,9 +541,8 @@ balanceTransaction then balanceWith SelectionStrategyMinimal else throwE e where - adjustedPartialTx :: PartialTx era - adjustedPartialTx = flip (over #tx) partialTx $ - assignMinimalAdaQuantitiesToOutputsWithoutAda pp + adjustedPartialTx :: Tx era + adjustedPartialTx = assignMinimalAdaQuantitiesToOutputsWithoutAda pp tx balanceWith :: SelectionStrategy @@ -560,7 +559,7 @@ balanceTransaction strategy redeemers timelockKeyWitnessCounts - (view #tx adjustedPartialTx) + adjustedPartialTx guardExistingCollateral :: ExceptT (ErrBalanceTx era) m () guardExistingCollateral = do From 2936ecdd0189eeecc0e26f2e7940ade79fe82fc1 Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 18 Apr 2024 05:52:47 +0000 Subject: [PATCH 09/18] Use `tx` field of `PartialTx` directly. --- .../lib/internal/Internal/Cardano/Write/Tx/Balance.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs index ff42024a9cc..c4260ceb1ba 100644 --- a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs +++ b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs @@ -529,7 +529,7 @@ balanceTransaction utxo@UTxOIndex {availableUTxO} genChange s - partialTx@PartialTx {extraUTxO, tx, redeemers, timelockKeyWitnessCounts} + PartialTx {extraUTxO, tx, redeemers, timelockKeyWitnessCounts} = do guardExistingCollateral guardExistingReturnCollateral @@ -567,20 +567,20 @@ balanceTransaction -- consensus was that we /could/ allow for it with just a day's work or -- so, but that the need for it was unclear enough that it was not in -- any way a priority. - let collIns = partialTx ^. #tx . bodyTxL . collateralInputsTxBodyL + let collIns = tx ^. bodyTxL . collateralInputsTxBodyL unless (null collIns) $ throwE ErrBalanceTxExistingCollateral guardExistingReturnCollateral :: ExceptT (ErrBalanceTx era) m () guardExistingReturnCollateral = do - let collRet = partialTx ^. #tx . bodyTxL . collateralReturnTxBodyL + let collRet = tx ^. bodyTxL . collateralReturnTxBodyL case collRet of SNothing -> return () SJust _ -> throwE ErrBalanceTxExistingReturnCollateral guardExistingTotalCollateral :: ExceptT (ErrBalanceTx era) m () guardExistingTotalCollateral = do - let totColl = partialTx ^. #tx . bodyTxL . totalCollateralTxBodyL + let totColl = tx ^. bodyTxL . totalCollateralTxBodyL case totColl of SNothing -> return () SJust _ -> throwE ErrBalanceTxExistingTotalCollateral From 039afa2936a51e113f9e06f4de0c55ea65a5feac Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 18 Apr 2024 05:48:12 +0000 Subject: [PATCH 10/18] Unpack `UTxOIndex` argument to `balanceTx` inner helper function. --- .../internal/Internal/Cardano/Write/Tx/Balance.hs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs index c4260ceb1ba..c08ef1438fe 100644 --- a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs +++ b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs @@ -526,7 +526,7 @@ balanceTransaction pp timeTranslation utxoAssumptions - utxo@UTxOIndex {availableUTxO} + UTxOIndex {availableUTxO, availableUTxOIndex} genChange s PartialTx {extraUTxO, tx, redeemers, timelockKeyWitnessCounts} @@ -552,8 +552,9 @@ balanceTransaction pp timeTranslation utxoAssumptions - utxo extraUTxO + availableUTxO + availableUTxOIndex genChange s strategy @@ -676,9 +677,12 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment => PParams era -> TimeTranslation -> UTxOAssumptions - -> UTxOIndex era -> UTxO era -- ^ The set of UTxOs that were provided by the `PartialTx`. + -> UTxO era + -- ^ The set of UTxOs that are available to spend. + -> UTxOIndex.UTxOIndex WalletUTxO + -- ^ The set of UTxOs that are available to spend, in indexed form. -> ChangeAddressGen changeState -> changeState -> SelectionStrategy @@ -690,8 +694,9 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment pp timeTranslation utxoAssumptions - UTxOIndex {availableUTxO, availableUTxOIndex} extraUTxO + availableUTxO + availableUTxOIndex genChange s selectionStrategy From de283192698b383f4b652a81953d2585f54954ba Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 18 Apr 2024 06:01:32 +0000 Subject: [PATCH 11/18] Move computation of `combinedUTxO` out of inner helper function. --- .../Internal/Cardano/Write/Tx/Balance.hs | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs index c08ef1438fe..f50d78239ef 100644 --- a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs +++ b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs @@ -552,8 +552,7 @@ balanceTransaction pp timeTranslation utxoAssumptions - extraUTxO - availableUTxO + combinedUTxO availableUTxOIndex genChange s @@ -562,6 +561,18 @@ balanceTransaction timelockKeyWitnessCounts adjustedPartialTx + combinedUTxO :: UTxO era + combinedUTxO = mconcat + -- The @CardanoApi.UTxO@ can contain strictly more information than + -- @W.UTxO@. Therefore we make the user-specified @inputUTxO@ to take + -- precedence. This matters if a user is trying to balance a tx making + -- use of a datum hash in a UTxO which is also present in the wallet + -- UTxO set. (Whether or not this is a sane thing for the user to do, + -- is another question.) + [ extraUTxO + , availableUTxO + ] + guardExistingCollateral :: ExceptT (ErrBalanceTx era) m () guardExistingCollateral = do -- Coin selection does not support pre-defining collateral. In Sep 2021 @@ -678,11 +689,9 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment -> TimeTranslation -> UTxOAssumptions -> UTxO era - -- ^ The set of UTxOs that were provided by the `PartialTx`. - -> UTxO era - -- ^ The set of UTxOs that are available to spend. + -- ^ The reference set of all UTxOs. -> UTxOIndex.UTxOIndex WalletUTxO - -- ^ The set of UTxOs that are available to spend, in indexed form. + -- ^ The subset of UTxOs that are available to spend, in indexed form. -> ChangeAddressGen changeState -> changeState -> SelectionStrategy @@ -694,8 +703,7 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment pp timeTranslation utxoAssumptions - extraUTxO - availableUTxO + combinedUTxO availableUTxOIndex genChange s @@ -921,18 +929,6 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment minfee' = Convert.toLedgerCoin minfee return (balance, minfee', witCount) - combinedUTxO :: UTxO era - combinedUTxO = mconcat - -- The @CardanoApi.UTxO@ can contain strictly more information than - -- @W.UTxO@. Therefore we make the user-specified @inputUTxO@ to take - -- precedence. This matters if a user is trying to balance a tx making - -- use of a datum hash in a UTxO which is also present in the wallet - -- UTxO set. (Whether or not this is a sane thing for the user to do, - -- is another question.) - [ extraUTxO - , availableUTxO - ] - assembleTransaction :: TxUpdate -> ExceptT (ErrBalanceTx era) m (Tx era) From 2bc084562df76e8c2b943af760fbe95a44f32cfc Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 18 Apr 2024 06:06:22 +0000 Subject: [PATCH 12/18] Rename `combinedUTxO` to `utxoReference`. --- .../Internal/Cardano/Write/Tx/Balance.hs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs index f50d78239ef..8d297c8f40f 100644 --- a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs +++ b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs @@ -552,7 +552,7 @@ balanceTransaction pp timeTranslation utxoAssumptions - combinedUTxO + utxoReference availableUTxOIndex genChange s @@ -561,8 +561,8 @@ balanceTransaction timelockKeyWitnessCounts adjustedPartialTx - combinedUTxO :: UTxO era - combinedUTxO = mconcat + utxoReference :: UTxO era + utxoReference = mconcat -- The @CardanoApi.UTxO@ can contain strictly more information than -- @W.UTxO@. Therefore we make the user-specified @inputUTxO@ to take -- precedence. This matters if a user is trying to balance a tx making @@ -703,7 +703,7 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment pp timeTranslation utxoAssumptions - combinedUTxO + utxoReference availableUTxOIndex genChange s @@ -848,7 +848,7 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment era = recentEra @era -- | Extract the inputs from the raw 'tx' of the 'Partialtx', with the - -- corresponding 'TxOut' according to @combinedUTxO@. + -- corresponding 'TxOut' according to @utxoReference@. -- -- === Examples using pseudo-code -- @@ -867,7 +867,7 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment :: ExceptT (ErrBalanceTx era) m (UTxOIndex.UTxOIndex WalletUTxO) extractExternallySelectedUTxO = do let res = flip map txIns $ \i-> do - case txinLookup i combinedUTxO of + case txinLookup i utxoReference of Nothing -> Left i Just o -> do @@ -910,7 +910,7 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment txBalance :: Tx era -> Value txBalance - = evaluateTransactionBalance pp combinedUTxO + = evaluateTransactionBalance pp utxoReference . view bodyTxL balanceAfterSettingMinFee @@ -919,7 +919,7 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment balanceAfterSettingMinFee tx = ExceptT . pure $ do let witCount = estimateKeyWitnessCounts - combinedUTxO + utxoReference tx timelockKeyWitnessCounts minfee = Convert.toWalletCoin $ evaluateMinimumFee pp tx witCount @@ -936,7 +936,7 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment tx' <- left updateTxErrorToBalanceTxError $ updateTx partialTx update left ErrBalanceTxAssignRedeemers $ - assignScriptRedeemers pp timeTranslation combinedUTxO redeemers tx' + assignScriptRedeemers pp timeTranslation utxoReference redeemers tx' -- | Select assets to cover the specified balance and fee. -- From e6a6a99facd1c23e0a288f0dcac8f28d433b6d6d Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 18 Apr 2024 06:12:35 +0000 Subject: [PATCH 13/18] Revise comment for `utxoReference`. The original comment was outdated, as it referred to the `CardanoApi.UTxO` and `Primitive.Types.UTxO` types, both of which are no longer accepted by the `balanceTransaction` function. --- .../internal/Internal/Cardano/Write/Tx/Balance.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs index 8d297c8f40f..5b2261cecbc 100644 --- a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs +++ b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs @@ -561,14 +561,14 @@ balanceTransaction timelockKeyWitnessCounts adjustedPartialTx + -- The set of all UTxOs that may be referenced by a balanced transaction. + -- + -- Note that when constructing this set, we give precedence to UTxOs + -- provided as part of the 'PartialTx' object. This relies on the + -- left-biased nature of the 'Semigroup' 'mappend' operation on UTxO sets. + -- utxoReference :: UTxO era utxoReference = mconcat - -- The @CardanoApi.UTxO@ can contain strictly more information than - -- @W.UTxO@. Therefore we make the user-specified @inputUTxO@ to take - -- precedence. This matters if a user is trying to balance a tx making - -- use of a datum hash in a UTxO which is also present in the wallet - -- UTxO set. (Whether or not this is a sane thing for the user to do, - -- is another question.) [ extraUTxO , availableUTxO ] From 304dd80c1fb945c62f7a160421f0ce5edec417cc Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 18 Apr 2024 06:14:24 +0000 Subject: [PATCH 14/18] Shorten definition of `utxoReference`. --- .../lib/internal/Internal/Cardano/Write/Tx/Balance.hs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs index 5b2261cecbc..5b7af89619c 100644 --- a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs +++ b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs @@ -568,10 +568,7 @@ balanceTransaction -- left-biased nature of the 'Semigroup' 'mappend' operation on UTxO sets. -- utxoReference :: UTxO era - utxoReference = mconcat - [ extraUTxO - , availableUTxO - ] + utxoReference = mconcat [extraUTxO, availableUTxO] guardExistingCollateral :: ExceptT (ErrBalanceTx era) m () guardExistingCollateral = do From 9201f330ec9d56fb2f1e5cfcd51895eec6e8fcbc Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 18 Apr 2024 06:45:37 +0000 Subject: [PATCH 15/18] Move computation of `utxoSelection` out of inner helper function. --- .../Internal/Cardano/Write/Tx/Balance.hs | 114 +++++++++--------- 1 file changed, 56 insertions(+), 58 deletions(-) diff --git a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs index 5b7af89619c..34520445ede 100644 --- a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs +++ b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs @@ -534,26 +534,35 @@ balanceTransaction guardExistingCollateral guardExistingReturnCollateral guardExistingTotalCollateral + guardUTxOConsistency - balanceWith SelectionStrategyOptimal + externallySelectedUtxo <- extractExternallySelectedUTxO + let utxoSelection = + UTxOSelection.fromIndexPair + (availableUTxOIndex, externallySelectedUtxo) + when (UTxOSelection.availableSize utxoSelection == 0) $ + throwE ErrBalanceTxUnableToCreateInput + + balanceWith utxoSelection SelectionStrategyOptimal `catchE` \e -> if minimalStrategyIsWorthTrying e - then balanceWith SelectionStrategyMinimal + then balanceWith utxoSelection SelectionStrategyMinimal else throwE e where adjustedPartialTx :: Tx era adjustedPartialTx = assignMinimalAdaQuantitiesToOutputsWithoutAda pp tx balanceWith - :: SelectionStrategy + :: UTxOSelection WalletUTxO + -> SelectionStrategy -> ExceptT (ErrBalanceTx era) m (Tx era, changeState) - balanceWith strategy = + balanceWith utxoSelection strategy = balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment pp timeTranslation utxoAssumptions utxoReference - availableUTxOIndex + utxoSelection genChange s strategy @@ -561,6 +570,44 @@ balanceTransaction timelockKeyWitnessCounts adjustedPartialTx + -- | Extract the inputs from the raw 'tx' of the 'Partialtx', with the + -- corresponding 'TxOut' according to @utxoReference@. + -- + -- === Examples using pseudo-code + -- + -- >>> let extraUTxO = {inA -> outA, inB -> outB } + -- >>> let tx = addInputs [inA] emptyTx + -- >>> let ptx = PartialTx tx extraUTxO [] + -- >>> extractExternallySelectedUTxO ptx + -- Right (UTxOIndex.fromMap {inA -> outA}) + -- + -- >>> let extraUTxO = {inB -> outB } + -- >>> let tx = addInputs [inA, inC] emptyTx + -- >>> let ptx = PartialTx tx extraUTxO [] + -- >>> extractExternallySelectedUTxO ptx + -- Left (ErrBalanceTxUnresolvedInputs [inA, inC]) + extractExternallySelectedUTxO + :: ExceptT (ErrBalanceTx era) m (UTxOIndex.UTxOIndex WalletUTxO) + extractExternallySelectedUTxO = do + let res = flip map txIns $ \i -> + case txinLookup i utxoReference of + Nothing -> + Left i + Just o -> do + let i' = Convert.toWallet i + let W.TxOut addr bundle = toWalletTxOut era o + pure (WalletUTxO i' addr, bundle) + case partitionEithers res of + ([], resolved) -> pure $ UTxOIndex.fromSequence resolved + (unresolvedInsHead : unresolvedInsTail, _) -> + throwE + . ErrBalanceTxUnresolvedInputs + $ (unresolvedInsHead :| unresolvedInsTail) + where + era = recentEra @era + txIns :: [TxIn] + txIns = Set.toList $ tx ^. bodyTxL . inputsTxBodyL + -- The set of all UTxOs that may be referenced by a balanced transaction. -- -- Note that when constructing this set, we give precedence to UTxOs @@ -687,8 +734,9 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment -> UTxOAssumptions -> UTxO era -- ^ The reference set of all UTxOs. - -> UTxOIndex.UTxOIndex WalletUTxO - -- ^ The subset of UTxOs that are available to spend, in indexed form. + -> UTxOSelection WalletUTxO + -- ^ The set of UTxOs that may be spent by the resultant transaction. + -- The subset of UTxOs that are already spent are pre-selected. -> ChangeAddressGen changeState -> changeState -> SelectionStrategy @@ -701,7 +749,7 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment timeTranslation utxoAssumptions utxoReference - availableUTxOIndex + utxoSelection genChange s selectionStrategy @@ -739,14 +787,6 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment , s' ) - externalSelectedUtxo <- extractExternallySelectedUTxO - let utxoSelection = - UTxOSelection.fromIndexPair - (availableUTxOIndex, externalSelectedUtxo) - - when (UTxOSelection.availableSize utxoSelection == 0) $ - throwE ErrBalanceTxUnableToCreateInput - let mSel = selectAssets pp utxoAssumptions @@ -842,48 +882,6 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment , feeUpdate = UseNewTxFee updatedFee } where - era = recentEra @era - - -- | Extract the inputs from the raw 'tx' of the 'Partialtx', with the - -- corresponding 'TxOut' according to @utxoReference@. - -- - -- === Examples using pseudo-code - -- - -- >>> let extraUTxO = {inA -> outA, inB -> outB } - -- >>> let tx = addInputs [inA] emptyTx - -- >>> let ptx = PartialTx tx extraUTxO [] - -- >>> extractExternallySelectedUTxO ptx - -- Right (UTxOIndex.fromMap {inA -> outA}) - -- - -- >>> let extraUTxO = {inB -> outB } - -- >>> let tx = addInputs [inA, inC] emptyTx - -- >>> let ptx = PartialTx tx extraUTxO [] - -- >>> extractExternallySelectedUTxO ptx - -- Left (ErrBalanceTxUnresolvedInputs [inA, inC]) - extractExternallySelectedUTxO - :: ExceptT (ErrBalanceTx era) m (UTxOIndex.UTxOIndex WalletUTxO) - extractExternallySelectedUTxO = do - let res = flip map txIns $ \i-> do - case txinLookup i utxoReference of - Nothing -> - Left i - Just o -> do - let i' = Convert.toWallet i - let W.TxOut addr bundle = toWalletTxOut era o - pure (WalletUTxO i' addr, bundle) - - case partitionEithers res of - ([], resolved) -> - pure $ UTxOIndex.fromSequence resolved - (unresolvedInsHead:unresolvedInsTail, _) -> - throwE - . ErrBalanceTxUnresolvedInputs - $ (unresolvedInsHead :| unresolvedInsTail) - where - txIns :: [TxIn] - txIns = - Set.toList $ partialTx ^. bodyTxL . inputsTxBodyL - guardTxSize :: KeyWitnessCounts -> Tx era From 10fed7e9983cb71c6f60cd48bbf1bd7194274936 Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 18 Apr 2024 07:00:22 +0000 Subject: [PATCH 16/18] Simplify comment for `extractExternallySelectedUTxO`. --- .../Internal/Cardano/Write/Tx/Balance.hs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs index 34520445ede..4314bd6dc35 100644 --- a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs +++ b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs @@ -570,22 +570,12 @@ balanceTransaction timelockKeyWitnessCounts adjustedPartialTx - -- | Extract the inputs from the raw 'tx' of the 'Partialtx', with the - -- corresponding 'TxOut' according to @utxoReference@. + -- Creates an index of all UTxOs that are already spent as inputs of the + -- partial transaction. -- - -- === Examples using pseudo-code + -- This function will fail if any of the inputs refers to a UTxO that + -- cannot be found in the UTxO reference set. -- - -- >>> let extraUTxO = {inA -> outA, inB -> outB } - -- >>> let tx = addInputs [inA] emptyTx - -- >>> let ptx = PartialTx tx extraUTxO [] - -- >>> extractExternallySelectedUTxO ptx - -- Right (UTxOIndex.fromMap {inA -> outA}) - -- - -- >>> let extraUTxO = {inB -> outB } - -- >>> let tx = addInputs [inA, inC] emptyTx - -- >>> let ptx = PartialTx tx extraUTxO [] - -- >>> extractExternallySelectedUTxO ptx - -- Left (ErrBalanceTxUnresolvedInputs [inA, inC]) extractExternallySelectedUTxO :: ExceptT (ErrBalanceTx era) m (UTxOIndex.UTxOIndex WalletUTxO) extractExternallySelectedUTxO = do From a4b744a17f4cf3b0c46571c809dd44857aec7692 Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 18 Apr 2024 07:13:35 +0000 Subject: [PATCH 17/18] Move definitions back to `do` block to minimise overall diff. --- .../Internal/Cardano/Write/Tx/Balance.hs | 39 ++++++++----------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs index 4314bd6dc35..1bf0f4ec63f 100644 --- a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs +++ b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs @@ -543,33 +543,26 @@ balanceTransaction when (UTxOSelection.availableSize utxoSelection == 0) $ throwE ErrBalanceTxUnableToCreateInput - balanceWith utxoSelection SelectionStrategyOptimal + let adjustedPartialTx = assignMinimalAdaQuantitiesToOutputsWithoutAda pp tx + balanceWith strategy = + balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment + pp + timeTranslation + utxoAssumptions + utxoReference + utxoSelection + genChange + s + strategy + redeemers + timelockKeyWitnessCounts + adjustedPartialTx + balanceWith SelectionStrategyOptimal `catchE` \e -> if minimalStrategyIsWorthTrying e - then balanceWith utxoSelection SelectionStrategyMinimal + then balanceWith SelectionStrategyMinimal else throwE e where - adjustedPartialTx :: Tx era - adjustedPartialTx = assignMinimalAdaQuantitiesToOutputsWithoutAda pp tx - - balanceWith - :: UTxOSelection WalletUTxO - -> SelectionStrategy - -> ExceptT (ErrBalanceTx era) m (Tx era, changeState) - balanceWith utxoSelection strategy = - balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment - pp - timeTranslation - utxoAssumptions - utxoReference - utxoSelection - genChange - s - strategy - redeemers - timelockKeyWitnessCounts - adjustedPartialTx - -- Creates an index of all UTxOs that are already spent as inputs of the -- partial transaction. -- From f1fa5da856aeeb288ac60424b5147ce781d4f875 Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Thu, 18 Apr 2024 12:43:26 +0000 Subject: [PATCH 18/18] Rename inner helper function to `balanceTransactionInner`. --- .../lib/internal/Internal/Cardano/Write/Tx/Balance.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs index 1bf0f4ec63f..0a91f956df4 100644 --- a/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs +++ b/lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs @@ -545,7 +545,7 @@ balanceTransaction let adjustedPartialTx = assignMinimalAdaQuantitiesToOutputsWithoutAda pp tx balanceWith strategy = - balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment + balanceTransactionInner pp timeTranslation utxoAssumptions @@ -707,7 +707,7 @@ assignMinimalAdaQuantitiesToOutputsWithoutAda pp = if c == mempty then computeMinimumCoinForTxOut pp out else c -- | Internal helper to 'balanceTransaction' -balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment +balanceTransactionInner :: forall era m changeState. ( MonadRandom m , IsRecentEra era @@ -727,7 +727,7 @@ balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment -> TimelockKeyWitnessCounts -> Tx era -> ExceptT (ErrBalanceTx era) m (Tx era, changeState) -balanceTransactionWithSelectionStrategyAndNoZeroAdaAdjustment +balanceTransactionInner pp timeTranslation utxoAssumptions