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

Better Point type factoring, again #706

Merged
merged 6 commits into from
Jul 9, 2019
Merged

Conversation

avieth
Copy link
Contributor

@avieth avieth commented Jul 4, 2019

Intended to replace #635 and #690 .

It's factored into 2 commits that could be reviewed separately (the third one is a tiny unrelated fix to byron-proxy).

The first commit introduces the Ouroboros.Network.Point module and uses it throughout ouroboros-network, making it build and tests pass.

The second makes ouroboros-consensus build and tests pass.

This commit retains the mistake pointHash :: Point block -> SlotNo rather than fixing it to be pointHash :: Point block -> WithOrigin SlotNo. The origin point is given SlotNo 0. It's kept this way so that the pull request will remain short and people will be willing to review it.

Alexander Vieth added 3 commits July 3, 2019 19:22
The ouroboros-network library builds and tests pass.

This does not fix the pointSlot mistake: it is still defined, and gives
SlotNo 0 to the origin. This will be fixed in a forthcoming commit.
This package builds and tests pass.

One perhaps controversial change is in the Byron ledger definition of
ledgerTipPoint. If the ledger state has the genesis hash as its latest,
then there are no blocks, so the tip point is set to Origin, rather than
a point with slot number 0. I believe this is the how it ought to be.
Apparently an update to iohk-monitoring broke it. But how did that get
past CI?
@@ -81,6 +81,8 @@ defaultLoggerConfig = Monitoring.Representation
, Monitoring.hasPrometheus = Nothing
, Monitoring.hasGUI = Nothing
, Monitoring.options = mempty
, Monitoring.hasGraylog = Nothing
, Monitoring.logOutput = Nothing
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently a new build of iohk-monitoring has been brought in recently, and bryon-proxy wasn't updated. How did this pass CI?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbgi could you take a look why this slipped through CI

@avieth avieth requested review from dcoutts, mrBliss and coot and removed request for mrBliss July 4, 2019 00:10
Copy link
Contributor

@mrBliss mrBliss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. I requested a few changes that will make my life easier.

Even without switching the slot and hash to WithOrigin I was expecting a bigger diff.

Thanks for taking the time to do this.

ouroboros-network/src/Ouroboros/Network/Point.hs Outdated Show resolved Hide resolved
, block
) where

data WithOrigin t = Origin | At t
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why Origin instead of Genesis?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Genesis is a constructor of Chain block. I thought it better not to overload.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fine for me. (What about data WithGenesis t = Gen | At t? 😈)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might have places in haddock where we refer to Genesis, which now becomes Origin.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Chain type is a model / mock impl. We shouldn't give it primacy in names. If we want Genesis for the point types we can use it, and we can rename the Chain one (e.g. GenesisBlock) or use qualified names.

ouroboros-consensus/src/Ouroboros/Storage/ChainDB/API.hs Outdated Show resolved Hide resolved
@@ -319,17 +321,30 @@ data UnknownRange blk =
--
-- > StreamFromExclusive (Point { pointSlot = SlotNo 3 , .. }
-- > StreamToInclusive (Point { pointSlot = SlotNo 3 , .. }
--
-- FIXME StreamFrom and StreamTo can be refined to not admit origin points
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will do that when this is merged.

Suggested by mrBliss
@mrBliss
Copy link
Contributor

mrBliss commented Jul 5, 2019

@avieth shall we wait for @dcoutts to give his blessing?

fmap _ Origin = Origin
fmap f (At t) = At (f t)

data Block slot hash = Block
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about calling this BlockPoint?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this module it is clear that it is a point since (apart from the type, the module is named Point), in most places we use unqualified imports so this might be confusing. Or maybe just leave a comment at the top that this module is supposed to be imported qualified.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now it is imported qualified in other places, just dropping a comment at the top might be useful.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intuition is also for BlockPoint and not using module-qualified names elsewhere.

at = At

origin :: WithOrigin t
origin = Origin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth to duplicate the api?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not clear it's worth using functions rather than constructors directly.

Copy link
Contributor

@coot coot 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 left a two comments, feel free to decide upon them.

@coot
Copy link
Contributor

coot commented Jul 5, 2019

@avieth @mrBliss I am fine merging without @dcoutts blessing, 😎 ;). I see this PR as an improvement on top of Duncan's #690.

@avieth
Copy link
Contributor Author

avieth commented Jul 9, 2019

bors r+

iohk-bors bot added a commit that referenced this pull request Jul 9, 2019
706: Better Point type factoring, again r=avieth a=avieth

Intended to replace #635 and #690 .

It's factored into 2 commits that could be reviewed separately (the third one is a tiny unrelated fix to byron-proxy).

The first commit introduces the `Ouroboros.Network.Point` module and uses it throughout ouroboros-network, making it build and tests pass.

The second makes ouroboros-consensus build and tests pass.

This commit retains the mistake `pointHash :: Point block -> SlotNo` rather than fixing it to be `pointHash :: Point block -> WithOrigin SlotNo`. The origin point is given `SlotNo 0`. It's kept this way so that the pull request will remain short and people will be willing to review it.

Co-authored-by: Alexander Vieth <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jul 9, 2019

@iohk-bors iohk-bors bot merged commit 3648d99 into master Jul 9, 2019
@iohk-bors iohk-bors bot deleted the avieth/point_type_redux branch July 9, 2019 15:00
Copy link
Contributor

@dcoutts dcoutts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I'm still not happy with the names and extra layers of indirection. The pattern synonyms are good, but this should just be the actual representation, and we can provide conversion functions when we need something else.

, block
) where

data WithOrigin t = Origin | At t
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Chain type is a model / mock impl. We shouldn't give it primacy in names. If we want Genesis for the point types we can use it, and we can rename the Chain one (e.g. GenesisBlock) or use qualified names.

fmap _ Origin = Origin
fmap f (At t) = At (f t)

data Block slot hash = Block
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intuition is also for BlockPoint and not using module-qualified names elsewhere.

at = At

origin :: WithOrigin t
origin = Origin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not clear it's worth using functions rather than constructors directly.

@mrBliss mrBliss added the consensus issues related to ouroboros-consensus label Aug 2, 2019
coot pushed a commit that referenced this pull request May 16, 2022
706: Better Point type factoring, again r=avieth a=avieth

Intended to replace #635 and #690 .

It's factored into 2 commits that could be reviewed separately (the third one is a tiny unrelated fix to byron-proxy).

The first commit introduces the `Ouroboros.Network.Point` module and uses it throughout ouroboros-network, making it build and tests pass.

The second makes ouroboros-consensus build and tests pass.

This commit retains the mistake `pointHash :: Point block -> SlotNo` rather than fixing it to be `pointHash :: Point block -> WithOrigin SlotNo`. The origin point is given `SlotNo 0`. It's kept this way so that the pull request will remain short and people will be willing to review it.

Co-authored-by: Alexander Vieth <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consensus issues related to ouroboros-consensus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants