Skip to content

Commit a0fe92c

Browse files
committed
Remove support for partial committing in regular commit process
Signed-off-by: Sasha Bogicevic <[email protected]>
1 parent a633c0e commit a0fe92c

File tree

18 files changed

+111
-141
lines changed

18 files changed

+111
-141
lines changed

hydra-cluster/src/Hydra/Cluster/Scenarios.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ import Hydra.Logging (Tracer, traceWith)
109109
import Hydra.Node.DepositPeriod (DepositPeriod (..))
110110
import Hydra.Options (CardanoChainConfig (..), ChainBackendOptions (..), DirectOptions (..), RunOptions (..), startChainFrom)
111111
import Hydra.Tx (HeadId, IsTx (balance), Party, txId)
112-
import Hydra.Tx.Commit (capUTxO)
113112
import Hydra.Tx.ContestationPeriod qualified as CP
113+
import Hydra.Tx.Deposit (capUTxO)
114114
import Hydra.Tx.Utils (dummyValidatorScript, verificationKeyToOnChainId)
115115
import HydraNode (
116116
HydraClient (..),
@@ -566,15 +566,13 @@ singlePartyCommitsFromExternal tracer workDir backend hydraScriptsTxId =
566566

567567
(walletVk, walletSk) <- keysFor AliceFunds
568568
utxoToCommit <- seedFromFaucet backend walletVk 5_000_000 (contramap FromFaucet tracer)
569-
let amount = 2_000_000
570-
let (toCommit, _leftover) = capUTxO utxoToCommit amount
571569

572570
res <-
573571
runReq defaultHttpConfig $
574572
req
575573
POST
576574
(http "127.0.0.1" /: "commit")
577-
(ReqBodyJson $ SimpleCommitRequest @Tx utxoToCommit (Just amount))
575+
(ReqBodyJson utxoToCommit)
578576
(Proxy :: Proxy (JsonResponse (DraftCommitTxResponse Tx)))
579577
(port $ 4000 + hydraNodeId)
580578

@@ -585,7 +583,7 @@ singlePartyCommitsFromExternal tracer workDir backend hydraScriptsTxId =
585583
guard $ v ^? key "headId" == Just (toJSON headId)
586584
guard $ v ^? key "tag" == Just "HeadIsOpen"
587585
pure $ v ^? key "utxo"
588-
lockedUTxO `shouldBe` Just (toJSON toCommit)
586+
lockedUTxO `shouldBe` Just (toJSON utxoToCommit)
589587

590588
singlePartyUsesScriptOnL2 ::
591589
ChainBackend backend =>

hydra-cluster/test/Test/BlockfrostChainSpec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ withBlockfrostChainTest tracer config party action = do
175175
{ postTx
176176
, waitCallback = atomically $ takeTMVar eventMVar
177177
, draftCommitTx = \headId utxo blueprintTx -> do
178-
eTx <- draftCommitTx headId CommitBlueprintTx{lookupUTxO = utxo, blueprintTx} Nothing
178+
eTx <- draftCommitTx headId CommitBlueprintTx{lookupUTxO = utxo, blueprintTx}
179179
case eTx of
180180
Left e -> throwIO e
181181
Right tx -> pure tx

hydra-cluster/test/Test/DirectChainSpec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ withDirectChainTest tracer config party action = do
559559
{ postTx
560560
, waitCallback = atomically $ takeTMVar eventMVar
561561
, draftCommitTx = \headId utxo blueprintTx -> do
562-
eTx <- draftCommitTx headId CommitBlueprintTx{lookupUTxO = utxo, blueprintTx} Nothing
562+
eTx <- draftCommitTx headId CommitBlueprintTx{lookupUTxO = utxo, blueprintTx}
563563
case eTx of
564564
Left e -> throwIO e
565565
Right tx -> pure tx

hydra-node/bench/tx-cost/TxCost.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ computeCommitCost = do
113113
(cctx, stInitial) <- genStInitial ctx
114114
let InitialState{headId} = stInitial
115115
knownUTxO = getKnownUTxO stInitial <> getKnownUTxO cctx
116-
pure (commit cctx headId knownUTxO utxo Nothing, knownUTxO)
116+
pure (commit cctx headId knownUTxO utxo, knownUTxO)
117117

118118
computeCollectComCost :: Gen [(NumParties, Natural, TxSize, MemUnit, CpuUnit, Coin)]
119119
computeCollectComCost =

hydra-node/src/Hydra/API/HTTPServer.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,10 @@ handleDraftCommitUtxo env pparams directChain getCommitInfo body = do
281281
NormalCommit headId ->
282282
case someCommitRequest of
283283
FullCommitRequest{blueprintTx, utxo} -> do
284-
draftCommit headId utxo blueprintTx Nothing
285-
SimpleCommitRequest{utxoToCommit, amount} -> do
284+
draftCommit headId utxo blueprintTx
285+
SimpleCommitRequest{utxoToCommit} -> do
286286
let blueprintTx = txSpendingUTxO utxoToCommit
287-
draftCommit headId utxoToCommit blueprintTx amount
287+
draftCommit headId utxoToCommit blueprintTx
288288
IncrementalCommit headId -> do
289289
case someCommitRequest of
290290
FullCommitRequest{blueprintTx, utxo} -> do
@@ -302,8 +302,8 @@ handleDraftCommitUtxo env pparams directChain getCommitInfo body = do
302302
Left e -> responseLBS status400 jsonContent (Aeson.encode $ toJSON e)
303303
Right depositTx -> okJSON $ DraftCommitTxResponse depositTx
304304

305-
draftCommit headId lookupUTxO blueprintTx amount = do
306-
draftCommitTx headId CommitBlueprintTx{lookupUTxO, blueprintTx} amount <&> \case
305+
draftCommit headId lookupUTxO blueprintTx = do
306+
draftCommitTx headId CommitBlueprintTx{lookupUTxO, blueprintTx} <&> \case
307307
Left e ->
308308
-- Distinguish between errors users can actually benefit from and
309309
-- other errors that are turned into 500 responses.

hydra-node/src/Hydra/Chain.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ data Chain tx m = Chain
265265
MonadThrow m =>
266266
HeadId ->
267267
CommitBlueprintTx tx ->
268-
Maybe Coin ->
269268
m (Either (PostTxError tx) tx)
270269
-- ^ Create a commit transaction using user provided utxos (zero or many) and
271270
-- a _blueprint_ transaction which spends these outputs.

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,11 @@ mkChain tracer queryTimeHandle wallet ctx LocalChainState{getLatest} submitTx =
179179
atomically (prepareTxToPost timeHandle wallet ctx spendableUTxO tx)
180180
>>= finalizeTx wallet ctx spendableUTxO mempty
181181
submitTx vtx
182-
, draftCommitTx = \headId commitBlueprintTx amount -> do
182+
, draftCommitTx = \headId commitBlueprintTx -> do
183183
ChainStateAt{spendableUTxO} <- atomically getLatest
184184
let CommitBlueprintTx{lookupUTxO} = commitBlueprintTx
185-
traverse (finalizeTx wallet ctx spendableUTxO lookupUTxO) $ do
186-
checkAmount lookupUTxO amount
187-
commit' ctx headId spendableUTxO commitBlueprintTx amount
185+
traverse (finalizeTx wallet ctx spendableUTxO lookupUTxO) $
186+
commit' ctx headId spendableUTxO commitBlueprintTx
188187
, draftDepositTx = \headId pparams commitBlueprintTx deadline amount -> do
189188
let CommitBlueprintTx{lookupUTxO} = commitBlueprintTx
190189
ChainStateAt{spendableUTxO} <- atomically getLatest

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import Hydra.Cardano.Api (
1919
AssetId (..),
2020
AssetName (AssetName),
2121
ChainPoint (..),
22-
Coin,
2322
CtxUTxO,
2423
Key (SigningKey, VerificationKey, verificationKeyHash),
2524
NetworkId (Mainnet, Testnet),
@@ -329,11 +328,10 @@ commit ::
329328
UTxO ->
330329
-- | 'UTxO' to commit. All outputs are assumed to be owned by public keys
331330
UTxO ->
332-
Maybe Coin ->
333331
Either (PostTxError Tx) Tx
334-
commit ctx headId spendableUTxO lookupUTxO amount =
332+
commit ctx headId spendableUTxO lookupUTxO =
335333
let blueprintTx = txSpendingUTxO lookupUTxO
336-
in commit' ctx headId spendableUTxO CommitBlueprintTx{lookupUTxO, blueprintTx} amount
334+
in commit' ctx headId spendableUTxO CommitBlueprintTx{lookupUTxO, blueprintTx}
337335

338336
-- | Construct a commit transaction based on known, spendable UTxO and some
339337
-- user UTxO inputs to commit. This does look for "our initial output" to spend
@@ -347,14 +345,13 @@ commit' ::
347345
-- | Spendable 'UTxO'
348346
UTxO ->
349347
CommitBlueprintTx Tx ->
350-
Maybe Coin ->
351348
Either (PostTxError Tx) Tx
352-
commit' ctx headId spendableUTxO commitBlueprintTx amount = do
349+
commit' ctx headId spendableUTxO commitBlueprintTx = do
353350
pid <- headIdToPolicyId headId ?> InvalidHeadId{headId}
354351
(i, o) <- ownInitial pid ?> CannotFindOwnInitial{knownUTxO = spendableUTxO}
355352
rejectByronAddress lookupUTxO
356353
rejectMoreThanMainnetLimit networkId lookupUTxO
357-
pure $ commitTx networkId scriptRegistry headId ownParty commitBlueprintTx (i, o, vkh) amount
354+
pure $ commitTx networkId scriptRegistry headId ownParty commitBlueprintTx (i, o, vkh)
358355
where
359356
CommitBlueprintTx{lookupUTxO} = commitBlueprintTx
360357

@@ -940,7 +937,7 @@ genChainStateWithTx =
940937
(cctx, stInitial) <- genStInitial ctx
941938
utxo <- genCommit
942939
let InitialState{headId} = stInitial
943-
let tx = unsafeCommit cctx headId (getKnownUTxO stInitial) utxo Nothing
940+
let tx = unsafeCommit cctx headId (getKnownUTxO stInitial) utxo
944941
pure (cctx, Initial stInitial, mempty, tx, Commit)
945942

946943
genCollectWithState :: Gen (ChainContext, ChainState, UTxO, Tx, ChainTransition)
@@ -1101,7 +1098,7 @@ genCommits' genUTxO ctx txInit = do
11011098
allChainContexts <- deriveChainContexts ctx
11021099
forM (zip allChainContexts scaledCommitUTxOs) $ \(cctx, toCommit) -> do
11031100
let stInitial@InitialState{headId} = unsafeObserveInit cctx (ctxVerificationKeys ctx) txInit
1104-
pure $ unsafeCommit cctx headId (getKnownUTxO stInitial) toCommit Nothing
1101+
pure $ unsafeCommit cctx headId (getKnownUTxO stInitial) toCommit
11051102
where
11061103
scaleCommitUTxOs :: [UTxO] -> [UTxO]
11071104
scaleCommitUTxOs commitUTxOs =
@@ -1320,10 +1317,9 @@ unsafeCommit ::
13201317
UTxO ->
13211318
-- | 'UTxO' to commit. All outputs are assumed to be owned by public keys.
13221319
UTxO ->
1323-
Maybe Coin ->
13241320
Tx
1325-
unsafeCommit ctx headId spendableUTxO utxoToCommit amount =
1326-
either (error . show) id $ commit ctx headId spendableUTxO utxoToCommit amount
1321+
unsafeCommit ctx headId spendableUTxO utxoToCommit =
1322+
either (error . show) id $ commit ctx headId spendableUTxO utxoToCommit
13271323

13281324
unsafeAbort ::
13291325
HasCallStack =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ withOfflineChain config party otherParties chainStateHistory callback action = d
8686
Chain
8787
{ mkChainState = initialChainState
8888
, submitTx = const $ pure ()
89-
, draftCommitTx = \_ _ _ -> pure $ Left FailedToDraftTxNotInitializing
89+
, draftCommitTx = \_ _ -> pure $ Left FailedToDraftTxNotInitializing
9090
, draftDepositTx = \_ _ _ _ _ -> pure $ Left FailedToConstructDepositTx{failureReason = "not implemented"}
9191
, postTx = const $ pure ()
9292
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ apiServerSpec = do
493493
let getHeadId = pure $ NormalCommit (generateWith arbitrary 42)
494494
let workingChainHandle =
495495
dummyChainHandle
496-
{ draftCommitTx = \_ _ _ -> do
496+
{ draftCommitTx = \_ _ -> do
497497
tx <- generate $ arbitrary @Tx
498498
pure $ Right tx
499499
}
@@ -521,7 +521,7 @@ apiServerSpec = do
521521
let failingChainHandle :: PostTxError tx -> Chain tx IO
522522
failingChainHandle postTxError =
523523
dummyChainHandle
524-
{ draftCommitTx = \_ _ _ -> pure $ Left postTxError
524+
{ draftCommitTx = \_ _ -> pure $ Left postTxError
525525
, draftDepositTx = \_ _ _ _ _ -> pure $ Left postTxError
526526
}
527527

0 commit comments

Comments
 (0)