Skip to content
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

Merged
merged 5 commits into from
Mar 14, 2019
Merged

Add startBlockSyncer #54

merged 5 commits into from
Mar 14, 2019

Conversation

rvl
Copy link
Contributor

@rvl rvl commented Mar 13, 2019

Relates to #52.

Overview

This combines BlockSyncer.tickingFunction and ChainProducer.getNextBlocks into a process that retrieves blocks from cardano-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).
  • Error handling should be fixed. One possibility is to remove ExceptT ErrGetNextBlocks and use throwIO to throw the Servant.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 #63
  • Where should the state be kept? The state being the slot where the block syncer is up to (can be less than the network tip). ⇒ Modified tickingFunction

The following can go in a later PR:

  • How to initially catch up to the network tip, while still consuming blocks in small batches.
  • The BlockHeadersConsumed is unnecessary because nextBlocks never returns blocks before the start slot given to it.

@rvl rvl self-assigned this Mar 13, 2019
@rvl rvl force-pushed the rvl/52/start-block-syncer branch from fb34c1f to e77897a Compare March 13, 2019 06:54
@rvl rvl mentioned this pull request Mar 13, 2019
6 tasks
@rvl rvl force-pushed the rvl/52/start-block-syncer branch from e77897a to 1dd3044 Compare March 14, 2019 04:47
@rvl rvl changed the base branch from master to rvl/12/review-network-layer March 14, 2019 06:35
@rvl rvl force-pushed the rvl/52/start-block-syncer branch 2 times, most recently from abd3258 to 3880cd6 Compare March 14, 2019 06:49
@KtorZ KtorZ force-pushed the rvl/12/review-network-layer branch 2 times, most recently from 3dfd7e5 to 1bfdbff Compare March 14, 2019 09:36
rvl added 3 commits March 14, 2019 10:58
So that we can remember the block we are up to.
This makes it simpler and better.
@KtorZ KtorZ force-pushed the rvl/52/start-block-syncer branch from 3880cd6 to f46f898 Compare March 14, 2019 10:01
@KtorZ
Copy link
Member

KtorZ commented Mar 14, 2019

rebased on top of latest master.

@KtorZ KtorZ changed the base branch from rvl/12/review-network-layer to master March 14, 2019 10:03
Copy link
Member

@KtorZ KtorZ left a 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.

Copy link
Contributor

@paweljakubas paweljakubas left a 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
Copy link
Contributor

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?

Copy link
Member

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
Copy link
Contributor

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?

Copy link
Member

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)
Copy link
Contributor

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)
Copy link
Contributor

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 ?

Copy link
Member

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.

@KtorZ KtorZ merged commit 8ad13a9 into master Mar 14, 2019
@KtorZ KtorZ deleted the rvl/52/start-block-syncer branch March 14, 2019 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants