Skip to content

Commit 523aa23

Browse files
committed
Deprecate BHeaderView with EraBlockHeader.
Add Cardano.Ledger.BlockHeader and the EraBlockHeader typeclass with the following lenses: * blockIssuerBHeaderG * blockBodySizeBHeaderG * blockHeaderSizeBHeaderG * blockBodyHashBHeaderG * blockSlotBHeaderG Move isOverlaySlot from BHeaderView to Cardano.Ledger.Slot since that function has nothing to do with BHeaderView, and we need it.
1 parent fe0af09 commit 523aa23

File tree

5 files changed

+47
-24
lines changed

5 files changed

+47
-24
lines changed

libs/cardano-ledger-core/cardano-ledger-core.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ library
4848
Cardano.Ledger.BaseTypes
4949
Cardano.Ledger.BaseTypes.NonZero
5050
Cardano.Ledger.Block
51+
Cardano.Ledger.BlockHeader
5152
Cardano.Ledger.Coin
5253
Cardano.Ledger.Compactible
5354
Cardano.Ledger.Core

libs/cardano-ledger-core/src/Cardano/Ledger/BHeaderView.hs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
{-# LANGUAGE DeriveGeneric #-}
33
{-# LANGUAGE MultiParamTypeClasses #-}
44

5-
module Cardano.Ledger.BHeaderView where
5+
module Cardano.Ledger.BHeaderView {-# DEPRECATED "Use the {Era|ShelleyEra|DijkstraEra|...}BlockHeader typeclasses instead." #-} where
66

7-
import Cardano.Ledger.BaseTypes (BoundedRational (..), Nonce, UnitInterval)
7+
import Cardano.Ledger.BaseTypes (Nonce)
88
import Cardano.Ledger.Hashes (EraIndependentBlockBody, HASH, Hash, KeyHash, KeyRole (..))
9-
import Cardano.Ledger.Slot (SlotNo (..), (-*))
9+
import Cardano.Ledger.Slot (SlotNo (..))
1010
import Control.DeepSeq (NFData)
1111
import Data.Word (Word32)
1212
import GHC.Generics (Generic)
@@ -39,19 +39,3 @@ data BHeaderView = BHeaderView
3939
deriving (Generic)
4040

4141
instance NFData BHeaderView
42-
43-
-- | Determine if the given slot is reserved for the overlay schedule.
44-
isOverlaySlot ::
45-
-- | The first slot of the given epoch.
46-
SlotNo ->
47-
-- | The decentralization parameter.
48-
UnitInterval ->
49-
-- | The slot to check.
50-
SlotNo ->
51-
Bool
52-
isOverlaySlot firstSlotNo dval slot = step s < step (s + 1)
53-
where
54-
s = fromIntegral $ slot -* firstSlotNo
55-
d = unboundRational dval
56-
step :: Rational -> Integer
57-
step x = ceiling (x * d)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{-# LANGUAGE FunctionalDependencies #-}
2+
{-# LANGUAGE UndecidableSuperClasses #-}
3+
4+
module Cardano.Ledger.BlockHeader (
5+
EraBlockHeader (..),
6+
) where
7+
8+
import Cardano.Ledger.BaseTypes (SlotNo)
9+
import Cardano.Ledger.Block (Block)
10+
import Cardano.Ledger.Core (BlockIssuer, Era, EraIndependentBlockBody, HASH, Hash, KeyHash)
11+
import Data.Word (Word32)
12+
import Lens.Micro
13+
14+
class Era era => EraBlockHeader h era | era -> h where
15+
blockIssuerBHeaderG :: SimpleGetter (Block h era) (KeyHash BlockIssuer)
16+
blockBodySizeBHeaderG :: SimpleGetter (Block h era) Word32
17+
blockHeaderSizeBHeaderG :: SimpleGetter (Block h era) Int
18+
blockBodyHashBHeaderG :: SimpleGetter (Block h era) (Hash HASH EraIndependentBlockBody)
19+
blockSlotBHeaderG :: SimpleGetter (Block h era) SlotNo

libs/cardano-ledger-core/src/Cardano/Ledger/Slot.hs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{-# LANGUAGE BangPatterns #-}
21
{-# LANGUAGE DeriveGeneric #-}
32
{-# LANGUAGE DerivingVia #-}
43
{-# LANGUAGE FlexibleContexts #-}
@@ -8,6 +7,7 @@
87
module Cardano.Ledger.Slot (
98
SlotNo (..),
109
getTheSlotOfNoReturn,
10+
isOverlaySlot,
1111
Duration (..),
1212
(-*),
1313
(+*),
@@ -23,7 +23,13 @@ module Cardano.Ledger.Slot (
2323
epochInfoSize,
2424
) where
2525

26-
import Cardano.Ledger.BaseTypes (Globals (Globals, stabilityWindow), ShelleyBase, epochInfoPure)
26+
import Cardano.Ledger.BaseTypes (
27+
Globals (Globals, stabilityWindow),
28+
ShelleyBase,
29+
UnitInterval,
30+
epochInfoPure,
31+
unboundRational,
32+
)
2733
import Cardano.Slotting.Block (BlockNo (..))
2834
import Cardano.Slotting.EpochInfo (EpochInfo)
2935
import qualified Cardano.Slotting.EpochInfo as EI
@@ -98,3 +104,19 @@ getTheSlotOfNoReturn slot = do
98104
firstSlotNextEpoch = epochInfoFirst epochInfo nextEpochNo
99105
pointOfNoReturn = firstSlotNextEpoch *- Duration (2 * stabilityWindow)
100106
pure (epochNo, pointOfNoReturn, nextEpochNo)
107+
108+
-- | Determine if the given slot is reserved for the overlay schedule.
109+
isOverlaySlot ::
110+
-- | The first slot of the given epoch.
111+
SlotNo ->
112+
-- | The decentralization parameter.
113+
UnitInterval ->
114+
-- | The slot to check.
115+
SlotNo ->
116+
Bool
117+
isOverlaySlot firstSlotNo dval slot = step s < step (s + 1)
118+
where
119+
s = fromIntegral $ slot -* firstSlotNo
120+
d = unboundRational dval
121+
step :: Rational -> Integer
122+
step x = ceiling (x * d)

libs/cardano-ledger-core/testlib/Test/Cardano/Ledger/TreeDiff.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ module Test.Cardano.Ledger.TreeDiff (
1616
) where
1717

1818
import Cardano.Ledger.Address
19-
import Cardano.Ledger.BHeaderView
2019
import Cardano.Ledger.BaseTypes
2120
import Cardano.Ledger.Block
2221
import Cardano.Ledger.Coin
@@ -263,6 +262,4 @@ instance ToExpr a => ToExpr (NonZero a) where
263262
instance ToExpr PositiveInterval where
264263
toExpr = toExpr . unboundRational
265264

266-
instance ToExpr BHeaderView
267-
268265
instance (ToExpr h, ToExpr (BlockBody era)) => ToExpr (Block h era)

0 commit comments

Comments
 (0)