Skip to content

Commit

Permalink
Add CommitIgnored message
Browse files Browse the repository at this point in the history
  • Loading branch information
v0d1ch committed Dec 3, 2024
1 parent 053a2c5 commit b7874d3
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1 deletion.
34 changes: 34 additions & 0 deletions hydra-node/json-schemas/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,12 @@ components:
Recover transaction is observed and deposited funds are recovered to L1.
payload:
$ref: "api.yaml#/components/schemas/CommitRecovered"
CommitIgnored:
title: CommitIgnored
description: |
Deposit was recorded initially but next snapshot utxo to commit was not found in pending deposits.
payload:
$ref: "api.yaml#/components/schemas/CommitIgnored"


# END OF SERVER OUTPUT MESSAGES
Expand Down Expand Up @@ -728,6 +734,7 @@ components:
- $ref: "api.yaml#/components/schemas/CommitApproved"
- $ref: "api.yaml#/components/schemas/CommitFinalized"
- $ref: "api.yaml#/components/schemas/CommitRecovered"
- $ref: "api.yaml#/components/schemas/CommitIgnored"

Greetings:
type: object
Expand Down Expand Up @@ -1430,6 +1437,33 @@ components:
$ref: "api.yaml#/components/schemas/SequenceNumber"
timestamp:
$ref: "api.yaml#/components/schemas/UTCTime"
CommitIgnored:
title: CommitIgnored
description: |
Deposit not matching snapshot utxo to commit.
additionalProperties: false
type: object
required:
- tag
- headId
- depositUTxO
- snapshotUTxO
- seq
- timestamp
properties:
tag:
type: string
enum: ["CommitIgnored"]
headId:
$ref: "api.yaml#/components/schemas/HeadId"
depositUTxO:
$ref: "api.yaml#/components/schemas/UTxO"
snapshotUTxO:
$ref: "api.yaml#/components/schemas/UTxO"
seq:
$ref: "api.yaml#/components/schemas/SequenceNumber"
timestamp:
$ref: "api.yaml#/components/schemas/UTCTime"

# END OF SERVER OUTPUT SCHEMAS

Expand Down
17 changes: 17 additions & 0 deletions hydra-node/json-schemas/logs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,23 @@ definitions:
$ref: "api.yaml#/components/schemas/UTxO"
recoveredTxId:
type: string
- title: "CommitIgnored"
additionalProperties: false
required:
- tag
- headId
- depositUTxO
- snapshotUTxO
properties:
tag:
type: string
enum: ["CommitIgnored"]
headId:
$ref: "api.yaml#/components/schemas/HeadId"
depositUTxO:
$ref: "api.yaml#/components/schemas/UTxO"
snapshotUTxO:
$ref: "api.yaml#/components/schemas/UTxO"
- title: "DecommitRecorded"
additionalProperties: false
required:
Expand Down
3 changes: 3 additions & 0 deletions hydra-node/src/Hydra/API/ServerOutput.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ data ServerOutput tx
| DecommitFinalized {headId :: HeadId, decommitTxId :: TxIdType tx}
| CommitFinalized {headId :: HeadId, theDeposit :: TxIdType tx}
| CommitRecovered {headId :: HeadId, recoveredUTxO :: UTxOType tx, recoveredTxId :: TxIdType tx}
| CommitIgnored {headId :: HeadId, depositUTxO :: [UTxOType tx], snapshotUTxO :: Maybe (UTxOType tx)}
deriving stock (Generic)

deriving stock instance IsChainState tx => Eq (ServerOutput tx)
Expand Down Expand Up @@ -201,6 +202,7 @@ instance (ArbitraryIsTx tx, IsChainState tx) => Arbitrary (ServerOutput tx) wher
CommitRecovered headId u rid -> CommitRecovered headId <$> shrink u <*> shrink rid
DecommitFinalized{} -> []
CommitFinalized{} -> []
CommitIgnored{} -> []

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

Expand Down Expand Up @@ -262,6 +264,7 @@ prepareServerOutput ServerOutputConfig{utxoInSnapshot} response =
CommitFinalized{} -> encodedResponse
DecommitInvalid{} -> encodedResponse
CommitRecovered{} -> encodedResponse
CommitIgnored{} -> encodedResponse
where
handleUtxoInclusion f bs =
case utxoInSnapshot of
Expand Down
41 changes: 40 additions & 1 deletion hydra-node/src/Hydra/HeadLogic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,17 @@ onOpenNetworkReqTx ::
onOpenNetworkReqTx env ledger st ttl tx =
-- Keep track of transactions by-id
(newState TransactionReceived{tx} <>) $
-- Spec: wait L̂ ◦ tx ≠ ⊥
-- Spec: wait L̂ ◦ tx ≠ ⊥

-- Spec: wait L̂ ◦ tx ≠ ⊥
waitApplyTx $ \newLocalUTxO ->
(cause (ClientEffect $ ServerOutput.TxValid headId (txId tx) tx) <>) $
-- Spec: T̂ ← T̂ ⋃ {tx}
-- Spec: T̂ ← T̂ ⋃ {tx}
-- L̂ ← L̂ ◦ tx
-- L̂ ← L̂ ◦ tx

-- Spec: T̂ ← T̂ ⋃ {tx}
-- L̂ ← L̂ ◦ tx
newState TransactionAppliedToLocalUTxO{tx, newLocalUTxO}
Expand Down Expand Up @@ -417,8 +425,26 @@ onOpenNetworkReqSn ::
onOpenNetworkReqSn env ledger st otherParty sv sn requestedTxIds mDecommitTx mIncrementUTxO =
-- Spec: require s = ŝ + 1 ∧ leader(s) = j
requireReqSn $
-- Spec: wait ŝ = ̅S.s
-- Spec: wait ŝ = ̅S.s
-- Spec: wait ŝ = ̅S.s
-- Spec: wait ŝ = ̅S.s
-- Spec: wait ŝ = ̅S.s
-- Spec: wait ŝ = ̅S.s
-- Spec: wait ŝ = ̅S.s
-- Spec: wait ŝ = ̅S.s

-- Spec: wait ŝ = ̅S.s
waitNoSnapshotInFlight $
-- Spec: wait v = v̂
-- Spec: wait v = v̂
-- Spec: wait v = v̂
-- Spec: wait v = v̂
-- Spec: wait v = v̂
-- Spec: wait v = v̂
-- Spec: wait v = v̂
-- Spec: wait v = v̂

-- Spec: wait v = v̂
waitOnSnapshotVersion $
requireApplicableDecommitTx $ \(activeUTxOAfterDecommit, mUtxoToDecommit) ->
Expand Down Expand Up @@ -612,6 +638,9 @@ onOpenNetworkAckSn Environment{party} openState otherParty snapshotSignature sn
requireNotSignedYet sigs $ do
-- Spec: ̂Σ[j] ← σⱼ
(newState PartySignedSnapshot{snapshot, party = otherParty, signature = snapshotSignature} <>) $
-- if ∀k ∈ [1..n] : (k,·) ∈ ̂Σ
-- if ∀k ∈ [1..n] : (k,·) ∈ ̂Σ

-- if ∀k ∈ [1..n] : (k,·) ∈ ̂Σ
ifAllMembersHaveSigned snapshot sigs $ \sigs' -> do
-- Spec: σ̃ ← MS-ASig(kₕˢᵉᵗᵘᵖ,̂Σ)
Expand Down Expand Up @@ -703,7 +732,17 @@ onOpenNetworkAckSn Environment{party} openState otherParty snapshotSignature sn
}
}
]
_ -> outcome -- TODO: output some error here?
_ ->
cause
( ClientEffect $
ServerOutput.CommitIgnored
{ headId
, depositUTxO = Map.elems pendingDeposits
, snapshotUTxO = utxoToCommit
}
)
<> outcome

maybePostDecrementTx snapshot@Snapshot{utxoToDecommit} signatures outcome =
case (decommitTx, utxoToDecommit) of
(Just tx, Just utxo) ->
Expand Down

0 comments on commit b7874d3

Please sign in to comment.