Skip to content

Commit d5d1fd0

Browse files
committed
Split degenerate BlockSupportsPeras instance
1 parent 8f735e5 commit d5d1fd0

51 files changed

Lines changed: 997 additions & 324 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ouroboros-consensus-cardano/src/byron/Ouroboros/Consensus/Byron/Ledger/Ledger.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ import Ouroboros.Consensus.Ledger.CommonProtocolParams
8989
import Ouroboros.Consensus.Ledger.Extended
9090
import Ouroboros.Consensus.Ledger.Query
9191
import Ouroboros.Consensus.Ledger.SupportsPeerSelection
92+
import Ouroboros.Consensus.Ledger.SupportsPeras (LedgerSupportsPeras)
9293
import Ouroboros.Consensus.Ledger.SupportsProtocol
9394
import Ouroboros.Consensus.Ledger.Tables.Utils
9495
import Ouroboros.Consensus.Util (ShowProxy (..))
@@ -574,3 +575,10 @@ decodeByronResult query = case query of
574575

575576
instance CanUpgradeLedgerTables LedgerState ByronBlock where
576577
upgradeTables _ _ = id
578+
579+
{-------------------------------------------------------------------------------
580+
LedgerSupportsPeras
581+
-------------------------------------------------------------------------------}
582+
583+
-- | Default instance with no Peras support
584+
instance LedgerSupportsPeras ByronBlock

ouroboros-consensus-cardano/src/byron/Ouroboros/Consensus/Byron/Node.hs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ import Ouroboros.Consensus.Byron.Crypto.DSIGN
4343
import Ouroboros.Consensus.Byron.Ledger
4444
import Ouroboros.Consensus.Byron.Ledger.Conversions
4545
import Ouroboros.Consensus.Byron.Ledger.Inspect ()
46+
import Ouroboros.Consensus.Byron.Node.Peras ()
4647
import Ouroboros.Consensus.Byron.Node.Serialisation ()
4748
import Ouroboros.Consensus.Byron.Protocol
4849
import Ouroboros.Consensus.Config
4950
import Ouroboros.Consensus.Config.SupportsNode
5051
import Ouroboros.Consensus.HeaderValidation
5152
import Ouroboros.Consensus.Ledger.Abstract
5253
import Ouroboros.Consensus.Ledger.Extended
53-
import Ouroboros.Consensus.Ledger.SupportsPeras (LedgerSupportsPeras)
5454
import Ouroboros.Consensus.Node.InitStorage
5555
import Ouroboros.Consensus.Node.ProtocolInfo
5656
import Ouroboros.Consensus.Node.Run
@@ -303,8 +303,6 @@ instance NodeInitStorage ByronBlock where
303303
RunNode instance
304304
-------------------------------------------------------------------------------}
305305

306-
instance LedgerSupportsPeras ByronBlock
307-
308306
instance BlockSupportsMetrics ByronBlock where
309307
isSelfIssued = isSelfIssuedConstUnknown
310308

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{-# LANGUAGE FlexibleInstances #-}
2+
{-# LANGUAGE MultiParamTypeClasses #-}
3+
{-# LANGUAGE TypeFamilies #-}
4+
{-# OPTIONS_GHC -Wno-orphans #-}
5+
6+
-- | Mocked up Peras support for Byron.
7+
--
8+
-- NOTE: this module only exists to break an otherwise cyclic dependency between
9+
-- 'Ouroboros.Consensus.Byron.Node' and
10+
-- 'Ouroboros.Consensus.Byron.Node.Serialisation'.
11+
module Ouroboros.Consensus.Byron.Node.Peras () where
12+
13+
import Ouroboros.Consensus.Block.SupportsPeras (BlockSupportsPeras (..))
14+
import Ouroboros.Consensus.Byron.Ledger.Block (ByronBlock)
15+
import Ouroboros.Consensus.Peras.Cert.Mock
16+
( MockPerasCert (..)
17+
, forgeMockPerasCert
18+
, validateMockPerasCert
19+
)
20+
import Ouroboros.Consensus.Peras.Vote.Mock
21+
( MockPerasVote (..)
22+
, validateMockPerasVote
23+
)
24+
25+
{-------------------------------------------------------------------------------
26+
BlockSupportsPeras
27+
-------------------------------------------------------------------------------}
28+
29+
-- NOTE: this is a mocked up implementation without crypto!
30+
31+
instance BlockSupportsPeras ByronBlock where
32+
type PerasVote ByronBlock = MockPerasVote ByronBlock
33+
type PerasCert ByronBlock = MockPerasCert ByronBlock
34+
35+
validatePerasVote = validateMockPerasVote
36+
validatePerasCert = validateMockPerasCert
37+
forgePerasCert = forgeMockPerasCert
38+
39+
-- This is fine, Byron will never support Peras
40+
getPerasCertInBlock _ = Nothing

ouroboros-consensus-cardano/src/byron/Ouroboros/Consensus/Byron/Node/Serialisation.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import Data.Word
2525
import Ouroboros.Consensus.Block
2626
import Ouroboros.Consensus.Byron.Ledger
2727
import Ouroboros.Consensus.Byron.Ledger.Conversions
28+
import Ouroboros.Consensus.Byron.Node.Peras ()
2829
import Ouroboros.Consensus.Byron.Protocol
2930
import Ouroboros.Consensus.HeaderValidation
3031
import Ouroboros.Consensus.Ledger.Query

ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Block.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ class
126126
HasPartialConsensusConfig proto
127127
, DecCBOR (SL.PState era)
128128
, Crypto (ProtoCrypto proto)
129+
, -- Peras constraints
130+
BlockSupportsPeras (ShelleyBlock proto era)
129131
, -- Backwards compatibility
130132
Plain.FromCBOR (LegacyPParams era)
131133
, Plain.ToCBOR (LegacyPParams era)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{-# LANGUAGE DerivingStrategies #-}
2+
{-# LANGUAGE FlexibleInstances #-}
3+
{-# LANGUAGE MultiParamTypeClasses #-}
4+
{-# LANGUAGE ScopedTypeVariables #-}
5+
{-# LANGUAGE TypeFamilies #-}
6+
{-# OPTIONS_GHC -Wno-orphans #-}
7+
8+
-- | Peras support for Shelley.
9+
--
10+
-- NOTE: this module only exists to break an otherwise cyclic dependency between
11+
-- 'Ouroboros.Consensus.Shelley.Node' and
12+
-- 'Ouroboros.Consensus.Shelley.Node.Serialisation'.
13+
module Ouroboros.Consensus.Shelley.Node.Peras () where
14+
15+
import Ouroboros.Consensus.Block.SupportsPeras (BlockSupportsPeras (..))
16+
import Ouroboros.Consensus.Peras.Cert.Mock
17+
( MockPerasCert (..)
18+
, forgeMockPerasCert
19+
, validateMockPerasCert
20+
)
21+
import Ouroboros.Consensus.Peras.Vote.Mock
22+
( MockPerasVote (..)
23+
, validateMockPerasVote
24+
)
25+
import Ouroboros.Consensus.Shelley.Ledger.Block
26+
( ShelleyBlock
27+
, ShelleyCompatible
28+
)
29+
30+
{-------------------------------------------------------------------------------
31+
BlockSupportsPeras
32+
-------------------------------------------------------------------------------}
33+
34+
-- NOTE: this is a mocked up implementation without crypto!
35+
36+
instance
37+
ShelleyCompatible proto era =>
38+
BlockSupportsPeras (ShelleyBlock proto era)
39+
where
40+
type PerasVote (ShelleyBlock proto era) = MockPerasVote (ShelleyBlock proto era)
41+
type PerasCert (ShelleyBlock proto era) = MockPerasCert (ShelleyBlock proto era)
42+
43+
validatePerasVote = validateMockPerasVote
44+
validatePerasCert = validateMockPerasCert
45+
forgePerasCert = forgeMockPerasCert
46+
47+
-- TODO: extract actual Peras certificates from blocks
48+
getPerasCertInBlock _ = Nothing

ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node/Serialisation.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import Ouroboros.Consensus.Protocol.TPraos
4747
import Ouroboros.Consensus.Shelley.Eras
4848
import Ouroboros.Consensus.Shelley.Ledger
4949
import Ouroboros.Consensus.Shelley.Ledger.NetworkProtocolVersion ()
50+
import Ouroboros.Consensus.Shelley.Node.Peras ()
5051
import Ouroboros.Consensus.Shelley.Protocol.Abstract
5152
( pHeaderBlockSize
5253
, pHeaderSize

ouroboros-consensus-cardano/src/unstable-byron-testlib/Ouroboros/Consensus/ByronDual/Node.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import Ouroboros.Consensus.Byron.Ledger
2828
import Ouroboros.Consensus.Byron.Node
2929
import Ouroboros.Consensus.Byron.Protocol
3030
import Ouroboros.Consensus.ByronDual.Ledger
31+
import Ouroboros.Consensus.ByronDual.Node.Peras ()
3132
import Ouroboros.Consensus.ByronDual.Node.Serialisation ()
3233
import Ouroboros.Consensus.ByronSpec.Ledger
3334
import qualified Ouroboros.Consensus.ByronSpec.Ledger.Genesis as Genesis
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{-# LANGUAGE FlexibleInstances #-}
2+
{-# LANGUAGE MultiParamTypeClasses #-}
3+
{-# LANGUAGE TypeFamilies #-}
4+
{-# OPTIONS_GHC -Wno-orphans #-}
5+
6+
-- | Mocked up Peras support for DualByron.
7+
--
8+
-- NOTE: this module only exists to break an otherwise cyclic dependency between
9+
-- 'Ouroboros.Consensus.ByronDual.Node' and
10+
-- 'Ouroboros.Consensus.ByronDual.Node.Serialisation'.
11+
module Ouroboros.Consensus.ByronDual.Node.Peras () where
12+
13+
import Ouroboros.Consensus.Block.SupportsPeras (BlockSupportsPeras (..))
14+
import Ouroboros.Consensus.ByronDual.Ledger (DualByronBlock)
15+
import Ouroboros.Consensus.Peras.Cert.Mock
16+
( MockPerasCert (..)
17+
, forgeMockPerasCert
18+
, validateMockPerasCert
19+
)
20+
import Ouroboros.Consensus.Peras.Vote.Mock
21+
( MockPerasVote (..)
22+
, validateMockPerasVote
23+
)
24+
25+
{-------------------------------------------------------------------------------
26+
BlockSupportsPeras
27+
-------------------------------------------------------------------------------}
28+
29+
-- NOTE: this is a mocked up implementation without crypto!
30+
31+
instance BlockSupportsPeras DualByronBlock where
32+
type PerasVote DualByronBlock = MockPerasVote DualByronBlock
33+
type PerasCert DualByronBlock = MockPerasCert DualByronBlock
34+
35+
validatePerasVote = validateMockPerasVote
36+
validatePerasCert = validateMockPerasCert
37+
forgePerasCert = forgeMockPerasCert
38+
39+
-- TODO: extract actual Peras certificates from blocks
40+
getPerasCertInBlock _ = Nothing

ouroboros-consensus-cardano/src/unstable-byron-testlib/Ouroboros/Consensus/ByronDual/Node/Serialisation.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Ouroboros.Consensus.Byron.Ledger
1717
import Ouroboros.Consensus.Byron.Node.Serialisation ()
1818
import Ouroboros.Consensus.Byron.Protocol
1919
import Ouroboros.Consensus.ByronDual.Ledger
20+
import Ouroboros.Consensus.ByronDual.Node.Peras ()
2021
import Ouroboros.Consensus.ByronSpec.Ledger
2122
import Ouroboros.Consensus.HeaderValidation
2223
import Ouroboros.Consensus.Ledger.Dual

0 commit comments

Comments
 (0)