Skip to content

Commit 3463758

Browse files
committed
Implement FetchTip for cardano-node
Unfortunately, we have to use an MVar to pass return value from the client since 'connectTo' swallows whatever the client is trying to return. This is unfortunate, but also pretty safe given that we are guaranteed to either: exit with an exception or put a tip in the MVar before attempting to take it.
1 parent 2efef03 commit 3463758

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

kupo.cabal

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Kupo/App.hs

+15-2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ import qualified Kupo.App.ChainSync.Node as Node
142142
import qualified Kupo.App.ChainSync.Ogmios as Ogmios
143143
import qualified Kupo.App.FetchBlock.Node as Node
144144
import qualified Kupo.App.FetchBlock.Ogmios as Ogmios
145+
import qualified Kupo.App.FetchTip.Node as Node
145146
import qualified Kupo.App.FetchTip.Ogmios as Ogmios
146147

147148
--
@@ -305,8 +306,20 @@ newFetchTipClient = \case
305306
throwIO UnableToFetchTipFromHydra
306307
Ogmios{ogmiosHost, ogmiosPort} ->
307308
Ogmios.newFetchTipClient ogmiosHost ogmiosPort
308-
CardanoNode{} ->
309-
error "TODO: newFetchTipClient for CardanoNode"
309+
CardanoNode{nodeSocket, nodeConfig} -> do
310+
NetworkParameters
311+
{ networkMagic
312+
, slotsPerEpoch
313+
} <- liftIO (parseNetworkParameters nodeConfig)
314+
response <- newEmptyTMVarIO
315+
withChainSyncServer
316+
noConnectionStatusToggle
317+
[ NodeToClientV_9 .. maxBound ]
318+
networkMagic
319+
slotsPerEpoch
320+
nodeSocket
321+
(Node.newFetchTipClient response)
322+
atomically $ takeTMVar response
310323

311324
-- | Consumer process that is reading messages from the 'Mailbox'. Messages are
312325
-- enqueued by another process (the producer).

src/Kupo/App/FetchTip/Node.hs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
-- This Source Code Form is subject to the terms of the Mozilla Public
2+
-- License, v. 2.0. If a copy of the MPL was not distributed with this
3+
-- file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
module Kupo.App.FetchTip.Node
6+
( newFetchTipClient
7+
) where
8+
9+
import Kupo.Prelude
10+
11+
import Control.Concurrent.Class.MonadSTM
12+
( MonadSTM (..)
13+
)
14+
import Kupo.Data.Cardano
15+
( Point
16+
, Tip
17+
)
18+
import Ouroboros.Network.Protocol.ChainSync.ClientPipelined
19+
( ChainSyncClientPipelined (..)
20+
, ClientPipelinedStIdle (..)
21+
, ClientStNext (..)
22+
)
23+
24+
newFetchTipClient
25+
:: (MonadSTM m)
26+
=> TMVar m Tip
27+
-> ChainSyncClientPipelined block Point Tip m ()
28+
newFetchTipClient response =
29+
ChainSyncClientPipelined $ pure $
30+
SendMsgRequestNext
31+
(pure ())
32+
ClientStNext
33+
{ recvMsgRollForward = \_header tip -> do
34+
atomically $ putTMVar response tip
35+
pure (SendMsgDone ())
36+
, recvMsgRollBackward = \_point tip -> do
37+
atomically $ putTMVar response tip
38+
pure (SendMsgDone ())
39+
}

test/Test/KupoSpec.hs

+2
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,8 @@ spec = skippableContext "End-to-end" $ do
548548
}
549549
runSpec env 120 $ do
550550
waitSlot (>= getPointSlotNo tip)
551+
points <- listCheckpoints
552+
forM_ points $ \point -> getPointSlotNo point `shouldSatisfy` (>= getPointSlotNo tip)
551553
Health{configuration} <- getHealth
552554
configuration `shouldBe` (Just InstallIndexesIfNotExist)
553555

0 commit comments

Comments
 (0)