Skip to content

Commit

Permalink
Start explorer from genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
ffakenz committed Jan 12, 2024
1 parent 759acb1 commit 74bf84d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
19 changes: 4 additions & 15 deletions hydra-cluster/test/Test/HydraExplorerSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,36 +80,25 @@ spec = do
let hydraTracer = contramap FromHydraNode tracer
hydraScriptsTxId <- publishHydraScriptsAs cardanoNode Faucet

let initAndCloseHead hydraNode = do
let initHead hydraNode = do
send hydraNode $ input "Init" []

headId <- waitMatch 5 hydraNode $ \v -> do
waitMatch 5 hydraNode $ \v -> do
guard $ v ^? key "tag" == Just "HeadIsInitializing"
v ^? key "headId" . _String

requestCommitTx hydraNode mempty >>= submitTx cardanoNode
waitFor hydraTracer 5 [hydraNode] $
output "HeadIsOpen" ["utxo" .= object mempty, "headId" .= headId]

send hydraNode $ input "Close" []

pure headId

(aliceCardanoVk, _aliceCardanoSk) <- keysFor Alice
seedFromFaucet_ cardanoNode aliceCardanoVk 100_000_000 (contramap FromFaucet tracer)
aliceChainConfig <- chainConfigFor Alice tmpDir nodeSocket hydraScriptsTxId [] cperiod
aliceHeadId <- withHydraNode hydraTracer aliceChainConfig tmpDir 1 aliceSk [] [1] initAndCloseHead
aliceHeadId <- withHydraNode hydraTracer aliceChainConfig tmpDir 1 aliceSk [] [1] initHead

(bobCardanoVk, _bobCardanoSk) <- keysFor Bob
seedFromFaucet_ cardanoNode bobCardanoVk 100_000_000 (contramap FromFaucet tracer)
bobChainConfig <- chainConfigFor Bob tmpDir nodeSocket hydraScriptsTxId [] cperiod
bobHeadId <- withHydraNode hydraTracer bobChainConfig tmpDir 2 bobSk [] [2] initAndCloseHead
bobHeadId <- withHydraNode hydraTracer bobChainConfig tmpDir 2 bobSk [] [2] initHead

withHydraExplorer cardanoNode $ \explorer -> do
headExplorerSees explorer "HeadInitTx" aliceHeadId
headExplorerSees explorer "HeadCloseTx" aliceHeadId
headExplorerSees explorer "HeadInitTx" bobHeadId
headExplorerSees explorer "HeadCloseTx" aliceHeadId

it "can query for all hydra heads observed" $
failAfter 60 $
Expand Down
5 changes: 4 additions & 1 deletion hydra-explorer/src/Hydra/Explorer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Network.Wai (
responseLBS,
)
import Network.Wai.Handler.Warp qualified as Warp
import System.Environment (withArgs)

type ExplorerState = Map ChainPoint [(TxId, HeadObservation)]

Expand All @@ -36,8 +37,10 @@ main :: IO ()
main = do
withTracer (Verbose "hydra-explorer") $ \tracer -> do
explorerState <- newTVarIO (mempty :: ExplorerState)
args <- getArgs
race
(Hydra.ChainObserver.main (observerHandler explorerState))
-- FIXME: this is going to be problematic on mainnet.
(withArgs (args <> ["--start-chain-from", "0"]) $ Hydra.ChainObserver.main (observerHandler explorerState))
( traceWith tracer (APIServerStarted (fromIntegral port :: PortNumber))
*> Warp.runSettings (settings tracer) (httpApp tracer explorerState)
)
Expand Down

0 comments on commit 74bf84d

Please sign in to comment.