Skip to content

Commit 704b67c

Browse files
authored
Merge pull request #1162 from input-output-hk/inline-datums
Protocol change: Inline datums
2 parents ac19103 + a4f9758 commit 704b67c

File tree

26 files changed

+14226
-11938
lines changed

26 files changed

+14226
-11938
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ changes.
3636

3737
- Persist network messages on disk in order to gracefully handle crashes
3838

39-
- **BREAKING** Changes to Hydra script hashes due to upgrading our toolchain to
40-
GHC 9.6
39+
- **BREAKING** Changes to Hydra scripts:
40+
- Switch to using inline datums instead of (optionally) published datums in
41+
transactions.
42+
- Upgrading our toolchain to GHC 9.6
43+
44+
- **BREAKING** Changes to persisted state:
45+
- The internal chain state serialization changed when switching to inline datums.
4146

4247
## [0.13.0] - 2023-10-03
4348

fourmolu.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ fixities:
1111
- infixr 0 $
1212
- infixr 1 &
1313
- infixl 3 <|>
14+
- infixr 3 &&

hydra-cluster/test/Test/ChainObserverSpec.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ spec = do
5353
chainObserverSees observer "HeadInitTx" headId
5454

5555
requestCommitTx hydraNode mempty >>= submitTx cardanoNode
56-
waitFor hydraTracer 600 [hydraNode] $
56+
waitFor hydraTracer 5 [hydraNode] $
5757
output "HeadIsOpen" ["utxo" .= object mempty, "headId" .= headId]
5858

5959
chainObserverSees observer "HeadCommitTx" headId
@@ -63,7 +63,7 @@ spec = do
6363

6464
chainObserverSees observer "HeadCloseTx" headId
6565

66-
waitFor hydraTracer 600 [hydraNode] $
66+
waitFor hydraTracer 50 [hydraNode] $
6767
output "ReadyToFanout" ["headId" .= headId]
6868

6969
send hydraNode $ input "Fanout" []

hydra-node/golden/ChainState.json

Lines changed: 252 additions & 148 deletions
Large diffs are not rendered by default.

hydra-node/golden/ReasonablySized (ServerOutput (Tx BabbageEra)).json

Lines changed: 13617 additions & 11360 deletions
Large diffs are not rendered by default.

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

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ import Hydra.Chain.Direct.Tx (
8080
NotAnInit (..),
8181
OpenThreadOutput (..),
8282
UTxOHash (UTxOHash),
83-
UTxOWithScript,
8483
abortTx,
8584
closeTx,
8685
collectComTx,
@@ -241,8 +240,8 @@ allVerificationKeys ChainContext{peerVerificationKeys, ownVerificationKey} =
241240

242241
data InitialState = InitialState
243242
{ initialThreadOutput :: InitialThreadOutput
244-
, initialInitials :: [UTxOWithScript]
245-
, initialCommits :: [UTxOWithScript]
243+
, initialInitials :: [(TxIn, TxOut CtxUTxO)]
244+
, initialCommits :: [(TxIn, TxOut CtxUTxO)]
246245
, headId :: HeadId
247246
, seedTxIn :: TxIn
248247
}
@@ -253,10 +252,8 @@ instance HasKnownUTxO InitialState where
253252
getKnownUTxO st =
254253
UTxO $
255254
Map.fromList $
256-
take2Of3 initialThreadUTxO : (take2Of3 <$> (initialInitials <> initialCommits))
255+
initialThreadUTxO : initialCommits <> initialInitials
257256
where
258-
take2Of3 (a, b, _c) = (a, b)
259-
260257
InitialState
261258
{ initialThreadOutput = InitialThreadOutput{initialThreadUTxO}
262259
, initialInitials
@@ -274,10 +271,10 @@ data OpenState = OpenState
274271

275272
instance HasKnownUTxO OpenState where
276273
getKnownUTxO st =
277-
UTxO.singleton (i, o)
274+
UTxO.singleton openThreadUTxO
278275
where
279276
OpenState
280-
{ openThreadOutput = OpenThreadOutput{openThreadUTxO = (i, o, _)}
277+
{ openThreadOutput = OpenThreadOutput{openThreadUTxO}
281278
} = st
282279

283280
data ClosedState = ClosedState
@@ -290,10 +287,10 @@ data ClosedState = ClosedState
290287

291288
instance HasKnownUTxO ClosedState where
292289
getKnownUTxO st =
293-
UTxO.singleton (i, o)
290+
UTxO.singleton closedThreadUTxO
294291
where
295292
ClosedState
296-
{ closedThreadOutput = ClosedThreadOutput{closedThreadUTxO = (i, o, _)}
293+
{ closedThreadOutput = ClosedThreadOutput{closedThreadUTxO}
297294
} = st
298295

299296
-- * Constructing transactions
@@ -354,7 +351,7 @@ ownInitial ChainContext{ownVerificationKey} st@InitialState{initialInitials} =
354351
foldl' go Nothing initialInitials
355352
where
356353
go (Just x) _ = Just x
357-
go Nothing (i, out, _) = do
354+
go Nothing (i, out) = do
358355
let vkh = verificationKeyHash ownVerificationKey
359356
guard $ hasMatchingPT st vkh (txOutValue out)
360357
pure (i, out, vkh)
@@ -403,10 +400,10 @@ abort ::
403400
UTxO ->
404401
Tx
405402
abort ctx st committedUTxO = do
406-
let InitialThreadOutput{initialThreadUTxO = (i, o, dat)} = initialThreadOutput
407-
initials = Map.fromList $ map tripleToPair initialInitials
408-
commits = Map.fromList $ map tripleToPair initialCommits
409-
in case abortTx committedUTxO scriptRegistry ownVerificationKey (i, o, dat) headTokenScript initials commits of
403+
let InitialThreadOutput{initialThreadUTxO = (i, o)} = initialThreadOutput
404+
initials = Map.fromList initialInitials
405+
commits = Map.fromList initialCommits
406+
in case abortTx committedUTxO scriptRegistry ownVerificationKey (i, o) headTokenScript initials commits of
410407
Left OverlappingInputs ->
411408
-- FIXME: This is a "should not happen" error. We should try to fix
412409
-- the arguments of abortTx to make it impossible of having
@@ -426,16 +423,14 @@ abort ctx st committedUTxO = do
426423
, seedTxIn
427424
} = st
428425

429-
tripleToPair (a, b, c) = (a, (b, c))
430-
431426
-- | Construct a collect transaction based on the 'InitialState'. This will know
432427
-- collect all the committed outputs.
433428
collect ::
434429
ChainContext ->
435430
InitialState ->
436431
Tx
437432
collect ctx st = do
438-
let commits = Map.fromList $ fmap tripleToPair initialCommits
433+
let commits = Map.fromList initialCommits
439434
in collectComTx networkId scriptRegistry ownVerificationKey initialThreadOutput commits headId
440435
where
441436
ChainContext{networkId, ownVerificationKey, scriptRegistry} = ctx
@@ -446,8 +441,6 @@ collect ctx st = do
446441
, headId
447442
} = st
448443

449-
tripleToPair (a, b, c) = (a, (b, c))
450-
451444
-- | Construct a close transaction based on the 'OpenState' and a confirmed
452445
-- snapshot.
453446
-- - 'SlotNo' parameter will be used as the 'Tx' lower bound.
@@ -519,15 +512,15 @@ fanout ::
519512
SlotNo ->
520513
Tx
521514
fanout ctx st utxo deadlineSlotNo = do
522-
fanoutTx scriptRegistry utxo (i, o, dat) deadlineSlotNo headTokenScript
515+
fanoutTx scriptRegistry utxo closedThreadUTxO deadlineSlotNo headTokenScript
523516
where
524517
headTokenScript = mkHeadTokenScript seedTxIn
525518

526519
ChainContext{scriptRegistry} = ctx
527520

528521
ClosedState{closedThreadOutput, seedTxIn} = st
529522

530-
ClosedThreadOutput{closedThreadUTxO = (i, o, dat)} = closedThreadOutput
523+
ClosedThreadOutput{closedThreadUTxO} = closedThreadOutput
531524

532525
-- * Observing Transitions
533526

@@ -617,7 +610,7 @@ observeCommit ctx st tx = do
617610
{ initialInitials =
618611
-- NOTE: A commit tx has been observed and thus we can
619612
-- remove all it's inputs from our tracked initials
620-
filter ((`notElem` txIns' tx) . fst3) initialInitials
613+
filter ((`notElem` txIns' tx) . fst) initialInitials
621614
, initialCommits =
622615
commitOutput : initialCommits
623616
}
@@ -631,8 +624,6 @@ observeCommit ctx st tx = do
631624
, headId
632625
} = st
633626

634-
fst3 (a, _b, _c) = a
635-
636627
-- | Observe an collect transition using a 'InitialState' and 'observeCollectComTx'.
637628
-- This function checks the head id and ignores if not relevant.
638629
observeCollect ::

0 commit comments

Comments
 (0)