-
Notifications
You must be signed in to change notification settings - Fork 217
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 startBlockSyncer #54
Conversation
fb34c1f
to
e77897a
Compare
e77897a
to
1dd3044
Compare
abd3258
to
3880cd6
Compare
3dfd7e5
to
1bfdbff
Compare
So that we can remember the block we are up to.
This makes it simpler and better.
3880cd6
to
f46f898
Compare
rebased on top of latest master. |
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.
LGTM. I generalized the tick function to make it now really just about ticking, using the state instead of the block header consumed. We'll move the responsibility of keeping track of blocks and duplicates to the network layer.
I've adjusted the file header comments and the tests to reflect that.
I've also moved the instantiation of a network layer outside of the startBlockSyncer function to leave the function really about, fetching blocks from a chain producer.
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.
I like very much using SlotId
in the tick function rather than header hashes!
@@ -117,6 +124,15 @@ data BlockHeader = BlockHeader | |||
|
|||
instance NFData BlockHeader | |||
|
|||
instance Buildable BlockHeader where | |||
build (BlockHeader s prev) = mempty |
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.
Do we need mempty
here?
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.
Not really. But it makes the alignment nicer below. With monoids or applicatives, I usually like starting with an empty case and then, on each newline, have a consistent alignment with <> ...
, rather than having to do something like:
fn =
myFirstCase
<> MySecondCase
<> MyThirdCase
-- or
fn = myFirstCase
<> MySecondCase
<> MyThirdCase
It's purely aesthetic 🤷♂️
@@ -135,6 +151,11 @@ data Tx = Tx | |||
|
|||
instance NFData Tx | |||
|
|||
instance Buildable Tx where | |||
build (Tx ins outs) = mempty |
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.
Do we need mempty here?
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.
same as above.
-> (Block -> IO ()) | ||
-> IO () | ||
listen network action = do | ||
tick getNextBlocks action 5000 (SlotId 0 0) |
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.
definitely replacing BlockHeadersConsumed
with SlotId
will make it easier to follow in the logs!!!
) | ||
mapM duplicateMaybe blocks >>= fmap Blocks . groups . mconcat | ||
let b0 = (blockHeaderHash h0, Block h0 mempty) | ||
Blocks <$> groups (map snd $ take n $ iterate next b0) |
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.
does it going to produce duplicated Blocks ?
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.
Nope it's not. I've removed that responsibility from the ticking function for now, and we'll have to make this a responsibility of the network layer.
Relates to #52.
Overview
This combines
BlockSyncer.tickingFunction
andChainProducer.getNextBlocks
into a process that retrieves blocks fromcardano-http-bridge
.Comments
It's pretty clear after looking at this feature "as a whole" that we must rework the code to address a few issues:
nextBlocks
should return more than the requested number of blocks if that makes sense (for example, returning the entire contents of an epoch pack file, or returning all the blocks from unstable epochs).ExceptT ErrGetNextBlocks
and usethrowIO
to throw theServant.Client.Core.ClientError
(or whatever exception), and let the exception bubble up. (Because there's no way to recover from these errors). ⇒ fixed in Simplify NetworkLayer #63tickingFunction
The following can go in a later PR:
BlockHeadersConsumed
is unnecessary becausenextBlocks
never returns blocks before the start slot given to it.