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 authored and v0d1ch committed May 7, 2024
1 parent 7ea77db commit 0cd7ca3
Show file tree
Hide file tree
Showing 3 changed files with 24 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 -> []
20 changes: 20 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,23 @@ 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 =
coordinatedHeadState
{ seenSnapshot = LastSeenSnapshot lastSeen
, localTxs = []
, localUTxO = confirmedUTxO
}
}
where
Snapshot{utxo = confirmedUTxO, number = lastSeen} = getSnapshot confirmedSnapshot

CoordinatedHeadState{confirmedSnapshot} = coordinatedHeadState
_otherState -> st
HeadInitialized{parameters = parameters@HeadParameters{parties}, headId, headSeed, chainState} ->
Initial
InitialState
Expand Down Expand Up @@ -1021,6 +1040,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 0cd7ca3

Please sign in to comment.