Skip to content

Commit 48928b2

Browse files
authored
API: Full transaction in SnapshotConfirmed (#1685)
Updates `SnapshotConfirmed` server output to contain full transactions (instead of only transaction ids). This also updates TxValid to only include the transaction id, such that transactions are only submitted once per client still. Hence, this will not change the overall bandwidth requirement on websocket clients, but will make their implementation significantly easier. Before, if clients wanted to act on transactions this was a lot easier to do upon seing `TxValid`. However, this was only confirming local ledger application and not consensus / enforcability of this transaction onto the L1. The new API suggests to do the right thing by making it straight-forward to act upon seeing a transaction in a `SnapshotConfirmed`. **TBD:** Changed `ServerOutput` field name `snapshotNumber` -> `number` to be consistent with `version` (and the internal Haskell data type names). Does anyone like `version` -> `snapshotVersion` better as an alternative? **TBD:** The field holding the transaction id in `TxValid` is called `transactionId` now. The transaction (envelop) itself though contains `txId`. This feels a bit inconsistent, which of the two should be renamed? This will also make #1612 easier (is mentioned as a sub-task there). --- * [x] CHANGELOG updated * [x] Documentation updated * [x] Haddocks updated * [x] No new TODOs introduced
2 parents 5862033 + a125d9b commit 48928b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+28966
-46286
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ changes.
3131

3232
- Fix the bug where commit endpoint drops withdraw redeemers [#1643](https://github.com/cardano-scaling/hydra/issues/1643)
3333

34+
- **BREAKING** Change to `SnapshotConfirmed` and `TxValid` server outputs, as
35+
well as to persisted `StateEvent` format:
36+
- Snapshots now contain the full transactions in `confirmed` and field names changed.
37+
- Persisted `StateChanged` events containing a snapshot changed consequently
38+
and are not backward compatible.
39+
- `TxValid` only refers to the transaction by id.
40+
- Overall this results in transactions still to be submitted once per client,
41+
but requires signifanctly less book-keeping on the client-side.
42+
3443
## [0.19.0] - 2024-09-13
3544

3645
- Tested with `cardano-node 9.1.1` and `cardano-cli 9.2.1.0`

hydra-cluster/bench/Bench/EndToEnd.hs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import Control.Concurrent.Class.MonadSTM (
1818
tryReadTBQueue,
1919
writeTBQueue,
2020
)
21-
import Control.Lens (to, (^?))
21+
import Control.Lens (to, (^..), (^?))
2222
import Control.Monad.Class.MonadAsync (mapConcurrently)
2323
import Data.Aeson (Result (Error, Success), Value, encode, fromJSON, (.=))
24-
import Data.Aeson.Lens (key, _Array, _JSON, _Number, _String)
24+
import Data.Aeson.Lens (key, values, _JSON, _Number, _String)
2525
import Data.Aeson.Types (parseMaybe)
2626
import Data.List qualified as List
2727
import Data.Map qualified as Map
@@ -424,7 +424,7 @@ newTx registry client tx = do
424424
data WaitResult
425425
= TxInvalid {transactionId :: TxId, reason :: Text}
426426
| TxValid {transactionId :: TxId}
427-
| SnapshotConfirmed {txIds :: [Value], snapshotNumber :: Scientific}
427+
| SnapshotConfirmed {txIds :: [Value], number :: Scientific}
428428

429429
data Registry tx = Registry
430430
{ processedTxs :: TVar IO (Map.Map TxId Event)
@@ -486,7 +486,7 @@ waitForAllConfirmations n1 Registry{processedTxs} allIds = do
486486
maybeTxValid v = do
487487
guard (v ^? key "tag" == Just "TxValid")
488488
v
489-
^? key "transaction" . key "txId" . to fromJSON >>= \case
489+
^? key "transactionId" . to fromJSON >>= \case
490490
Error _ -> Nothing
491491
Success txid -> pure $ TxValid txid
492492

@@ -501,14 +501,12 @@ waitForAllConfirmations n1 Registry{processedTxs} allIds = do
501501
maybeSnapshotConfirmed v = do
502502
guard (v ^? key "tag" == Just "SnapshotConfirmed")
503503
snapshot <- v ^? key "snapshot"
504-
SnapshotConfirmed
505-
<$> snapshot
506-
^? key "confirmedTransactions"
507-
. _Array
508-
. to toList
509-
<*> snapshot
510-
^? key "snapshotNumber"
511-
. _Number
504+
number <- snapshot ^? key "number" . _Number
505+
pure $
506+
SnapshotConfirmed
507+
{ txIds = snapshot ^.. key "confirmed" . values . key "txId"
508+
, number
509+
}
512510

513511
confirmTx ::
514512
TVar IO (Map.Map TxId Event) ->

hydra-cluster/src/Hydra/Cluster/Scenarios.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,8 +1025,8 @@ respendUTxO client sk delay = do
10251025
waitMatch 10 client $ \v -> do
10261026
guard $ v ^? key "tag" == Just "SnapshotConfirmed"
10271027
guard $
1028-
toJSON (txId tx)
1029-
`elem` (v ^.. key "snapshot" . key "confirmedTransactions" . values)
1028+
toJSON tx
1029+
`elem` (v ^.. key "snapshot" . key "confirmed" . values)
10301030
v ^? key "snapshot" . key "utxo" >>= parseMaybe parseJSON
10311031

10321032
-- * Utilities

hydra-cluster/test/Test/EndToEndSpec.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -632,12 +632,12 @@ timedTx tmpDir tracer node@RunningNode{networkId, nodeSocket} hydraScriptsTxId =
632632
-- Second submission: now valid
633633
send n1 $ input "NewTx" ["transaction" .= tx]
634634
waitFor hydraTracer 3 [n1] $
635-
output "TxValid" ["transaction" .= tx, "headId" .= headId]
635+
output "TxValid" ["transactionId" .= txId tx, "headId" .= headId]
636636

637637
confirmedTransactions <- waitMatch 3 n1 $ \v -> do
638638
guard $ v ^? key "tag" == Just "SnapshotConfirmed"
639-
v ^? key "snapshot" . key "confirmedTransactions"
640-
confirmedTransactions ^.. values `shouldBe` [toJSON $ txId tx]
639+
v ^? key "snapshot" . key "confirmed"
640+
confirmedTransactions ^.. values `shouldBe` [toJSON tx]
641641

642642
initAndClose :: FilePath -> Tracer IO EndToEndLog -> Int -> TxId -> RunningNode -> IO ()
643643
initAndClose tmpDir tracer clusterIx hydraScriptsTxId node@RunningNode{nodeSocket} = do
@@ -687,7 +687,7 @@ initAndClose tmpDir tracer clusterIx hydraScriptsTxId node@RunningNode{nodeSocke
687687
aliceExternalSk
688688
send n1 $ input "NewTx" ["transaction" .= tx]
689689
waitFor hydraTracer 10 [n1, n2, n3] $
690-
output "TxValid" ["transaction" .= tx, "headId" .= headId]
690+
output "TxValid" ["transactionId" .= txId tx, "headId" .= headId]
691691

692692
-- The expected new utxo set is the created payment to bob,
693693
-- alice's remaining utxo in head and whatever bot has
@@ -724,12 +724,12 @@ initAndClose tmpDir tracer clusterIx hydraScriptsTxId node@RunningNode{nodeSocke
724724
waitMatch 10 n1 $ \v -> do
725725
guard $ v ^? key "tag" == Just "SnapshotConfirmed"
726726
guard $ v ^? key "headId" == Just (toJSON headId)
727-
snapshotNumber <- v ^? key "snapshot" . key "snapshotNumber"
727+
snapshotNumber <- v ^? key "snapshot" . key "number"
728728
guard $ snapshotNumber == toJSON expectedSnapshotNumber
729729
utxo <- v ^? key "snapshot" . key "utxo"
730730
guard $ utxo == toJSON newUTxO
731-
confirmedTransactions <- v ^? key "snapshot" . key "confirmedTransactions"
732-
guard $ confirmedTransactions == toJSON [txId tx]
731+
confirmedTransactions <- v ^? key "snapshot" . key "confirmed"
732+
guard $ confirmedTransactions == toJSON [tx]
733733

734734
(toJSON <$> getSnapshotUTxO n1) `shouldReturn` toJSON newUTxO
735735

hydra-node/golden/ReasonablySized (ServerOutput (Tx ConwayEra)).json

Lines changed: 0 additions & 19180 deletions
This file was deleted.

0 commit comments

Comments
 (0)