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 classes each era must satisfy for consensus integration #1944

Merged
merged 4 commits into from
Oct 29, 2020

Conversation

mrBliss
Copy link
Contributor

@mrBliss mrBliss commented Oct 27, 2020

See the individual commits for more details.

Copy link
Contributor Author

@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.

The goal of this PR is to have something very concrete that needs to be completed before consensus can proceed with CAD-1679, i.e., the instances in Allegra.hs and Mary.hs.

Ideally, these instances are provided ASAP, maybe not necessarily with complete working implementations (error?). The actual implementations can follow later, in the meantime, the integration in downstream repos can proceed and we can at least propagate the types.

ApplyBlock era,
ApplyTx era
) =>
ShelleyBasedEra era
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm open to suggestions for a better name and/or a better place for it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this top level of bundling especially useful? I feel like it'll be potentially confusing to have so many different variants on this...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO, very. It is the constraint that consensus uses on era, as it implies everything we need. See for example: https://github.com/input-output-hk/ouroboros-network/blob/master/ouroboros-consensus-shelley/src/Ouroboros/Consensus/Shelley/Ledger/Block.hs.

Also, this gives us a single check to verify whether an era satisfies everything that is needed. (If you have to provide 3-4 instances, it easier to forget to provide one of them, e.g., ApplyTx.)

I could see that the name is confusing (compared to ShelleyBased), so I'm certainly open to a better name.

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'm also strugging to come up with a good name...

Copy link
Contributor

Choose a reason for hiding this comment

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

ShelleyMinimum? I struggle as well...

KESignable c (BHBody c),
VRFSignable c Seed
) =>
TPraosCrypto c
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm open to suggestions for a better name and/or a better place for it.

Copy link
Contributor

Choose a reason for hiding this comment

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

What does the T stand for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Transitional Praos (transition from PBFT to Praos). PraosCrypto would also be fine for me. Or ShelleyCrypto, or ShelleyBasedCrypto, ...

Copy link
Contributor

Choose a reason for hiding this comment

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

ah! thanks :) I like PraosCrypto or ShelleyCrypto. I don't have strong opinions here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I prefer ShelleyBasedCrypto over ShelleyCrypto because the latter might give the impression that it is related to the Shelley era while it is in fact not specific to the Shelley era? 🤔

PraosCrypto is shorter and avoids the confusion?

Up to you.

@mrBliss
Copy link
Contributor Author

mrBliss commented Oct 28, 2020

I'll rebase this PR once #1931 has been merged. I'll do the renaming/moves that have been decided by then at the same time.

UPDATE: done

This class exists in consensus and bundles all *signable* constraints that the
Shelley(-based) ledger needs. Since these constraints all originate from the
ledger, it makes sense to just put them in the ledger.

Using this class (which implies `Crypto crypto`) also simplifies the API
slightly.

Why not make this a constraint synonym? Because with a class, one can easily
check whether a given crypto type satisfies all the required constraints by
providing an instance declaration:

```haskell
instance PraosCrypto C_Crypto
```

If one of the constraints required for `PraosCrypto` is not satisfied by
`C_Crypto`, then there will be an error at the instance declaration.

When using a constraint synonym, there is no instance to define. An error about
a missing constraint will be only be visible where `PraosCrypto crypto` is
instantiated to `C_Crypto`, e.g., somewhere in consensus (way too late) or in
the testsuite.
This is *the* constraint that an era must satisfy in order to be used by
consensus.

As discussed in the previous commit, this is a class and not a constraint
synonym. This means that instances of it can (and should!) be defined in the
ledger, which requires all constraints to be satisfied at the site of the
instance definitions.

With a constraint synonym, the constraints are only checked when the synonym is
instantiated and used, which would be *in the consensus layer*. This would mean
that the ledger won't be alerted when the required constraints are accidentally
removed. Instead, the consensus layer would detect it when updating its
dependency on the ledger, which is *too late*. By having the instance in the
ledger, it is up to the ledger to make sure all required constraints keep being
satisfied.
Now that `AllegraEra` implements all the needed constraints,
`ShelleyBased (AllegraEra c)` should be trivially true.
@mrBliss mrBliss force-pushed the mrBliss/consensus-requirements branch from 13fdd59 to cc9995f Compare October 28, 2020 17:42
@mrBliss mrBliss marked this pull request as ready for review October 28, 2020 17:47
@mrBliss
Copy link
Contributor Author

mrBliss commented Oct 28, 2020

I have rebased this PR on master and renamed TPraosCrypto to PraosCrypto.

@JaredCorduan @nc6 Note that the last commit is unrelated to this PR, but it is needed to compile warning-free.

I believe this warning snuck in because CI is not properly configured: -Werror is not enabled for all packages in: https://github.com/input-output-hk/cardano-ledger-specs/blob/e1f839bff708e1938355b56ad3a7fe03930851ff/nix/haskell.nix#L32-L36

@nc6 nc6 merged commit 5da7dd8 into master Oct 29, 2020
@iohk-bors iohk-bors bot deleted the mrBliss/consensus-requirements branch October 29, 2020 08:01
mrBliss added a commit to IntersectMBO/ouroboros-network that referenced this pull request Oct 29, 2020
This pulls in IntersectMBO/cardano-ledger#1944
which moves `ShelleyBasedEra` and `TPraosCrypto` (renamed to `PraosCrypto`) to
`cardano-ledger-specs`.
mrBliss added a commit to IntersectMBO/ouroboros-network that referenced this pull request Oct 29, 2020
This pulls in IntersectMBO/cardano-ledger#1944
which moves `ShelleyBasedEra` and `TPraosCrypto` (renamed to `PraosCrypto`) to
`cardano-ledger-specs`.
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