@@ -131,10 +131,15 @@ newtype ShelleyDelegEvent era = DelegNewEpoch EpochNo
131131instance NFData (ShelleyDelegEvent era )
132132
133133instance
134- (EraPParams era , ShelleyEraAccounts era , ShelleyEraTxCert era , AtMostEra " Babbage" era ) =>
134+ ( EraCertState era
135+ , EraPParams era
136+ , ShelleyEraAccounts era
137+ , ShelleyEraTxCert era
138+ , AtMostEra " Babbage" era
139+ ) =>
135140 STS (ShelleyDELEG era )
136141 where
137- type State (ShelleyDELEG era ) = DState era
142+ type State (ShelleyDELEG era ) = CertState era
138143 type Signal (ShelleyDELEG era ) = TxCert era
139144 type Environment (ShelleyDELEG era ) = DelegEnv era
140145 type BaseM (ShelleyDELEG era ) = ShelleyBase
@@ -242,17 +247,23 @@ instance
242247 k -> invalidKey k
243248
244249delegationTransition ::
245- (ShelleyEraAccounts era , ShelleyEraTxCert era , EraPParams era , AtMostEra " Babbage" era ) =>
250+ ( EraCertState era
251+ , ShelleyEraAccounts era
252+ , ShelleyEraTxCert era
253+ , EraPParams era
254+ , AtMostEra " Babbage" era
255+ ) =>
246256 TransitionRule (ShelleyDELEG era )
247257delegationTransition = do
248- TRC (DelegEnv slot epochNo ptr chainAccountState pp, ds , c) <- judgmentContext
258+ TRC (DelegEnv slot epochNo ptr chainAccountState pp, certState , c) <- judgmentContext
249259 let pv = pp ^. ppProtocolVersionL
260+ ds = certState ^. certDStateL
250261 case c of
251262 RegTxCert cred -> do
252263 -- (hk ∉ dom (rewards ds))
253264 not (isAccountRegistered cred (ds ^. accountsL)) ?! StakeKeyAlreadyRegisteredDELEG cred
254265 let compactDeposit = compactCoinOrError (pp ^. ppKeyDepositL)
255- pure (ds & accountsL %~ registerShelleyAccount cred ptr compactDeposit Nothing )
266+ pure $ certState & certDStateL . accountsL %~ registerShelleyAccount cred ptr compactDeposit Nothing
256267 UnRegTxCert cred -> do
257268 let ! (mAccountState, ! accounts) = unregisterShelleyAccount cred (ds ^. accountsL)
258269 checkStakeKeyHasZeroRewardBalance = do
@@ -263,13 +274,14 @@ delegationTransition = do
263274 -- (hk ∈ dom (rewards ds))
264275 isJust mAccountState ?! StakeKeyNotRegisteredDELEG cred
265276 failOnJust checkStakeKeyHasZeroRewardBalance StakeKeyNonZeroAccountBalanceDELEG
266- pure $ ds & accountsL .~ accounts
277+ pure $ certState & certDStateL . accountsL .~ accounts
267278 DelegStakeTxCert cred stakePool -> do
268279 -- note that pattern match is used instead of cwitness and dpool, as in the spec
269280 -- (hk ∈ dom (rewards ds))
270281 isAccountRegistered cred (ds ^. accountsL) ?! StakeDelegationImpossibleDELEG cred
271282 pure $
272- ds & accountsL %~ adjustAccountState (stakePoolDelegationAccountStateL ?~ stakePool) cred
283+ certState
284+ & certDStateL . accountsL %~ adjustAccountState (stakePoolDelegationAccountStateL ?~ stakePool) cred
273285 GenesisDelegTxCert gkh vkh vrf -> do
274286 sp <- liftSTS $ asks stabilityWindow
275287 -- note that pattern match is used instead of genesisDeleg, as in the spec
@@ -294,13 +306,12 @@ delegationTransition = do
294306 ?! DuplicateGenesisVRFDELEG vrf
295307
296308 pure $
297- ds
298- { dsFutureGenDelegs =
299- eval (dsFutureGenDelegs ds ⨃ singleton (FutureGenDeleg s' gkh) (GenDelegPair vkh vrf))
300- }
309+ certState
310+ & certDStateL . dsFutureGenDelegsL
311+ .~ eval (dsFutureGenDelegs ds ⨃ singleton (FutureGenDeleg s' gkh) (GenDelegPair vkh vrf))
301312 RegPoolTxCert _ -> do
302313 failBecause WrongCertificateTypeDELEG -- this always fails
303- pure ds
314+ pure certState
304315 _ | Just (MIRCert targetPot mirTarget) <- getMirTxCert c -> do
305316 checkSlotNotTooLate slot epochNo
306317 case mirTarget of
@@ -327,46 +338,39 @@ delegationTransition = do
327338 else do
328339 all (>= mempty ) credCoinMap ?! MIRNegativesNotCurrentlyAllowed
329340 pure (Map. union credCoinMap' instantaneousRewards, potAmount)
330- updateReservesAndTreasury targetPot combinedMap available ds
341+ updateReservesAndTreasury targetPot combinedMap available certState
331342 SendToOppositePotMIR coin ->
332343 if hardforkAlonzoAllowMIRTransfer pv
333344 then do
334345 let available = availableAfterMIR targetPot chainAccountState (dsIRewards ds)
335346 coin >= mempty ?! MIRNegativeTransfer targetPot coin
336347 coin <= available ?! InsufficientForTransferDELEG targetPot (Mismatch coin available)
337-
338- let ir = dsIRewards ds
339- dr = deltaReserves ir
340- dt = deltaTreasury ir
341348 case targetPot of
342349 ReservesMIR ->
343350 pure $
344- ds
345- { dsIRewards =
346- ir
347- { deltaReserves = dr <> invert (toDeltaCoin coin)
348- , deltaTreasury = dt <> toDeltaCoin coin
349- }
350- }
351+ certState
352+ & certDStateL . dsIRewardsL . iRDeltaReservesL %~ (<> invert (toDeltaCoin coin))
353+ & certDStateL . dsIRewardsL . iRDeltaTreasuryL %~ (<> toDeltaCoin coin)
351354 TreasuryMIR ->
352355 pure $
353- ds
354- { dsIRewards =
355- ir
356- { deltaReserves = dr <> toDeltaCoin coin
357- , deltaTreasury = dt <> invert (toDeltaCoin coin)
358- }
359- }
356+ certState
357+ & certDStateL . dsIRewardsL . iRDeltaReservesL %~ (<> toDeltaCoin coin)
358+ & certDStateL . dsIRewardsL . iRDeltaTreasuryL %~ (<> invert (toDeltaCoin coin))
360359 else do
361360 failBecause MIRTransferNotCurrentlyAllowed
362- pure ds
361+ pure certState
363362 _ -> do
364363 -- The impossible case
365364 failBecause WrongCertificateTypeDELEG -- this always fails
366- pure ds
365+ pure certState
367366
368367checkSlotNotTooLate ::
369- (ShelleyEraAccounts era , ShelleyEraTxCert era , EraPParams era , AtMostEra " Babbage" era ) =>
368+ ( EraCertState era
369+ , ShelleyEraAccounts era
370+ , ShelleyEraTxCert era
371+ , EraPParams era
372+ , AtMostEra " Babbage" era
373+ ) =>
370374 SlotNo ->
371375 EpochNo ->
372376 Rule (ShelleyDELEG era ) 'Transition ()
@@ -380,12 +384,13 @@ checkSlotNotTooLate slot curEpochNo = do
380384 slot < tooLate ?! MIRCertificateTooLateinEpochDELEG (Mismatch slot tooLate)
381385
382386updateReservesAndTreasury ::
387+ EraCertState era =>
383388 MIRPot ->
384389 Map. Map (Credential 'Staking) Coin ->
385390 Coin ->
386- DState era ->
387- Rule (ShelleyDELEG era ) 'Transition (DState era )
388- updateReservesAndTreasury targetPot combinedMap available ds = do
391+ CertState era ->
392+ Rule (ShelleyDELEG era ) 'Transition (CertState era )
393+ updateReservesAndTreasury targetPot combinedMap available certState = do
389394 let requiredForRewards = fold combinedMap
390395 requiredForRewards
391396 <= available
@@ -397,5 +402,5 @@ updateReservesAndTreasury targetPot combinedMap available ds = do
397402 }
398403 pure $
399404 case targetPot of
400- ReservesMIR -> ds {dsIRewards = (dsIRewards ds) {iRReserves = combinedMap}}
401- TreasuryMIR -> ds {dsIRewards = (dsIRewards ds) {iRTreasury = combinedMap}}
405+ ReservesMIR -> certState & certDStateL . dsIRewardsL . iRReservesL .~ combinedMap
406+ TreasuryMIR -> certState & certDStateL . dsIRewardsL . iRTreasuryL .~ combinedMap
0 commit comments