Skip to content

Commit

Permalink
Draft handle of head reset input in open state
Browse files Browse the repository at this point in the history
  • Loading branch information
ffakenz committed May 7, 2024
1 parent 7ea77db commit 7f160a4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hydra-node/src/Hydra/API/ClientInput.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data ClientInput tx
| Close
| Contest
| Fanout
| Reset
deriving stock (Generic)

deriving stock instance IsTx tx => Eq (ClientInput tx)
Expand All @@ -35,3 +36,4 @@ instance Arbitrary tx => Arbitrary (ClientInput tx) where
Close -> []
Contest -> []
Fanout -> []
Reset -> []
21 changes: 21 additions & 0 deletions hydra-node/src/Hydra/HeadLogic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,8 @@ update ::
update env ledger st ev = case (st, ev) of
(_, NetworkInput _ (ConnectivityEvent conn)) ->
onConnectionEvent conn
(Open{}, ClientInput Reset) ->
newState HeadReset
(Idle _, ClientInput Init) ->
onIdleClientInit env
(Idle _, ChainInput Observation{observedTx = OnInitTx{headId, headSeed, headParameters, participants}, newChainState}) ->
Expand Down Expand Up @@ -779,6 +781,24 @@ update env ledger st ev = case (st, ev) of
-- | Reflect 'StateChanged' events onto the 'HeadState' aggregate.
aggregate :: IsChainState tx => HeadState tx -> StateChanged tx -> HeadState tx
aggregate st = \case
HeadReset ->
case st of
Open os@OpenState{coordinatedHeadState} ->
Open
os
{ coordinatedHeadState =
-- Spec: Tall ← ̂Tall ∪ { (hash(tx), tx) }
coordinatedHeadState
{ seenSnapshot = LastSeenSnapshot lastSeen
}
}
where
lastSeen = case confirmedSnapshot of
InitialSnapshot{} -> 0
ConfirmedSnapshot{snapshot = Snapshot{number}} -> number

CoordinatedHeadState{confirmedSnapshot} = coordinatedHeadState
_otherState -> st
HeadInitialized{parameters = parameters@HeadParameters{parties}, headId, headSeed, chainState} ->
Initial
InitialState
Expand Down Expand Up @@ -1021,6 +1041,7 @@ recoverChainStateHistory initialChainState =
ChainRolledBack{chainState} ->
rollbackHistory (chainStateSlot chainState) history
TickObserved{} -> history
HeadReset -> history

recoverState ::
(Foldable t, IsChainState tx) =>
Expand Down
2 changes: 2 additions & 0 deletions hydra-node/src/Hydra/HeadLogic/Outcome.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ data StateChanged tx
| HeadFannedOut {chainState :: ChainStateType tx}
| ChainRolledBack {chainState :: ChainStateType tx}
| TickObserved {chainSlot :: ChainSlot}
| HeadReset
deriving stock (Generic)

deriving stock instance (IsTx tx, Eq (HeadState tx), Eq (ChainStateType tx)) => Eq (StateChanged tx)
Expand Down Expand Up @@ -106,6 +107,7 @@ genStateChanged env =
, HeadFannedOut <$> arbitrary
, ChainRolledBack <$> arbitrary
, TickObserved <$> arbitrary
, pure HeadReset
]
where
Environment{party} = env
Expand Down

0 comments on commit 7f160a4

Please sign in to comment.