Skip to content

Commit c24d507

Browse files
committed
Add NFData and ToExpr instances for block-related types
1 parent 9e632b5 commit c24d507

File tree

16 files changed

+72
-1
lines changed

16 files changed

+72
-1
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import Cardano.Ledger.Binary (
4747
)
4848
import Cardano.Ledger.Core
4949
import Cardano.Ledger.Shelley.BlockBody (auxDataSeqDecoder)
50+
import Control.DeepSeq (NFData)
5051
import Control.Monad (unless)
5152
import Data.ByteString (ByteString)
5253
import Data.ByteString.Builder (Builder, shortByteString, toLazyByteString)
@@ -88,6 +89,8 @@ data AlonzoBlockBody era = AlonzoBlockBodyInternal
8889
}
8990
deriving (Generic)
9091

92+
instance NFData (Tx TopTx era) => NFData (AlonzoBlockBody era)
93+
9194
instance EraBlockBody AlonzoEra where
9295
type BlockBody AlonzoEra = AlonzoBlockBody AlonzoEra
9396
mkBasicBlockBody = mkBasicBlockBodyAlonzo

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import Cardano.Ledger.Shelley.Rules (
5555
ShelleyUtxowPredFailure,
5656
)
5757
import Cardano.Ledger.Slot (epochInfoEpoch, epochInfoFirst)
58+
import Control.DeepSeq (NFData)
5859
import Control.Monad.Trans.Reader (asks)
5960
import Control.State.Transition (
6061
Embed (..),
@@ -80,6 +81,8 @@ data AlonzoBbodyPredFailure era
8081
| TooManyExUnits (Mismatch RelLTEQ ExUnits)
8182
deriving (Generic)
8283

84+
instance NFData (PredicateFailure (EraRule "LEDGERS" era)) => NFData (AlonzoBbodyPredFailure era)
85+
8386
newtype AlonzoBbodyEvent era
8487
= ShelleyInAlonzoEvent (ShelleyBbodyEvent era)
8588
deriving (Generic)

eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/TreeDiff.hs

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

1616
import Cardano.Ledger.Alonzo (AlonzoEra)
17+
import Cardano.Ledger.Alonzo.BlockBody
1718
import Cardano.Ledger.Alonzo.Core
1819
import Cardano.Ledger.Alonzo.PParams
1920
import Cardano.Ledger.Alonzo.Plutus.Context
@@ -122,6 +123,8 @@ instance ToExpr (AlonzoTxBodyRaw TopTx AlonzoEra) where
122123

123124
instance ToExpr (TxBody TopTx AlonzoEra)
124125

126+
instance ToExpr (Tx TopTx era) => ToExpr (AlonzoBlockBody era)
127+
125128
-- Tx
126129
instance ToExpr IsValid
127130

eras/conway/impl/src/Cardano/Ledger/Conway/Rules/Bbody.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import Cardano.Ledger.Shelley.Rules (
8282
)
8383
import qualified Cardano.Ledger.Shelley.Rules as Shelley (ShelleyBbodyPredFailure (..))
8484
import Cardano.Ledger.Shelley.UTxO (UTxO (..), txouts, unUTxO)
85+
import Control.DeepSeq (NFData)
8586
import Control.State.Transition (
8687
Embed (..),
8788
STS (..),
@@ -119,6 +120,10 @@ deriving instance
119120
(Era era, Eq (PredicateFailure (EraRule "LEDGERS" era))) =>
120121
Eq (ConwayBbodyPredFailure era)
121122

123+
deriving anyclass instance
124+
(Era era, NFData (PredicateFailure (EraRule "LEDGERS" era))) =>
125+
NFData (ConwayBbodyPredFailure era)
126+
122127
deriving anyclass instance
123128
(Era era, NoThunks (PredicateFailure (EraRule "LEDGERS" era))) =>
124129
NoThunks (ConwayBbodyPredFailure era)

eras/dijkstra/impl/src/Cardano/Ledger/Dijkstra/BlockBody/Internal.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import Cardano.Ledger.Core
5151
import Cardano.Ledger.Dijkstra.Era
5252
import Cardano.Ledger.Dijkstra.Tx ()
5353
import Cardano.Ledger.Shelley.BlockBody (auxDataSeqDecoder)
54+
import Control.DeepSeq (NFData)
5455
import Control.Monad (unless)
5556
import Data.Bifunctor (Bifunctor (..))
5657
import Data.ByteString (ByteString)
@@ -102,6 +103,8 @@ data DijkstraBlockBody era = DijkstraBlockBodyInternal
102103
}
103104
deriving (Generic)
104105

106+
instance (NFData (Tx TopTx era), NFData PerasCert) => NFData (DijkstraBlockBody era)
107+
105108
instance EraBlockBody DijkstraEra where
106109
type BlockBody DijkstraEra = DijkstraBlockBody DijkstraEra
107110
mkBasicBlockBody = mkBasicBlockBodyDijkstra

eras/dijkstra/impl/src/Cardano/Ledger/Dijkstra/Rules/Bbody.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import Cardano.Ledger.Shelley.Rules (
7979
ShelleyUtxowPredFailure,
8080
)
8181
import qualified Cardano.Ledger.Shelley.Rules as Shelley
82+
import Control.DeepSeq (NFData)
8283
import Control.State.Transition (
8384
Embed (..),
8485
STS (..),
@@ -96,6 +97,8 @@ data DijkstraBbodyPredFailure era
9697
| BodyRefScriptsSizeTooBig (Mismatch RelLTEQ Int)
9798
deriving (Generic)
9899

100+
instance NFData (PredicateFailure (EraRule "LEDGERS" era)) => NFData (DijkstraBbodyPredFailure era)
101+
99102
deriving instance
100103
(Era era, Show (PredicateFailure (EraRule "LEDGERS" era))) =>
101104
Show (DijkstraBbodyPredFailure era)

eras/dijkstra/impl/testlib/Test/Cardano/Ledger/Dijkstra/TreeDiff.hs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ module Test.Cardano.Ledger.Dijkstra.TreeDiff (
1616
module Test.Cardano.Ledger.Conway.TreeDiff,
1717
) where
1818

19-
import Cardano.Ledger.BaseTypes (StrictMaybe)
19+
import Cardano.Ledger.BaseTypes (PerasCert, StrictMaybe)
2020
import Cardano.Ledger.Dijkstra (DijkstraEra)
2121
import Cardano.Ledger.Dijkstra.Core (
2222
AlonzoEraScript (..),
2323
AsItem,
2424
AsIx,
25+
DijkstraBlockBody,
2526
Era,
2627
EraPParams (..),
2728
EraRule,
@@ -30,10 +31,12 @@ import Cardano.Ledger.Dijkstra.Core (
3031
EraTxCert (..),
3132
EraTxOut (..),
3233
PlutusScript,
34+
TopTx,
3335
Value,
3436
)
3537
import Cardano.Ledger.Dijkstra.PParams (DijkstraPParams)
3638
import Cardano.Ledger.Dijkstra.Rules (
39+
DijkstraBbodyPredFailure,
3740
DijkstraGovCertPredFailure,
3841
DijkstraGovPredFailure,
3942
DijkstraLedgerPredFailure,
@@ -122,6 +125,10 @@ instance ToExpr (DijkstraTxBodyRaw l DijkstraEra) where
122125

123126
instance ToExpr (TxBody l DijkstraEra)
124127

128+
instance ToExpr PerasCert
129+
130+
instance (ToExpr (Tx TopTx era), ToExpr PerasCert) => ToExpr (DijkstraBlockBody era)
131+
125132
instance ToExpr (DijkstraTx l DijkstraEra) where
126133
toExpr = \case
127134
txBody@(DijkstraTx _ _ _ _) ->
@@ -186,3 +193,7 @@ instance
186193
ToExpr (DijkstraGovPredFailure era)
187194

188195
instance ToExpr (DijkstraGovCertPredFailure era)
196+
197+
instance
198+
ToExpr (PredicateFailure (EraRule "LEDGERS" era)) =>
199+
ToExpr (DijkstraBbodyPredFailure era)

eras/shelley/impl/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@
4949

5050
### `testlib`
5151

52+
* Add `NFData` and `ToExpr` constraints and instances for:
53+
- `AlonzoBlockBody`
54+
- `AlonzoBbodyPredFailure`
55+
- `ConwayBbodyPredFailure`
56+
- `ShelleyBlockBody`
57+
- `ShelleyBbodyPredFailure`
58+
- `BHeaderView`
59+
- `Block`
60+
* Add a `Generic` instance for `BHeaderView`
5261
* Add `impEventsFrom`
5362
* Change type of `ImpTestState.impEvents` field from `[]` to `Seq`
5463
* Renamed `impLastTick` to `impCurSlotNo` and `impLastTickG` to `impCurSlotNoG`

eras/shelley/impl/src/Cardano/Ledger/Shelley/BlockBody/Internal.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import Cardano.Ledger.Core
6363
import Cardano.Ledger.Shelley.Era (ShelleyEra)
6464
import Cardano.Ledger.Shelley.Tx ()
6565
import Cardano.Ledger.Slot (SlotNo (..))
66+
import Control.DeepSeq (NFData)
6667
import Control.Monad (unless)
6768
import Data.ByteString (ByteString)
6869
import Data.ByteString.Builder (Builder, shortByteString, toLazyByteString)
@@ -95,6 +96,8 @@ data ShelleyBlockBody era = ShelleyBlockBodyInternal
9596
}
9697
deriving (Generic)
9798

99+
instance NFData (Tx TopTx era) => NFData (ShelleyBlockBody era)
100+
98101
instance EraBlockBody ShelleyEra where
99102
type BlockBody ShelleyEra = ShelleyBlockBody ShelleyEra
100103
mkBasicBlockBody = mkBasicBlockBodyShelley

eras/shelley/impl/src/Cardano/Ledger/Shelley/Rules/Bbody.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import Cardano.Ledger.Shelley.Rules.Ppup (ShelleyPpupPredFailure)
5858
import Cardano.Ledger.Shelley.Rules.Utxo (ShelleyUtxoPredFailure)
5959
import Cardano.Ledger.Shelley.Rules.Utxow (ShelleyUtxowPredFailure)
6060
import Cardano.Ledger.Slot (epochInfoEpoch, epochInfoFirst)
61+
import Control.DeepSeq (NFData)
6162
import Control.Monad.Trans.Reader (asks)
6263
import Control.State.Transition (
6364
Embed (..),
@@ -98,6 +99,8 @@ data ShelleyBbodyPredFailure era
9899
| LedgersFailure (PredicateFailure (EraRule "LEDGERS" era)) -- Subtransition Failures
99100
deriving (Generic)
100101

102+
instance NFData (PredicateFailure (EraRule "LEDGERS" era)) => NFData (ShelleyBbodyPredFailure era)
103+
101104
type instance EraRuleFailure "BBODY" ShelleyEra = ShelleyBbodyPredFailure ShelleyEra
102105

103106
instance InjectRuleFailure "BBODY" ShelleyBbodyPredFailure ShelleyEra

0 commit comments

Comments
 (0)