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

genesis/origin does not have a slot number #774

Merged
merged 10 commits into from
Jul 19, 2019
Merged

Conversation

avieth
Copy link
Contributor

@avieth avieth commented Jul 15, 2019

pointSlot now has type Point block ->WithOrigin SlotNo. There is no slot for the origin/genesis point.

@avieth
Copy link
Contributor Author

avieth commented Jul 15, 2019

@mrBliss I've just pushed a commit that makes ouroboros-consensus build and tests pass, but I may have done some dodgy things so please review and change.

@avieth avieth force-pushed the avieth/point_slot branch from 4b5edf7 to 0eeb798 Compare July 15, 2019 20:29
@avieth avieth requested a review from dcoutts July 16, 2019 00:41
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.

Great!

Can you do the same thing for BlockNo? Because we need BlockNo 0 for the genesis EBB, so the empty chain should have no BlockNo at all (i.e., Origin).

ouroboros-network/src/Ouroboros/Network/ChainFragment.hs Outdated Show resolved Hide resolved
@@ -385,7 +385,7 @@ instance (ByronGiven, Typeable cfg, ConfigContainsGenesis cfg)
lvUB = SlotNo $ unSlotNo currentSlot + (2 * paramK)
lvLB
| 2 * paramK > unSlotNo currentSlot
= genesisSlotNo
= SlotNo 0
Copy link
Contributor

Choose a reason for hiding this comment

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

@nc6 Is this correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the lower bound is non-strict, it should be fine.

ouroboros-network/test/Test/ChainFragment.hs Show resolved Hide resolved
ouroboros-network/test/Test/ChainFragment.hs Show resolved Hide resolved
@avieth
Copy link
Contributor Author

avieth commented Jul 16, 2019

Can you do the same thing for BlockNo? Because we need BlockNo 0 for the genesis EBB, so the empty chain should have no BlockNo at all (i.e., Origin).

Giving BlockNo 0 for the empty chain may be right. It's basically the length of the chain, so 0 makes sense. Also, in cardano-sl, the genesis block has BlockNo 0, and every EBB has the same BlockNo as its parent block, so there's precedent.

@mrBliss
Copy link
Contributor

mrBliss commented Jul 16, 2019

Can you do the same thing for BlockNo? Because we need BlockNo 0 for the genesis EBB, so the empty chain should have no BlockNo at all (i.e., Origin).

Giving BlockNo 0 for the empty chain may be right. It's basically the length of the chain, so 0 makes sense. Also, in cardano-sl, the genesis block has BlockNo 0, and every EBB has the same BlockNo as its parent block, so there's precedent.

With genesis block, you mean the very first EBB (and thus "thing" on the chain), right? (I call it the genesis EBB)

An argument for WithOrigin BlockNo: during chain selection, we use the BlockNo of the tip of a chain(fragment) as a proxy for the length of the corresponding chain (because we're dealing with fragments, we can't use the fragment length). When we're given the choice between an empty chain (blockNo = Origin) and one containing only the genesis EBB (blockNo = At (BlockNo 0)), we should prefer the latter.

Alexander Vieth added 3 commits July 18, 2019 16:29
This patches ouroboros-network to build and pass tests.
ouroboros-consensus will be patched in a follow-up.
Follow-up to pointSlot type change in ouroboros-network, to make
ouroboros-consensus build and tests pass.

Must be reviewed by someone more familiar with ouroboros-consensus. I've
probably made some changes that aren't right.
@avieth avieth force-pushed the avieth/point_slot branch from 04cc32f to 03aaf57 Compare July 18, 2019 20:30
@avieth
Copy link
Contributor Author

avieth commented Jul 18, 2019

@mrBliss I agree that the empty chain should have no BlockNo. Then chain length can be defined as

chainLength :: HasHeader block => Chain block -> Word64
chainLength = maybe 0 (succ . unBlockNo) . headBlockNo

which corresponds to the actual chain length, for valid chains.

I went ahead and tried to do this but there is too much affected, including the ChainDB, so I gave up. Perhaps you should try?

I had done this before. Somehow it was lost in a merge/rebase.
pointOnChain p@(BlockPoint pslot phash) (c :> b)
| pslot > blockSlot b = False
| pslot == blockSlot b = phash == blockHash b
| otherwise = pointOnChain p c
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you align this last case on = to appease my OCD 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. Will do

@mrBliss
Copy link
Contributor

mrBliss commented Jul 19, 2019

@mrBliss I agree that the empty chain should have no BlockNo. Then chain length can be defined as

chainLength :: HasHeader block => Chain block -> Word64
chainLength = maybe 0 (succ . unBlockNo) . headBlockNo

which corresponds to the actual chain length, for valid chains.

I went ahead and tried to do this but there is too much affected, including the ChainDB, so I gave up. Perhaps you should try?

I'll give it a try.

@@ -144,11 +144,8 @@ pattern BlockPoint { atSlot, withHash } = Point (At (Point.Block atSlot withHash
{-# COMPLETE GenesisPoint, BlockPoint #-}

-- Should be
Copy link
Contributor

Choose a reason for hiding this comment

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

This line should also be removed.

@mrBliss
Copy link
Contributor

mrBliss commented Jul 19, 2019

@mrBliss I agree that the empty chain should have no BlockNo. Then chain length can be defined as

chainLength :: HasHeader block => Chain block -> Word64
chainLength = maybe 0 (succ . unBlockNo) . headBlockNo

which corresponds to the actual chain length, for valid chains.
I went ahead and tried to do this but there is too much affected, including the ChainDB, so I gave up. Perhaps you should try?

I'll give it a try.

I have a branch for this: https://github.com/input-output-hk/ouroboros-network/tree/mrBliss/point_blockno
But after talking with Duncan and Nick, I'm no longer convinced it is really needed.

The main advantage of WithOrigin BlockNo was the ability to distinguish an empty chain (Origin) from a chain containing just the genesis EBB (At (BlockNo 0)). This is handy because we use the block number as a proxy for the chain length. However, as you say, all other EBBs will have the same BlockNo as the block before them. So this advantage is only true for the single edge case.

And quoting Duncan:

I think we generally don't need to worry too much about block number vs chain length.

When we're doing chain selection when we're syncing from the old part of the chain that has EBBs, then every time we find an EBB we will shortly find another block after it. So even if it means we don't immediately select a chain that has just one more block that is an EBB, we will select it as soon as it has an EBB + 1 block.

@avieth
Copy link
Contributor Author

avieth commented Jul 19, 2019

bors r+

iohk-bors bot added a commit that referenced this pull request Jul 19, 2019
774: genesis/origin does not have a slot number r=avieth a=avieth

`pointSlot` now has type `Point block ->WithOrigin SlotNo`. There is no slot for the origin/genesis point.

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

iohk-bors bot commented Jul 19, 2019

@iohk-bors iohk-bors bot merged commit d4453cf into master Jul 19, 2019
@iohk-bors iohk-bors bot deleted the avieth/point_slot branch July 19, 2019 14:23
@mrBliss mrBliss added the consensus issues related to ouroboros-consensus label Aug 2, 2019
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.

2 participants