Skip to content

Commit 833b880

Browse files
authored
Reuse Shelley CrossEraForecaster in tests (#1296)
`forecastAcrossShelleyWrapper` was just locally redefining `crossEraForecastAcrossShelley`, so just use that one instead.
2 parents 44d8867 + 47b811e commit 833b880

File tree

4 files changed

+38
-45
lines changed

4 files changed

+38
-45
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
### Breaking
2+
3+
- Changed `Ouroboros.Consensus.Cardano.CanHardFork` to expose
4+
`crossEraForecastAcrossShelley`, in particular for testing.

ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/CanHardFork.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module Ouroboros.Consensus.Cardano.CanHardFork (
2424
, TriggerHardFork (..)
2525
-- * Re-exports of Shelley code
2626
, ShelleyPartialLedgerConfig (..)
27-
, forecastAcrossShelley
27+
, crossEraForecastAcrossShelley
2828
, translateChainDepStateAcrossShelley
2929
) where
3030

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

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import qualified Cardano.Protocol.TPraos.API as SL
3232
import Cardano.Slotting.EpochInfo (hoistEpochInfo)
3333
import Control.Monad (guard)
3434
import Control.Monad.Except (runExcept, throwError, withExceptT)
35+
import Data.Coerce
3536
import qualified Data.Map.Strict as Map
3637
import Data.SOP.BasicFunctors
3738
import Data.SOP.InPairs (RequiringBoth (..), ignoringBoth)
@@ -237,6 +238,35 @@ instance ShelleyCompatible proto era => HasPartialLedgerConfig (ShelleyBlock pro
237238
}
238239
}
239240

241+
translateChainDepStateAcrossShelley ::
242+
forall eraFrom eraTo protoFrom protoTo.
243+
( TranslateProto protoFrom protoTo
244+
)
245+
=> RequiringBoth
246+
WrapConsensusConfig
247+
(Translate WrapChainDepState)
248+
(ShelleyBlock protoFrom eraFrom)
249+
(ShelleyBlock protoTo eraTo)
250+
translateChainDepStateAcrossShelley =
251+
ignoringBoth $
252+
Translate $ \_epochNo (WrapChainDepState chainDepState) ->
253+
-- Same protocol, same 'ChainDepState'. Note that we don't have to apply
254+
-- any changes related to an epoch transition, this is already done when
255+
-- ticking the state.
256+
WrapChainDepState $ translateChainDepState (Proxy @(protoFrom, protoTo)) chainDepState
257+
258+
crossEraForecastAcrossShelley ::
259+
forall eraFrom eraTo protoFrom protoTo.
260+
( TranslateProto protoFrom protoTo
261+
, LedgerSupportsProtocol (ShelleyBlock protoFrom eraFrom)
262+
)
263+
=> RequiringBoth
264+
WrapLedgerConfig
265+
(CrossEraForecaster LedgerState WrapLedgerView)
266+
(ShelleyBlock protoFrom eraFrom)
267+
(ShelleyBlock protoTo eraTo)
268+
crossEraForecastAcrossShelley = coerce forecastAcrossShelley
269+
240270
-- | Forecast from a Shelley-based era to the next Shelley-based era.
241271
forecastAcrossShelley ::
242272
forall protoFrom protoTo eraFrom eraTo.
@@ -278,38 +308,6 @@ forecastAcrossShelley cfgFrom cfgTo transition forecastFor ledgerStateFrom
278308
(SL.stabilityWindow (shelleyLedgerGlobals cfgFrom))
279309
(SL.stabilityWindow (shelleyLedgerGlobals cfgTo))
280310

281-
translateChainDepStateAcrossShelley ::
282-
forall eraFrom eraTo protoFrom protoTo.
283-
( TranslateProto protoFrom protoTo
284-
)
285-
=> RequiringBoth
286-
WrapConsensusConfig
287-
(Translate WrapChainDepState)
288-
(ShelleyBlock protoFrom eraFrom)
289-
(ShelleyBlock protoTo eraTo)
290-
translateChainDepStateAcrossShelley =
291-
ignoringBoth $
292-
Translate $ \_epochNo (WrapChainDepState chainDepState) ->
293-
-- Same protocol, same 'ChainDepState'. Note that we don't have to apply
294-
-- any changes related to an epoch transition, this is already done when
295-
-- ticking the state.
296-
WrapChainDepState $ translateChainDepState (Proxy @(protoFrom, protoTo)) chainDepState
297-
298-
crossEraForecastAcrossShelley ::
299-
forall eraFrom eraTo protoFrom protoTo.
300-
( TranslateProto protoFrom protoTo
301-
, LedgerSupportsProtocol (ShelleyBlock protoFrom eraFrom)
302-
)
303-
=> RequiringBoth
304-
WrapLedgerConfig
305-
(CrossEraForecaster LedgerState WrapLedgerView)
306-
(ShelleyBlock protoFrom eraFrom)
307-
(ShelleyBlock protoTo eraTo)
308-
crossEraForecastAcrossShelley =
309-
RequireBoth $ \(WrapLedgerConfig cfgFrom)
310-
(WrapLedgerConfig cfgTo) ->
311-
CrossEraForecaster $ forecastAcrossShelley cfgFrom cfgTo
312-
313311
{-------------------------------------------------------------------------------
314312
Translation from one Shelley-based era to another Shelley-based era
315313
-------------------------------------------------------------------------------}

ouroboros-consensus-cardano/src/unstable-cardano-testlib/Test/ThreadNet/Infra/ShelleyBasedHardFork.hs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ import Data.Void (Void)
4040
import Lens.Micro ((^.))
4141
import Ouroboros.Consensus.Block.Forging (BlockForging)
4242
import Ouroboros.Consensus.Cardano.CanHardFork
43-
(ShelleyPartialLedgerConfig (..), forecastAcrossShelley,
43+
(ShelleyPartialLedgerConfig (..),
44+
crossEraForecastAcrossShelley,
4445
translateChainDepStateAcrossShelley)
4546
import Ouroboros.Consensus.Cardano.Node (TriggerHardFork (..))
4647
import Ouroboros.Consensus.HardFork.Combinator
@@ -174,7 +175,7 @@ instance ShelleyBasedHardForkConstraints proto1 era1 proto2 era2
174175
hardForkEraTranslation = EraTranslation {
175176
translateLedgerState = PCons translateLedgerState PNil
176177
, translateChainDepState = PCons translateChainDepStateAcrossShelley PNil
177-
, crossEraForecast = PCons forecastAcrossShelleyWrapper PNil
178+
, crossEraForecast = PCons crossEraForecastAcrossShelley PNil
178179
}
179180
where
180181
translateLedgerState ::
@@ -192,16 +193,6 @@ instance ShelleyBasedHardForkConstraints proto1 era1 proto2 era2
192193
(shelleyLedgerTranslationContext (unwrapLedgerConfig cfg2))
193194
. Comp
194195

195-
forecastAcrossShelleyWrapper ::
196-
InPairs.RequiringBoth
197-
WrapLedgerConfig
198-
(HFC.CrossEraForecaster LedgerState WrapLedgerView)
199-
(ShelleyBlock proto1 era1)
200-
(ShelleyBlock proto2 era2)
201-
forecastAcrossShelleyWrapper =
202-
InPairs.RequireBoth $ \(WrapLedgerConfig cfg1) (WrapLedgerConfig cfg2) ->
203-
HFC.CrossEraForecaster $ forecastAcrossShelley cfg1 cfg2
204-
205196
hardForkChainSel = Tails.mk2 CompareSameSelectView
206197

207198
hardForkInjectTxs =

0 commit comments

Comments
 (0)