Skip to content

Commit

Permalink
logging of unused collateral option
Browse files Browse the repository at this point in the history
  • Loading branch information
mmontin committed Jul 11, 2024
1 parent e8b2091 commit 32100bd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@
* it is now a component of `MonadBlockChainBalancing`
* it can be turned on/off in skeleton options
* it now displays the discarding of utxos during balancing.
* it now displays when the users specifies useless collateral utxos

### Fixed

- All kinds of scripts can now be used as reference scripts.
- Transactions that do not involve script are now properly generated without any
collateral.

## [[4.0.0]](https://github.com/tweag/cooked-validators/releases/tag/v4.0.0) - 2024-06-28

Expand Down
19 changes: 10 additions & 9 deletions src/Cooked/MockChain/Balancing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,16 @@ balanceTxSkel skelUnbal@TxSkel {..} = do
-- We retrieve the various kinds of scripts
spendingScripts <- txSkelInputValidators skelUnbal
-- The transaction will only require collaterals when involving scripts
if Map.null txSkelMints && null (mapMaybe txSkelProposalWitness txSkelProposals) && Map.null spendingScripts
then return Nothing
else
Just <$> case txOptCollateralUtxos txSkelOpts of
CollateralUtxosFromBalancingWallet -> case balancingWallet of
Nothing -> fail "Can't select collateral utxos from a balancing wallet because it does not exist."
Just bWallet -> (,bWallet) . Set.fromList . map fst <$> runUtxoSearch (onlyValueOutputsAtSearch bWallet)
CollateralUtxosFromWallet cWallet -> (,cWallet) . Set.fromList . map fst <$> runUtxoSearch (onlyValueOutputsAtSearch cWallet)
CollateralUtxosFromSet utxos rWallet -> return (utxos, rWallet)
let noScriptInvolved = Map.null txSkelMints && null (mapMaybe txSkelProposalWitness txSkelProposals) && Map.null spendingScripts
case (noScriptInvolved, txOptCollateralUtxos txSkelOpts) of
(True, CollateralUtxosFromSet utxos _) -> publish (MCLogUnusedCollaterals $ Right utxos) >> return Nothing
(True, CollateralUtxosFromWallet cWallet) -> publish (MCLogUnusedCollaterals $ Left cWallet) >> return Nothing
(True, CollateralUtxosFromBalancingWallet) -> return Nothing
(False, CollateralUtxosFromSet utxos rWallet) -> return $ Just (utxos, rWallet)
(False, CollateralUtxosFromWallet cWallet) -> Just . (,cWallet) . Set.fromList . map fst <$> runUtxoSearch (onlyValueOutputsAtSearch cWallet)
(False, CollateralUtxosFromBalancingWallet) -> case balancingWallet of
Nothing -> fail "Can't select collateral utxos from a balancing wallet because it does not exist."
Just bWallet -> Just . (,bWallet) . Set.fromList . map fst <$> runUtxoSearch (onlyValueOutputsAtSearch bWallet)

-- At this point, the presence (or absence) of balancing wallet dictates
-- whether the transaction should be automatically balanced or not.
Expand Down
5 changes: 4 additions & 1 deletion src/Cooked/MockChain/BlockChain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,11 @@ data MockChainLogEntry where
-- successfully sent for validation.
MCLogNewTx :: Api.TxId -> MockChainLogEntry
-- | Logging the fact that utxos provided by the user for balancing have to be
-- discarded for a specific reason.
-- discarded for a given reason.
MCLogDiscardedUtxos :: Integer -> String -> MockChainLogEntry
-- | Logging the fact that utxos provided as collaterals will not be used
-- because the transaction does not need involve scripts.
MCLogUnusedCollaterals :: Either Wallet (Set Api.TxOutRef) -> MockChainLogEntry

-- | Contains methods needed for balancing.
class (MonadFail m, MonadError MockChainError m) => MonadBlockChainBalancing m where
Expand Down
8 changes: 8 additions & 0 deletions src/Cooked/Pretty/Cooked.hs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ instance PrettyCooked MockChainLogEntry where
]
prettyCookedOpt opts (MCLogNewTx txId) = "New transaction:" <+> prettyCookedOpt opts txId
prettyCookedOpt opts (MCLogDiscardedUtxos n s) = prettyCookedOpt opts n <+> "balancing utxos were discarded:" <+> PP.pretty s
prettyCookedOpt opts (MCLogUnusedCollaterals (Left cWallet)) =
"Specific request to fetch collateral utxos from"
<+> prettyCookedOpt opts (walletPKHash cWallet)
<+> "has been disregarded because the transaction does not require collaterals"
prettyCookedOpt opts (MCLogUnusedCollaterals (Right (length -> n))) =
"Specific request to fetch collateral utxos from the given set of"
<+> prettyCookedOpt opts n
<+> "elements has been disregarded because the transaction does not require collaterals"

prettyTxSkel :: PrettyCookedOpts -> SkelContext -> TxSkel -> DocCooked
prettyTxSkel opts skelContext (TxSkel lbl txopts mints signers validityRange ins insReference outs proposals) =
Expand Down

0 comments on commit 32100bd

Please sign in to comment.