Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
186331b
Introduce Bytes32RealPoint
agustinmista May 7, 2026
8ff6384
Introduce O.C.Util.Bitmap
agustinmista Mar 27, 2026
0f23fff
Define concrete Peras certs and votes using BLS signatures
agustinmista Mar 27, 2026
6747d5f
Define PerasCrypto and wire up voting committee instance using BLS
agustinmista Apr 10, 2026
e021161
Add conversions between Peras votes/certs and voting committee types
agustinmista Apr 21, 2026
283d68c
Add test helpers for PerasCrypto
agustinmista Apr 21, 2026
b69fdc8
Add property tests for Bitmap library
agustinmista Apr 21, 2026
134418b
Add serialization roundtrip tests for PerasCert and PerasVote
agustinmista Mar 27, 2026
7e4cc94
Add conversion roundtrip tests between Peras votes/certs and voting c…
agustinmista Apr 21, 2026
a7118cf
Add changelog
agustinmista Apr 21, 2026
54f7b7d
Split base Peras types into separate module
agustinmista May 5, 2026
3530deb
Remove PerasCfg type family
agustinmista May 5, 2026
ea7e49c
Consolidate Peras vote and certificate projection type classes
agustinmista May 8, 2026
4b071c2
Introduce O.C.Peras.(Vote|Cert).Mock
agustinmista May 13, 2026
66c7984
Split degenerate BlockSupportsPeras instance
agustinmista May 8, 2026
1c7aa1a
Tweak TestBlock to use getPerasCertInBlock in tests
agustinmista May 18, 2026
e2f6e65
Re-change Peras target to use `Point blk` instead of `PerasBoostedBlock`
tbagrel1 May 18, 2026
b3310a6
Define differentiated BlockSupportsPeras instances for ShelleyBlocks
tbagrel1 May 19, 2026
e24451e
Revert "Re-change Peras target to use `Point blk` instead of `PerasBo…
agustinmista May 20, 2026
1669198
Add WithOrigin to PerasBoostedBlock
agustinmista May 20, 2026
328ef8e
Rename Peras.Voting.Committee to Peras.Voting.Adapter
agustinmista May 20, 2026
e150e7d
Add phantom type parameter to `V1.Peras{Vote,Cert}`
tbagrel1 May 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!--
A new scriv changelog fragment.

Uncomment the section that is right (remove the HTML comment wrapper).
For top level release notes, leave all the headers commented out.
-->

<!--
### Breaking

- A bullet item for the Breaking category.

-->

### Non-Breaking

- Introduce `Ouroboros.Consensus.Util.Bitmap` providing `ByteString`-based compact bitmaps.
- Define `PerasBLSCrypto` scheme with support for all the voting committee superclasses.
- Define concrete `PerasVote` and `PerasCert` types using BLS signatures.
- Define `PerasVoteCompatibleWithVotingCommittee` and `PerasCertCompatibleWithVotingCommittee` type classes with conversions between concrete Peras types and their abstract voting committee counterparts.
- Instantiate `VotingCommitteeSupportsPeras` for both `WFALS` and `EveryoneVotes`.

<!--
### Patch

- A bullet item for the Patch category.

-->
23 changes: 23 additions & 0 deletions changelog.d/20260507_102103_agustin.mista_bytes32realpoint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
A new scriv changelog fragment.

Uncomment the section that is right (remove the HTML comment wrapper).
For top level release notes, leave all the headers commented out.
-->

<!--
### Breaking

- A bullet item for the Breaking category.

-->
### Non-Breaking

- Introduce `Bytes32RealPoint` for real points with 32byte header hashes.

<!--
### Patch

- A bullet item for the Patch category.

-->
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import Ouroboros.Consensus.Ledger.CommonProtocolParams
import Ouroboros.Consensus.Ledger.Extended
import Ouroboros.Consensus.Ledger.Query
import Ouroboros.Consensus.Ledger.SupportsPeerSelection
import Ouroboros.Consensus.Ledger.SupportsPeras (LedgerSupportsPeras)
import Ouroboros.Consensus.Ledger.SupportsProtocol
import Ouroboros.Consensus.Ledger.Tables.Utils
import Ouroboros.Consensus.Util (ShowProxy (..))
Expand Down Expand Up @@ -573,3 +574,10 @@ decodeByronResult query = case query of

instance CanUpgradeLedgerTables LedgerState ByronBlock where
upgradeTables _ _ = id

{-------------------------------------------------------------------------------
LedgerSupportsPeras
-------------------------------------------------------------------------------}

-- | Default instance with no Peras support
instance LedgerSupportsPeras ByronBlock
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ import Ouroboros.Consensus.Byron.Crypto.DSIGN
import Ouroboros.Consensus.Byron.Ledger
import Ouroboros.Consensus.Byron.Ledger.Conversions
import Ouroboros.Consensus.Byron.Ledger.Inspect ()
import Ouroboros.Consensus.Byron.Node.Peras ()
import Ouroboros.Consensus.Byron.Node.Serialisation ()
import Ouroboros.Consensus.Byron.Protocol
import Ouroboros.Consensus.Config
import Ouroboros.Consensus.Config.SupportsNode
import Ouroboros.Consensus.HeaderValidation
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.Extended
import Ouroboros.Consensus.Ledger.SupportsPeras (LedgerSupportsPeras)
import Ouroboros.Consensus.Node.InitStorage
import Ouroboros.Consensus.Node.ProtocolInfo
import Ouroboros.Consensus.Node.Run
Expand Down Expand Up @@ -302,8 +302,6 @@ instance NodeInitStorage ByronBlock where
RunNode instance
-------------------------------------------------------------------------------}

instance LedgerSupportsPeras ByronBlock

instance BlockSupportsMetrics ByronBlock where
isSelfIssued = isSelfIssuedConstUnknown

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{-# LANGUAGE FlexibleInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

-- | Empty Peras support for Byron.
--
-- NOTE: this module exists solely because the orphan module
-- 'Ouroboros.Consensus.Byron.Node.Serialisation' needs this instance, but
-- defining it there would be too confusing.
module Ouroboros.Consensus.Byron.Node.Peras () where

import Ouroboros.Consensus.Block.SupportsPeras (BlockSupportsPeras)
import Ouroboros.Consensus.Byron.Ledger.Block (ByronBlock)

{-------------------------------------------------------------------------------
BlockSupportsPeras
-------------------------------------------------------------------------------}

-- NOTE: Byron does not support Peras, so we can use the empty instance here.
instance BlockSupportsPeras ByronBlock
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Data.Word
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Byron.Ledger
import Ouroboros.Consensus.Byron.Ledger.Conversions
import Ouroboros.Consensus.Byron.Node.Peras ()
import Ouroboros.Consensus.Byron.Protocol
import Ouroboros.Consensus.HeaderValidation
import Ouroboros.Consensus.Ledger.Query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class
HasPartialConsensusConfig proto
, DecCBOR (SL.PState era)
, Crypto (ProtoCrypto proto)
, -- Peras constraints
BlockSupportsPeras (ShelleyBlock proto era)
, -- Backwards compatibility
Plain.FromCBOR (LegacyPParams era)
, Plain.ToCBOR (LegacyPParams era)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

Expand All @@ -24,14 +25,14 @@ import qualified Data.Map.Strict as Map
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Config
import Ouroboros.Consensus.HardFork.Combinator.Abstract.NoHardForks
import Ouroboros.Consensus.Ledger.SupportsMempool (TxLimits)
import Ouroboros.Consensus.Ledger.SupportsProtocol
( LedgerSupportsProtocol
)
import Ouroboros.Consensus.Node.ProtocolInfo
import Ouroboros.Consensus.Node.Run
import Ouroboros.Consensus.Protocol.Abstract
import Ouroboros.Consensus.Protocol.TPraos
import Ouroboros.Consensus.Shelley.Eras
import Ouroboros.Consensus.Shelley.Ledger
import Ouroboros.Consensus.Shelley.Ledger.Inspect ()
import Ouroboros.Consensus.Shelley.Ledger.NetworkProtocolVersion ()
Expand Down Expand Up @@ -107,11 +108,64 @@ instance ConsensusProtocol proto => BlockSupportsSanityCheck (ShelleyBlock proto
configAllSecurityParams = pure . protocolSecurityParam . topLevelConfigProtocol

instance
( ShelleyCompatible proto era
, LedgerSupportsProtocol (ShelleyBlock proto era)
, BlockSupportsSanityCheck (ShelleyBlock proto era)
, TxLimits (ShelleyBlock proto era)
, NoHardForks (ShelleyBlock proto era)
( ShelleyCompatible proto ShelleyEra
, LedgerSupportsProtocol (ShelleyBlock proto ShelleyEra)
, BlockSupportsSanityCheck (ShelleyBlock proto ShelleyEra)
, NoHardForks (ShelleyBlock proto ShelleyEra)
, Crypto (ProtoCrypto proto)
) =>
RunNode (ShelleyBlock proto era)
RunNode (ShelleyBlock proto ShelleyEra)

instance
( ShelleyCompatible proto AllegraEra
, LedgerSupportsProtocol (ShelleyBlock proto AllegraEra)
, BlockSupportsSanityCheck (ShelleyBlock proto AllegraEra)
, NoHardForks (ShelleyBlock proto AllegraEra)
, Crypto (ProtoCrypto proto)
) =>
RunNode (ShelleyBlock proto AllegraEra)

instance
( ShelleyCompatible proto MaryEra
, LedgerSupportsProtocol (ShelleyBlock proto MaryEra)
, BlockSupportsSanityCheck (ShelleyBlock proto MaryEra)
, NoHardForks (ShelleyBlock proto MaryEra)
, Crypto (ProtoCrypto proto)
) =>
RunNode (ShelleyBlock proto MaryEra)

instance
( ShelleyCompatible proto AlonzoEra
, LedgerSupportsProtocol (ShelleyBlock proto AlonzoEra)
, BlockSupportsSanityCheck (ShelleyBlock proto AlonzoEra)
, NoHardForks (ShelleyBlock proto AlonzoEra)
, Crypto (ProtoCrypto proto)
) =>
RunNode (ShelleyBlock proto AlonzoEra)

instance
( ShelleyCompatible proto BabbageEra
, LedgerSupportsProtocol (ShelleyBlock proto BabbageEra)
, BlockSupportsSanityCheck (ShelleyBlock proto BabbageEra)
, NoHardForks (ShelleyBlock proto BabbageEra)
, Crypto (ProtoCrypto proto)
) =>
RunNode (ShelleyBlock proto BabbageEra)

instance
( ShelleyCompatible proto ConwayEra
, LedgerSupportsProtocol (ShelleyBlock proto ConwayEra)
, BlockSupportsSanityCheck (ShelleyBlock proto ConwayEra)
, NoHardForks (ShelleyBlock proto ConwayEra)
, Crypto (ProtoCrypto proto)
) =>
RunNode (ShelleyBlock proto ConwayEra)

instance
( ShelleyCompatible proto DijkstraEra
, LedgerSupportsProtocol (ShelleyBlock proto DijkstraEra)
, BlockSupportsSanityCheck (ShelleyBlock proto DijkstraEra)
, NoHardForks (ShelleyBlock proto DijkstraEra)
, Crypto (ProtoCrypto proto)
) =>
RunNode (ShelleyBlock proto DijkstraEra)
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wno-orphans #-}

-- | Mocked Peras support for Shelley.
--
-- NOTE: this module exists solely because the orphan module
-- 'Ouroboros.Consensus.Shelley.Node.Serialisation' needs this instance, but
-- defining it there would be too confusing.
module Ouroboros.Consensus.Shelley.Node.Peras () where

import Cardano.Ledger.Api
import Ouroboros.Consensus.Block.SupportsPeras
( BlockSupportsPeras (..)
, VoidPerasError
)
import Ouroboros.Consensus.Peras.Cert.Mock
( MockPerasCert (..)
, forgeMockPerasCert
, validateMockPerasCert
)
import Ouroboros.Consensus.Peras.Vote.Mock
( MockPerasVote (..)
, validateMockPerasVote
)
import Ouroboros.Consensus.Shelley.Ledger.Block
( ShelleyBlock
, ShelleyCompatible
)

{-------------------------------------------------------------------------------
BlockSupportsPeras
-------------------------------------------------------------------------------}

-- Peras support starts with DijkstraEra, so earlier eras use the default void
-- implementation.

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
Contributor

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.

instance ShelleyCompatible proto ShelleyEra => BlockSupportsPeras (ShelleyBlock proto ShelleyEra)
instance ShelleyCompatible proto AllegraEra => BlockSupportsPeras (ShelleyBlock proto AllegraEra)
instance ShelleyCompatible proto MaryEra => BlockSupportsPeras (ShelleyBlock proto MaryEra)
instance ShelleyCompatible proto AlonzoEra => BlockSupportsPeras (ShelleyBlock proto AlonzoEra)
instance ShelleyCompatible proto BabbageEra => BlockSupportsPeras (ShelleyBlock proto BabbageEra)
instance ShelleyCompatible proto ConwayEra => BlockSupportsPeras (ShelleyBlock proto ConwayEra)

-- NOTE: this is a mocked up implementation without crypto!
-- TODO: replace this with a concrete implementation using 'Peras.Vote.V1' and
-- 'Peras.Cert.V1' for era >= DijkstraEra.
instance
ShelleyCompatible proto DijkstraEra =>
BlockSupportsPeras (ShelleyBlock proto DijkstraEra)
where
type PerasVote (ShelleyBlock proto DijkstraEra) = MockPerasVote (ShelleyBlock proto DijkstraEra)
type PerasCert (ShelleyBlock proto DijkstraEra) = MockPerasCert (ShelleyBlock proto DijkstraEra)
type PerasError (ShelleyBlock proto DijkstraEra) = VoidPerasError (ShelleyBlock proto DijkstraEra)

validatePerasVote = validateMockPerasVote
validatePerasCert = validateMockPerasCert
forgePerasCert = forgeMockPerasCert

-- TODO: extract actual Peras certificates from blocks
getPerasCertInBlock _ = Nothing
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import Ouroboros.Consensus.Protocol.TPraos
import Ouroboros.Consensus.Shelley.Eras
import Ouroboros.Consensus.Shelley.Ledger
import Ouroboros.Consensus.Shelley.Ledger.NetworkProtocolVersion ()
import Ouroboros.Consensus.Shelley.Node.Peras ()
import Ouroboros.Consensus.Shelley.Protocol.Abstract
( pHeaderBlockSize
, pHeaderSize
Expand Down Expand Up @@ -126,22 +127,47 @@ instance
SerialiseNodeToNode
-------------------------------------------------------------------------------}

instance
-- | Shared implementation of 'estimateBlockSize' for all Shelley-based eras.
estimateBlockSizeShelley ::
ShelleyCompatible proto era =>
SerialiseNodeToNodeConstraints (ShelleyBlock proto era)
Header (ShelleyBlock proto era) ->
SizeInBytes
estimateBlockSizeShelley hdr = overhead + hdrSize + bodySize
where
-- The maximum block size is 65536, the CBOR-in-CBOR tag for this block
-- is:
--
-- > D8 18 # tag(24)
-- > 1A 00010000 # bytes(65536)
--
-- Which is 7 bytes, enough for up to 4294967295 bytes.
overhead = 7 {- CBOR-in-CBOR -} + 1 {- encodeListLen -}
bodySize = fromIntegral . pHeaderBlockSize . shelleyHeaderRaw $ hdr
hdrSize = fromIntegral . pHeaderSize . shelleyHeaderRaw $ hdr

instance ShelleyCompatible proto ShelleyEra => SerialiseNodeToNodeConstraints (ShelleyBlock proto ShelleyEra) where
estimateBlockSize = estimateBlockSizeShelley

instance ShelleyCompatible proto AllegraEra => SerialiseNodeToNodeConstraints (ShelleyBlock proto AllegraEra) where
estimateBlockSize = estimateBlockSizeShelley

instance ShelleyCompatible proto MaryEra => SerialiseNodeToNodeConstraints (ShelleyBlock proto MaryEra) where
estimateBlockSize = estimateBlockSizeShelley

instance ShelleyCompatible proto AlonzoEra => SerialiseNodeToNodeConstraints (ShelleyBlock proto AlonzoEra) where
estimateBlockSize = estimateBlockSizeShelley

instance ShelleyCompatible proto BabbageEra => SerialiseNodeToNodeConstraints (ShelleyBlock proto BabbageEra) where
estimateBlockSize = estimateBlockSizeShelley

instance ShelleyCompatible proto ConwayEra => SerialiseNodeToNodeConstraints (ShelleyBlock proto ConwayEra) where
estimateBlockSize = estimateBlockSizeShelley

instance
ShelleyCompatible proto DijkstraEra =>
SerialiseNodeToNodeConstraints (ShelleyBlock proto DijkstraEra)
where
estimateBlockSize hdr = overhead + hdrSize + bodySize
where
-- The maximum block size is 65536, the CBOR-in-CBOR tag for this block
-- is:
--
-- > D8 18 # tag(24)
-- > 1A 00010000 # bytes(65536)
--
-- Which is 7 bytes, enough for up to 4294967295 bytes.
overhead = 7 {- CBOR-in-CBOR -} + 1 {- encodeListLen -}
bodySize = fromIntegral . pHeaderBlockSize . shelleyHeaderRaw $ hdr
hdrSize = fromIntegral . pHeaderSize . shelleyHeaderRaw $ hdr
estimateBlockSize = estimateBlockSizeShelley

-- | CBOR-in-CBOR for the annotation. This also makes it compatible with the
-- wrapped ('Serialised') variant.
Expand Down
Loading