Skip to content

Commit f25ea0b

Browse files
authored
Factor out class ShelleyBasedBlock and type family ShelleyBlockLedgerEra (#1073)
Pending change from #934 (comment)
2 parents ddd6266 + 4056c3f commit f25ea0b

File tree

3 files changed

+20
-17
lines changed
  • ouroboros-consensus-cardano/src
    • ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano
    • shelley/Ouroboros/Consensus/Shelley/Ledger
    • unstable-cardano-tools/Cardano/Tools/DBAnalyser/Block

3 files changed

+20
-17
lines changed

ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/Node.hs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ import qualified Ouroboros.Consensus.Protocol.TPraos as Shelley
112112
import Ouroboros.Consensus.Shelley.HFEras ()
113113
import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock)
114114
import qualified Ouroboros.Consensus.Shelley.Ledger as Shelley
115+
import Ouroboros.Consensus.Shelley.Ledger.Block (IsShelleyBlock,
116+
ShelleyBlockLedgerEra)
115117
import Ouroboros.Consensus.Shelley.Ledger.NetworkProtocolVersion
116118
import Ouroboros.Consensus.Shelley.Node
117119
import Ouroboros.Consensus.Shelley.Node.Common (ShelleyEraWithCrypto,
@@ -1119,15 +1121,6 @@ mkPartialLedgerConfigShelley transitionConfig maxMajorProtVer shelleyTriggerHard
11191121
, shelleyTriggerHardFork = shelleyTriggerHardFork
11201122
}
11211123

1122-
class
1123-
( ShelleyBasedEra (ShelleyBlockLedgerEra blk)
1124-
, blk ~ ShelleyBlock (BlockProtocol blk) (ShelleyBlockLedgerEra blk)
1125-
) => IsShelleyBlock blk
1126-
instance ShelleyBasedEra era => IsShelleyBlock (ShelleyBlock proto era)
1127-
1128-
type family ShelleyBlockLedgerEra blk where
1129-
ShelleyBlockLedgerEra (ShelleyBlock proto era) = era
1130-
11311124
-- | We need this wrapper to partially apply a 'TransitionConfig' in an NP.
11321125
newtype WrapTransitionConfig blk =
11331126
WrapTransitionConfig (L.TransitionConfig (ShelleyBlockLedgerEra blk))

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
{-# LANGUAGE TypeApplications #-}
1313
{-# LANGUAGE TypeFamilyDependencies #-}
1414
{-# LANGUAGE TypeOperators #-}
15+
{-# LANGUAGE UndecidableInstances #-}
1516
{-# LANGUAGE UndecidableSuperClasses #-}
1617
module Ouroboros.Consensus.Shelley.Ledger.Block (
1718
GetHeader (..)
1819
, Header (..)
20+
, IsShelleyBlock
1921
, NestedCtxt_ (..)
2022
, ShelleyBasedEra
2123
, ShelleyBlock (..)
24+
, ShelleyBlockLedgerEra
2225
, ShelleyHash (..)
2326
-- * Shelley Compatibility
2427
, ShelleyCompatible
@@ -138,6 +141,18 @@ mkShelleyBlock raw = ShelleyBlock {
138141
, shelleyBlockHeaderHash = pHeaderHash $ SL.bheader raw
139142
}
140143

144+
class
145+
( ShelleyCompatible (BlockProtocol blk) (ShelleyBlockLedgerEra blk)
146+
, blk ~ ShelleyBlock (BlockProtocol blk) (ShelleyBlockLedgerEra blk)
147+
) => IsShelleyBlock blk
148+
149+
instance ( proto ~ BlockProtocol (ShelleyBlock proto era)
150+
, ShelleyCompatible proto era
151+
) => IsShelleyBlock (ShelleyBlock proto era)
152+
153+
type family ShelleyBlockLedgerEra blk where
154+
ShelleyBlockLedgerEra (ShelleyBlock proto era) = era
155+
141156
data instance Header (ShelleyBlock proto era) = ShelleyHeader {
142157
shelleyHeaderRaw :: !(ShelleyProtocolHeader proto)
143158
, shelleyHeaderHash :: !(ShelleyHash (ProtoCrypto proto))

ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBAnalyser/Block/Cardano.hs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ import Ouroboros.Consensus.Node.ProtocolInfo
7676
import Ouroboros.Consensus.Protocol.Praos.Translate ()
7777
import Ouroboros.Consensus.Shelley.HFEras ()
7878
import qualified Ouroboros.Consensus.Shelley.Ledger as Shelley.Ledger
79-
import Ouroboros.Consensus.Shelley.Ledger.Block (ShelleyBlock)
79+
import Ouroboros.Consensus.Shelley.Ledger.Block (IsShelleyBlock,
80+
ShelleyBlock, ShelleyBlockLedgerEra)
8081
import Ouroboros.Consensus.Shelley.Ledger.SupportsProtocol ()
8182
import System.Directory (makeAbsolute)
8283
import System.FilePath (takeDirectory, (</>))
@@ -214,12 +215,6 @@ instance AdjustFilePaths CardanoConfig where
214215
-- genesis data.
215216
}
216217

217-
type family ShelleyBlockEra blk where
218-
ShelleyBlockEra (ShelleyBlock proto era) = era
219-
220-
class L.Era (ShelleyBlockEra blk) => IsShelleyBlock blk
221-
instance L.Era era => IsShelleyBlock (ShelleyBlock proto era)
222-
223218
instance Aeson.FromJSON CardanoConfig where
224219
parseJSON = Aeson.withObject "CardanoConfigFile" $ \v -> do
225220

@@ -241,7 +236,7 @@ instance Aeson.FromJSON CardanoConfig where
241236

242237
triggers <- do
243238
let parseTrigger ::
244-
forall blk era. (IsShelleyBlock blk, ShelleyBlockEra blk ~ era)
239+
forall blk era. (IsShelleyBlock blk, ShelleyBlockLedgerEra blk ~ era)
245240
=> (Aeson.Parser :.: K TriggerHardFork) blk
246241
parseTrigger = Comp $ fmap K $
247242
(fmap TriggerHardForkAtEpoch <$> (v Aeson..:? nm))

0 commit comments

Comments
 (0)