Skip to content

Commit

Permalink
Merge pull request #1240 from input-output-hk/lc/cbor
Browse files Browse the repository at this point in the history
Replace ToJSON/FromJSON Tx with cbor encoding
  • Loading branch information
locallycompact authored Jan 24, 2024
2 parents 148a0c3 + a682340 commit 560a7bf
Show file tree
Hide file tree
Showing 25 changed files with 16,888 additions and 48,696 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ As a minor extension, we also keep a semantic version for the `UNRELEASED`
changes.


## [0.16.0] - UNRELEASED

- **BREAKING** Transaction serialization on hydra-node api and persisted data changed.

## [0.15.0] - 2024-01-18

- Tested with `cardano-node 8.7.3` and `cardano-cli 8.17.0.0`.
Expand Down
3 changes: 1 addition & 2 deletions docs/core-concepts/behavior.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Not pictured is the `CommandFailed` output, which is implicit emitted whenever a
There are some options for API clients to control the server outputs. Server outputs are controlled using the following query parameters:

+ `history=no` -> Prevents historical outputs display. All server outputs are recorded and when a client re-connects these outputs are replayed unless `history=no` query param is used.
+ `tx-output=cbor` -> Outputs transaction fields encoded as CBOR instead of default JSON.
+ `snapshot-utxo=no` -> In case of a `SnapshotConfirmed` message the `utxo` field in the inner `Snapshot` will be omitted.

## Replay of past server outputs
Expand All @@ -28,4 +27,4 @@ When a `hydra-node` restarts, by default it will load its history from persisten

Clients can optionally decide to skip history outputs and receive only the `Greetings` and following ones. In order to do that they can use query param `history=no`.

For example if the client wants to connect to a local `hydra-node` and doesn't want to view the server history but also wants to have the transactions encoded as CBOR (base16) and prevent utxo display in `SnapshotConfirmed` messages, they would connect using default port `4001` and the full path `ws://localhost:4001/?history=no&tx-output=cbor`.
For example if the client wants to connect to a local `hydra-node` and doesn't want to view the server history and prevent utxo display in `SnapshotConfirmed` messages, they would connect using default port `4001` and the full path `ws://localhost:4001/?history=no`.
8 changes: 4 additions & 4 deletions hydra-cluster/bench/Bench/EndToEnd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Data.Scientific (Scientific)
import Data.Set ((\\))
import Data.Set qualified as Set
import Data.Time (UTCTime (UTCTime), utctDayTime)
import Hydra.Cardano.Api (Tx, TxId, UTxO, getVerificationKey, serialiseToTextEnvelope, signTx)
import Hydra.Cardano.Api (Tx, TxId, UTxO, getVerificationKey, signTx)
import Hydra.Cluster.Faucet (FaucetLog, publishHydraScriptsAs, seedFromFaucet)
import Hydra.Cluster.Fixture (Actor (Faucet))
import Hydra.Cluster.Scenarios (
Expand Down Expand Up @@ -329,7 +329,7 @@ newTx registry client tx = do
, invalidAt = Nothing
, confirmedAt = Nothing
}
send client $ input "NewTx" ["transaction" .= serialiseToTextEnvelope Nothing tx]
send client $ input "NewTx" ["transaction" .= toJSON tx]

data WaitResult
= TxInvalid {transactionId :: TxId, reason :: Text}
Expand Down Expand Up @@ -396,14 +396,14 @@ waitForAllConfirmations n1 Registry{processedTxs} allIds = do
maybeTxValid v = do
guard (v ^? key "tag" == Just "TxValid")
v
^? key "transaction" . key "id" . to fromJSON >>= \case
^? key "transaction" . key "txId" . to fromJSON >>= \case
Error _ -> Nothing
Success txid -> pure $ TxValid txid

maybeTxInvalid v = do
guard (v ^? key "tag" == Just "TxInvalid")
v
^? key "transaction" . key "id" . to fromJSON >>= \case
^? key "transaction" . key "txId" . to fromJSON >>= \case
Error _ -> Nothing
Success tx ->
TxInvalid tx <$> v ^? key "validationError" . key "reason" . _String
Expand Down
1 change: 0 additions & 1 deletion hydra-cluster/hydra-cluster.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ test-suite tests
Test.Hydra.Cluster.CardanoCliSpec
Test.Hydra.Cluster.FaucetSpec
Test.Hydra.Cluster.MithrilSpec
Test.LogFilterSpec
Test.OfflineChainSpec

build-depends:
Expand Down
5 changes: 2 additions & 3 deletions hydra-cluster/src/Hydra/Cluster/Scenarios.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import Hydra.Cardano.Api (
mkVkAddress,
selectLovelace,
signTx,
toLedgerTx,
toScriptData,
writeFileTextEnvelope,
pattern ReferenceScriptNone,
Expand Down Expand Up @@ -525,12 +524,12 @@ canSubmitTransactionThroughAPI tracer workDir node hydraScriptsTxId =
Left e -> failure $ show e
Right body -> do
let unsignedTx = makeSignedTransaction [] body
let unsignedRequest = toJSON $ toLedgerTx unsignedTx
let unsignedRequest = toJSON unsignedTx
sendRequest hydraNodeId unsignedRequest
`shouldThrow` expectErrorStatus 400 (Just "MissingVKeyWitnessesUTXOW")

let signedTx = signTx cardanoBobSk unsignedTx
let signedRequest = toJSON $ toLedgerTx signedTx
let signedRequest = toJSON signedTx
(sendRequest hydraNodeId signedRequest <&> responseBody)
`shouldReturn` TransactionSubmitted
where
Expand Down
47 changes: 0 additions & 47 deletions hydra-cluster/test/Test/LogFilterSpec.hs

This file was deleted.

Loading

0 comments on commit 560a7bf

Please sign in to comment.