Skip to content

Commit

Permalink
Add snapshotNumber field to Open head state
Browse files Browse the repository at this point in the history
  • Loading branch information
locallycompact authored and ch1bo committed Apr 17, 2024
1 parent e8f3cc7 commit 1e7d0b0
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 8 deletions.
4 changes: 3 additions & 1 deletion hydra-node/src/Hydra/Chain/Direct/Tx.hs
Expand Up @@ -326,6 +326,7 @@ collectComTx networkId scriptRegistry vk headId headParameters (headInput, initi
Head.Open
{ Head.parties = partyToChain <$> parties
, utxoHash
, snapshotNumber = 0
, contestationPeriod = toChain contestationPeriod
, headId = headIdToCurrencySymbol headId
}
Expand Down Expand Up @@ -394,10 +395,11 @@ decrementTx scriptRegistry vk headId headParameters (headInput, headOutput) snap
Head.Open
{ Head.parties = partyToChain <$> parties
, utxoHash
, snapshotNumber = toInteger number
, contestationPeriod = toChain contestationPeriod
, headId = headIdToCurrencySymbol headId
}
Snapshot{utxo, utxoToDecommit} = snapshot
Snapshot{utxo, utxoToDecommit, number} = snapshot

-- | Low-level data type of a snapshot to close the head with. This is different
-- to the 'ConfirmedSnasphot', which is provided to `CloseTx` as it also
Expand Down
2 changes: 2 additions & 0 deletions hydra-node/test/Hydra/Chain/Direct/Contract/Close.hs
Expand Up @@ -164,6 +164,7 @@ healthyOpenHeadDatum =
Head.Open
{ parties = healthyOnChainParties
, utxoHash = toBuiltin $ hashUTxO @Tx healthyUTxO
, snapshotNumber = toInteger healthyCloseSnapshotNumber
, contestationPeriod = healthyContestationPeriod
, headId = toPlutusCurrencySymbol Fixture.testPolicyId
}
Expand Down Expand Up @@ -310,6 +311,7 @@ genCloseMutation (tx, _utxo) =
Head.Open
{ parties = mutatedParties
, utxoHash = ""
, snapshotNumber = toInteger healthyCloseSnapshotNumber
, contestationPeriod = healthyContestationPeriod
, headId = toPlutusCurrencySymbol Fixture.testPolicyId
}
Expand Down
8 changes: 4 additions & 4 deletions hydra-node/test/Hydra/Chain/Direct/Contract/CollectCom.hs
Expand Up @@ -275,15 +275,15 @@ genCollectComMutation (tx, _utxo) =

mutatedPartiesHeadTxOut parties =
modifyInlineDatum $ \case
Head.Open{utxoHash, contestationPeriod, headId} ->
Head.Open{Head.parties = parties, contestationPeriod, utxoHash, headId}
Head.Open{utxoHash, snapshotNumber, contestationPeriod, headId} ->
Head.Open{Head.parties = parties, snapshotNumber, contestationPeriod, utxoHash, headId}
st -> error $ "Unexpected state " <> show st

mutateUTxOHash = do
mutatedUTxOHash <- genHash
pure $ modifyInlineDatum (mutateState mutatedUTxOHash) headTxOut

mutateState mutatedUTxOHash = \case
Head.Open{parties, contestationPeriod, headId} ->
Head.Open{parties, contestationPeriod, Head.utxoHash = toBuiltin mutatedUTxOHash, headId}
Head.Open{parties, contestationPeriod, snapshotNumber, headId} ->
Head.Open{parties, snapshotNumber, contestationPeriod, Head.utxoHash = toBuiltin mutatedUTxOHash, headId}
st -> st
1 change: 1 addition & 0 deletions hydra-node/test/Hydra/Chain/Direct/Contract/Decrement.hs
Expand Up @@ -132,6 +132,7 @@ healthyDatum =
{ utxoHash = toBuiltin $ hashUTxO @Tx healthyUTxO
, parties = healthyOnChainParties
, contestationPeriod = toChain healthyContestationPeriod
, snapshotNumber = toInteger healthySnapshotNumber
, headId = toPlutusCurrencySymbol testPolicyId
}

Expand Down
9 changes: 6 additions & 3 deletions hydra-node/test/Hydra/Chain/Direct/Contract/Mutation.hs
Expand Up @@ -783,10 +783,11 @@ replaceParties parties = \case
, Head.headId = headId
, Head.seed = seed
}
Head.Open{contestationPeriod, utxoHash, headId} ->
Head.Open{contestationPeriod, snapshotNumber, utxoHash, headId} ->
Head.Open
{ Head.contestationPeriod = contestationPeriod
, Head.parties = parties
, Head.snapshotNumber = snapshotNumber
, Head.utxoHash = utxoHash
, Head.headId = headId
}
Expand All @@ -805,10 +806,11 @@ replaceParties parties = \case

replaceUtxoHash :: Head.Hash -> Head.State -> Head.State
replaceUtxoHash utxoHash = \case
Head.Open{contestationPeriod, parties, headId} ->
Head.Open{contestationPeriod, snapshotNumber, parties, headId} ->
Head.Open
{ Head.contestationPeriod = contestationPeriod
, Head.parties = parties
, Head.snapshotNumber = snapshotNumber
, Head.utxoHash = utxoHash
, Head.headId = headId
}
Expand Down Expand Up @@ -864,10 +866,11 @@ replaceHeadId headId = \case
, Head.headId = headId
, Head.seed = seed
}
Head.Open{contestationPeriod, utxoHash, parties} ->
Head.Open{contestationPeriod, utxoHash, snapshotNumber, parties} ->
Head.Open
{ Head.contestationPeriod = contestationPeriod
, Head.parties = parties
, Head.snapshotNumber = snapshotNumber
, Head.utxoHash = utxoHash
, Head.headId = headId
}
Expand Down
1 change: 1 addition & 0 deletions hydra-node/test/Hydra/Chain/Direct/TxTraceSpec.hs
Expand Up @@ -288,6 +288,7 @@ openHeadUTxO =
, utxoHash = toBuiltin $ hashUTxO @Tx $ snapshotUTxO 0
, contestationPeriod = CP.toChain Fixture.cperiod
, headId = headIdToCurrencySymbol $ mkHeadId Fixture.testPolicyId
, snapshotNumber = 0
}

-- | Creates a transaction that closes 'openHeadUTxO' with given the snapshot.
Expand Down
1 change: 1 addition & 0 deletions hydra-plutus/src/Hydra/Contract/HeadState.hs
Expand Up @@ -31,6 +31,7 @@ data State
, parties :: [Party]
, utxoHash :: Hash
, headId :: CurrencySymbol
, snapshotNumber :: SnapshotNumber
}
| Closed
{ parties :: [Party]
Expand Down

0 comments on commit 1e7d0b0

Please sign in to comment.