Skip to content

Commit 8aaffc5

Browse files
committed
Add a new function registerInState to EraTransition
... which allows to inject transition configuration data in the given `NewEpochState`. This change allows the Ledger to define this logic in this component without needing to do it in the Consensus layer. In this way, we improve the separation of concerns.
1 parent 654f3e6 commit 8aaffc5

File tree

7 files changed

+45
-0
lines changed

7 files changed

+45
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ instance Crypto c => EraTransition (AllegraEra c) where
2222

2323
mkTransitionConfig () = AllegraTransitionConfig
2424

25+
registerInState = registerInitialFundsThenStaking
26+
2527
tcPreviousEraConfigL =
2628
lens atcShelleyTransitionConfig (\atc pc -> atc {atcShelleyTransitionConfig = pc})
2729

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Transition.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ instance Crypto c => EraTransition (AlonzoEra c) where
4141

4242
mkTransitionConfig = AlonzoTransitionConfig
4343

44+
registerInState = registerInitialFundsThenStaking
45+
4446
tcPreviousEraConfigL =
4547
lens atcMaryTransitionConfig (\atc pc -> atc {atcMaryTransitionConfig = pc})
4648

eras/babbage/impl/src/Cardano/Ledger/Babbage/Transition.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ instance Crypto c => EraTransition (BabbageEra c) where
2323

2424
mkTransitionConfig () = BabbageTransitionConfig
2525

26+
registerInState = registerInitialFundsThenStaking
27+
2628
tcPreviousEraConfigL =
2729
lens btcAlonzoTransitionConfig (\btc pc -> btc {btcAlonzoTransitionConfig = pc})
2830

eras/conway/impl/src/Cardano/Ledger/Conway/Transition.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ class EraTransition era => ConwayEraTransition era where
7272

7373
tcConwayGenesisL :: Lens' (TransitionConfig era) (ConwayGenesis (EraCrypto era))
7474

75+
registerDRepsThenDelegs ::
76+
ConwayEraTransition era =>
77+
TransitionConfig era ->
78+
NewEpochState era ->
79+
NewEpochState era
80+
registerDRepsThenDelegs cfg =
81+
-- NOTE: The order of registration does not matter.
82+
registerDelegs cfg . registerInitialDReps cfg
83+
7584
instance Crypto c => EraTransition (ConwayEra c) where
7685
data TransitionConfig (ConwayEra c) = ConwayTransitionConfig
7786
{ ctcConwayGenesis :: !(ConwayGenesis c)
@@ -81,6 +90,10 @@ instance Crypto c => EraTransition (ConwayEra c) where
8190

8291
mkTransitionConfig = ConwayTransitionConfig
8392

93+
registerInState cfg =
94+
registerDRepsThenDelegs cfg
95+
. registerInitialFundsThenStaking cfg
96+
8497
tcPreviousEraConfigL =
8598
lens ctcBabbageTransitionConfig (\ctc pc -> ctc {ctcBabbageTransitionConfig = pc})
8699

eras/mary/impl/src/Cardano/Ledger/Mary/Transition.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ instance Crypto c => EraTransition (MaryEra c) where
2323

2424
mkTransitionConfig () = MaryTransitionConfig
2525

26+
registerInState = registerInitialFundsThenStaking
27+
2628
tcPreviousEraConfigL =
2729
lens mtcAllegraTransitionConfig (\mtc pc -> mtc {mtcAllegraTransitionConfig = pc})
2830

eras/shelley/impl/src/Cardano/Ledger/Shelley/Transition.hs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module Cardano.Ledger.Shelley.Transition (
2525
mkShelleyTransitionConfig,
2626
createInitialState,
2727
registerInitialFunds,
28+
registerInitialFundsThenStaking,
2829
registerInitialStaking,
2930
toShelleyTransitionConfigPairs,
3031
protectMainnet,
@@ -85,6 +86,16 @@ class
8586
TransitionConfig (PreviousEra era) ->
8687
TransitionConfig era
8788

89+
registerInState ::
90+
-- | Extract data from the given transition configuration and store it in the given state.
91+
--
92+
-- FIXME: Are there any other contextual consideration we need to comment on here?
93+
--
94+
-- FIXME: Perhaps 'injectInState' is a more fitting name?
95+
TransitionConfig era ->
96+
NewEpochState era ->
97+
NewEpochState era
98+
8899
-- | In case when a previous era is available, we should always be able to access
89100
-- `TransitionConfig` for the previous era, from within the current era's
90101
-- `TransitionConfig`
@@ -130,6 +141,16 @@ class
130141
tcNetworkIDG :: EraTransition era => SimpleGetter (TransitionConfig era) Network
131142
tcNetworkIDG = tcShelleyGenesisL . to sgNetworkId
132143

144+
registerInitialFundsThenStaking ::
145+
EraTransition era =>
146+
TransitionConfig era ->
147+
NewEpochState era ->
148+
NewEpochState era
149+
registerInitialFundsThenStaking cfg =
150+
-- We must first register the initial funds, because the stake
151+
-- information depends on it.
152+
registerInitialStaking cfg . registerInitialFunds cfg
153+
133154
instance Crypto c => EraTransition (ShelleyEra c) where
134155
newtype TransitionConfig (ShelleyEra c) = ShelleyTransitionConfig
135156
{ stcShelleyGenesis :: ShelleyGenesis c
@@ -139,6 +160,8 @@ instance Crypto c => EraTransition (ShelleyEra c) where
139160
mkTransitionConfig =
140161
error "Impossible: There is no EraTransition instance for ByronEra"
141162

163+
registerInState = registerInitialFundsThenStaking
164+
142165
tcPreviousEraConfigL = notSupportedInThisEraL
143166

144167
tcTranslationContextL =

libs/cardano-ledger-api/src/Cardano/Ledger/Api/Transition.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module Cardano.Ledger.Api.Transition (
2121
tcInitialFundsL,
2222
tcInitialStakingL,
2323
createInitialState,
24+
registerInState,
2425
registerInitialFunds,
2526
registerInitialStaking,
2627
registerInitialDReps,

0 commit comments

Comments
 (0)