Skip to content

Commit

Permalink
Fixes after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
v0d1ch committed Mar 11, 2024
1 parent 8fd1bf8 commit 23eea99
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 85 deletions.
2 changes: 1 addition & 1 deletion hydra-cluster/test/Test/ChainObserverSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ spec = do

commitTx <- requestCommitTx hydraNode commitUTxO

pure (signTx walletSk commitTx) >>= submitTx cardanoNode
submitTx cardanoNode (signTx walletSk commitTx)

waitFor hydraTracer 5 [hydraNode] $
output "HeadIsOpen" ["utxo" .= commitUTxO, "headId" .= headId]
Expand Down
163 changes: 118 additions & 45 deletions hydra-node/golden/Event SimpleTx.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,45 @@
"samples": [
{
"clientInput": {
"tag": "Contest"
"tag": "Fanout"
},
"tag": "ClientEvent"
},
{
"message": {
"tag": "ReqTx",
"decommitRequester": {
"vkey": "6250421a689f91e7b1e18875710835624d01d9d0fd031562127f019ebdffc859"
},
"tag": "ReqDec",
"transaction": {
"id": -2,
"id": 5,
"inputs": [
-29,
-27,
-26,
-25,
-24,
-30,
-23,
-21,
-20,
-18,
-14,
-11,
-17,
-12,
-8,
-7,
-6,
-4,
-3,
-1,
2,
4,
5,
-2,
0,
6,
9,
17,
18,
8,
16,
20,
25,
21,
27
],
"outputs": [
-27,
-25,
-21,
-18,
-15,
-3,
-1,
0,
5,
6,
11,
14,
17,
20,
21,
22,
23,
25,
26,
30
-29,
-24,
-19,
-17,
13,
26
]
}
},
Expand Down Expand Up @@ -110,11 +93,63 @@
},
{
"message": {
"decommitTx": {
"id": 9,
"inputs": [
-23,
-21,
-19,
-17,
-14,
-13,
-7,
0,
2,
4,
5,
16,
17,
19,
24,
26,
30
],
"outputs": [
-27,
-17,
-16,
-14,
-11,
-9,
-3,
-1,
7,
22,
24,
26,
28
]
},
"snapshotNumber": 3,
"tag": "ReqSn",
"transactionIds": [
22,
-13
0,
4,
16,
26,
-19,
-1,
11,
0,
10,
-6,
19,
-2,
-20,
12,
7,
8,
14
]
},
"party": {
Expand All @@ -125,9 +160,47 @@
},
{
"message": {
"signed": "a27f8582e9c12e66b02b24b029716d5a4ab32da11c899b1aba99650c7a972318b031e8a57df63f22d38561da7dbb23e9c8504ecb11bee34877b01a02372aa20b",
"snapshotNumber": 0,
"tag": "AckSn"
"decommitRequester": {
"vkey": "928cc3b30d0f3d3f6e31d82c95ee98d06702affde1918c2d5d13177470598154"
},
"tag": "ReqDec",
"transaction": {
"id": 4,
"inputs": [
-25,
-9,
6,
11,
24,
27,
30
],
"outputs": [
-29,
-28,
-26,
-21,
-13,
-11,
-10,
-9,
-6,
-3,
-1,
1,
2,
5,
10,
13,
14,
15,
19,
22,
24,
26,
27
]
}
},
"party": {
"vkey": "3a31af3b199ce0f7d1efda02534708c9cb969d018b5b09e16584c1b40f41ec47"
Expand Down
19 changes: 18 additions & 1 deletion hydra-node/json-schemas/logs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,10 @@ definitions:
seenSnapshot:
$ref: "logs.yaml#/definitions/SeenSnapshot"
decommitTx:
$ref: "api.yaml#/components/schemas/Transaction"
oneOf:
- type: "null"
- type: object
$ref: "api.yaml#/components/schemas/Transaction"

SeenSnapshot:
oneOf:
Expand Down Expand Up @@ -2171,6 +2174,20 @@ definitions:
type: array
items:
$ref: "api.yaml#/components/schemas/TxId"
- title: WaitOnNotApplicableDecommitTx
description: >-
Somebody requested a Decommit but there is another one in flight already.
type: object
additionalProperties: false
required:
- tag
- waitingOnDecommitTx
properties:
tag:
type: string
enum: ["WaitOnNotApplicableDecommitTx"]
waitingOnDecommitTx:
$ref: "api.yaml#/components/schemas/Transaction"

IP:
type: object
Expand Down
3 changes: 1 addition & 2 deletions hydra-node/src/Hydra/Chain/Direct/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,7 @@ closeTx scriptRegistry vk closing startSlotNo (endSlotNo, utcTime) openThreadOut
Head.Closed
{ snapshotNumber
, utxoHash = toBuiltin utxoHashBytes
, -- TODO: find a way to introduce this value
utxoToDecommitHash = toBuiltin decommitUTxOHashBytes
, utxoToDecommitHash = toBuiltin decommitUTxOHashBytes
, parties = openParties
, contestationDeadline
, contestationPeriod = openContestationPeriod
Expand Down
60 changes: 27 additions & 33 deletions hydra-node/src/Hydra/HeadLogic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,16 @@ onOpenNetworkReqTx env ledger st ttl tx =
(newState TransactionReceived{tx} <>) $
-- Spec: wait L̂ ◦ tx ≠ ⊥ combined with L̂ ← L̂ ◦ tx
waitApplyTx $ \newLocalUTxO ->
-- Spec: if ŝ = s̄ ∧ leader(s̄ + 1) = i
( if not snapshotInFlight && isLeader parameters party nextSn
then
newState TransactionAppliedToLocalUTxO{tx = tx, newLocalUTxO}
<>
newState SnapshotRequestDecided{snapshotNumber = nextSn}
<> cause (NetworkEffect $ ReqSn nextSn (txId <$> localTxs') decommitTx)
else newState TransactionAppliedToLocalUTxO{tx, newLocalUTxO}
)
newState TransactionAppliedToLocalUTxO{tx = tx, newLocalUTxO}
<>
-- Spec: if ŝ = s̄ ∧ leader(s̄ + 1) = i
( if not snapshotInFlight && isLeader parameters party nextSn
then
newState TransactionAppliedToLocalUTxO{tx = tx, newLocalUTxO}
<> newState SnapshotRequestDecided{snapshotNumber = nextSn}
<> cause (NetworkEffect $ ReqSn nextSn (txId <$> localTxs') decommitTx)
else newState TransactionAppliedToLocalUTxO{tx, newLocalUTxO}
)
<> cause (ClientEffect $ ServerOutput.TxValid headId tx)
where
waitApplyTx cont =
Expand Down Expand Up @@ -579,7 +580,7 @@ onOpenNetworkAckSn Environment{party} openState otherParty snapshotSignature sn
case utxoToDecommit of
Just utxoToDecommit' ->
outcome
<> Effects
<> causes
[ ClientEffect $ ServerOutput.DecommitApproved{headId, utxoToDecommit = utxoToDecommit'}
, OnChainEffect
{ postChainTx =
Expand Down Expand Up @@ -620,27 +621,25 @@ onOpenClientDecommit ::
onOpenClientDecommit env headId ledger currentSlot coordinatedHeadState decommitTx =
checkNoDecommitInFlight $
checkValidDecommitTx $
Effects
[ NetworkEffect ReqDec{transaction = decommitTx, decommitRequester = party}
]
cause (NetworkEffect ReqDec{transaction = decommitTx, decommitRequester = party})
where
checkNoDecommitInFlight continue =
case mExistingDecommitTx of
Just existingDecommitTx ->
Effects
[ ClientEffect
cause
( ClientEffect
ServerOutput.DecommitInvalid
{ headId
, decommitInvalidReason = ServerOutput.DecommitAlreadyInFlight{decommitTx = existingDecommitTx}
}
]
)
Nothing -> continue

checkValidDecommitTx cont =
case applyTransactions ledger currentSlot confirmedUTxO [decommitTx] of
Left (_, err) ->
Effects
[ ClientEffect
cause
( ClientEffect
ServerOutput.DecommitInvalid
{ headId
, decommitInvalidReason =
Expand All @@ -650,7 +649,7 @@ onOpenClientDecommit env headId ledger currentSlot coordinatedHeadState decommit
, validationError = err
}
}
]
)
Right _ -> cont

confirmedUTxO = (getSnapshot confirmedSnapshot).utxo
Expand Down Expand Up @@ -691,22 +690,18 @@ onOpenNetworkReqDec ::
onOpenNetworkReqDec env ttl openState decommitTx =
waitOnApplicableDecommit $
let decommitUTxO = utxoFromTx decommitTx
in StateChanged (DecommitRecorded decommitTx)
<> Effects
[ ClientEffect $ ServerOutput.DecommitRequested headId decommitUTxO
]
in newState (DecommitRecorded decommitTx)
<> cause (ClientEffect $ ServerOutput.DecommitRequested headId decommitUTxO)
<> if isLeader parameters party nextSn
then
Effects
[NetworkEffect (ReqSn nextSn (txId <$> localTxs) (Just decommitTx))]
else Error $ RequireFailed $ ReqSnNotLeader{requestedSn = nextSn, leader = party}
then cause (NetworkEffect (ReqSn nextSn (txId <$> localTxs) (Just decommitTx)))
else noop
where
waitOnApplicableDecommit cont =
case mExistingDecommitTx of
Nothing -> cont
Just existingDecommitTx
| ttl > 0 ->
Wait $ WaitOnNotApplicableDecommitTx decommitTx
wait $ WaitOnNotApplicableDecommitTx decommitTx
| otherwise ->
Error $ RequireFailed $ DecommitTxInFlight{decommitTx = existingDecommitTx}
Environment{party} = env
Expand Down Expand Up @@ -916,13 +911,12 @@ update env ledger st ev = case (st, ev) of
)
-- TODO: What happens if observed decrement tx get's rolled back?
| ourHeadId == headId ->
Effects
[ClientEffect $ ServerOutput.DecommitFinalized{headId}]
<> StateChanged DecommitFinalized
cause (ClientEffect $ ServerOutput.DecommitFinalized{headId})
<> newState DecommitFinalized
| otherwise ->
Error NotOurHead{ourHeadId, otherHeadId = headId}
(Open{}, PostTxError{postChainTx = CollectComTx{}}) ->
Effects []
(Open{}, OnChainEvent PostTxError{postChainTx = CollectComTx{}}) ->
noop
-- Closed
(Closed closedState@ClosedState{headId = ourHeadId}, OnChainEvent Observation{observedTx = OnContestTx{headId, snapshotNumber, contestationDeadline}, newChainState})
| ourHeadId == headId ->
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/src/Hydra/HeadLogic/Outcome.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ data WaitReason tx
| WaitOnSeenSnapshot
| WaitOnTxs {waitingForTxIds :: [TxIdType tx]}
| WaitOnContestationDeadline
| WaitOnNotApplicableDecommitTx { waitingOnDecommitTx :: tx}
| WaitOnNotApplicableDecommitTx {waitingOnDecommitTx :: tx}
deriving stock (Generic)

deriving stock instance IsTx tx => Eq (WaitReason tx)
Expand Down
Loading

0 comments on commit 23eea99

Please sign in to comment.