Skip to content

Commit b0a9ee2

Browse files
authored
Split out ImmutableEraParams (#1441)
This PR extracts some small changes from #1288 in order to make the rebase of #1288 onto main more manageable.
2 parents cf4695a + 0191ab4 commit b0a9ee2

File tree

11 files changed

+89
-38
lines changed

11 files changed

+89
-38
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
-->
6+
7+
<!--
8+
### Patch
9+
10+
- A bullet item for the Patch category.
11+
12+
-->
13+
<!--
14+
### Non-Breaking
15+
16+
- A bullet item for the Non-Breaking category.
17+
18+
-->
19+
20+
### Breaking
21+
22+
- Update now that `ImmutableEraParams` was split out
23+

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ type ByronBlockHFC = HardForkBlock '[ByronBlock]
5050
NoHardForks instance
5151
-------------------------------------------------------------------------------}
5252

53-
instance NoHardForks ByronBlock where
54-
getEraParams cfg =
53+
instance ImmutableEraParams ByronBlock where
54+
immutableEraParams cfg =
5555
byronEraParamsNeverHardForks (byronGenesisConfig (configBlock cfg))
56+
57+
instance NoHardForks ByronBlock where
5658
toPartialLedgerConfig _ cfg = ByronPartialLedgerConfig {
5759
byronLedgerConfig = cfg
5860
, byronTriggerHardFork = TriggerHardForkNotDuringThisExecution

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,17 @@ type ShelleyBlockHFC proto era = HardForkBlock '[ShelleyBlock proto era]
7676

7777
instance ( ShelleyCompatible proto era
7878
, LedgerSupportsProtocol (ShelleyBlock proto era)
79-
, TxLimits (ShelleyBlock proto era)
80-
, Crypto (ProtoCrypto proto)
81-
) => NoHardForks (ShelleyBlock proto era) where
82-
getEraParams =
79+
) => ImmutableEraParams (ShelleyBlock proto era) where
80+
immutableEraParams =
8381
shelleyEraParamsNeverHardForks
8482
. shelleyLedgerGenesis
8583
. configLedger
84+
85+
instance ( ShelleyCompatible proto era
86+
, LedgerSupportsProtocol (ShelleyBlock proto era)
87+
, TxLimits (ShelleyBlock proto era)
88+
, Crypto (ProtoCrypto proto)
89+
) => NoHardForks (ShelleyBlock proto era) where
8690
toPartialLedgerConfig _ cfg = ShelleyPartialLedgerConfig {
8791
shelleyLedgerConfig = cfg
8892
, shelleyTriggerHardFork = TriggerHardForkNotDuringThisExecution
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
-->
6+
7+
<!--
8+
### Patch
9+
10+
- A bullet item for the Patch category.
11+
12+
-->
13+
14+
### Breaking
15+
16+
- Split out `ImmutableEraParams` so that the test blocks don't have to
17+
instantiate the `SingleEraBlock` omnibus.
18+
19+
- Remove the `NoThunks Bimap` orphan instance (it's now upstream in the `resource-registry` library).

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Block/Abstract.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ type instance BlockProtocol (Header blk) = BlockProtocol blk
154154

155155
type instance HeaderHash (Header blk) = HeaderHash blk
156156

157-
instance HasHeader blk => StandardHash (Header blk)
157+
instance StandardHash blk => StandardHash (Header blk)
158158

159159
-- | Get the 'HeaderFields' of a block, without requiring 'HasHeader blk'
160160
--

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Block/RealPoint.hs

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{-# LANGUAGE CPP #-}
21
{-# LANGUAGE DeriveGeneric #-}
32
{-# LANGUAGE FlexibleContexts #-}
43
{-# LANGUAGE OverloadedStrings #-}
@@ -87,17 +86,15 @@ blockRealPoint blk = RealPoint s h
8786
HeaderFields { headerFieldSlot = s, headerFieldHash = h } = getHeaderFields blk
8887

8988
headerRealPoint ::
90-
( HasHeader (Header blk)
91-
#if __GLASGOW_HASKELL__ >= 904
92-
-- GHC 9.4+ considers these constraints insufficient.
93-
, HasHeader blk
94-
#endif
95-
)
89+
forall blk. HasHeader (Header blk)
9690
=> Header blk
9791
-> RealPoint blk
9892
headerRealPoint hdr = RealPoint s h
9993
where
100-
HeaderFields { headerFieldSlot = s, headerFieldHash = h } = getHeaderFields hdr
94+
HeaderFields { headerFieldSlot = s, headerFieldHash = h } = hf
95+
96+
hf :: HeaderFields (Header blk)
97+
hf = getHeaderFields hdr
10198

10299
realPointToPoint :: RealPoint blk -> Point blk
103100
realPointToPoint (RealPoint s h) = BlockPoint s h
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Ouroboros.Consensus.HardFork.Combinator.Abstract.NoHardForks (
2-
NoHardForks (..)
3-
, noHardForksEpochInfo
2+
ImmutableEraParams (..)
3+
, NoHardForks (..)
4+
, immutableEpochInfo
45
) where
56

67
import Cardano.Slotting.EpochInfo
@@ -15,28 +16,39 @@ import Ouroboros.Consensus.Ledger.Abstract
1516
Blocks that don't /have/ any transitions
1617
-------------------------------------------------------------------------------}
1718

18-
class SingleEraBlock blk => NoHardForks blk where
19+
-- | A block type for which the 'EraParams' will /never/ change
20+
--
21+
-- Technically, some application of
22+
-- 'Ouroboros.Consensus.HardFork.Combinator.Basics.HardForkBlock' could have an
23+
-- instance for this. But that would only be appropriate if two conditions were
24+
-- met.
25+
--
26+
-- * all the eras in that block have the same 'EraParams'
27+
--
28+
-- * all eras that will /ever/ be added to that block in the future will also
29+
-- have those same 'EraParams'
30+
class ImmutableEraParams blk where
1931
-- | Extract 'EraParams' from the top-level config
2032
--
2133
-- The HFC itself does not care about this, as it must be given the full shape
2234
-- across /all/ eras.
23-
getEraParams :: TopLevelConfig blk -> EraParams
24-
35+
immutableEraParams :: TopLevelConfig blk -> EraParams
2536

37+
class (SingleEraBlock blk, ImmutableEraParams blk) => NoHardForks blk where
2638
-- | Construct partial ledger config from full ledger config
2739
--
2840
-- See also 'toPartialConsensusConfig'
2941
toPartialLedgerConfig :: proxy blk
3042
-> LedgerConfig blk -> PartialLedgerConfig blk
3143

32-
noHardForksEpochInfo :: (Monad m, NoHardForks blk)
33-
=> TopLevelConfig blk
34-
-> EpochInfo m
35-
noHardForksEpochInfo cfg =
44+
immutableEpochInfo :: (Monad m, ImmutableEraParams blk)
45+
=> TopLevelConfig blk
46+
-> EpochInfo m
47+
immutableEpochInfo cfg =
3648
hoistEpochInfo (pure . runIdentity)
3749
$ fixedEpochInfo
3850
(History.eraEpochSize params)
3951
(History.eraSlotLength params)
4052
where
4153
params :: EraParams
42-
params = getEraParams cfg
54+
params = immutableEraParams cfg

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/Combinator/Embed/Unary.hs

+4-4
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ instance Isomorphic TopLevelConfig where
267267
emptyCheckpointsMap
268268
where
269269
ei :: EpochInfo (Except PastHorizonException)
270-
ei = noHardForksEpochInfo $ project tlc
270+
ei = immutableEpochInfo $ project tlc
271271

272272
auxLedger :: LedgerConfig (HardForkBlock '[blk]) -> LedgerConfig blk
273273
auxLedger =
@@ -297,7 +297,7 @@ instance Isomorphic TopLevelConfig where
297297
(inject $ configStorage tlc)
298298
emptyCheckpointsMap
299299
where
300-
eraParams = getEraParams tlc
300+
eraParams = immutableEraParams tlc
301301

302302
auxLedger :: LedgerConfig blk -> LedgerConfig (HardForkBlock '[blk])
303303
auxLedger cfg = HardForkLedgerConfig {
@@ -423,15 +423,15 @@ instance Functor m => Isomorphic (BlockForging m) where
423423
(inject cfg)
424424
sno
425425
(injTickedChainDepSt
426-
(noHardForksEpochInfo cfg)
426+
(immutableEpochInfo cfg)
427427
tickedChainDepSt)
428428
, checkCanForge = \cfg sno tickedChainDepSt isLeader forgeStateInfo ->
429429
first (project' (Proxy @(WrapCannotForge blk))) $
430430
checkCanForge
431431
(inject cfg)
432432
sno
433433
(injTickedChainDepSt
434-
(noHardForksEpochInfo cfg)
434+
(immutableEpochInfo cfg)
435435
tickedChainDepSt)
436436
(inject' (Proxy @(WrapIsLeader blk)) isLeader)
437437
(inject' (Proxy @(WrapForgeStateInfo blk)) forgeStateInfo)

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Protocol/PBFT.hs

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import Codec.Serialise (Serialise (..))
5656
import qualified Control.Exception as Exn
5757
import Control.Monad (unless)
5858
import Control.Monad.Except (throwError)
59+
import Control.ResourceRegistry ()
5960
import Data.Bifunctor (first)
6061
import Data.Bimap (Bimap)
6162
import qualified Data.Bimap as Bimap

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Util/Orphans.hs

+1-8
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,14 @@ import Cardano.Ledger.Genesis (NoGenesis (..))
1919
import Codec.CBOR.Decoding (Decoder)
2020
import Codec.Serialise (Serialise (..))
2121
import Control.Tracer (Tracer)
22-
import Data.Bimap (Bimap)
23-
import qualified Data.Bimap as Bimap
2422
import Data.IntPSQ (IntPSQ)
2523
import qualified Data.IntPSQ as PSQ
2624
import Data.MultiSet (MultiSet)
2725
import qualified Data.MultiSet as MultiSet
2826
import Data.SOP.BasicFunctors
2927
import GHC.TypeLits (KnownNat)
3028
import NoThunks.Class (InspectHeap (..), InspectHeapNamed (..),
31-
NoThunks (..), OnlyCheckWhnfNamed (..), allNoThunks,
32-
noThunksInKeysAndValues)
29+
NoThunks (..), OnlyCheckWhnfNamed (..), allNoThunks)
3330
import Ouroboros.Network.Util.ShowProxy
3431
import System.FS.API (SomeHasFS)
3532
import System.FS.API.Types (FsPath, Handle)
@@ -53,10 +50,6 @@ instance NoThunks (NoGenesis era) where
5350
showTypeOf _ = "NoGenesis"
5451
wNoThunks _ NoGenesis = return Nothing
5552

56-
instance (NoThunks k, NoThunks v)
57-
=> NoThunks (Bimap k v) where
58-
wNoThunks ctxt = noThunksInKeysAndValues ctxt . Bimap.toList
59-
6053
instance ( NoThunks p
6154
, NoThunks v
6255
, Ord p

ouroboros-consensus/src/unstable-consensus-testlib/Test/Util/TestBlock.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ newtype instance Header (TestBlockWith ptype) =
305305

306306
instance Typeable ptype => ShowProxy (Header (TestBlockWith ptype)) where
307307

308-
instance (Typeable ptype, Eq ptype) => HasHeader (Header (TestBlockWith ptype)) where
308+
instance (Typeable ptype) => HasHeader (Header (TestBlockWith ptype)) where
309309
getHeaderFields (TestHeader TestBlockWith{..}) = HeaderFields {
310310
headerFieldHash = tbHash
311311
, headerFieldSlot = tbSlot

0 commit comments

Comments
 (0)