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

Define interfaces for consensus #1923

Merged
merged 3 commits into from
Oct 21, 2020
Merged

Conversation

mrBliss
Copy link
Contributor

@mrBliss mrBliss commented Oct 19, 2020

In the Shelley.Spec.Ledger.API.* modules, define type classes for the most
important functionality consensus. These classes are parametric in the era.
Instances should be provided for each era (Shelley, Allegra, Mary, etc.). At the
moment, only instances for ShelleyEra are provided.

These classes list a bunch of super-class constraints that consensus relies on.
I have tried to be complete, but there's a good chance I forgot to add a few
constraints that are currently already satisfied.

Default implementations are provided for each method so that an empty instance
declaration should be enough for each class + era combination. The constraints
on these instances are what matters, they should be minimal, e.g., just Crypto crypto and DSignable ...

Note: the super-class constraints of the classes are what consensus needs, not
what the default implementations of the methods need. If a default
implementation needs more constraints, add them to the default signature.

@mrBliss
Copy link
Contributor Author

mrBliss commented Oct 19, 2020

Draft because this depends on #1902.

@mrBliss mrBliss force-pushed the mrBliss/era-translations branch 2 times, most recently from df5427e to 9d16f70 Compare October 21, 2020 07:02
@mrBliss mrBliss changed the base branch from mrBliss/era-translations to master October 21, 2020 07:05
@mrBliss mrBliss force-pushed the mrBliss/consensus-interfaces branch from 2cd6fed to 0c5f00d Compare October 21, 2020 07:09
@mrBliss mrBliss force-pushed the mrBliss/consensus-interfaces branch from 0c5f00d to 1e3f617 Compare October 21, 2020 07:45
@mrBliss mrBliss marked this pull request as ready for review October 21, 2020 07:45
@mrBliss
Copy link
Contributor Author

mrBliss commented Oct 21, 2020

#1902 has been merged. I have rebased this PR on master. Ready for review.

Comment on lines 53 to 73
( Eq (Block era),
Show (Block era),
NoThunks (Block era),
FromCBOR (Annotator (Block era)),
ToCBOR (Block era),
Eq (BHeader (Crypto era)),
Show (BHeader (Crypto era)),
NoThunks (BHeader (Crypto era)),
FromCBOR (Annotator (BHeader (Crypto era))),
ToCBOR (Block era),
Eq (ShelleyState era),
Show (ShelleyState era),
NoThunks (ShelleyState era),
FromCBOR (ShelleyState era),
ToCBOR (ShelleyState era),
Eq (BlockTransitionError era),
Show (BlockTransitionError era),
NoThunks (BlockTransitionError era),
Eq (STS.PredicateFailure (STS.CHAIN era)),
Show (STS.PredicateFailure (STS.CHAIN era)),
NoThunks (STS.PredicateFailure (STS.CHAIN 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.

This list is already rather long, but I expect some things are missing. So at some point, I might have to add more constraints here.

import Shelley.Spec.Ledger.TxBody (EraIndependentTxBody)

-- TODO #1304: add reapplyTxs
class
Copy link
Contributor

Choose a reason for hiding this comment

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

I might move these class definitions to Cardano.Ledger.API since we now expect them to apply across eras. But can do that in a separate PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We decided to postpone this.

Show (Tx era),
NoThunks (Tx era),
FromCBOR (Annotator (Tx era)),
ToCBOR (Tx era),
Copy link
Contributor

Choose a reason for hiding this comment

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

Tim has proposed packaging these things up as ChainData, which would make this list somewhat cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See the last commit.

-- few header level checks, such as size constraints.
applyTick ::
Globals ->
ShelleyState era ->
Copy link
Contributor

Choose a reason for hiding this comment

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

[bikeshedding] ShelleyState was an alias for downstream use, but now feels a bit awkward, since generally this won't be shelley. We could use the wrapped type NewEpochState, or come up with a better name (but all the obvious ones are taken...)

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 have gone for NewEpochState for now.

@mrBliss mrBliss force-pushed the mrBliss/consensus-interfaces branch from 1e3f617 to 40610c5 Compare October 21, 2020 09:38
In the `Shelley.Spec.Ledger.API.*` modules, define type classes for the most
important functionality consensus. These classes are parametric in the era.
Instances should be provided for each era (Shelley, Allegra, Mary, etc.). At the
moment, only instances for `ShelleyEra` are provided.

These classes list a bunch of super-class constraints that consensus relies on.
I have tried to be complete, but there's a good chance I forgot to add a few
constraints that are currently already satisfied.

Default implementations are provided for each method so that an empty instance
declaration should be enough for each class + era combination. The constraints
on these instances are what matters, they should be minimal, e.g., just `Crypto
crypto` and `DSignable ..`.

Note: the super-class constraints of the classes are what consensus needs, *not*
what the default implementations of the methods need. If a default
implementation needs more constraints, add them to the *default signature*.
It will be used by all eras, so having Shelley in the name is confusing.
@mrBliss mrBliss force-pushed the mrBliss/consensus-interfaces branch from 40610c5 to 6cb87f9 Compare October 21, 2020 09:42
These constraint synonyms make the contexts of the API classes much more
readable.
@mrBliss mrBliss force-pushed the mrBliss/consensus-interfaces branch from 6cb87f9 to a0d58d3 Compare October 21, 2020 09:48
@mrBliss mrBliss merged commit 1a2d771 into master Oct 21, 2020
@iohk-bors iohk-bors bot deleted the mrBliss/consensus-interfaces branch October 21, 2020 11:30
iohk-bors bot added a commit to IntersectMBO/ouroboros-network that referenced this pull request Oct 23, 2020
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.

2 participants