-
Notifications
You must be signed in to change notification settings - Fork 88
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
Create a hydra-explorer executable that can track all heads on-chain #1235
Merged
Merged
Changes from all commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
0dc6ab9
Add base e2e test for hydra-exporer
ffakenz 590ac43
Create base explorer project
ffakenz e814444
Reuse the hydra-chain-observer library code to collect the observations
ffakenz baaa267
Fix after rebase: remove pparams arg from withHydraNode process
ffakenz 5cb2347
Add GET /heads e2e spec
ffakenz 13a0cc6
Draft http server for explorer
ffakenz 73f5cdd
Introduce ObserverHandler as callback to chain-observer
ffakenz 5273ccc
Simplify endpoint
ffakenz 5a1cb53
Add e2e spec to explore multiple heads in the past
ffakenz 8ccfdf1
Add check process has not die to hydra-explorer in e2e specs
ffakenz 3b7822d
Fix minor typo on observations
ffakenz 184cc2c
Make hydra-cluster depend on hydra-explorer to run tests
ch1bo 844ca02
Add point to RollForward to see slots pass
ch1bo d597222
Refactor explorer e2e test slightly
ch1bo 4b6ec50
Start explorer from genesis
ffakenz 69a00e4
Enhance e2e spec over api
ffakenz 9befece
Draft some plumbing in explorer HTTP server
ch1bo d2b2dfe
Make use of ObserverHandler during roll forward
ffakenz c2a59be
Fix GetHeadIds read model
ch1bo 6dbc9dd
Draft openapi
ffakenz 448d62a
Introduce ipc server on chain-observer
ffakenz 20cc187
Revert "Introduce ipc server on chain-observer"
ffakenz adcc8fe
Enhance explorer state to be an aggregation of head observations
ffakenz 580deaf
Aggregate observations into explorer state
ffakenz 2eacbb0
Fix assertion for the HeadId equality
v0d1ch c915090
Add api server spec to validate openapi schema against server responses
ffakenz 3b71137
Fix match openapi schema spec
ffakenz 9d15d5b
Ehance e2e spec for explorer
ffakenz 03cfee9
Fix chain-observer spec as observeTx is now returning a head observation
ffakenz 25d25bc
Remove unused packages
ffakenz 31bdbc0
Minor fix to readme run cmd
ffakenz 6b815d4
Remove prints before server starts as traces already log this info
ffakenz b221cb8
Improve README.md spelling
ffakenz f3e3a0a
Remove not needed endpoints
ffakenz 92bfead
Remove unnecessary handle from withChainObserver and withHydraExplore…
ffakenz 155fad5
Update README
ffakenz c1f81cc
Refactor e2e to use http simple library instead
ffakenz 9de27ed
Remove unimplemented endpoint from openapi spec
ffakenz 8590af7
Rename test module to match where the actual code is implemented
ffakenz 41b6cf7
Improve explorer spec to only assert on headers that we care about
ffakenz de9e943
Update explorer api spec to specify required fields
ffakenz d9d9853
Use eitherDecode to print why the responded bytes where not a proper …
ffakenz bdb28b8
Refactor HydraExplorerHandle as an easy access to the API (= a client)
ffakenz 4f0b0eb
Remove unused import from chain observer e2e spec
ffakenz 291c792
Replace PartyCommit by UTxO type
ffakenz c49c38a
Increase the time dealy to wait for the explorer http server to be li…
ffakenz 24fde0f
Draft property spec for aggregate head observations
ffakenz 8309f53
Update aggregate observation logic to fulfill the expected properties
ffakenz 6740648
Refactor aggregation to work over OnChainTx type instead of HeadObser…
ffakenz a9e4809
Add tracking of contestation deadline as part of explorer's head states
ffakenz dca46e5
Add head state haddock
ffakenz 44e3d76
Remove unsupported attribute propertyNames by swagger
ffakenz 9ce5965
Minor fix after rebasing
ffakenz ea0aa8e
Use 5 ADA for internal wallets
v0d1ch 35a9479
Remove misplaced comment
v0d1ch 0f3ba3b
Refactor http server to use servant
ffakenz 3e7b2d2
Fix explorer e2e specs by increasing the amount of fuel provided to e…
ffakenz 594558b
Minor formatting changes
ffakenz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
module Main where | ||
|
||
import Hydra.ChainObserver (defaultObserverHandler) | ||
import Hydra.ChainObserver qualified | ||
import Hydra.Prelude | ||
|
||
main :: IO () | ||
main = Hydra.ChainObserver.main | ||
main = Hydra.ChainObserver.main defaultObserverHandler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
|
||
-- | Integration tests for the 'hydra-explorer' executable. These will run | ||
-- also 'hydra-node' on a devnet and assert correct observation. | ||
module Test.HydraExplorerSpec where | ||
|
||
import Hydra.Prelude hiding (get) | ||
import Test.Hydra.Prelude | ||
|
||
import CardanoClient (RunningNode (..)) | ||
import CardanoNode (NodeLog, withCardanoNodeDevnet) | ||
import Control.Lens ((^.), (^?)) | ||
import Data.Aeson as Aeson | ||
import Data.Aeson.Lens (key, nth, _Array, _String) | ||
import Hydra.Cardano.Api (NetworkId (..), NetworkMagic (..), unFile) | ||
import Hydra.Cluster.Faucet (FaucetLog, publishHydraScriptsAs, seedFromFaucet_) | ||
import Hydra.Cluster.Fixture (Actor (..), aliceSk, bobSk, cperiod) | ||
import Hydra.Cluster.Util (chainConfigFor, keysFor) | ||
import Hydra.Logging (showLogsOnFailure) | ||
import HydraNode (HydraNodeLog, input, send, waitMatch, withHydraNode) | ||
import Network.HTTP.Client (responseBody) | ||
import Network.HTTP.Simple (httpJSON, parseRequestThrow) | ||
import System.Process (CreateProcess (..), StdStream (..), proc, withCreateProcess) | ||
|
||
spec :: Spec | ||
spec = do | ||
it "can observe hydra transactions created by multiple hydra-nodes" $ | ||
failAfter 60 $ | ||
showLogsOnFailure "HydraExplorerSpec" $ \tracer -> do | ||
withTempDir "hydra-explorer-history" $ \tmpDir -> do | ||
withCardanoNodeDevnet (contramap FromCardanoNode tracer) tmpDir $ \cardanoNode@RunningNode{nodeSocket} -> do | ||
let hydraTracer = contramap FromHydraNode tracer | ||
hydraScriptsTxId <- publishHydraScriptsAs cardanoNode Faucet | ||
|
||
let initHead hydraNode = do | ||
send hydraNode $ input "Init" [] | ||
waitMatch 5 hydraNode $ \v -> do | ||
guard $ v ^? key "tag" == Just "HeadIsInitializing" | ||
v ^? key "headId" . _String | ||
|
||
(aliceCardanoVk, _aliceCardanoSk) <- keysFor Alice | ||
aliceChainConfig <- chainConfigFor Alice tmpDir nodeSocket hydraScriptsTxId [] cperiod | ||
seedFromFaucet_ cardanoNode aliceCardanoVk 25_000_000 (contramap FromFaucet tracer) | ||
aliceHeadId <- withHydraNode hydraTracer aliceChainConfig tmpDir 1 aliceSk [] [1] initHead | ||
|
||
(bobCardanoVk, _bobCardanoSk) <- keysFor Bob | ||
bobChainConfig <- chainConfigFor Bob tmpDir nodeSocket hydraScriptsTxId [] cperiod | ||
seedFromFaucet_ cardanoNode bobCardanoVk 25_000_000 (contramap FromFaucet tracer) | ||
bobHeadId <- withHydraNode hydraTracer bobChainConfig tmpDir 2 bobSk [] [2] initHead | ||
|
||
withHydraExplorer cardanoNode $ \explorer -> do | ||
allHeads <- getHeads explorer | ||
length (allHeads ^. _Array) `shouldBe` 2 | ||
allHeads ^. nth 0 . key "headId" . _String `shouldBe` aliceHeadId | ||
allHeads ^. nth 0 . key "status" . _String `shouldBe` "Initializing" | ||
allHeads ^. nth 1 . key "headId" . _String `shouldBe` bobHeadId | ||
allHeads ^. nth 1 . key "status" . _String `shouldBe` "Initializing" | ||
|
||
it "can query for all hydra heads observed" $ | ||
failAfter 60 $ | ||
showLogsOnFailure "HydraExplorerSpec" $ \tracer -> do | ||
withTempDir "hydra-explorer-get-heads" $ \tmpDir -> do | ||
withCardanoNodeDevnet (contramap FromCardanoNode tracer) tmpDir $ \cardanoNode@RunningNode{nodeSocket} -> do | ||
let hydraTracer = contramap FromHydraNode tracer | ||
hydraScriptsTxId <- publishHydraScriptsAs cardanoNode Faucet | ||
withHydraExplorer cardanoNode $ \explorer -> do | ||
(aliceCardanoVk, _aliceCardanoSk) <- keysFor Alice | ||
aliceChainConfig <- chainConfigFor Alice tmpDir nodeSocket hydraScriptsTxId [] cperiod | ||
seedFromFaucet_ cardanoNode aliceCardanoVk 25_000_000 (contramap FromFaucet tracer) | ||
aliceHeadId <- withHydraNode hydraTracer aliceChainConfig tmpDir 1 aliceSk [] [1] $ \hydraNode -> do | ||
v0d1ch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
send hydraNode $ input "Init" [] | ||
|
||
waitMatch 5 hydraNode $ \v -> do | ||
guard $ v ^? key "tag" == Just "HeadIsInitializing" | ||
v ^? key "headId" . _String | ||
|
||
(bobCardanoVk, _bobCardanoSk) <- keysFor Bob | ||
bobChainConfig <- chainConfigFor Bob tmpDir nodeSocket hydraScriptsTxId [] cperiod | ||
seedFromFaucet_ cardanoNode bobCardanoVk 25_000_000 (contramap FromFaucet tracer) | ||
bobHeadId <- withHydraNode hydraTracer bobChainConfig tmpDir 2 bobSk [] [2] $ \hydraNode -> do | ||
send hydraNode $ input "Init" [] | ||
|
||
bobHeadId <- waitMatch 5 hydraNode $ \v -> do | ||
guard $ v ^? key "tag" == Just "HeadIsInitializing" | ||
v ^? key "headId" . _String | ||
|
||
send hydraNode $ input "Abort" [] | ||
|
||
waitMatch 5 hydraNode $ \v -> do | ||
guard $ v ^? key "tag" == Just "HeadIsAborted" | ||
guard $ v ^? key "headId" . _String == Just bobHeadId | ||
|
||
pure bobHeadId | ||
|
||
allHeads <- getHeads explorer | ||
length (allHeads ^. _Array) `shouldBe` 2 | ||
allHeads ^. nth 0 . key "headId" . _String `shouldBe` aliceHeadId | ||
allHeads ^. nth 0 . key "status" . _String `shouldBe` "Initializing" | ||
allHeads ^. nth 1 . key "headId" . _String `shouldBe` bobHeadId | ||
allHeads ^. nth 1 . key "status" . _String `shouldBe` "Aborted" | ||
|
||
newtype HydraExplorerHandle = HydraExplorerHandle {getHeads :: IO Value} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
data HydraExplorerLog | ||
v0d1ch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
= FromCardanoNode NodeLog | ||
| FromHydraNode HydraNodeLog | ||
| FromFaucet FaucetLog | ||
deriving (Eq, Show, Generic) | ||
deriving anyclass (ToJSON) | ||
|
||
-- | Starts a 'hydra-explorer' on some Cardano network. | ||
withHydraExplorer :: RunningNode -> (HydraExplorerHandle -> IO ()) -> IO () | ||
withHydraExplorer cardanoNode action = | ||
withCreateProcess process{std_out = CreatePipe, std_err = CreatePipe} $ | ||
\_in _stdOut err processHandle -> | ||
race | ||
(checkProcessHasNotDied "hydra-explorer" processHandle err) | ||
( -- XXX: wait for the http server to be listening on port | ||
threadDelay 3 | ||
*> action HydraExplorerHandle{getHeads} | ||
) | ||
<&> either absurd id | ||
where | ||
getHeads = responseBody <$> (parseRequestThrow "http://127.0.0.1:9090/heads" >>= httpJSON) | ||
|
||
process = | ||
proc | ||
"hydra-explorer" | ||
$ ["--node-socket", unFile nodeSocket] | ||
<> case networkId of | ||
Mainnet -> ["--mainnet"] | ||
Testnet (NetworkMagic magic) -> ["--testnet-magic", show magic] | ||
|
||
RunningNode{nodeSocket, networkId} = cardanoNode |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could: remove this as http-conduit includes the same things