-
Notifications
You must be signed in to change notification settings - Fork 90
POC: chainsync client as pipe producer #5027
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| {-# LANGUAGE DataKinds #-} | ||
| {-# LANGUAGE GADTs #-} | ||
| {-# LANGUAGE NamedFieldPuns #-} | ||
| {-# LANGUAGE ScopedTypeVariables #-} | ||
| {-# LANGUAGE RankNTypes #-} | ||
|
|
||
| module Ouroboros.Network.Protocol.ChainSync.PipeClient | ||
| where | ||
|
|
||
| import Network.TypedProtocol | ||
| import Ouroboros.Network.Protocol.ChainSync.Client | ||
| import Ouroboros.Network.Protocol.ChainSync.Type | ||
| import Pipes | ||
|
|
||
| data ChainSyncResponse header point tip | ||
| = RollForward header tip | ||
| | RollBackward point tip | ||
| | IntersectFound point tip | ||
| | IntersectNotFound tip | ||
|
||
| deriving (Show) | ||
|
|
||
| -- | Run a chain sync client as a 'Producer'. | ||
| -- Pass a suitable 'Driver', and a list of known 'point's. The 'Producer' will | ||
| -- initialize itself by requesting an intersection, and yielding either | ||
| -- 'IntersectFound' or 'IntersectNotFound' to indicate the server's response. | ||
| -- After that, it will indefinitely request updates and 'yield' them as | ||
| -- 'RollForward' and 'RollBackward', respectively. | ||
| chainSyncClientProducer :: forall header point tip m dstate | ||
| . ( Monad m | ||
| ) | ||
| => Driver | ||
| (ChainSync header point tip) | ||
| AsClient | ||
| dstate | ||
| (Producer (ChainSyncResponse header point tip) m) | ||
| -> [point] | ||
| -> Producer (ChainSyncResponse header point tip) m dstate | ||
| chainSyncClientProducer driver known = | ||
| snd <$> runPeerWithDriver driver peer | ||
|
||
| where | ||
| peer = chainSyncClientPeer (ChainSyncClient runPeer) | ||
|
|
||
| runPeer :: Producer | ||
| (ChainSyncResponse header point tip) | ||
| m | ||
| (ClientStIdle header point tip (Producer (ChainSyncResponse header point tip) m) ()) | ||
| runPeer = | ||
|
||
| pure . SendMsgFindIntersect known $ | ||
| ClientStIntersect | ||
| { recvMsgIntersectFound = \p t -> ChainSyncClient $ do | ||
| yield (IntersectFound p t) | ||
| runProducer | ||
| , recvMsgIntersectNotFound = \t -> ChainSyncClient $ do | ||
| yield (IntersectNotFound t) | ||
| runProducer | ||
| } | ||
| runProducer :: Producer | ||
| (ChainSyncResponse header point tip) | ||
| m | ||
| (ClientStIdle header point tip (Producer (ChainSyncResponse header point tip) m) ()) | ||
| runProducer = | ||
| pure . SendMsgRequestNext (pure ()) $ | ||
| ClientStNext | ||
| { recvMsgRollForward = \h t -> ChainSyncClient $ do | ||
| yield (RollForward h t) | ||
| runProducer | ||
| , recvMsgRollBackward = \p t -> ChainSyncClient $ do | ||
| yield (RollBackward p t) | ||
| runProducer | ||
| } | ||
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.
Suggest renaming
headereverywhere toblock. This will be intended to be used with blocks. With the node-to-client protocol, the chain sync provides blocks (whereas for the node-to-node it's used at type header).