Skip to content

Commit 566d1e5

Browse files
committed
WIP rename and document HasEraParams
1 parent 70c25e7 commit 566d1e5

File tree

6 files changed

+38
-27
lines changed

6 files changed

+38
-27
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Ouroboros.Consensus.HardFork.Combinator.Abstract.NoHardForks (
2-
HasEraParams (..)
2+
ImmutableEraParams (..)
33
, NoHardForks (..)
4-
, getEpochInfo
4+
, immutableEpochInfo
55
) where
66

77
import Cardano.Slotting.EpochInfo
@@ -16,30 +16,40 @@ import Ouroboros.Consensus.Ledger.Abstract
1616
Blocks that don't /have/ any transitions
1717
-------------------------------------------------------------------------------}
1818

19-
class HasEraParams 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
2031
-- | Extract 'EraParams' from the top-level config
2132
--
2233
-- The HFC itself does not care about this, as it must be given the full shape
2334
-- across /all/ eras.
24-
getEraParams :: TopLevelConfig blk -> EraParams
35+
immutableEraParams :: TopLevelConfig blk -> EraParams
2536

26-
27-
class (SingleEraBlock blk, HasEraParams blk) => NoHardForks blk where
37+
class (SingleEraBlock blk, ImmutableEraParams blk) => NoHardForks blk where
2838
-- | Construct partial ledger config from full ledger config
2939
--
3040
-- See also 'toPartialConsensusConfig'
3141
toPartialLedgerConfig :: proxy blk
3242
-> LedgerConfig blk -> PartialLedgerConfig blk
3343

34-
getEpochInfo ::
35-
(Monad m, HasEraParams blk)
44+
immutableEpochInfo ::
45+
(Monad m, ImmutableEraParams blk)
3646
=> TopLevelConfig blk
3747
-> EpochInfo m
38-
getEpochInfo cfg =
48+
immutableEpochInfo cfg =
3949
hoistEpochInfo (pure . runIdentity)
4050
$ fixedEpochInfo
4151
(History.eraEpochSize params)
4252
(History.eraSlotLength params)
4353
where
4454
params :: EraParams
45-
params = getEraParams cfg
55+
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 = getEpochInfo $ 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-
(getEpochInfo 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-
(getEpochInfo cfg)
434+
(immutableEpochInfo cfg)
435435
tickedChainDepSt)
436436
(inject' (Proxy @(WrapIsLeader blk)) isLeader)
437437
(inject' (Proxy @(WrapForgeStateInfo blk)) forgeStateInfo)

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import Data.Functor.Identity (runIdentity)
1414
import Data.Typeable (Typeable)
1515
import Ouroboros.Consensus.Block (Header, blockSlot)
1616
import Ouroboros.Consensus.Config (TopLevelConfig)
17-
import Ouroboros.Consensus.HardFork.Combinator.Abstract (HasEraParams,
18-
getEpochInfo)
17+
import Ouroboros.Consensus.HardFork.Combinator.Abstract
18+
(ImmutableEraParams, immutableEpochInfo)
1919
import Ouroboros.Consensus.HeaderValidation (HeaderWithTime (..))
2020
import Ouroboros.Network.AnchoredFragment (AnchoredFragment)
2121
import qualified Ouroboros.Network.AnchoredFragment as AF
@@ -32,14 +32,14 @@ dropTimeFromFragment = AF.mapAnchoredFragment hwtHeader
3232
attachSlotTimeToFragment ::
3333
( AF.HasHeader (Header blk)
3434
, Typeable blk
35-
, HasEraParams blk)
35+
, ImmutableEraParams blk)
3636
=> TopLevelConfig blk
3737
-> AnchoredFragment (Header blk)
3838
-> AnchoredFragment (HeaderWithTime blk)
3939
attachSlotTimeToFragment cfg = AF.mapAnchoredFragment (attachSlotTime cfg)
4040

4141
attachSlotTime ::
42-
(AF.HasHeader (Header blk), HasEraParams blk)
42+
(AF.HasHeader (Header blk), ImmutableEraParams blk)
4343
=> TopLevelConfig blk
4444
-> Header blk
4545
-> HeaderWithTime blk
@@ -49,4 +49,4 @@ attachSlotTime cfg hdr = HeaderWithTime {
4949
runIdentity $ epochInfoSlotToRelativeTime ei (blockSlot hdr)
5050
}
5151
where
52-
ei = getEpochInfo cfg
52+
ei = immutableEpochInfo cfg

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ import Ouroboros.Consensus.Config
115115
import Ouroboros.Consensus.Forecast
116116
import Ouroboros.Consensus.HardFork.Abstract
117117
import Ouroboros.Consensus.HardFork.Combinator.Abstract
118-
(HasEraParams (getEraParams))
118+
(ImmutableEraParams (immutableEraParams))
119119
import qualified Ouroboros.Consensus.HardFork.History as HardFork
120120
import Ouroboros.Consensus.HeaderValidation
121121
import Ouroboros.Consensus.Ledger.Abstract
@@ -636,8 +636,8 @@ singleNodeTestConfigWith codecConfig storageConfig k genesisWindow = TopLevelCon
636636
_eraParams :: HardFork.EraParams
637637
_eraParams = (HardFork.defaultEraParams k slotLength) {HardFork.eraGenesisWin = genesisWindow}
638638

639-
instance HasEraParams (TestBlockWith ptype) where
640-
getEraParams = tblcHardForkParams . topLevelConfigLedger
639+
instance ImmutableEraParams (TestBlockWith ptype) where
640+
immutableEraParams = tblcHardForkParams . topLevelConfigLedger
641641

642642
{-------------------------------------------------------------------------------
643643
Test blocks without payload

ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/ChainDB/StateMachine.hs

+3-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ import Ouroboros.Consensus.Block
108108
import Ouroboros.Consensus.Config
109109
import qualified Ouroboros.Consensus.Fragment.InFuture as InFuture
110110
import Ouroboros.Consensus.HardFork.Abstract
111-
import Ouroboros.Consensus.HardFork.Combinator.Abstract (HasEraParams)
111+
import Ouroboros.Consensus.HardFork.Combinator.Abstract
112+
(ImmutableEraParams)
112113
import Ouroboros.Consensus.HeaderValidation
113114
import Ouroboros.Consensus.Ledger.Abstract
114115
import Ouroboros.Consensus.Ledger.Extended
@@ -332,7 +333,7 @@ type TestConstraints blk =
332333
, ConvertRawHash blk
333334
, HasHardForkHistory blk
334335
, SerialiseDiskConstraints blk
335-
, HasEraParams blk
336+
, ImmutableEraParams blk
336337
)
337338

338339
deriving instance (TestConstraints blk, Eq it, Eq flr)

ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/TestBlock.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ import Ouroboros.Consensus.Config
8989
import Ouroboros.Consensus.Forecast
9090
import Ouroboros.Consensus.HardFork.Abstract
9191
import Ouroboros.Consensus.HardFork.Combinator.Abstract
92-
(HasEraParams (getEraParams))
92+
(ImmutableEraParams (immutableEraParams))
9393
import qualified Ouroboros.Consensus.HardFork.History as HardFork
9494
import Ouroboros.Consensus.HardFork.History.EraParams
9595
(EraParams (eraGenesisWin))
@@ -696,8 +696,8 @@ mkTestConfig k ChunkSize { chunkCanContainEBB, numRegularBlocks } =
696696
, eraGenesisWin = GenesisWindow (maxRollbacks k * 2)
697697
}
698698

699-
instance HasEraParams TestBlock where
700-
getEraParams = topLevelConfigLedger
699+
instance ImmutableEraParams TestBlock where
700+
immutableEraParams = topLevelConfigLedger
701701

702702
{-------------------------------------------------------------------------------
703703
NestedCtxt

0 commit comments

Comments
 (0)