Skip to content

Commit a65a286

Browse files
committed
fixes after rebase
1 parent 6ad8e0a commit a65a286

File tree

6 files changed

+26
-41
lines changed

6 files changed

+26
-41
lines changed

hydra-node/json-schemas/api.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -1527,13 +1527,16 @@ components:
15271527
type: object
15281528
required:
15291529
- tag
1530+
- headId
15301531
- confirmedSnapshot
15311532
- seq
15321533
- timestamp
15331534
properties:
15341535
tag:
15351536
type: string
15361537
enum: ["SnapshotSideLoaded"]
1538+
headId:
1539+
$ref: "api.yaml#/components/schemas/HeadId"
15371540
confirmedSnapshot:
15381541
$ref: "api.yaml#/components/schemas/ConfirmedSnapshot"
15391542
seq:

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ instance (Arbitrary tx, Arbitrary (TxIdType tx), Arbitrary (UTxOType tx), IsTx t
4141
Fanout -> []
4242
SideLoadSnapshot sn -> SideLoadSnapshot <$> shrink sn
4343

44-
instance (Arbitrary tx, Arbitrary (TxIdType tx)) => ToADTArbitrary (ClientInput tx)
44+
instance (Arbitrary tx, Arbitrary (TxIdType tx), Arbitrary (UTxOType tx), IsTx tx) => ToADTArbitrary (ClientInput tx)

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

+9
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ mkTimedServerOutputFromStateEvent event =
225225
StateChanged.TransactionAppliedToLocalUTxO{..} -> Just TxValid{headId, transactionId = txId tx, transaction = tx}
226226
StateChanged.TxInvalid{..} -> Just $ TxInvalid{..}
227227
StateChanged.SnapshotConfirmed{..} -> Just SnapshotConfirmed{..}
228+
StateChanged.SnapshotSideLoaded{..} -> Just SnapshotSideLoaded{..}
228229
StateChanged.IgnoredHeadInitializing{..} -> Just IgnoredHeadInitializing{..}
229230
StateChanged.DecommitRecorded{..} -> Just DecommitRequested{..}
230231
StateChanged.DecommitInvalid{..} -> Just DecommitInvalid{..}
@@ -294,3 +295,11 @@ projectSnapshotUtxo snapshotUtxo = \case
294295
StateChanged.SnapshotConfirmed _ snapshot _ -> Just $ Tx.utxo snapshot <> fromMaybe mempty (Tx.utxoToCommit snapshot)
295296
StateChanged.HeadOpened _ _ utxos -> Just utxos
296297
_other -> snapshotUtxo
298+
299+
-- | Projection of latest confirmed snapshot.
300+
projectSnapshotConfirmed :: Maybe (ConfirmedSnapshot tx) -> StateChanged.StateChanged tx -> Maybe (ConfirmedSnapshot tx)
301+
projectSnapshotConfirmed snapshotConfirmed = \case
302+
StateChanged.SnapshotConfirmed _ snapshot signatures -> Just $ ConfirmedSnapshot snapshot signatures
303+
StateChanged.HeadIsOpen headId utxos -> Just $ InitialSnapshot headId utxos
304+
StateChanged.SnapshotSideLoaded _ confirmedSnapshot -> Just $ confirmedSnapshot
305+
_other -> snapshotConfirmed

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ data ServerOutput tx
191191
| -- | Snapshot was side-loaded, and the included transactions can be considered final.
192192
-- The local state has been reset, meaning pending transactions were pruned.
193193
-- Any signing round has been discarded, and the snapshot leader has changed accordingly.
194-
SnapshotSideLoaded {confirmedSnapshot :: ConfirmedSnapshot tx}
194+
SnapshotSideLoaded {headId :: HeadId, confirmedSnapshot :: ConfirmedSnapshot tx}
195195
deriving stock (Generic)
196196

197197
deriving stock instance IsChainState tx => Eq (ServerOutput tx)
@@ -244,7 +244,7 @@ instance ArbitraryIsTx tx => Arbitrary (ServerOutput tx) where
244244
PeerConnected peer -> PeerConnected <$> shrink peer
245245
PeerDisconnected peer -> PeerDisconnected <$> shrink peer
246246
PeerHandshakeFailure host our theirs -> PeerHandshakeFailure <$> shrink host <*> shrink our <*> shrink theirs
247-
SnapshotSideLoaded confirmedSnapshot -> SnapshotSideLoaded <$> shrink confirmedSnapshot
247+
SnapshotSideLoaded headId confirmedSnapshot -> SnapshotSideLoaded headId <$> shrink confirmedSnapshot
248248

249249
instance (ArbitraryIsTx tx, IsChainState tx) => ToADTArbitrary (ServerOutput tx)
250250

@@ -307,15 +307,18 @@ prepareServerOutput config response =
307307
SnapshotSideLoaded{confirmedSnapshot} ->
308308
case confirmedSnapshot of
309309
InitialSnapshot{} ->
310-
handleUtxoInclusion (atKey "initialUTxO" .~ Nothing) encodedResponse
310+
handleUtxoInclusion config removeInitialUTxO encodedResponse
311311
ConfirmedSnapshot{} ->
312-
handleUtxoInclusion (key "snapshot" . atKey "utxo" .~ Nothing) encodedResponse
312+
handleUtxoInclusion config removeSnapshotUTxO encodedResponse
313313
where
314314
encodedResponse = encode response
315315

316316
removeSnapshotUTxO :: LBS.ByteString -> LBS.ByteString
317317
removeSnapshotUTxO = key "snapshot" . atKey "utxo" .~ Nothing
318318

319+
removeInitialUTxO :: LBS.ByteString -> LBS.ByteString
320+
removeInitialUTxO = atKey "initialUTxO" .~ Nothing
321+
319322
handleUtxoInclusion :: ServerOutputConfig -> (a -> a) -> a -> a
320323
handleUtxoInclusion config f bs =
321324
case utxoInSnapshot config of

hydra-node/src/Hydra/HeadLogic.hs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1118,8 +1118,7 @@ onOpenClientSideLoadSnapshot openState sideLoadConfirmedSnapshot =
11181118
then -- Spec: ̅S ← snObj(v̂, ŝ, Û, T̂, 𝑈𝛼, 𝑈𝜔)
11191119
-- ̅S.σ ← ̃σ
11201120

1121-
newState SnapshotSideLoaded{confirmedSnapshot = sideLoadConfirmedSnapshot}
1122-
<> cause (ClientEffect $ ServerOutput.SnapshotSideLoaded sideLoadConfirmedSnapshot)
1121+
newState SnapshotSideLoaded{headId, confirmedSnapshot = sideLoadConfirmedSnapshot}
11231122
else Error $ AssertionFailed "InitalSnapshot side loaded does not match last known."
11241123
ConfirmedSnapshot{snapshot, signatures} ->
11251124
-- REVIEW! should we check utxoToCommit and utxoToDecommit are the same ???
@@ -1134,12 +1133,12 @@ onOpenClientSideLoadSnapshot openState sideLoadConfirmedSnapshot =
11341133
do
11351134
-- Spec: ̅S ← snObj(v̂, ŝ, Û, T̂, 𝑈𝛼, 𝑈𝜔)
11361135
-- ̅S.σ ← ̃σ
1137-
newState SnapshotSideLoaded{confirmedSnapshot = sideLoadConfirmedSnapshot}
11381136
-- REVIEW! what if we WaitOnNotApplicableTx for current localTxs not in snapshot confirmed ???
1139-
<> cause (ClientEffect $ ServerOutput.SnapshotSideLoaded sideLoadConfirmedSnapshot)
1137+
newState SnapshotSideLoaded{headId, confirmedSnapshot = sideLoadConfirmedSnapshot}
11401138
where
11411139
OpenState
1142-
{ parameters = HeadParameters{parties}
1140+
{ headId
1141+
, parameters = HeadParameters{parties}
11431142
, coordinatedHeadState
11441143
} = openState
11451144

hydra-node/src/Hydra/HeadLogic/Outcome.hs

+2-31
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,12 @@ data StateChanged tx
114114
| CommitFinalized {headId :: HeadId, newVersion :: SnapshotVersion, depositTxId :: TxIdType tx}
115115
| DecommitFinalized {headId :: HeadId, decommitTxId :: TxIdType tx, newVersion :: SnapshotVersion}
116116
| PartySignedSnapshot {snapshot :: Snapshot tx, party :: Party, signature :: Signature (Snapshot tx)}
117-
<<<<<<< HEAD
118117
| SnapshotConfirmed {headId :: HeadId, snapshot :: Snapshot tx, signatures :: MultiSignature (Snapshot tx)}
118+
| SnapshotSideLoaded {headId :: HeadId, confirmedSnapshot :: ConfirmedSnapshot tx}
119119
| HeadClosed {headId :: HeadId, snapshotNumber :: SnapshotNumber, chainState :: ChainStateType tx, contestationDeadline :: UTCTime}
120120
| HeadContested {headId :: HeadId, chainState :: ChainStateType tx, contestationDeadline :: UTCTime, snapshotNumber :: SnapshotNumber}
121121
| HeadIsReadyToFanout {headId :: HeadId}
122122
| HeadFannedOut {headId :: HeadId, utxo :: UTxOType tx, chainState :: ChainStateType tx}
123-
=======
124-
| SnapshotConfirmed {snapshot :: Snapshot tx, signatures :: MultiSignature (Snapshot tx)}
125-
| SnapshotSideLoaded {confirmedSnapshot :: ConfirmedSnapshot tx}
126-
| HeadClosed {chainState :: ChainStateType tx, contestationDeadline :: UTCTime}
127-
| HeadContested {chainState :: ChainStateType tx, contestationDeadline :: UTCTime}
128-
| HeadIsReadyToFanout
129-
| HeadFannedOut {chainState :: ChainStateType tx}
130-
>>>>>>> 156d853b5 (introduce server output, outcome event and aggregate handle in logic)
131123
| ChainRolledBack {chainState :: ChainStateType tx}
132124
| TickObserved {chainSlot :: ChainSlot}
133125
| IgnoredHeadInitializing
@@ -155,41 +147,20 @@ instance (ArbitraryIsTx tx, IsChainState tx) => ToADTArbitrary (StateChanged tx)
155147
genStateChanged :: (ArbitraryIsTx tx, IsChainState tx) => Environment -> Gen (StateChanged tx)
156148
genStateChanged env =
157149
oneof
158-
<<<<<<< HEAD
159150
[ HeadInitialized (mkHeadParameters env) <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
160151
, CommittedUTxO <$> arbitrary <*> pure party <*> arbitrary <*> arbitrary
161152
, HeadAborted <$> arbitrary <*> arbitrary <*> arbitrary
162153
, HeadOpened <$> arbitrary <*> arbitrary <*> arbitrary
163154
, TransactionAppliedToLocalUTxO <$> arbitrary <*> arbitrary <*> arbitrary
164155
, SnapshotConfirmed <$> arbitrary <*> arbitrary <*> arbitrary
156+
, SnapshotSideLoaded <$> arbitrary <*> arbitrary
165157
, CommitRecorded <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
166158
, CommitFinalized <$> arbitrary <*> arbitrary <*> arbitrary
167159
, DecommitFinalized <$> arbitrary <*> arbitrary <*> arbitrary
168160
, HeadClosed <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
169161
, HeadContested <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
170162
, HeadIsReadyToFanout <$> arbitrary
171163
, HeadFannedOut <$> arbitrary <*> arbitrary <*> arbitrary
172-
=======
173-
[ HeadInitialized (mkHeadParameters env) <$> arbitrary <*> arbitrary <*> arbitrary
174-
, CommittedUTxO party <$> arbitrary <*> arbitrary
175-
, HeadAborted <$> arbitrary
176-
, HeadOpened <$> arbitrary <*> arbitrary
177-
, TransactionReceived <$> arbitrary
178-
, TransactionAppliedToLocalUTxO <$> arbitrary <*> arbitrary
179-
, DecommitRecorded <$> arbitrary <*> arbitrary
180-
, SnapshotRequestDecided <$> arbitrary
181-
, SnapshotRequested <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
182-
, PartySignedSnapshot <$> arbitrary <*> arbitrary <*> arbitrary
183-
, SnapshotConfirmed <$> arbitrary <*> arbitrary
184-
, SnapshotSideLoaded <$> arbitrary
185-
, DecommitFinalized <$> arbitrary
186-
, HeadClosed <$> arbitrary <*> arbitrary
187-
, HeadContested <$> arbitrary <*> arbitrary
188-
, pure HeadIsReadyToFanout
189-
, HeadFannedOut <$> arbitrary
190-
, ChainRolledBack <$> arbitrary
191-
, TickObserved <$> arbitrary
192-
>>>>>>> 156d853b5 (introduce server output, outcome event and aggregate handle in logic)
193164
]
194165
where
195166
Environment{party} = env

0 commit comments

Comments
 (0)