Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add address query parameter to ws server #1739

Merged
merged 30 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c96f10c
add address query parameter to websocket
ffakenz Nov 11, 2024
f73b671
update api spec
ffakenz Nov 11, 2024
f0b108a
update docs
ffakenz Nov 11, 2024
1083cef
update CHANGELOG
ffakenz Nov 11, 2024
301b520
draft e2e spec
ffakenz Nov 13, 2024
2426c04
remove server spec
ffakenz Nov 13, 2024
612745e
complete e2e spec ~ happy path
ffakenz Nov 13, 2024
6ba2aa9
minor refactor to enhance consistency btw other server output prepara…
ffakenz Nov 13, 2024
55e6836
minor renaming given the query params arg has become wider than before
ffakenz Nov 13, 2024
6a3904e
break down e2e
ffakenz Nov 13, 2024
9fe662f
fix address inclusion to work along with utxo inclusion
ffakenz Nov 13, 2024
7ad5613
add transaction info to TxValid
ffakenz Nov 13, 2024
6eb0420
filter TxValid and TxInvalid outputs based on address
ffakenz Nov 14, 2024
d0955f3
move filtering logic out so that can be reused when forwarding history
ffakenz Nov 14, 2024
69229e5
fix specs by defining waitNoMatch helper
ffakenz Nov 15, 2024
f38cee3
add missing test on new incomming tx being filtered out
ffakenz Nov 15, 2024
dc97f04
fix golden specs
ffakenz Nov 15, 2024
91895b0
remove debugging
ffakenz Nov 15, 2024
d5b64d2
Update CHANGELOG.md
ffakenz Nov 15, 2024
af0fc04
fix api spec
ffakenz Nov 15, 2024
ab744fd
minor fix on e2e spec
ffakenz Nov 15, 2024
c69b05e
DBG
ffakenz Nov 15, 2024
a466b2d
move server outs filter to its own module
ffakenz Nov 18, 2024
13ef025
rename server output filter used in test
ffakenz Nov 18, 2024
d87f91e
add filtering logic to SnapshotConfirmed server outputs
ffakenz Nov 18, 2024
19697eb
minor refactor to promote dry
ffakenz Nov 19, 2024
568a70b
Update hydra-node/json-schemas/api.yaml
ffakenz Nov 19, 2024
76a3ccb
Update docs/docs/api-behavior.md
ffakenz Nov 19, 2024
01a1da8
avoid using err during addr unwrapping
ffakenz Nov 19, 2024
0e6b259
minor golden spec fix
ffakenz Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ changes.

- Update mithril to `2442.0`


- New websocket URL parameter `?address=...` to filter `SnapshotConfirmed`, `TxValid` and `TxInvalid` server outputs by address.

## [0.19.0] - 2024-09-13

Expand Down
1 change: 1 addition & 0 deletions docs/docs/api-behavior.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ There are some options for API clients to control the server outputs. Server out

+ `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.
+ `snapshot-utxo=no` -> In case of a `SnapshotConfirmed` message the `utxo` field in the inner `Snapshot` will be omitted.
+ `address=$address` -> In the case of a `TxValid` or a `TxInvalid` message, it will be filtered if its `transaction` address does not contain a reference to the provided. In the case of a `SnapshotConfirmed` message, it will be filtered if its `confirmed` transactions do not contain an address that references the one provided.

## Replay of past server outputs

Expand Down
1 change: 1 addition & 0 deletions hydra-cluster/hydra-cluster.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ test-suite tests
Test.GeneratorSpec
Test.Hydra.Cluster.CardanoCliSpec
Test.Hydra.Cluster.FaucetSpec
Test.Hydra.Cluster.HydraClientSpec
Test.Hydra.Cluster.MithrilSpec
Test.Hydra.Cluster.Utils
Test.OfflineChainSpec
Expand Down
14 changes: 11 additions & 3 deletions hydra-cluster/src/HydraNode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ output tag pairs = object $ ("tag" .= tag) : pairs
waitFor :: HasCallStack => Tracer IO HydraNodeLog -> NominalDiffTime -> [HydraClient] -> Aeson.Value -> IO ()
waitFor tracer delay nodes v = waitForAll tracer delay nodes [v]

-- | Wait up to some time and succeed if no API server output matches the given predicate.
waitNoMatch :: HasCallStack => NominalDiffTime -> HydraClient -> (Aeson.Value -> Maybe a) -> IO ()
waitNoMatch delay client match = do
result <- try (void $ waitMatch delay client match) :: IO (Either SomeException ())
case result of
Left _ -> pure () -- Success: waitMatch failed to find a match
Right _ -> failure "waitNoMatch: A match was found when none was expected"

-- | Wait up to some time for an API server output to match the given predicate.
waitMatch :: HasCallStack => NominalDiffTime -> HydraClient -> (Aeson.Value -> Maybe a) -> IO a
waitMatch delay client@HydraClient{tracer, hydraNodeId} match = do
Expand Down Expand Up @@ -406,7 +414,7 @@ withConnectionToNode tracer hydraNodeId =
port = fromInteger $ 4_000 + toInteger hydraNodeId

withConnectionToNodeHost :: forall a. Tracer IO HydraNodeLog -> Int -> Host -> Maybe String -> (HydraClient -> IO a) -> IO a
withConnectionToNodeHost tracer hydraNodeId apiHost@Host{hostname, port} queryParams action = do
withConnectionToNodeHost tracer hydraNodeId apiHost@Host{hostname, port} mQueryParams action = do
connectedOnce <- newIORef False
tryConnect connectedOnce (200 :: Int)
where
Expand All @@ -424,9 +432,9 @@ withConnectionToNodeHost tracer hydraNodeId apiHost@Host{hostname, port} queryPa
, Handler $ retryOrThrow (Proxy @HandshakeException)
]

historyMode = fromMaybe "/" queryParams
queryParams = fromMaybe "/" mQueryParams

doConnect connectedOnce = runClient (T.unpack hostname) (fromInteger . toInteger $ port) historyMode $
doConnect connectedOnce = runClient (T.unpack hostname) (fromInteger . toInteger $ port) queryParams $
\connection -> do
atomicWriteIORef connectedOnce True
traceWith tracer (NodeStarted hydraNodeId)
Expand Down
4 changes: 2 additions & 2 deletions hydra-cluster/test/Test/EndToEndSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ timedTx tmpDir tracer node@RunningNode{networkId, nodeSocket} hydraScriptsTxId =
-- Second submission: now valid
send n1 $ input "NewTx" ["transaction" .= tx]
waitFor hydraTracer 3 [n1] $
output "TxValid" ["transactionId" .= txId tx, "headId" .= headId]
output "TxValid" ["transactionId" .= txId tx, "headId" .= headId, "transaction" .= tx]

confirmedTransactions <- waitMatch 3 n1 $ \v -> do
guard $ v ^? key "tag" == Just "SnapshotConfirmed"
Expand Down Expand Up @@ -693,7 +693,7 @@ initAndClose tmpDir tracer clusterIx hydraScriptsTxId node@RunningNode{nodeSocke
aliceExternalSk
send n1 $ input "NewTx" ["transaction" .= tx]
waitFor hydraTracer 10 [n1, n2, n3] $
output "TxValid" ["transactionId" .= txId tx, "headId" .= headId]
output "TxValid" ["transactionId" .= txId tx, "headId" .= headId, "transaction" .= tx]

-- The expected new utxo set is the created payment to bob,
-- alice's remaining utxo in head and whatever bot has
Expand Down
Loading