Skip to content

Commit 2fb8159

Browse files
authored
add Show instance for HardForkLedgerConfig (#1488)
# Description Adds a `Show` instance for `HardForkLedgerConfig` Fixes #1414
2 parents 292d711 + 5330d6c commit 2fb8159

File tree

11 files changed

+27
-2
lines changed

11 files changed

+27
-2
lines changed

ouroboros-consensus-cardano/ouroboros-consensus-cardano.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ test-suite cardano-test
439439
Test.Consensus.Cardano.MiniProtocol.LocalTxSubmission.ByteStringTxParser
440440
Test.Consensus.Cardano.MiniProtocol.LocalTxSubmission.Server
441441
Test.Consensus.Cardano.Serialisation
442+
Test.Consensus.Cardano.Show
442443
Test.Consensus.Cardano.SupportedNetworkProtocolVersion
443444
Test.Consensus.Cardano.SupportsSanityCheck
444445
Test.Consensus.Cardano.Translation

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ data ByronPartialLedgerConfig = ByronPartialLedgerConfig {
259259
byronLedgerConfig :: !(LedgerConfig ByronBlock)
260260
, byronTriggerHardFork :: !TriggerHardFork
261261
}
262-
deriving (Generic, NoThunks)
262+
deriving (Show, Generic, NoThunks)
263263

264264
instance HasPartialLedgerConfig ByronBlock where
265265

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import Cardano.Ledger.Binary (Annotator (..), DecCBOR (..),
4444
import qualified Cardano.Ledger.Binary.Plain as Plain
4545
import Cardano.Ledger.Core as SL (eraDecoder, eraProtVerLow,
4646
toEraCBOR)
47-
import qualified Cardano.Ledger.Core as SL (hashTxSeq)
47+
import qualified Cardano.Ledger.Core as SL (TranslationContext, hashTxSeq)
4848
import Cardano.Ledger.Hashes (HASH)
4949
import qualified Cardano.Ledger.Shelley.API as SL
5050
import Cardano.Protocol.Crypto (Crypto)
@@ -89,6 +89,7 @@ class
8989
, EncCBOR (ShelleyProtocolHeader proto)
9090
, DecCBOR (Annotator (ShelleyProtocolHeader proto))
9191
, Show (CannotForgeError proto)
92+
, Show (SL.TranslationContext era)
9293
-- Currently the chain select view is identical
9394
-- Era and proto crypto must coincide
9495
, SelectView proto ~ PraosChainSelectView (ProtoCrypto proto)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ data ShelleyPartialLedgerConfig era = ShelleyPartialLedgerConfig {
195195
}
196196
deriving (Generic)
197197

198+
deriving instance Show (ShelleyLedgerConfig era) => Show (ShelleyPartialLedgerConfig era)
199+
198200
deriving instance (NoThunks (Core.TranslationContext era), Core.Era era) =>
199201
NoThunks (ShelleyPartialLedgerConfig era)
200202

ouroboros-consensus-cardano/test/cardano-test/Main.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import qualified Test.Consensus.Cardano.DiffusionPipelining
55
import qualified Test.Consensus.Cardano.Golden
66
import qualified Test.Consensus.Cardano.MiniProtocol.LocalTxSubmission.Server
77
import qualified Test.Consensus.Cardano.Serialisation (tests)
8+
import qualified Test.Consensus.Cardano.Show ()
89
import qualified Test.Consensus.Cardano.SupportedNetworkProtocolVersion
910
import qualified Test.Consensus.Cardano.SupportsSanityCheck
1011
import qualified Test.Consensus.Cardano.Translation (tests)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Test.Consensus.Cardano.Show () where
2+
3+
import Ouroboros.Consensus.Cardano ()
4+
import Ouroboros.Consensus.Cardano.Block
5+
import Ouroboros.Consensus.Shelley.Ledger.SupportsProtocol ()
6+
7+
-- | This definition exists solely to ensure that 'CardanoLedgerConfig' has a working 'Show' instance that isn't accidentally removed or broken in future
8+
_showCardanoLedgerConfig :: CardanoLedgerConfig StandardCrypto -> String
9+
_showCardanoLedgerConfig = show

ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/HardFork/Combinator/A.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ data PartialLedgerConfigA = LCfgA {
226226
, lcfgA_systemStart :: SystemStart
227227
, lcfgA_forgeTxs :: Map SlotNo [GenTx BlockA]
228228
}
229+
deriving Show
229230
deriving NoThunks via OnlyCheckWhnfNamed "LCfgA" PartialLedgerConfigA
230231
deriving Generic
231232
deriving Serialise

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/AcrossEras.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ deriving via LiftNS WrapTipInfo xs instance CanHardFork xs => Show
350350
deriving via LiftNS WrapValidatedGenTx xs instance CanHardFork xs => Show (OneEraValidatedGenTx xs)
351351
deriving via LiftNS WrapValidationErr xs instance CanHardFork xs => Show (OneEraValidationErr xs)
352352

353+
deriving instance Show (PartialLedgerConfig xs) => Show (WrapPartialLedgerConfig xs)
354+
deriving via LiftNP WrapPartialLedgerConfig xs instance CanHardFork xs => Show (PerEraLedgerConfig xs)
355+
353356
deriving via LiftMismatch SingleEraInfo LedgerEraInfo xs instance All SingleEraBlock xs => Eq (MismatchEraInfo xs)
354357
deriving via LiftMismatch SingleEraInfo LedgerEraInfo xs instance All SingleEraBlock xs => Show (MismatchEraInfo xs)
355358

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/Basics.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
{-# LANGUAGE StandaloneDeriving #-}
1010
{-# LANGUAGE TypeApplications #-}
1111
{-# LANGUAGE TypeFamilies #-}
12+
{-# LANGUAGE UndecidableInstances #-}
1213

1314
module Ouroboros.Consensus.HardFork.Combinator.Basics (
1415
-- * Hard fork protocol, block, and ledger state
@@ -139,6 +140,7 @@ data HardForkLedgerConfig xs = HardForkLedgerConfig {
139140
}
140141
deriving (Generic)
141142

143+
deriving instance Show (PerEraLedgerConfig xs) => Show (HardForkLedgerConfig xs)
142144
instance CanHardFork xs => NoThunks (HardForkLedgerConfig xs)
143145

144146
type instance LedgerCfg (LedgerState (HardForkBlock xs)) = HardForkLedgerConfig xs

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/PartialConfig.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class ( ConsensusProtocol p
6868

6969
-- | Partial ledger config
7070
class ( UpdateLedger blk
71+
, Show (PartialLedgerConfig blk)
7172
, NoThunks (PartialLedgerConfig blk)
7273
) => HasPartialLedgerConfig blk where
7374
type PartialLedgerConfig blk :: Type

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Ledger/Dual.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,15 @@ class (
238238
, CommonProtocolParams m
239239
, HasTxId (GenTx m)
240240
, Show (ApplyTxErr m)
241+
, Show (LedgerConfig m)
241242

242243
-- Requirements on the auxiliary block
243244
-- No 'LedgerSupportsProtocol' for @a@!
244245
, Typeable a
245246
, UpdateLedger a
246247
, LedgerSupportsMempool a
247248
, Show (ApplyTxErr a)
249+
, Show (LedgerConfig a)
248250
, NoThunks (LedgerConfig a)
249251
, NoThunks (CodecConfig a)
250252
, NoThunks (StorageConfig a)
@@ -334,6 +336,8 @@ data DualLedgerConfig m a = DualLedgerConfig {
334336
}
335337
deriving NoThunks via AllowThunk (DualLedgerConfig m a)
336338

339+
deriving instance (Show (LedgerConfig m), Show (LedgerConfig a)) => Show (DualLedgerConfig m a)
340+
337341
type instance LedgerCfg (LedgerState (DualBlock m a)) = DualLedgerConfig m a
338342

339343
instance Bridge m a => HasPartialLedgerConfig (DualBlock m a)

0 commit comments

Comments
 (0)