From b7874d344d289cc375f8a041089011bdb21b044e Mon Sep 17 00:00:00 2001 From: Sasha Bogicevic Date: Tue, 3 Dec 2024 12:02:37 +0100 Subject: [PATCH] Add CommitIgnored message --- hydra-node/json-schemas/api.yaml | 34 ++++++++++++++++++++ hydra-node/json-schemas/logs.yaml | 17 ++++++++++ hydra-node/src/Hydra/API/ServerOutput.hs | 3 ++ hydra-node/src/Hydra/HeadLogic.hs | 41 +++++++++++++++++++++++- 4 files changed, 94 insertions(+), 1 deletion(-) diff --git a/hydra-node/json-schemas/api.yaml b/hydra-node/json-schemas/api.yaml index 3fb728559e4..36a23cfccfd 100644 --- a/hydra-node/json-schemas/api.yaml +++ b/hydra-node/json-schemas/api.yaml @@ -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 @@ -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 @@ -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 diff --git a/hydra-node/json-schemas/logs.yaml b/hydra-node/json-schemas/logs.yaml index 92cbf2f9b5a..b1c7bb58bbe 100644 --- a/hydra-node/json-schemas/logs.yaml +++ b/hydra-node/json-schemas/logs.yaml @@ -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: diff --git a/hydra-node/src/Hydra/API/ServerOutput.hs b/hydra-node/src/Hydra/API/ServerOutput.hs index 1fb570e8a85..5ad06dbe913 100644 --- a/hydra-node/src/Hydra/API/ServerOutput.hs +++ b/hydra-node/src/Hydra/API/ServerOutput.hs @@ -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) @@ -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) @@ -262,6 +264,7 @@ prepareServerOutput ServerOutputConfig{utxoInSnapshot} response = CommitFinalized{} -> encodedResponse DecommitInvalid{} -> encodedResponse CommitRecovered{} -> encodedResponse + CommitIgnored{} -> encodedResponse where handleUtxoInclusion f bs = case utxoInSnapshot of diff --git a/hydra-node/src/Hydra/HeadLogic.hs b/hydra-node/src/Hydra/HeadLogic.hs index b841e2a0f18..81f85951381 100644 --- a/hydra-node/src/Hydra/HeadLogic.hs +++ b/hydra-node/src/Hydra/HeadLogic.hs @@ -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} @@ -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) -> @@ -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ₕˢᵉᵗᵘᵖ,̂Σ) @@ -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) ->