Skip to content

Commit 5c7080d

Browse files
authored
fix smoke-tests by squashing the UTxO to get a suitable output (#1964)
Mainnet smoke tests [failed](https://github.com/cardano-scaling/hydra/actions/runs/14647088689/job/41103915845) to publish the hydra script txs, despite the faucet UTxO having sufficient total value. > hydra-cluster: FailedToFindUTxOToCoverDeposit {totalDeposit = Coin 80747850} We suspect the reason is because the required deposit amount couldn't be covered by any single output. Here we propose to squash the UTxO outputs to create one large enough. <!-- Describe your change here --> --- <!-- Consider each and tick it off one way or the other --> * [x] CHANGELOG updated or not needed * [x] Documentation updated or not needed * [x] Haddocks updated or not needed * [x] No new TODOs introduced or explained herafter
1 parent 202caba commit 5c7080d

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

hydra-cluster/test/Test/Hydra/Cluster/FaucetSpec.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ spec =
6363
difference `shouldSatisfy` (< 400_000)
6464

6565
describe "publishHydraScriptsAs" $ do
66-
it "selects a suitable output" $ \(tracer, node@RunningNode{networkId, nodeSocket}) -> do
66+
it "squash the UTxO to get a suitable output" $ \(tracer, node@RunningNode{networkId, nodeSocket}) -> do
6767
-- NOTE: Note use 'Faucet' as this has a very big initial amount
6868
(vk, _) <- keysFor Alice
6969
-- NOTE: 83 ADA is just enough to pay for reference scripts deposits.
7070
forM_ [1_000_000, 2_000_000, 83_000_000] $ \c -> seedFromFaucet node vk c tracer
71-
utxoBefore <- queryUTxOFor networkId nodeSocket QueryTip vk
7271

7372
void $ publishHydraScriptsAs node Alice
7473

75-
-- Also, does not squash UTxO
74+
-- it squashed the UTxO
7675
utxoAfter <- queryUTxOFor networkId nodeSocket QueryTip vk
77-
length utxoAfter `shouldBe` length utxoBefore
76+
77+
length utxoAfter `shouldBe` 1

hydra-node/src/Hydra/Chain/ScriptRegistry.hs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import Hydra.Prelude
77
import Cardano.Api.UTxO qualified as UTxO
88
import Data.List ((!!))
99
import Hydra.Cardano.Api (
10-
Coin,
1110
Era,
1211
EraHistory,
1312
Key (..),
@@ -32,9 +31,7 @@ import Hydra.Cardano.Api (
3231
mkTxIn,
3332
mkTxOutAutoBalance,
3433
mkVkAddress,
35-
selectLovelace,
3634
toCtxUTxOTxOut,
37-
txOutValue,
3835
txOuts',
3936
pattern TxOutDatumNone,
4037
)
@@ -103,10 +100,9 @@ publishHydraScripts networkId socketPath sk = do
103100
vk = getVerificationKey sk
104101

105102
-- | Exception raised when building the script publishing transactions.
106-
data PublishScriptException
103+
newtype PublishScriptException
107104
= FailedToBuildPublishingTx (TxBodyErrorAutoBalance Era)
108-
| FailedToFindUTxOToCoverDeposit {totalDeposit :: Coin}
109-
deriving (Show)
105+
deriving newtype (Show)
110106
deriving anyclass (Exception)
111107

112108
-- | Builds a chain of script publishing transactions.
@@ -124,22 +120,14 @@ buildScriptPublishingTxs ::
124120
SigningKey PaymentKey ->
125121
m [Tx]
126122
buildScriptPublishingTxs pparams systemStart networkId eraHistory stakePools availableUTxO sk = do
127-
startUTxO <- findUTxO
128-
go startUTxO scriptOutputs
123+
go availableUTxO scriptOutputs
129124
where
130-
-- Find a suitable utxo that covers at least the total deposit
131-
findUTxO =
132-
case UTxO.find (\o -> selectLovelace (txOutValue o) > totalDeposit) availableUTxO of
133-
Nothing -> throwIO FailedToFindUTxOToCoverDeposit{totalDeposit}
134-
Just (i, o) -> pure $ UTxO.singleton (i, o)
135-
136-
totalDeposit = sum $ selectLovelace . txOutValue <$> scriptOutputs
137-
138125
scriptOutputs =
139126
mkScriptTxOut . mkScriptRef
140127
<$> [initialValidatorScript, commitValidatorScript, Head.validatorScript]
141128

142-
-- Loop over all script outputs to create while re-spending the change output
129+
-- Loop over all script outputs to create while re-spending the change output.
130+
-- Note that we spend the entire UTxO set to cover the deposit scripts, resulting in a squashed UTxO at the end.
143131
go _ [] = pure []
144132
go utxo (out : rest) = do
145133
tx <- case buildTransactionWithPParams' pparams systemStart eraHistory stakePools changeAddress utxo [] [out] of

0 commit comments

Comments
 (0)