From e627ea899b13aa90da18e7dd1b607d0fd3b31817 Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Fri, 4 Mar 2022 01:22:57 +0000 Subject: [PATCH 1/9] Repair formatting in `Api.Server` and `restore-bench`. Fixes: - Use 4-space indents everywhere instead of other indent widths. - Coalesce lines that don't need to be wrapped. - Shorten excessively-long lines to fit within the 80 column limit (where practical). --- lib/core/src/Cardano/Wallet/Api/Server.hs | 188 +++++++++++----------- lib/shelley/bench/restore-bench.hs | 24 +-- 2 files changed, 106 insertions(+), 106 deletions(-) diff --git a/lib/core/src/Cardano/Wallet/Api/Server.hs b/lib/core/src/Cardano/Wallet/Api/Server.hs index 786ce638197..86a91da015f 100644 --- a/lib/core/src/Cardano/Wallet/Api/Server.hs +++ b/lib/core/src/Cardano/Wallet/Api/Server.hs @@ -1591,20 +1591,17 @@ selectCoins ctx genChange (ApiT wid) body = do (utxoAvailable, wallet, pendingTxs) <- liftHandler $ W.readWalletUTxOIndex @_ @s @k wrk wid pp <- liftIO $ NW.currentProtocolParameters (wrk ^. networkLayer) - utx <- liftHandler - $ W.selectAssets @_ @_ @s @k wrk pp W.SelectAssetsParams + let selectAssetsParams = W.SelectAssetsParams { outputs = F.toList outs , pendingTxs , randomSeed = Nothing , txContext = txCtx - , utxoAvailableForInputs = - UTxOSelection.fromIndex utxoAvailable - , utxoAvailableForCollateral = - UTxOIndex.toMap utxoAvailable + , utxoAvailableForInputs = UTxOSelection.fromIndex utxoAvailable + , utxoAvailableForCollateral = UTxOIndex.toMap utxoAvailable , wallet } - transform - + utx <- liftHandler $ + W.selectAssets @_ @_ @s @k wrk pp selectAssetsParams transform pure $ mkApiCoinSelection [] [] Nothing md utx selectCoinsForJoin @@ -1644,19 +1641,18 @@ selectCoinsForJoin ctx knownPools getPoolStatus pid wid = do (utxoAvailable, wallet, pendingTxs) <- liftHandler $ W.readWalletUTxOIndex @_ @s @k wrk wid pp <- liftIO $ NW.currentProtocolParameters (wrk ^. networkLayer) - utx <- liftHandler - $ W.selectAssets @_ @_ @s @k wrk pp W.SelectAssetsParams + + let selectAssetsParams = W.SelectAssetsParams { outputs = [] , pendingTxs , randomSeed = Nothing , txContext = txCtx - , utxoAvailableForInputs = - UTxOSelection.fromIndex utxoAvailable - , utxoAvailableForCollateral = - UTxOIndex.toMap utxoAvailable + , utxoAvailableForInputs = UTxOSelection.fromIndex utxoAvailable + , utxoAvailableForCollateral = UTxOIndex.toMap utxoAvailable , wallet } - transform + utx <- liftHandler + $ W.selectAssets @_ @_ @s @k wrk pp selectAssetsParams transform (_, _, path) <- liftHandler $ W.readRewardAccount @_ @s @k @n wrk wid @@ -1697,19 +1693,17 @@ selectCoinsForQuit ctx (ApiT wid) = do liftHandler $ W.readWalletUTxOIndex @_ @s @k wrk wid pp <- liftIO $ NW.currentProtocolParameters (wrk ^. networkLayer) let refund = W.stakeKeyDeposit pp - utx <- liftHandler - $ W.selectAssets @_ @_ @s @k wrk pp W.SelectAssetsParams + let selectAssetsParams = W.SelectAssetsParams { outputs = [] , pendingTxs , randomSeed = Nothing , txContext = txCtx - , utxoAvailableForInputs = - UTxOSelection.fromIndex utxoAvailable - , utxoAvailableForCollateral = - UTxOIndex.toMap utxoAvailable + , utxoAvailableForInputs = UTxOSelection.fromIndex utxoAvailable + , utxoAvailableForCollateral = UTxOIndex.toMap utxoAvailable , wallet } - transform + utx <- liftHandler + $ W.selectAssets @_ @_ @s @k wrk pp selectAssetsParams transform (_, _, path) <- liftHandler $ W.readRewardAccount @_ @s @k @n wrk wid pure $ mkApiCoinSelection [] [refund] (Just (action, path)) Nothing utx @@ -1961,30 +1955,32 @@ postTransactionOld ctx genChange (ApiT wid) body = do } (sel, tx, txMeta, txTime, pp) <- withWorkerCtx ctx wid liftE liftE $ \wrk -> - atomicallyWithHandler (ctx ^. walletLocks) (PostTransactionOld wid) $ do - (utxoAvailable, wallet, pendingTxs) <- - liftHandler $ W.readWalletUTxOIndex @_ @s @k wrk wid - pp <- liftIO $ NW.currentProtocolParameters (wrk ^. networkLayer) - sel <- liftHandler - $ W.selectAssets @_ @_ @s @k wrk pp W.SelectAssetsParams - { outputs = F.toList outs - , pendingTxs - , randomSeed = Nothing - , txContext = txCtx - , utxoAvailableForInputs = - UTxOSelection.fromIndex utxoAvailable - , utxoAvailableForCollateral = - UTxOIndex.toMap utxoAvailable - , wallet - } - (const Prelude.id) - sel' <- liftHandler - $ W.assignChangeAddressesAndUpdateDb wrk wid genChange sel - (tx, txMeta, txTime, sealedTx) <- liftHandler - $ W.buildAndSignTransaction @_ @s @k wrk wid mkRwdAcct pwd txCtx sel' - liftHandler - $ W.submitTx @_ @s @k wrk wid (tx, txMeta, sealedTx) - pure (sel, tx, txMeta, txTime, pp) + atomicallyWithHandler (ctx ^. walletLocks) (PostTransactionOld wid) $ do + (utxoAvailable, wallet, pendingTxs) <- + liftHandler $ W.readWalletUTxOIndex @_ @s @k wrk wid + pp <- liftIO $ NW.currentProtocolParameters (wrk ^. networkLayer) + let selectAssetsParams = W.SelectAssetsParams + { outputs = F.toList outs + , pendingTxs + , randomSeed = Nothing + , txContext = txCtx + , utxoAvailableForInputs = + UTxOSelection.fromIndex utxoAvailable + , utxoAvailableForCollateral = + UTxOIndex.toMap utxoAvailable + , wallet + } + sel <- liftHandler + $ W.selectAssets @_ @_ @s @k wrk pp selectAssetsParams + $ const Prelude.id + sel' <- liftHandler + $ W.assignChangeAddressesAndUpdateDb wrk wid genChange sel + (tx, txMeta, txTime, sealedTx) <- liftHandler + $ W.buildAndSignTransaction + @_ @s @k wrk wid mkRwdAcct pwd txCtx sel' + liftHandler + $ W.submitTx @_ @s @k wrk wid (tx, txMeta, sealedTx) + pure (sel, tx, txMeta, txTime, pp) liftIO $ mkApiTransaction (timeInterpreter $ ctx ^. networkLayer) @@ -2114,18 +2110,18 @@ postTransactionFeeOld ctx (ApiT wid) body = do liftHandler $ W.readWalletUTxOIndex @_ @s @k wrk wid let outs = addressAmountToTxOut <$> body ^. #payments pp <- liftIO $ NW.currentProtocolParameters (wrk ^. networkLayer) - let runSelection = W.selectAssets @_ @_ @s @k wrk pp W.SelectAssetsParams + let getFee = const (selectionDelta TokenBundle.getCoin) + let selectAssetsParams = W.SelectAssetsParams { outputs = F.toList outs , pendingTxs , randomSeed = Nothing , txContext = txCtx - , utxoAvailableForInputs = - UTxOSelection.fromIndex utxoAvailable - , utxoAvailableForCollateral = - UTxOIndex.toMap utxoAvailable + , utxoAvailableForInputs = UTxOSelection.fromIndex utxoAvailable + , utxoAvailableForCollateral = UTxOIndex.toMap utxoAvailable , wallet - } getFee - where getFee = const (selectionDelta TokenBundle.getCoin) + } + let runSelection = + W.selectAssets @_ @_ @s @k wrk pp selectAssetsParams getFee minCoins <- liftIO (W.calcMinimumCoinValues @_ @k wrk (F.toList outs)) liftHandler $ mkApiFee Nothing minCoins <$> W.estimateFee runSelection @@ -2195,14 +2191,16 @@ constructTransaction ctx genChange knownPools getPoolStatus (ApiT wid) body = do poolStatus <- liftIO (getPoolStatus pid) pools <- liftIO knownPools curEpoch <- getCurrentEpoch ctx - (del, act) <- liftHandler $ - W.joinStakePool @_ @s @k wrk curEpoch pools pid poolStatus wid + (del, act) <- liftHandler $ W.joinStakePool + @_ @s @k wrk curEpoch pools pid poolStatus wid pure (del, act, Nothing) [(Leaving _)] -> do - del <- liftHandler $ W.quitStakePool @_ @s @k wrk wid wdrl + del <- liftHandler $ + W.quitStakePool @_ @s @k wrk wid wdrl pure (del, Nothing, Just $ W.stakeKeyDeposit pp) _ -> - liftHandler $ throwE ErrConstructTxMultidelegationNotSupported + liftHandler $ + throwE ErrConstructTxMultidelegationNotSupported pure (deposit, refund, defaultTransactionCtx { txWithdrawal = wdrl @@ -2219,17 +2217,20 @@ constructTransaction ctx genChange knownPools getPoolStatus (ApiT wid) body = do (utxoAvailable, wallet, pendingTxs) <- liftHandler $ W.readWalletUTxOIndex @_ @s @k wrk wid - let runSelection outs = W.selectAssets @_ @_ @s @k wrk pp W.SelectAssetsParams - { outputs = outs - , pendingTxs - , randomSeed = Nothing - , txContext = txCtx - , utxoAvailableForInputs = - UTxOSelection.fromIndex utxoAvailable - , utxoAvailableForCollateral = - UTxOIndex.toMap utxoAvailable - , wallet - } transform + let runSelection outs = + W.selectAssets @_ @_ @s @k wrk pp selectAssetsParams transform + where + selectAssetsParams = W.SelectAssetsParams + { outputs = outs + , pendingTxs + , randomSeed = Nothing + , txContext = txCtx + , utxoAvailableForInputs = + UTxOSelection.fromIndex utxoAvailable + , utxoAvailableForCollateral = + UTxOIndex.toMap utxoAvailable + , wallet + } (sel, sel', fee) <- do outs <- case (body ^. #payments) of @@ -2237,7 +2238,8 @@ constructTransaction ctx genChange knownPools getPoolStatus (ApiT wid) body = do Just (ApiPaymentAddresses content) -> pure $ F.toList (addressAmountToTxOut <$> content) Just (ApiPaymentAll _) -> do - liftHandler $ throwE $ ErrConstructTxNotImplemented "ADP-1189" + liftHandler $ + throwE $ ErrConstructTxNotImplemented "ADP-1189" (sel', utx, fee') <- liftHandler $ runSelection outs sel <- liftHandler $ @@ -2250,8 +2252,8 @@ constructTransaction ctx genChange knownPools getPoolStatus (ApiT wid) body = do pure $ ApiConstructTransaction { transaction = ApiT tx - , coinSelection = - mkApiCoinSelection (maybeToList deposit) (maybeToList refund) Nothing md sel' + , coinSelection = mkApiCoinSelection + (maybeToList deposit) (maybeToList refund) Nothing md sel' , fee = Quantity $ fromIntegral fee } where @@ -2578,19 +2580,18 @@ joinStakePool ctx knownPools getPoolStatus apiPoolId (ApiT wid) body = do (utxoAvailable, wallet, pendingTxs) <- liftHandler $ W.readWalletUTxOIndex @_ @s @k wrk wid pp <- liftIO $ NW.currentProtocolParameters (wrk ^. networkLayer) - sel <- liftHandler - $ W.selectAssets @_ @_ @s @k wrk pp W.SelectAssetsParams + let selectAssetsParams = W.SelectAssetsParams { outputs = [] , pendingTxs , randomSeed = Nothing , txContext = txCtx - , utxoAvailableForInputs = - UTxOSelection.fromIndex utxoAvailable - , utxoAvailableForCollateral = - UTxOIndex.toMap utxoAvailable + , utxoAvailableForInputs = UTxOSelection.fromIndex utxoAvailable + , utxoAvailableForCollateral = UTxOIndex.toMap utxoAvailable , wallet } - (const Prelude.id) + sel <- liftHandler + $ W.selectAssets @_ @_ @s @k wrk pp selectAssetsParams + $ const Prelude.id sel' <- liftHandler $ W.assignChangeAddressesAndUpdateDb wrk wid genChange sel (tx, txMeta, txTime, sealedTx) <- liftHandler @@ -2644,19 +2645,18 @@ delegationFee ctx (ApiT wid) = do txCtx = defaultTransactionCtx runSelection wrk pp _deposit (utxoAvailable, wallet, pendingTxs) = - W.selectAssets @_ @_ @s @k wrk pp W.SelectAssetsParams + W.selectAssets @_ @_ @s @k wrk pp selectAssetsParams calcFee + where + calcFee _ = selectionDelta TokenBundle.getCoin + selectAssetsParams = W.SelectAssetsParams { outputs = [] , pendingTxs , randomSeed = Nothing , txContext = txCtx - , utxoAvailableForInputs = - UTxOSelection.fromIndex utxoAvailable - , utxoAvailableForCollateral = - UTxOIndex.toMap utxoAvailable + , utxoAvailableForInputs = UTxOSelection.fromIndex utxoAvailable + , utxoAvailableForCollateral = UTxOIndex.toMap utxoAvailable , wallet - } calcFee - where - calcFee _ = selectionDelta TokenBundle.getCoin + } quitStakePool :: forall ctx s n k. @@ -2681,7 +2681,8 @@ quitStakePool ctx (ApiT wid) body = do let pwd = coerce $ getApiT $ body ^. #passphrase (sel, tx, txMeta, txTime, pp) <- withWorkerCtx ctx wid liftE liftE $ \wrk -> do - (wdrl, mkRwdAcct) <- mkRewardAccountBuilder @_ @s @_ @n ctx wid (Just SelfWithdrawal) + (wdrl, mkRwdAcct) <- + mkRewardAccountBuilder @_ @s @_ @n ctx wid (Just SelfWithdrawal) action <- liftHandler $ W.quitStakePool wrk wid wdrl ttl <- liftIO $ W.getTxExpiry ti Nothing let txCtx = defaultTransactionCtx @@ -2693,19 +2694,18 @@ quitStakePool ctx (ApiT wid) body = do (utxoAvailable, wallet, pendingTxs) <- liftHandler $ W.readWalletUTxOIndex @_ @s @k wrk wid pp <- liftIO $ NW.currentProtocolParameters (wrk ^. networkLayer) - sel <- liftHandler - $ W.selectAssets @_ @_ @s @k wrk pp W.SelectAssetsParams + let selectAssetsParams = W.SelectAssetsParams { outputs = [] , pendingTxs , randomSeed = Nothing , txContext = txCtx - , utxoAvailableForInputs = - UTxOSelection.fromIndex utxoAvailable - , utxoAvailableForCollateral = - UTxOIndex.toMap utxoAvailable + , utxoAvailableForInputs = UTxOSelection.fromIndex utxoAvailable + , utxoAvailableForCollateral = UTxOIndex.toMap utxoAvailable , wallet } - (const Prelude.id) + sel <- liftHandler + $ W.selectAssets @_ @_ @s @k wrk pp selectAssetsParams + $ const Prelude.id sel' <- liftHandler $ W.assignChangeAddressesAndUpdateDb wrk wid genChange sel (tx, txMeta, txTime, sealedTx) <- liftHandler diff --git a/lib/shelley/bench/restore-bench.hs b/lib/shelley/bench/restore-bench.hs index 9640281f8f0..fbea7c6b479 100644 --- a/lib/shelley/bench/restore-bench.hs +++ b/lib/shelley/bench/restore-bench.hs @@ -458,17 +458,17 @@ benchmarksRnd _ w wid wname benchname restoreTime = do (utxoAvailable, wallet, pendingTxs) <- unsafeRunExceptT $ W.readWalletUTxOIndex @_ @s @k w wid pp <- liftIO $ currentProtocolParameters (w ^. networkLayer) - let runSelection = W.selectAssets @_ @_ @s @k w pp W.SelectAssetsParams + let selectAssetsParams = W.SelectAssetsParams { outputs = [out] , pendingTxs , randomSeed = Nothing , txContext = txCtx - , utxoAvailableForInputs = - UTxOSelection.fromIndex utxoAvailable - , utxoAvailableForCollateral = - UTxOIndex.toMap utxoAvailable + , utxoAvailableForInputs = UTxOSelection.fromIndex utxoAvailable + , utxoAvailableForCollateral = UTxOIndex.toMap utxoAvailable , wallet - } getFee + } + let runSelection = + W.selectAssets @_ @_ @s @k w pp selectAssetsParams getFee runExceptT $ withExceptT show $ W.estimateFee runSelection oneAddress <- genAddresses 1 cp @@ -561,17 +561,17 @@ benchmarksSeq _ w wid _wname benchname restoreTime = do (utxoAvailable, wallet, pendingTxs) <- unsafeRunExceptT $ W.readWalletUTxOIndex w wid pp <- liftIO $ currentProtocolParameters (w ^. networkLayer) - let runSelection = W.selectAssets @_ @_ @s @k w pp W.SelectAssetsParams + let selectAssetsParams = W.SelectAssetsParams { outputs = [out] , pendingTxs , randomSeed = Nothing , txContext = txCtx - , utxoAvailableForInputs = - UTxOSelection.fromIndex utxoAvailable - , utxoAvailableForCollateral = - UTxOIndex.toMap utxoAvailable + , utxoAvailableForInputs = UTxOSelection.fromIndex utxoAvailable + , utxoAvailableForCollateral = UTxOIndex.toMap utxoAvailable , wallet - } getFee + } + let runSelection = + W.selectAssets @_ @_ @s @k w pp selectAssetsParams getFee runExceptT $ withExceptT show $ W.estimateFee runSelection let walletOverview = WalletOverview{utxo,addresses,transactions} From 73d99aa410e2a2330376f6e0d54e9f4d354719e0 Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Fri, 4 Mar 2022 00:05:52 +0000 Subject: [PATCH 2/9] Add type `SelectionStrategy` and corresponding field to type `SelectionLens`. To begin with, we give this type just a single constructor: `SelectionStrategyOptimal`. --- .../Wallet/CoinSelection/Internal/Balance.hs | 20 +++++++++++++++++++ .../CoinSelection/Internal/BalanceSpec.hs | 2 ++ 2 files changed, 22 insertions(+) diff --git a/lib/core/src/Cardano/Wallet/CoinSelection/Internal/Balance.hs b/lib/core/src/Cardano/Wallet/CoinSelection/Internal/Balance.hs index a44efee6036..86d7a53ac03 100644 --- a/lib/core/src/Cardano/Wallet/CoinSelection/Internal/Balance.hs +++ b/lib/core/src/Cardano/Wallet/CoinSelection/Internal/Balance.hs @@ -38,6 +38,7 @@ module Cardano.Wallet.CoinSelection.Internal.Balance , SelectionSkeleton (..) , SelectionResult , SelectionResultOf (..) + , SelectionStrategy (..) , SelectionBalanceError (..) , BalanceInsufficientError (..) , InsufficientMinCoinValueError (..) @@ -277,6 +278,21 @@ deriving instance (Show (outputs (Address, TokenBundle)), Show u) => Show (SelectionParamsOf outputs u) +-- | Indicates a choice of selection strategy. +-- +-- A 'SelectionStrategy' determines __how much__ of each asset the selection +-- algorithm will attempt to select from the available UTxO set, relative to +-- the minimum amount necessary to make the selection balance. +-- +-- The default 'SelectionStrategy' is 'SelectionStrategyOptimal', which when +-- specified will cause the selection algorithm to attempt to select around +-- __/twice/__ the minimum possible amount of each asset from the available +-- UTxO set, making it possible to generate change outputs that are roughly +-- the same sizes and shapes as the user-specified outputs. +-- +data SelectionStrategy + = SelectionStrategyOptimal + -- | Indicates whether the balance of available UTxO entries is sufficient. -- -- See 'computeUTxOBalanceSufficiency'. @@ -1140,6 +1156,7 @@ assetSelectionLens limit (asset, minimumAssetQuantity) = SelectionLens , updatedQuantity = selectedAssetQuantity asset , minimumQuantity = unTokenQuantity minimumAssetQuantity , selectQuantity = selectAssetQuantity asset limit + , selectionStrategy = SelectionStrategyOptimal } coinSelectionLens @@ -1153,6 +1170,7 @@ coinSelectionLens limit minimumCoinQuantity = SelectionLens , updatedQuantity = selectedCoinQuantity , minimumQuantity = intCast $ unCoin minimumCoinQuantity , selectQuantity = selectCoinQuantity limit + , selectionStrategy = SelectionStrategyOptimal } -- | Specializes 'selectMatchingQuantity' to a particular asset. @@ -1240,6 +1258,8 @@ data SelectionLens m state state' = SelectionLens :: state -> m (Maybe state') , minimumQuantity :: Natural + , selectionStrategy + :: SelectionStrategy } -- | Runs just a single step of a coin selection. diff --git a/lib/core/test/unit/Cardano/Wallet/CoinSelection/Internal/BalanceSpec.hs b/lib/core/test/unit/Cardano/Wallet/CoinSelection/Internal/BalanceSpec.hs index 92b5f6c81ee..8f097f523b2 100644 --- a/lib/core/test/unit/Cardano/Wallet/CoinSelection/Internal/BalanceSpec.hs +++ b/lib/core/test/unit/Cardano/Wallet/CoinSelection/Internal/BalanceSpec.hs @@ -57,6 +57,7 @@ import Cardano.Wallet.CoinSelection.Internal.Balance , SelectionResult , SelectionResultOf (..) , SelectionSkeleton (..) + , SelectionStrategy (..) , UnableToConstructChangeError (..) , addMintValueToChangeMaps , addMintValuesToChangeMaps @@ -1494,6 +1495,7 @@ runMockSelectionStep d = , updatedQuantity = id , minimumQuantity = mockMinimum d , selectQuantity = \s -> pure $ (+ s) <$> mockNext d + , selectionStrategy = SelectionStrategyOptimal } prop_runSelectionStep_supplyExhausted From bf24395fb2b2e1bf379619af1ec095d8ba13e80a Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Fri, 4 Mar 2022 00:08:28 +0000 Subject: [PATCH 3/9] Make `targetQuantity` depend on `selectionStrategy` within `runSelectionStep`. --- .../src/Cardano/Wallet/CoinSelection/Internal/Balance.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/core/src/Cardano/Wallet/CoinSelection/Internal/Balance.hs b/lib/core/src/Cardano/Wallet/CoinSelection/Internal/Balance.hs index 86d7a53ac03..ba0c3926e7a 100644 --- a/lib/core/src/Cardano/Wallet/CoinSelection/Internal/Balance.hs +++ b/lib/core/src/Cardano/Wallet/CoinSelection/Internal/Balance.hs @@ -1295,6 +1295,7 @@ runSelectionStep lens s , updatedQuantity , minimumQuantity , selectQuantity + , selectionStrategy } = lens requireImprovement :: state' -> Maybe state' @@ -1308,8 +1309,12 @@ runSelectionStep lens s updatedDistanceFromTarget :: state' -> Natural updatedDistanceFromTarget = distance targetQuantity . updatedQuantity + targetMultiplier :: Natural + targetMultiplier = case selectionStrategy of + SelectionStrategyOptimal -> 2 + targetQuantity :: Natural - targetQuantity = minimumQuantity * 2 + targetQuantity = minimumQuantity * targetMultiplier -------------------------------------------------------------------------------- -- Making change From 367e67dd09799bb9b20141988f4a886b17bf8345 Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Fri, 4 Mar 2022 00:16:24 +0000 Subject: [PATCH 4/9] Add `SelectionStrategy` argument to `{asset,coin}SelectionLens` functions. --- .../Wallet/CoinSelection/Internal/Balance.hs | 15 +++++++++------ .../Wallet/CoinSelection/Internal/BalanceSpec.hs | 6 ++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/core/src/Cardano/Wallet/CoinSelection/Internal/Balance.hs b/lib/core/src/Cardano/Wallet/CoinSelection/Internal/Balance.hs index ba0c3926e7a..07c940f696f 100644 --- a/lib/core/src/Cardano/Wallet/CoinSelection/Internal/Balance.hs +++ b/lib/core/src/Cardano/Wallet/CoinSelection/Internal/Balance.hs @@ -1139,9 +1139,10 @@ runSelection params = reverse (coinSelector : fmap assetSelector minimumAssetQuantities) where assetSelector = runSelectionStep . - assetSelectionLens selectionLimit + assetSelectionLens selectionLimit SelectionStrategyOptimal coinSelector = runSelectionStep $ - coinSelectionLens selectionLimit minimumCoinQuantity + coinSelectionLens selectionLimit SelectionStrategyOptimal + minimumCoinQuantity (minimumCoinQuantity, minimumAssetQuantities) = TokenBundle.toFlatList minimumBalance @@ -1149,28 +1150,30 @@ runSelection params = assetSelectionLens :: (MonadRandom m, Ord u) => SelectionLimit + -> SelectionStrategy -> (AssetId, TokenQuantity) -> SelectionLens m (UTxOSelection u) (UTxOSelectionNonEmpty u) -assetSelectionLens limit (asset, minimumAssetQuantity) = SelectionLens +assetSelectionLens limit strategy (asset, minimumAssetQuantity) = SelectionLens { currentQuantity = selectedAssetQuantity asset , updatedQuantity = selectedAssetQuantity asset , minimumQuantity = unTokenQuantity minimumAssetQuantity , selectQuantity = selectAssetQuantity asset limit - , selectionStrategy = SelectionStrategyOptimal + , selectionStrategy = strategy } coinSelectionLens :: (MonadRandom m, Ord u) => SelectionLimit + -> SelectionStrategy -> Coin -- ^ Minimum coin quantity. -> SelectionLens m (UTxOSelection u) (UTxOSelectionNonEmpty u) -coinSelectionLens limit minimumCoinQuantity = SelectionLens +coinSelectionLens limit strategy minimumCoinQuantity = SelectionLens { currentQuantity = selectedCoinQuantity , updatedQuantity = selectedCoinQuantity , minimumQuantity = intCast $ unCoin minimumCoinQuantity , selectQuantity = selectCoinQuantity limit - , selectionStrategy = SelectionStrategyOptimal + , selectionStrategy = strategy } -- | Specializes 'selectMatchingQuantity' to a particular asset. diff --git a/lib/core/test/unit/Cardano/Wallet/CoinSelection/Internal/BalanceSpec.hs b/lib/core/test/unit/Cardano/Wallet/CoinSelection/Internal/BalanceSpec.hs index 8f097f523b2..0cc070ac046 100644 --- a/lib/core/test/unit/Cardano/Wallet/CoinSelection/Internal/BalanceSpec.hs +++ b/lib/core/test/unit/Cardano/Wallet/CoinSelection/Internal/BalanceSpec.hs @@ -1613,7 +1613,8 @@ prop_assetSelectionLens_givesPriorityToSingletonAssets (Blind (Small u)) = asset = Set.findMin $ UTxOIndex.assets u assetCount = Set.size $ UTxOIndex.assets u initialState = UTxOSelection.fromIndex u - lens = assetSelectionLens NoLimit (asset, minimumAssetQuantity) + lens = assetSelectionLens + NoLimit SelectionStrategyOptimal (asset, minimumAssetQuantity) minimumAssetQuantity = TokenQuantity 1 prop_coinSelectionLens_givesPriorityToCoins @@ -1643,7 +1644,8 @@ prop_coinSelectionLens_givesPriorityToCoins (Blind (Small u)) = where entryCount = UTxOIndex.size u initialState = UTxOSelection.fromIndex u - lens = coinSelectionLens NoLimit minimumCoinQuantity + lens = coinSelectionLens + NoLimit SelectionStrategyOptimal minimumCoinQuantity minimumCoinQuantity = Coin 1 -------------------------------------------------------------------------------- From 5f758bc419208862a82bc42f37dd6d4f9d073ec0 Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Fri, 4 Mar 2022 00:23:02 +0000 Subject: [PATCH 5/9] Add field `selectionStrategy` to `RunSelectionParams`. Additionally, adjust `runSelection` to pass the value of this field through to inner functions. --- .../src/Cardano/Wallet/CoinSelection/Internal/Balance.hs | 9 +++++++-- .../Cardano/Wallet/CoinSelection/Internal/BalanceSpec.hs | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/core/src/Cardano/Wallet/CoinSelection/Internal/Balance.hs b/lib/core/src/Cardano/Wallet/CoinSelection/Internal/Balance.hs index 07c940f696f..045564f0e6f 100644 --- a/lib/core/src/Cardano/Wallet/CoinSelection/Internal/Balance.hs +++ b/lib/core/src/Cardano/Wallet/CoinSelection/Internal/Balance.hs @@ -292,6 +292,7 @@ deriving instance -- data SelectionStrategy = SelectionStrategyOptimal + deriving (Eq, Show) -- | Indicates whether the balance of available UTxO entries is sufficient. -- @@ -854,6 +855,7 @@ performSelectionNonEmpty constraints params { selectionLimit , utxoAvailable , minimumBalance = utxoBalanceRequired + , selectionStrategy = SelectionStrategyOptimal } case maybeSelection of Nothing | utxoAvailable == UTxOSelection.empty -> @@ -1096,6 +1098,8 @@ data RunSelectionParams u = RunSelectionParams -- ^ UTxO entries available for selection. , minimumBalance :: TokenBundle -- ^ Minimum balance to cover. + , selectionStrategy :: SelectionStrategy + -- ^ Specifies which selection strategy to use. See 'SelectionStrategy'. } deriving (Eq, Generic, Show) @@ -1128,6 +1132,7 @@ runSelection params = { selectionLimit , utxoAvailable , minimumBalance + , selectionStrategy } = params -- NOTE: We run the 'coinSelector' last, because we know that every input @@ -1139,9 +1144,9 @@ runSelection params = reverse (coinSelector : fmap assetSelector minimumAssetQuantities) where assetSelector = runSelectionStep . - assetSelectionLens selectionLimit SelectionStrategyOptimal + assetSelectionLens selectionLimit selectionStrategy coinSelector = runSelectionStep $ - coinSelectionLens selectionLimit SelectionStrategyOptimal + coinSelectionLens selectionLimit selectionStrategy minimumCoinQuantity (minimumCoinQuantity, minimumAssetQuantities) = diff --git a/lib/core/test/unit/Cardano/Wallet/CoinSelection/Internal/BalanceSpec.hs b/lib/core/test/unit/Cardano/Wallet/CoinSelection/Internal/BalanceSpec.hs index 0cc070ac046..3ede774e01a 100644 --- a/lib/core/test/unit/Cardano/Wallet/CoinSelection/Internal/BalanceSpec.hs +++ b/lib/core/test/unit/Cardano/Wallet/CoinSelection/Internal/BalanceSpec.hs @@ -1253,6 +1253,7 @@ prop_runSelection_UTxO_empty balanceRequested = monadicIO $ do { selectionLimit = NoLimit , utxoAvailable , minimumBalance = balanceRequested + , selectionStrategy = SelectionStrategyOptimal } let balanceSelected = UTxOSelection.selectedBalance result let balanceLeftover = UTxOSelection.leftoverBalance result @@ -1275,6 +1276,7 @@ prop_runSelection_UTxO_notEnough utxoAvailable = monadicIO $ do { selectionLimit = NoLimit , utxoAvailable , minimumBalance = balanceRequested + , selectionStrategy = SelectionStrategyOptimal } let balanceSelected = UTxOSelection.selectedBalance result let balanceLeftover = UTxOSelection.leftoverBalance result @@ -1298,6 +1300,7 @@ prop_runSelection_UTxO_exactlyEnough utxoAvailable = monadicIO $ do { selectionLimit = NoLimit , utxoAvailable , minimumBalance = balanceRequested + , selectionStrategy = SelectionStrategyOptimal } let balanceSelected = UTxOSelection.selectedBalance result let balanceLeftover = UTxOSelection.leftoverBalance result @@ -1325,6 +1328,7 @@ prop_runSelection_UTxO_moreThanEnough utxoAvailable = monadicIO $ do { selectionLimit = NoLimit , utxoAvailable , minimumBalance = balanceRequested + , selectionStrategy = SelectionStrategyOptimal } let balanceSelected = UTxOSelection.selectedBalance result let balanceLeftover = UTxOSelection.leftoverBalance result @@ -1372,6 +1376,7 @@ prop_runSelection_UTxO_muchMoreThanEnough (Blind (Large index)) = { selectionLimit = NoLimit , utxoAvailable , minimumBalance = balanceRequested + , selectionStrategy = SelectionStrategyOptimal } let balanceSelected = UTxOSelection.selectedBalance result let balanceLeftover = UTxOSelection.leftoverBalance result From 007b14784ab210edc1ca54a69ca5a33a039fcf71 Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Fri, 4 Mar 2022 00:28:35 +0000 Subject: [PATCH 6/9] Add field `selectionStrategy` to `Balance.SelectionConstraints`. Additionally, adjust `performSelection` to pass the value of this field through to inner functions. --- lib/core/src/Cardano/Wallet/CoinSelection/Internal.hs | 3 +++ .../src/Cardano/Wallet/CoinSelection/Internal/Balance.hs | 6 +++++- .../Cardano/Wallet/CoinSelection/Internal/BalanceSpec.hs | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/core/src/Cardano/Wallet/CoinSelection/Internal.hs b/lib/core/src/Cardano/Wallet/CoinSelection/Internal.hs index 6df1bd7d84f..8d059c07231 100644 --- a/lib/core/src/Cardano/Wallet/CoinSelection/Internal.hs +++ b/lib/core/src/Cardano/Wallet/CoinSelection/Internal.hs @@ -72,6 +72,7 @@ import Cardano.Wallet.CoinSelection.Internal.Balance , SelectionDelta (..) , SelectionLimit , SelectionSkeleton + , SelectionStrategy (..) ) import Cardano.Wallet.CoinSelection.Internal.Collateral ( SelectionCollateralError ) @@ -371,6 +372,8 @@ toBalanceConstraintsParams (constraints, params) = & adjustComputeSelectionLimit , assessTokenBundleSize = view #assessTokenBundleSize constraints + , selectionStrategy = + SelectionStrategyOptimal } where adjustComputeMinimumCost diff --git a/lib/core/src/Cardano/Wallet/CoinSelection/Internal/Balance.hs b/lib/core/src/Cardano/Wallet/CoinSelection/Internal/Balance.hs index 045564f0e6f..d23e5b41b72 100644 --- a/lib/core/src/Cardano/Wallet/CoinSelection/Internal/Balance.hs +++ b/lib/core/src/Cardano/Wallet/CoinSelection/Internal/Balance.hs @@ -230,6 +230,9 @@ data SelectionConstraints = SelectionConstraints :: [(Address, TokenBundle)] -> SelectionLimit -- ^ Computes an upper bound for the number of ordinary inputs to -- select, given a current set of outputs. + , selectionStrategy + :: SelectionStrategy + -- ^ Specifies which selection strategy to use. See 'SelectionStrategy'. } deriving Generic @@ -855,7 +858,7 @@ performSelectionNonEmpty constraints params { selectionLimit , utxoAvailable , minimumBalance = utxoBalanceRequired - , selectionStrategy = SelectionStrategyOptimal + , selectionStrategy } case maybeSelection of Nothing | utxoAvailable == UTxOSelection.empty -> @@ -877,6 +880,7 @@ performSelectionNonEmpty constraints params , computeMinimumAdaQuantity , computeMinimumCost , computeSelectionLimit + , selectionStrategy } = constraints SelectionParams { outputsToCover diff --git a/lib/core/test/unit/Cardano/Wallet/CoinSelection/Internal/BalanceSpec.hs b/lib/core/test/unit/Cardano/Wallet/CoinSelection/Internal/BalanceSpec.hs index 3ede774e01a..4c365ad5f58 100644 --- a/lib/core/test/unit/Cardano/Wallet/CoinSelection/Internal/BalanceSpec.hs +++ b/lib/core/test/unit/Cardano/Wallet/CoinSelection/Internal/BalanceSpec.hs @@ -1064,6 +1064,7 @@ prop_performSelection mockConstraints params coverage = , computeMinimumAdaQuantity = computeMinimumAdaQuantityZero , computeMinimumCost = computeMinimumCostZero , computeSelectionLimit = const NoLimit + , selectionStrategy = SelectionStrategyOptimal } performSelection' = performSelection constraints' params in @@ -1700,6 +1701,7 @@ mkBoundaryTestExpectation (BoundaryTestData params expectedResult) = do , assessTokenBundleSize = unMockAssessTokenBundleSize $ boundaryTestBundleSizeAssessor params , computeSelectionLimit = const NoLimit + , selectionStrategy = SelectionStrategyOptimal } encodeBoundaryTestCriteria :: BoundaryTestCriteria -> SelectionParams InputId @@ -2116,6 +2118,8 @@ unMockSelectionConstraints m = SelectionConstraints unMockComputeMinimumCost $ view #computeMinimumCost m , computeSelectionLimit = unMockComputeSelectionLimit $ view #computeSelectionLimit m + , selectionStrategy = + SelectionStrategyOptimal } -------------------------------------------------------------------------------- From 7e6835ecb96c18eb3d8e0b869c140ae5cb79daeb Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Fri, 4 Mar 2022 00:38:40 +0000 Subject: [PATCH 7/9] Add field `selectionStrategy` to `CoinSelection.Internal.SelectionConstraints`. Additionally, adjust `toBalanceConstraintsParams` to pass the value of this field through to inner functions. --- lib/core/src/Cardano/Wallet/CoinSelection.hs | 3 +++ lib/core/src/Cardano/Wallet/CoinSelection/Internal.hs | 5 ++++- .../test/unit/Cardano/Wallet/CoinSelection/InternalSpec.hs | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/core/src/Cardano/Wallet/CoinSelection.hs b/lib/core/src/Cardano/Wallet/CoinSelection.hs index e1084576f5c..b0050cb5056 100644 --- a/lib/core/src/Cardano/Wallet/CoinSelection.hs +++ b/lib/core/src/Cardano/Wallet/CoinSelection.hs @@ -69,6 +69,7 @@ import Cardano.Wallet.CoinSelection.Internal.Balance , SelectionBalanceError (..) , SelectionLimit , SelectionLimitOf (..) + , SelectionStrategy (..) , UnableToConstructChangeError (..) , balanceMissing ) @@ -174,6 +175,8 @@ toInternalSelectionConstraints SelectionConstraints {..} = computeMinimumCost . toExternalSelectionSkeleton , computeSelectionLimit = computeSelectionLimit . fmap (uncurry TxOut) + , selectionStrategy = + SelectionStrategyOptimal , .. } diff --git a/lib/core/src/Cardano/Wallet/CoinSelection/Internal.hs b/lib/core/src/Cardano/Wallet/CoinSelection/Internal.hs index 8d059c07231..9d38f936779 100644 --- a/lib/core/src/Cardano/Wallet/CoinSelection/Internal.hs +++ b/lib/core/src/Cardano/Wallet/CoinSelection/Internal.hs @@ -176,6 +176,9 @@ data SelectionConstraints = SelectionConstraints :: Natural -- ^ Specifies the minimum required amount of collateral as a -- percentage of the total transaction fee. + , selectionStrategy + :: SelectionStrategy + -- ^ Specifies which selection strategy to use. See 'SelectionStrategy'. } deriving Generic @@ -373,7 +376,7 @@ toBalanceConstraintsParams (constraints, params) = , assessTokenBundleSize = view #assessTokenBundleSize constraints , selectionStrategy = - SelectionStrategyOptimal + view #selectionStrategy constraints } where adjustComputeMinimumCost diff --git a/lib/core/test/unit/Cardano/Wallet/CoinSelection/InternalSpec.hs b/lib/core/test/unit/Cardano/Wallet/CoinSelection/InternalSpec.hs index f33ea898eba..47a078f3496 100644 --- a/lib/core/test/unit/Cardano/Wallet/CoinSelection/InternalSpec.hs +++ b/lib/core/test/unit/Cardano/Wallet/CoinSelection/InternalSpec.hs @@ -34,7 +34,7 @@ import Cardano.Wallet.CoinSelection.Internal , verifySelectionError ) import Cardano.Wallet.CoinSelection.Internal.Balance - ( SelectionLimit, SelectionSkeleton ) + ( SelectionLimit, SelectionSkeleton, SelectionStrategy (..) ) import Cardano.Wallet.CoinSelection.Internal.Balance.Gen ( genSelectionSkeleton, shrinkSelectionSkeleton ) import Cardano.Wallet.CoinSelection.Internal.BalanceSpec @@ -577,6 +577,8 @@ unMockSelectionConstraints m = SelectionConstraints view #maximumCollateralInputCount m , minimumCollateralPercentage = view #minimumCollateralPercentage m + , selectionStrategy = + SelectionStrategyOptimal } -------------------------------------------------------------------------------- From 72b9b5ac70bcf62dd561a61e53cd90a201a26d36 Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Fri, 4 Mar 2022 00:43:56 +0000 Subject: [PATCH 8/9] Add field `selectionStrategy` to `Wallet.CoinSelection.SelectionConstraints`. Additionally, adjust `toInternalSelectionConstraints` to pass the value of this field through to inner functions. --- lib/core/src/Cardano/Wallet.hs | 3 +++ lib/core/src/Cardano/Wallet/CoinSelection.hs | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/core/src/Cardano/Wallet.hs b/lib/core/src/Cardano/Wallet.hs index 5036e3d7531..bf68d047887 100644 --- a/lib/core/src/Cardano/Wallet.hs +++ b/lib/core/src/Cardano/Wallet.hs @@ -230,6 +230,7 @@ import Cardano.Wallet.CoinSelection , SelectionReportDetailed , SelectionReportSummarized , SelectionSkeleton (..) + , SelectionStrategy (..) , UnableToConstructChangeError (..) , emptySkeleton , makeSelectionReportDetailed @@ -1986,6 +1987,8 @@ selectAssets ctx pp params transform = do intCast @Word16 @Int $ view #maximumCollateralInputCount pp , minimumCollateralPercentage = view #minimumCollateralPercentage pp + , selectionStrategy = + SelectionStrategyOptimal } let selectionParams = SelectionParams { assetsToMint = diff --git a/lib/core/src/Cardano/Wallet/CoinSelection.hs b/lib/core/src/Cardano/Wallet/CoinSelection.hs index b0050cb5056..0d416ef4cdc 100644 --- a/lib/core/src/Cardano/Wallet/CoinSelection.hs +++ b/lib/core/src/Cardano/Wallet/CoinSelection.hs @@ -31,6 +31,7 @@ module Cardano.Wallet.CoinSelection , SelectionLimitOf (..) , SelectionOf (..) , SelectionParams (..) + , SelectionStrategy (..) -- * Selection skeletons , SelectionSkeleton (..) @@ -164,6 +165,9 @@ data SelectionConstraints = SelectionConstraints :: Natural -- ^ Specifies the minimum required amount of collateral as a -- percentage of the total transaction fee. + , selectionStrategy + :: SelectionStrategy + -- ^ Specifies which selection strategy to use. See 'SelectionStrategy'. } deriving Generic @@ -175,8 +179,6 @@ toInternalSelectionConstraints SelectionConstraints {..} = computeMinimumCost . toExternalSelectionSkeleton , computeSelectionLimit = computeSelectionLimit . fmap (uncurry TxOut) - , selectionStrategy = - SelectionStrategyOptimal , .. } From 455bf4273b4007cf680f193ebdd13583d527930e Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Fri, 4 Mar 2022 01:30:10 +0000 Subject: [PATCH 9/9] Add field `selectionStrategy` to `SelectAssetsParams`. Additionally, adjust `selectAssets` to pass the value of this field through to inner functions. --- lib/core/src/Cardano/Wallet.hs | 5 ++++- lib/core/src/Cardano/Wallet/Api/Server.hs | 10 ++++++++++ lib/shelley/bench/restore-bench.hs | 4 +++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/core/src/Cardano/Wallet.hs b/lib/core/src/Cardano/Wallet.hs index bf68d047887..f3bab5046e4 100644 --- a/lib/core/src/Cardano/Wallet.hs +++ b/lib/core/src/Cardano/Wallet.hs @@ -1541,6 +1541,7 @@ balanceTransaction , utxoAvailableForInputs , utxoAvailableForCollateral , wallet + , selectionStrategy = SelectionStrategyOptimal } transform @@ -1930,6 +1931,8 @@ data SelectAssetsParams s result = SelectAssetsParams , utxoAvailableForCollateral :: Map InputId TokenBundle , utxoAvailableForInputs :: UTxOSelection InputId , wallet :: Wallet s + , selectionStrategy :: SelectionStrategy + -- ^ Specifies which selection strategy to use. See 'SelectionStrategy'. } deriving Generic @@ -1988,7 +1991,7 @@ selectAssets ctx pp params transform = do , minimumCollateralPercentage = view #minimumCollateralPercentage pp , selectionStrategy = - SelectionStrategyOptimal + view #selectionStrategy params } let selectionParams = SelectionParams { assetsToMint = diff --git a/lib/core/src/Cardano/Wallet/Api/Server.hs b/lib/core/src/Cardano/Wallet/Api/Server.hs index 86a91da015f..09f2b8f7be3 100644 --- a/lib/core/src/Cardano/Wallet/Api/Server.hs +++ b/lib/core/src/Cardano/Wallet/Api/Server.hs @@ -314,6 +314,7 @@ import Cardano.Wallet.CoinSelection , SelectionOutputError (..) , SelectionOutputSizeExceedsLimitError (..) , SelectionOutputTokenQuantityExceedsLimitError (..) + , SelectionStrategy (..) , balanceMissing , selectionDelta , shortfall @@ -1599,6 +1600,7 @@ selectCoins ctx genChange (ApiT wid) body = do , utxoAvailableForInputs = UTxOSelection.fromIndex utxoAvailable , utxoAvailableForCollateral = UTxOIndex.toMap utxoAvailable , wallet + , selectionStrategy = SelectionStrategyOptimal } utx <- liftHandler $ W.selectAssets @_ @_ @s @k wrk pp selectAssetsParams transform @@ -1650,6 +1652,7 @@ selectCoinsForJoin ctx knownPools getPoolStatus pid wid = do , utxoAvailableForInputs = UTxOSelection.fromIndex utxoAvailable , utxoAvailableForCollateral = UTxOIndex.toMap utxoAvailable , wallet + , selectionStrategy = SelectionStrategyOptimal } utx <- liftHandler $ W.selectAssets @_ @_ @s @k wrk pp selectAssetsParams transform @@ -1701,6 +1704,7 @@ selectCoinsForQuit ctx (ApiT wid) = do , utxoAvailableForInputs = UTxOSelection.fromIndex utxoAvailable , utxoAvailableForCollateral = UTxOIndex.toMap utxoAvailable , wallet + , selectionStrategy = SelectionStrategyOptimal } utx <- liftHandler $ W.selectAssets @_ @_ @s @k wrk pp selectAssetsParams transform @@ -1969,6 +1973,7 @@ postTransactionOld ctx genChange (ApiT wid) body = do , utxoAvailableForCollateral = UTxOIndex.toMap utxoAvailable , wallet + , selectionStrategy = SelectionStrategyOptimal } sel <- liftHandler $ W.selectAssets @_ @_ @s @k wrk pp selectAssetsParams @@ -2119,6 +2124,7 @@ postTransactionFeeOld ctx (ApiT wid) body = do , utxoAvailableForInputs = UTxOSelection.fromIndex utxoAvailable , utxoAvailableForCollateral = UTxOIndex.toMap utxoAvailable , wallet + , selectionStrategy = SelectionStrategyOptimal } let runSelection = W.selectAssets @_ @_ @s @k wrk pp selectAssetsParams getFee @@ -2230,6 +2236,7 @@ constructTransaction ctx genChange knownPools getPoolStatus (ApiT wid) body = do , utxoAvailableForCollateral = UTxOIndex.toMap utxoAvailable , wallet + , selectionStrategy = SelectionStrategyOptimal } (sel, sel', fee) <- do @@ -2588,6 +2595,7 @@ joinStakePool ctx knownPools getPoolStatus apiPoolId (ApiT wid) body = do , utxoAvailableForInputs = UTxOSelection.fromIndex utxoAvailable , utxoAvailableForCollateral = UTxOIndex.toMap utxoAvailable , wallet + , selectionStrategy = SelectionStrategyOptimal } sel <- liftHandler $ W.selectAssets @_ @_ @s @k wrk pp selectAssetsParams @@ -2656,6 +2664,7 @@ delegationFee ctx (ApiT wid) = do , utxoAvailableForInputs = UTxOSelection.fromIndex utxoAvailable , utxoAvailableForCollateral = UTxOIndex.toMap utxoAvailable , wallet + , selectionStrategy = SelectionStrategyOptimal } quitStakePool @@ -2702,6 +2711,7 @@ quitStakePool ctx (ApiT wid) body = do , utxoAvailableForInputs = UTxOSelection.fromIndex utxoAvailable , utxoAvailableForCollateral = UTxOIndex.toMap utxoAvailable , wallet + , selectionStrategy = SelectionStrategyOptimal } sel <- liftHandler $ W.selectAssets @_ @_ @s @k wrk pp selectAssetsParams diff --git a/lib/shelley/bench/restore-bench.hs b/lib/shelley/bench/restore-bench.hs index fbea7c6b479..c9a6ec841fa 100644 --- a/lib/shelley/bench/restore-bench.hs +++ b/lib/shelley/bench/restore-bench.hs @@ -69,7 +69,7 @@ import Cardano.Wallet.BenchShared , runBenchmarks ) import Cardano.Wallet.CoinSelection - ( selectionDelta ) + ( SelectionStrategy (..), selectionDelta ) import Cardano.Wallet.DB ( DBLayer ) import Cardano.Wallet.DB.Sqlite @@ -466,6 +466,7 @@ benchmarksRnd _ w wid wname benchname restoreTime = do , utxoAvailableForInputs = UTxOSelection.fromIndex utxoAvailable , utxoAvailableForCollateral = UTxOIndex.toMap utxoAvailable , wallet + , selectionStrategy = SelectionStrategyOptimal } let runSelection = W.selectAssets @_ @_ @s @k w pp selectAssetsParams getFee @@ -569,6 +570,7 @@ benchmarksSeq _ w wid _wname benchname restoreTime = do , utxoAvailableForInputs = UTxOSelection.fromIndex utxoAvailable , utxoAvailableForCollateral = UTxOIndex.toMap utxoAvailable , wallet + , selectionStrategy = SelectionStrategyOptimal } let runSelection = W.selectAssets @_ @_ @s @k w pp selectAssetsParams getFee