Skip to content

Commit a0f8485

Browse files
committed
Rename EraSegWits->EraBlockBody, TxSeq->BlockBody.
- Rename EraSegWits and TxSeq. - class `EraSegWits` to `EraBlockBody`, and - type `TxSeq` to `BlockBody`. - Add mkBasicBlockBody to EraBlockBody - Add txSeqBlockBodyL lens to EraBlockBody - Deprecate fromTxSeq and toTxSeq in favour of txSeqBlockBodyL - Add hashBlockBody to EraBlockBody and deprecate hashTxSeq in favour of it. - Keep it exposed, since testlib depends on the TxSeq' constructor in a DecCBOR instance. - Move Shelley.BlockChain to an Internal module. - Rename Shelley.BlockChain to Shelley.BlockBody - Rename Alonzo.TxSeq to Alonzo.BlockBody and the corresponding Internal module too. - Rename ShelleyTxSeq to ShelleyBlockBody the data-type as well as the pattern. - Replace the superfluous accessor function `bbHash` with the actual field accessor, and export it directly. - Add missing Arbitrary constraints for BlockBody types. - Restore deleted modules with DEPRECATED warnings. - also bring back the functions, types and constructors so that downstream is notified by warnings rather than errors. - Don't export hash accessor, use hashBlockBody instead - Rename internal blockbody data constructors - Express deprecated EraBlockBody members in terms of their new counterparts - Rename {Allegra,Mary}.TxSeq to BlockBody - Rename ShelleyBlockBody constructor and fields. - TxSeq' to ShelleyBlockBody - txSeqTxns' to sbbTxs - txSeqHash to sbbHash - txSeqBodyBytes to sbbTxsBodyBytes - txSeqWitsBytes to sbbTxsWitsBytes - txSeqMetadataBytes to sbbTxsAuxDataBytes - Replace the superfluous accessor function `hashAlonzoTxSeq` with the actual field accessor, and export it directly. - Rename AlonzoBlockBody constructor and fields. - AlonzoTxSeqRaw to AlonzoBlockBodyRaw - txSeqTxns to abbTxs - txSeqHash to abbHash - txSeqBodyBytes to abbTxsBodyBytes - txSeqWitsBytes to abbTxsWitsBytes - txSeqMetadataBytes to abbTxsAuxDataBytes - txSeqIsValidBytes to abbTxsIsValidBytes
1 parent e250c6a commit a0f8485

File tree

56 files changed

+657
-518
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+657
-518
lines changed

eras/allegra/impl/cardano-ledger-allegra.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ library
3434

3535
hs-source-dirs: src
3636
other-modules:
37+
Cardano.Ledger.Allegra.BlockBody
3738
Cardano.Ledger.Allegra.Era
3839
Cardano.Ledger.Allegra.PParams
3940
Cardano.Ledger.Allegra.Rules.Bbody
@@ -50,7 +51,6 @@ library
5051
Cardano.Ledger.Allegra.State.Stake
5152
Cardano.Ledger.Allegra.TxCert
5253
Cardano.Ledger.Allegra.TxOut
53-
Cardano.Ledger.Allegra.TxSeq
5454
Cardano.Ledger.Allegra.TxWits
5555
Cardano.Ledger.Allegra.UTxO
5656

eras/allegra/impl/src/Cardano/Ledger/Allegra.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Cardano.Ledger.Allegra (
1111
Tx (..),
1212
) where
1313

14+
import Cardano.Ledger.Allegra.BlockBody ()
1415
import Cardano.Ledger.Allegra.Era (AllegraEra)
1516
import Cardano.Ledger.Allegra.PParams ()
1617
import Cardano.Ledger.Allegra.Rules ()
@@ -19,7 +20,6 @@ import Cardano.Ledger.Allegra.State ()
1920
import Cardano.Ledger.Allegra.Transition ()
2021
import Cardano.Ledger.Allegra.Translation ()
2122
import Cardano.Ledger.Allegra.Tx (Tx (..))
22-
import Cardano.Ledger.Allegra.TxSeq ()
2323
import Cardano.Ledger.Allegra.UTxO ()
2424
import Cardano.Ledger.Shelley.API
2525

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE FlexibleContexts #-}
3+
{-# LANGUAGE FlexibleInstances #-}
4+
{-# LANGUAGE MultiParamTypeClasses #-}
5+
{-# LANGUAGE ScopedTypeVariables #-}
6+
{-# LANGUAGE TypeFamilies #-}
7+
{-# LANGUAGE UndecidableInstances #-}
8+
{-# OPTIONS_GHC -Wno-orphans #-}
9+
10+
module Cardano.Ledger.Allegra.BlockBody () where
11+
12+
import Cardano.Ledger.Allegra.Era (AllegraEra)
13+
import Cardano.Ledger.Allegra.Tx ()
14+
import Cardano.Ledger.Core (EraBlockBody (..))
15+
import Cardano.Ledger.Shelley.BlockBody.Internal (
16+
ShelleyBlockBody (ShelleyBlockBody),
17+
sbbHash,
18+
sbbTxs,
19+
)
20+
import Lens.Micro
21+
22+
instance EraBlockBody AllegraEra where
23+
type BlockBody AllegraEra = ShelleyBlockBody AllegraEra
24+
mkBasicBlockBody = ShelleyBlockBody mempty
25+
txSeqBlockBodyL = lens sbbTxs (\_ s -> ShelleyBlockBody s)
26+
hashBlockBody = sbbHash
27+
numSegComponents = 3

eras/allegra/impl/src/Cardano/Ledger/Allegra/TxSeq.hs

Lines changed: 0 additions & 23 deletions
This file was deleted.

eras/alonzo/impl/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## 1.14.0.0
44

5+
* Deprecate `Alonzo.TxSeq` in favour of `Alonzo.BlockBody`. #5156
6+
* Rename `AlonzoTxSeq` to `AlonzoBlockBody`
57
* Rename `alonzoEqTxRaw` to `alonzoTxEqRaw`
68
* Add `Generic` instance to `TransactionScriptFailure`
79
* Add `Generic` instance for `AlonzoBbodyEvent`

eras/alonzo/impl/cardano-ledger-alonzo.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ source-repository head
2727
library
2828
exposed-modules:
2929
Cardano.Ledger.Alonzo
30+
Cardano.Ledger.Alonzo.BlockBody
31+
Cardano.Ledger.Alonzo.BlockBody.Internal
3032
Cardano.Ledger.Alonzo.Core
3133
Cardano.Ledger.Alonzo.Genesis
3234
Cardano.Ledger.Alonzo.PParams
@@ -43,7 +45,6 @@ library
4345
Cardano.Ledger.Alonzo.TxBody
4446
Cardano.Ledger.Alonzo.TxOut
4547
Cardano.Ledger.Alonzo.TxSeq
46-
Cardano.Ledger.Alonzo.TxSeq.Internal
4748
Cardano.Ledger.Alonzo.TxWits
4849
Cardano.Ledger.Alonzo.UTxO
4950

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Cardano.Ledger.Alonzo.BlockBody (
2+
AlonzoBlockBody (AlonzoBlockBody),
3+
) where
4+
5+
import Cardano.Ledger.Alonzo.BlockBody.Internal

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxSeq/Internal.hs renamed to eras/alonzo/impl/src/Cardano/Ledger/Alonzo/BlockBody/Internal.hs

Lines changed: 45 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,16 @@
1414
{-# OPTIONS_GHC -Wno-orphans #-}
1515
{-# OPTIONS_HADDOCK not-home #-}
1616

17-
-- | Provides TxSeq internals
17+
-- | Provides BlockBody internals
1818
--
1919
-- = Warning
2020
--
2121
-- This module is considered __internal__.
2222
--
2323
-- The contents of this module may change __in any way whatsoever__
2424
-- and __without any warning__ between minor versions of this package.
25-
module Cardano.Ledger.Alonzo.TxSeq.Internal (
26-
AlonzoTxSeq (.., AlonzoTxSeq),
27-
hashAlonzoTxSeq,
25+
module Cardano.Ledger.Alonzo.BlockBody.Internal (
26+
AlonzoBlockBody (AlonzoBlockBody, ..),
2827
hashAlonzoSegWits,
2928
alignedValidFlags,
3029
) where
@@ -45,7 +44,7 @@ import Cardano.Ledger.Binary (
4544
withSlice,
4645
)
4746
import Cardano.Ledger.Core
48-
import Cardano.Ledger.Shelley.BlockChain (auxDataSeqDecoder)
47+
import Cardano.Ledger.Shelley.BlockBody (auxDataSeqDecoder)
4948
import Control.Monad (unless)
5049
import Data.ByteString (ByteString)
5150
import Data.ByteString.Builder (Builder, shortByteString, toLazyByteString)
@@ -64,48 +63,48 @@ import NoThunks.Class (AllowThunksIn (..), NoThunks)
6463

6564
-- =================================================
6665

67-
-- $TxSeq
66+
-- $BlockBody
6867
--
69-
-- * TxSeq
68+
-- * BlockBody
7069
--
71-
-- TxSeq provides an alternate way of formatting transactions in a block, in
70+
-- BlockBody provides an alternate way of formatting transactions in a block, in
7271
-- order to support segregated witnessing.
7372

74-
data AlonzoTxSeq era = AlonzoTxSeqRaw
75-
{ txSeqTxns :: !(StrictSeq (Tx era))
76-
, txSeqHash :: Hash.Hash HASH EraIndependentBlockBody
73+
data AlonzoBlockBody era = AlonzoBlockBodyInternal
74+
{ abbTxs :: !(StrictSeq (Tx era))
75+
, abbHash :: Hash.Hash HASH EraIndependentBlockBody
7776
-- ^ Memoized hash to avoid recomputation. Lazy on purpose.
78-
, txSeqBodyBytes :: BSL.ByteString
77+
, abbTxsBodyBytes :: BSL.ByteString
7978
-- ^ Bytes encoding @Seq ('TxBody' era)@
80-
, txSeqWitsBytes :: BSL.ByteString
79+
, abbTxsWitsBytes :: BSL.ByteString
8180
-- ^ Bytes encoding @Seq ('TxWits' era)@
82-
, txSeqMetadataBytes :: BSL.ByteString
81+
, abbTxsAuxDataBytes :: BSL.ByteString
8382
-- ^ Bytes encoding a @'TxAuxData')@. Missing indices have
8483
-- 'SNothing' for metadata
85-
, txSeqIsValidBytes :: BSL.ByteString
84+
, abbTxsIsValidBytes :: BSL.ByteString
8685
-- ^ Bytes representing a set of integers. These are the indices of
8786
-- transactions with 'isValid' == False.
8887
}
8988
deriving (Generic)
9089

91-
instance EraSegWits AlonzoEra where
92-
type TxSeq AlonzoEra = AlonzoTxSeq AlonzoEra
93-
fromTxSeq = txSeqTxns
94-
toTxSeq = AlonzoTxSeq
95-
hashTxSeq = hashAlonzoTxSeq
90+
instance EraBlockBody AlonzoEra where
91+
type BlockBody AlonzoEra = AlonzoBlockBody AlonzoEra
92+
mkBasicBlockBody = AlonzoBlockBody mempty
93+
txSeqBlockBodyL = lens abbTxs (\_ s -> AlonzoBlockBody s)
94+
hashBlockBody = abbHash
9695
numSegComponents = 4
9796

98-
pattern AlonzoTxSeq ::
97+
pattern AlonzoBlockBody ::
9998
forall era.
10099
( AlonzoEraTx era
101100
, SafeToHash (TxWits era)
102101
) =>
103102
StrictSeq (Tx era) ->
104-
AlonzoTxSeq era
105-
pattern AlonzoTxSeq xs <-
106-
AlonzoTxSeqRaw xs _ _ _ _ _
103+
AlonzoBlockBody era
104+
pattern AlonzoBlockBody xs <-
105+
AlonzoBlockBodyInternal xs _ _ _ _ _
107106
where
108-
AlonzoTxSeq txns =
107+
AlonzoBlockBody txns =
109108
let version = eraProtVerLow @era
110109
serializeFoldablePreEncoded x =
111110
serialize version $
@@ -122,39 +121,39 @@ pattern AlonzoTxSeq xs <-
122121
fmap originalBytes . view auxDataTxL <$> txns
123122
txSeqIsValids =
124123
serialize version $ encCBOR $ nonValidatingIndices txns
125-
in AlonzoTxSeqRaw
126-
{ txSeqTxns = txns
127-
, txSeqHash = hashAlonzoSegWits txSeqBodies txSeqWits txSeqAuxDatas txSeqIsValids
128-
, txSeqBodyBytes = txSeqBodies
129-
, txSeqWitsBytes = txSeqWits
130-
, txSeqMetadataBytes = txSeqAuxDatas
131-
, txSeqIsValidBytes = txSeqIsValids
124+
in AlonzoBlockBodyInternal
125+
{ abbTxs = txns
126+
, abbHash = hashAlonzoSegWits txSeqBodies txSeqWits txSeqAuxDatas txSeqIsValids
127+
, abbTxsBodyBytes = txSeqBodies
128+
, abbTxsWitsBytes = txSeqWits
129+
, abbTxsAuxDataBytes = txSeqAuxDatas
130+
, abbTxsIsValidBytes = txSeqIsValids
132131
}
133132

134-
{-# COMPLETE AlonzoTxSeq #-}
133+
{-# COMPLETE AlonzoBlockBody #-}
135134

136135
deriving via
137136
AllowThunksIn
138-
'[ "txSeqHash"
139-
, "txSeqBodyBytes"
140-
, "txSeqWitsBytes"
141-
, "txSeqMetadataBytes"
142-
, "txSeqIsValidBytes"
137+
'[ "abbHash"
138+
, "abbTxsBodyBytes"
139+
, "abbTxsWitsBytes"
140+
, "abbTxsAuxDataBytes"
141+
, "abbTxsIsValidBytes"
143142
]
144-
(AlonzoTxSeq era)
143+
(AlonzoBlockBody era)
145144
instance
146-
(Typeable era, NoThunks (Tx era)) => NoThunks (AlonzoTxSeq era)
145+
(Typeable era, NoThunks (Tx era)) => NoThunks (AlonzoBlockBody era)
147146

148-
deriving stock instance Show (Tx era) => Show (AlonzoTxSeq era)
147+
deriving stock instance Show (Tx era) => Show (AlonzoBlockBody era)
149148

150-
deriving stock instance Eq (Tx era) => Eq (AlonzoTxSeq era)
149+
deriving stock instance Eq (Tx era) => Eq (AlonzoBlockBody era)
151150

152151
--------------------------------------------------------------------------------
153152
-- Serialisation and hashing
154153
--------------------------------------------------------------------------------
155154

156-
instance Era era => EncCBORGroup (AlonzoTxSeq era) where
157-
encCBORGroup (AlonzoTxSeqRaw _ _ bodyBytes witsBytes metadataBytes invalidBytes) =
155+
instance Era era => EncCBORGroup (AlonzoBlockBody era) where
156+
encCBORGroup (AlonzoBlockBodyInternal _ _ bodyBytes witsBytes metadataBytes invalidBytes) =
158157
encodePreEncoded $
159158
BSL.toStrict $
160159
bodyBytes <> witsBytes <> metadataBytes <> invalidBytes
@@ -166,13 +165,6 @@ instance Era era => EncCBORGroup (AlonzoTxSeq era) where
166165
listLen _ = 4
167166
listLenBound _ = 4
168167

169-
-- | Hash a given block body
170-
hashAlonzoTxSeq ::
171-
forall era.
172-
AlonzoTxSeq era ->
173-
Hash HASH EraIndependentBlockBody
174-
hashAlonzoTxSeq = txSeqHash
175-
176168
hashAlonzoSegWits ::
177169
BSL.ByteString ->
178170
-- | Bytes for transaction bodies
@@ -204,7 +196,7 @@ instance
204196
, DecCBOR (Annotator (TxBody era))
205197
, DecCBOR (Annotator (TxWits era))
206198
) =>
207-
DecCBOR (Annotator (AlonzoTxSeq era))
199+
DecCBOR (Annotator (AlonzoBlockBody era))
208200
where
209201
decCBOR = do
210202
(bodies, bodiesAnn) <- withSlice decCBOR
@@ -237,7 +229,7 @@ instance
237229
StrictSeq.forceToStrict $
238230
Seq.zipWith4 alonzoSegwitTx bodies wits validFlags auxData
239231
pure $
240-
AlonzoTxSeqRaw
232+
AlonzoBlockBodyInternal
241233
<$> txns
242234
<*> (hashAlonzoSegWits <$> bodiesAnn <*> witsAnn <*> auxDataAnn <*> isValAnn)
243235
<*> bodiesAnn

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Bbody.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module Cardano.Ledger.Alonzo.Rules.Bbody (
2222
) where
2323

2424
import Cardano.Ledger.Allegra.Rules (AllegraUtxoPredFailure)
25+
import Cardano.Ledger.Alonzo.BlockBody (AlonzoBlockBody)
2526
import Cardano.Ledger.Alonzo.Era (AlonzoBBODY, AlonzoEra)
2627
import Cardano.Ledger.Alonzo.PParams (AlonzoEraPParams, ppMaxBlockExUnitsL)
2728
import Cardano.Ledger.Alonzo.Rules.Ledgers ()
@@ -30,7 +31,6 @@ import Cardano.Ledger.Alonzo.Rules.Utxos (AlonzoUtxosPredFailure)
3031
import Cardano.Ledger.Alonzo.Rules.Utxow (AlonzoUtxowPredFailure)
3132
import Cardano.Ledger.Alonzo.Scripts (ExUnits (..), pointWiseExUnits)
3233
import Cardano.Ledger.Alonzo.Tx (totExUnits)
33-
import Cardano.Ledger.Alonzo.TxSeq (AlonzoTxSeq, txSeqTxns)
3434
import Cardano.Ledger.Alonzo.TxWits (AlonzoEraTxWits (..))
3535
import Cardano.Ledger.BHeaderView (BHeaderView (..), isOverlaySlot)
3636
import Cardano.Ledger.BaseTypes (Mismatch (..), Relation (..), ShelleyBase, epochInfoPure)
@@ -39,7 +39,7 @@ import Cardano.Ledger.Binary.Coders
3939
import Cardano.Ledger.Block (Block (..))
4040
import Cardano.Ledger.Core
4141
import Cardano.Ledger.Keys (coerceKeyRole)
42-
import Cardano.Ledger.Shelley.BlockChain (incrBlocks)
42+
import Cardano.Ledger.Shelley.BlockBody (incrBlocks)
4343
import Cardano.Ledger.Shelley.LedgerState (LedgerState)
4444
import Cardano.Ledger.Shelley.Rules (
4545
BbodyEnv (..),
@@ -182,9 +182,9 @@ alonzoBbodyTransition ::
182182
, Environment (EraRule "LEDGERS" era) ~ ShelleyLedgersEnv era
183183
, State (EraRule "LEDGERS" era) ~ LedgerState era
184184
, Signal (EraRule "LEDGERS" era) ~ Seq (Tx era)
185-
, EraSegWits era
185+
, EraBlockBody era
186186
, AlonzoEraTxWits era
187-
, TxSeq era ~ AlonzoTxSeq era
187+
, BlockBody era ~ AlonzoBlockBody era
188188
, AlonzoEraPParams era
189189
) =>
190190
TransitionRule (EraRule "BBODY" era)
@@ -196,9 +196,9 @@ alonzoBbodyTransition =
196196
, Block bh txsSeq
197197
)
198198
) -> do
199-
let txs = txSeqTxns txsSeq
199+
let txs = txsSeq ^. txSeqBlockBodyL
200200
actualBodySize = bBodySize (pp ^. ppProtocolVersionL) txsSeq
201-
actualBodyHash = hashTxSeq @era txsSeq
201+
actualBodyHash = hashBlockBody @era txsSeq
202202

203203
actualBodySize
204204
== fromIntegral (bhviewBSize bh)
@@ -267,8 +267,8 @@ instance
267267
, State (EraRule "LEDGERS" era) ~ LedgerState era
268268
, Signal (EraRule "LEDGERS" era) ~ Seq (Tx era)
269269
, AlonzoEraTxWits era
270-
, TxSeq era ~ AlonzoTxSeq era
271-
, EraSegWits era
270+
, BlockBody era ~ AlonzoBlockBody era
271+
, EraBlockBody era
272272
, AlonzoEraPParams era
273273
) =>
274274
STS (AlonzoBBODY era)

0 commit comments

Comments
 (0)