Skip to content

Commit

Permalink
Align decommit off-chain spec/impl
Browse files Browse the repository at this point in the history
These checks there are really not "require" statements, as they would
not "detect cheating" as described in the specification.
  • Loading branch information
ch1bo authored and v0d1ch committed May 7, 2024
1 parent 5e922d2 commit 8ef2b16
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 56 deletions.
90 changes: 39 additions & 51 deletions hydra-node/src/Hydra/HeadLogic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -620,24 +620,49 @@ onOpenClientDecommit ::
tx ->
Outcome tx
onOpenClientDecommit env headId ledger currentSlot coordinatedHeadState decommitTx =
case mExistingDecommitTx of
Just existingDecommitTx ->
causes
[ ClientEffect
ServerOutput.DecommitInvalid
{ headId
, decommitInvalidReason = ServerOutput.DecommitAlreadyInFlight{decommitTx = existingDecommitTx}
}
checkNoDecommitInFlight $
checkValidDecommitTx $
Effects
[ NetworkEffect ReqDec{transaction = decommitTx, decommitRequester = party}
]
Nothing ->
requireValidDecommitTx headId ledger currentSlot coordinatedHeadState decommitTx $
causes
[ NetworkEffect ReqDec{transaction = decommitTx, decommitRequester = party}
]
where
Environment{party} = env
checkNoDecommitInFlight continue =
case mExistingDecommitTx of
Just existingDecommitTx ->
Effects
[ ClientEffect
ServerOutput.DecommitInvalid
{ headId
, decommitInvalidReason = ServerOutput.DecommitAlreadyInFlight{decommitTx = existingDecommitTx}
}
]
Nothing -> continue

checkValidDecommitTx cont =
case applyTransactions ledger currentSlot confirmedUTxO [decommitTx] of
Left (_, err) ->
Effects
[ ClientEffect
ServerOutput.DecommitInvalid
{ headId
, decommitInvalidReason =
ServerOutput.DecommitTxInvalid
{ confirmedUTxO
, decommitTx
, validationError = err
}
}
]
Right _ -> cont

confirmedUTxO = (getSnapshot confirmedSnapshot).utxo

CoordinatedHeadState{confirmedSnapshot} = coordinatedHeadState

CoordinatedHeadState{decommitTx = mExistingDecommitTx} = coordinatedHeadState

Environment{party} = env

-- | Process the request 'ReqDec' to decommit something from the Open head.
--
-- __Transition__: 'OpenState' → 'OpenState'
Expand Down Expand Up @@ -1204,40 +1229,3 @@ recoverState ::
t (StateChanged tx) ->
HeadState tx
recoverState = foldl' aggregate

-- Decommit helpers

-- TODO: Spec: require U̅ ◦ decTx /= ⊥

-- | Prevents further evaluation if Decommit tx is not applicable to the local
-- ledger state. In this case emits 'DecommitInvalid' otherwise it alows
-- continuation to proceed.
requireValidDecommitTx ::
Monoid (UTxOType tx) =>
HeadId ->
Ledger tx ->
ChainSlot ->
CoordinatedHeadState tx ->
tx ->
Outcome tx ->
Outcome tx
requireValidDecommitTx headId ledger currentSlot coordinatedHeadState decommitTx cont =
case applyTransactions ledger currentSlot confirmedUTxO [decommitTx] of
Left (_, err) ->
causes
[ ClientEffect
ServerOutput.DecommitInvalid
{ headId
, decommitInvalidReason =
ServerOutput.DecommitTxInvalid
{ confirmedUTxO
, decommitTx
, validationError = err
}
}
]
Right _ -> cont
where
confirmedUTxO = (getSnapshot confirmedSnapshot).utxo

CoordinatedHeadState{confirmedSnapshot} = coordinatedHeadState
6 changes: 2 additions & 4 deletions spec/fig_offchain_prot.tex
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@

%%% DECOMMIT
\On{$(\mathtt{decommit},\tx)$ from client}{
\textcolor{red}{
% TODO: check U_\omega is bottom to not have multiple in-flight?
\Req{$\barmU \applytx \tx \not= \bot$} \;
\Multi{} $(\mathtt{reqDec},\tx)$%
\If{\textcolor{blue}{$\tx_{\omega} = \bot \land \barmU \applytx \tx \not= \bot$}}{
\Multi{} $(\mathtt{reqDec},\tx)$%
}
}

Expand Down
2 changes: 1 addition & 1 deletion spec/prel.tex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ \subsection{Notation}

\noindent Furthermore, given a set $\mathcal{A}$, let
\begin{itemize}
\item $\mathcal{A}^? = \mathcal{A} \cup \Diamond$ denotes an option: a value from $\mathcal{A}$ or no value at all,
\item $\mathcal{A}^? = \mathcal{A} \cup \Diamond$ denotes an option: a value from $\mathcal{A}$ or no value at all indicated by $\bot$,
\item $\mathcal{A}^n$ be the set of all n-sized sequences over $\mathcal{A}$,
\item $\mathcal{A}^! = \bigcup_{i=1}^{n \in \tyNatural} \mathcal{A}^{i}$ be the set of non-empty sequences over $\mathcal{A}$, and
\item $\mathcal{A}^* = \bigcup_{i=0}^{n \in \tyNatural} \mathcal{A}^{i}$ be
Expand Down

0 comments on commit 8ef2b16

Please sign in to comment.