Skip to content

[Peras 27] Split degenerate BlockSupportsPeras instance#2027

Draft
agustinmista wants to merge 12 commits into
peras/concrete-certs-and-votesfrom
peras/degenerate-peras-instances
Draft

[Peras 27] Split degenerate BlockSupportsPeras instance#2027
agustinmista wants to merge 12 commits into
peras/concrete-certs-and-votesfrom
peras/degenerate-peras-instances

Conversation

@agustinmista
Copy link
Copy Markdown
Contributor

@agustinmista agustinmista commented May 5, 2026

This PR has the main goal of removing the existing degenerate forall blk. BlockSupportsPeras blk instance and replace it with separate, independent ones for the several block types in the codebase that need it.

To aid with this process, we have made a couple of preliminary changes:

  • Moving base Peras types into a separate O.C.Peras.Types module to keep O.C.Block.SupportsPeras as focused on the blk-dependent API as possible.
  • Consolidating all the HasPeras(Vote|Cert)X classes into two, IsPerasVote and IsPerasCert, grouping all the necessary non-crypto-related projections needed to operate on Peras votes and certificates.
  • Removing the PerasCfg blk associated type, in favor of keeping things simple and using the monomorphic PerasParams for now. These will likely need a major overhaul in the future when on-chain governance of these parameters becomes necessary.
  • Introducing dedicated modules for MockPeras(Vote|Cert)s, containing the non-crypto mocked Peras votes and certificates that were previously hardcoded everywhere. These will still be used for certain (mostly test) block types.
  • Provide an "empty" default BlockSupportsPeras instance defined in terms of Void, so Peras votes, certs, and errors are uninstantiable and can be discharged via absurd.

With this in place, the remaining changes mostly encompass the plumbing needed after removing the existing BlockSupportsPeras instance and replacing it with dedicated ones. Concretely:

  • ByronBlock uses the "emtpy" instance
  • ShelleyBlock proto era uses a mocked instance (to be replaced with a concrete one using real type for era ~ Dijkstra and empty ones for every other era. (@tbagrel1 is working on this on a separate PR)
  • HardForkBlock xs uses a mocked instance, but will be replaced with a compositional one defined around the two previous ones (also WIP)

On the testing side:

  • BlockA and BlockB both use the "empty" instance
  • DualByronBlock uses the "empty" instance
  • O.C.Mock.Ledger.Block.SimpleBlock c ext uses the "empty" instance
  • O.C.Storage.TestBlock.TestBlock uses a mocked instance (now with a properly instantiated getPerasCertInBlock)
  • Test.Util.TestBlock.TestBlockWith ptype uses a mocked instance (without any support for certificates in blocks, as it's not needed for any of the existing tests)

Finally, some general notes (notice that some of these are already covered by new issues linked in the comments below):

  • There is a substantial number of instances involving type families that had to be derived using standalone deriving statements now to keep GHC happy.
  • BlockSupportsPeras is still missing a forgePerasVote method. This will become evident soon when trying to write a blk-generic voting thread (BlockSupportsPeras currently misses a forgeVote method tweag/cardano-peras#248)
  • Some of the new BlockSupportsPeras instances are defined via orphans in dedicated modules. This is because:
    • SerialiseNodeToNodeConstraints blk now requires SerialiseNodeToNode (PerasVote blk) and SerialiseNodeToNode (PerasCert blk) which are only in scope after PerasVote blk and PerasCert blk are established when defining BlockSupportsPeras blk
    • Some SerialiseNodeToNodeConstraints instances are already defined as orphans in their own dedicated modules, forcing us to create a new module or to define BlockSupportsPeras blk in the same one as SerialiseNodeToNodeConstraints blk (confusing!). We might be able to rearrange constraints to avoid this, but that would probably mean adding SerialiseNodeToNode (Peras(Vote|Cert) blk) as superclasses to a type-class higher-up in the chain.
    • We favored tight constraints over "umbrella" ones as much as possible to avoid having to implement unnecessary/unrelated interfaces for test blocks as much as possible.
  • Mocked votes and certs are trivially validatable without errors (technically, with uninstantiable errors if being pedantic). For this to work, MockPerasVote carries its own stake. Please note this is not the case for real votes, as their stake is retrieved from the stake distribution after validation.
  • Some Peras... types will become redundant and get removed in a later PR when we start integrating components.

@agustinmista agustinmista self-assigned this May 5, 2026
@agustinmista agustinmista force-pushed the peras/degenerate-peras-instances branch from 821b00a to 37fe870 Compare May 5, 2026 13:10
@agustinmista agustinmista force-pushed the peras/concrete-certs-and-votes branch from f47be9f to b084253 Compare May 5, 2026 13:11
@agustinmista agustinmista force-pushed the peras/degenerate-peras-instances branch from 37fe870 to 7fbebad Compare May 5, 2026 14:11
@agustinmista agustinmista force-pushed the peras/concrete-certs-and-votes branch from b084253 to 67855ea Compare May 5, 2026 14:12
@agustinmista agustinmista force-pushed the peras/degenerate-peras-instances branch from 7fbebad to 35a01bc Compare May 5, 2026 15:56
@agustinmista agustinmista force-pushed the peras/concrete-certs-and-votes branch 3 times, most recently from 8a2bab8 to 10f8c2e Compare May 7, 2026 12:39
@agustinmista agustinmista force-pushed the peras/degenerate-peras-instances branch 3 times, most recently from f827bf2 to c4b4797 Compare May 8, 2026 15:09
@agustinmista agustinmista force-pushed the peras/concrete-certs-and-votes branch from 10f8c2e to e8a284d Compare May 11, 2026 08:37
@agustinmista agustinmista force-pushed the peras/degenerate-peras-instances branch 9 times, most recently from d5d1fd0 to f7ecea3 Compare May 13, 2026 12:01
@agustinmista agustinmista force-pushed the peras/concrete-certs-and-votes branch from e8a284d to 00df1fa Compare May 13, 2026 12:01
@agustinmista agustinmista changed the title [Peras 29] Split degenerate BlockSupportsPeras instance [Peras 27] Split degenerate BlockSupportsPeras instance May 13, 2026
Copy link
Copy Markdown
Contributor

@tbagrel1 tbagrel1 left a comment

Choose a reason for hiding this comment

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

This was a long review ahah

General comments (when I didn't find an appropriate location to pin them):

  • We still have PerasVoterId clashing with SeatIndex. Same with Point blk and PerasBoostedBlock

  • ShelleyBlock and HFC block are using Mock Vote/Cert despite real vote and certs being available (Peras.{Vote,Cert}.V1)

  • It also could be worth generating a list of modified files with a mention for each saying if we just updated imports/replaced constraints StandardHash -> BlockSupportsPeras, or if we did something meaninful in them. It could be useful for future reviewers

Comment on lines +53 to +63
, Typeable blk
, Typeable (PerasVote blk)
, Typeable (PerasCert blk)
, IsPerasVote (PerasVote blk) blk
, IsPerasCert (PerasCert blk) blk
, Show (PerasVote blk)
, Show (PerasCert blk)
, Eq (PerasVote blk)
, Eq (PerasCert blk)
, NoThunks (PerasVote blk)
, NoThunks (PerasCert blk)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggested we could move the vote-related and cert-related constraints to the IsPerasVote and IsPerasCert classes. If there is a reason why this isn't desirable, we should probably document it :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, I took another stab at this, and I think I have a decent argument to avoid doing this for now:

  • Contrary to what I expected, we end up needing more constraints than before. E.g. StandardHash blk becomes necessary on every call site of a vote/cert projection, regardless of whether we need to Show, Eq, etc. a vote/cert's Point blk.

  • We additionally need the same constraints for PerasError blk, but we don't have a dedicated class to add these as superclasses to, creating an inconsistency.

) =>
BlockSupportsPeras blk
where
type PerasCfg blk
Copy link
Copy Markdown
Contributor

@tbagrel1 tbagrel1 May 13, 2026

Choose a reason for hiding this comment

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

Mention #wontfix-for-testnet in the PR description

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

#needs-a-todo(blk-dependent Peras params)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

--
-- Returns 'Nothing' if the block does not contain a Peras certificate, or
-- if the block is from an era that does not support Peras certificates.
getPerasCertInBlock ::
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Mention #wontfix-for-testnet

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread ouroboros-consensus-cardano/src/byron/Ouroboros/Consensus/Byron/Node/Peras.hs Outdated
-------------------------------------------------------------------------------}

-- NOTE: this is a mocked up implementation without crypto!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Again, we need to replace this with concrete Peras.Vote.V1 for >= Djisktra eras, or at least add a TODO that says we need to do it :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added a TODO, also:

#needs-a-todo(use real Peras types for Shelley and HFC)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So far I updated the bullet list in tweag/cardano-peras#73
I'll let @qnikst decide if we should create subtask with their dedicated issue

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@tbagrel1 item is ok for now, this way we will not lose it. We can spli to a dedicated issue in case if it can be done in later milestone or by another person.

Comment thread ouroboros-consensus.cabal
@agustinmista agustinmista force-pushed the peras/degenerate-peras-instances branch from d90bebf to 5008d65 Compare May 18, 2026 07:23
@agustinmista agustinmista force-pushed the peras/concrete-certs-and-votes branch from 00df1fa to fa3893c Compare May 18, 2026 07:23
@agustinmista agustinmista force-pushed the peras/degenerate-peras-instances branch from 5008d65 to a0c11ba Compare May 18, 2026 07:31
@agustinmista agustinmista force-pushed the peras/concrete-certs-and-votes branch from fa3893c to 2b8a77f Compare May 18, 2026 07:31
@agustinmista agustinmista force-pushed the peras/degenerate-peras-instances branch from a0c11ba to 6f1359d Compare May 18, 2026 07:53
@agustinmista agustinmista force-pushed the peras/concrete-certs-and-votes branch from 2b8a77f to 966acfc Compare May 18, 2026 07:53
@agustinmista agustinmista force-pushed the peras/degenerate-peras-instances branch 2 times, most recently from 4308107 to 4197f46 Compare May 18, 2026 13:10
Copy link
Copy Markdown
Contributor

@tbagrel1 tbagrel1 left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@agustinmista agustinmista force-pushed the peras/degenerate-peras-instances branch 2 times, most recently from 7c8ef80 to 51d4a31 Compare May 19, 2026 08:27
@agustinmista agustinmista force-pushed the peras/concrete-certs-and-votes branch from 966acfc to f63c166 Compare May 19, 2026 08:27
@agustinmista agustinmista force-pushed the peras/degenerate-peras-instances branch from 51d4a31 to 3392b04 Compare May 19, 2026 09:52
@agustinmista agustinmista force-pushed the peras/concrete-certs-and-votes branch from f63c166 to 45f5251 Compare May 19, 2026 09:52
@agustinmista agustinmista force-pushed the peras/degenerate-peras-instances branch from 3392b04 to 662ef8e Compare May 19, 2026 12:04
agustinmista and others added 6 commits May 19, 2026 15:44
Co-authored-by: Agustin Mista <agustin.mista@moduscreate.com>
Co-authored-by: Thomas BAGREL <thomas.bagrel@tweag.io>
Co-authored-by: Nicolas BACQUEY <nicolas.bacquey@tweag.io>
Co-authored-by: Agustin Mista <agustin.mista@moduscreate.com>
Co-authored-by: Thomas BAGREL <thomas.bagrel@tweag.io>
Co-authored-by: Nicolas BACQUEY <nicolas.bacquey@tweag.io>
Co-authored-by: Agustin Mista <agustin.mista@moduscreate.com>
Co-authored-by: Thomas BAGREL <thomas.bagrel@tweag.io>
Co-authored-by: Nicolas BACQUEY <nicolas.bacquey@tweag.io>
Co-authored-by: Agustin Mista <agustin.mista@moduscreate.com>
Co-authored-by: Thomas BAGREL <thomas.bagrel@tweag.io>
Co-authored-by: Nicolas BACQUEY <nicolas.bacquey@tweag.io>
Co-authored-by: Agustin Mista <agustin.mista@moduscreate.com>
Co-authored-by: Thomas BAGREL <thomas.bagrel@tweag.io>
Co-authored-by: Nicolas BACQUEY <nicolas.bacquey@tweag.io>
Co-authored-by: Agustin Mista <agustin.mista@moduscreate.com>
Co-authored-by: Thomas BAGREL <thomas.bagrel@tweag.io>
Co-authored-by: Nicolas BACQUEY <nicolas.bacquey@tweag.io>
@agustinmista agustinmista force-pushed the peras/degenerate-peras-instances branch from 662ef8e to 1c7aa1a Compare May 19, 2026 13:45
@agustinmista agustinmista force-pushed the peras/concrete-certs-and-votes branch from 45f5251 to a7118cf Compare May 19, 2026 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Split degenerate BlockSupportsPeras instance Interface design & HFC plumbing for Peras

3 participants