@@ -67,31 +67,33 @@ hardforkTransition = do
67
67
TRC (_, epochState, newPv) <-
68
68
judgmentContext
69
69
tellEvent $ ConwayHardForkEvent newPv
70
- if pvMajor newPv == natVersion @ 10
71
- then
72
- pure $
73
- epochState
74
- & esLStateL . lsCertStateL %~ \ certState ->
75
- let accountsMap = certState ^. certDStateL . accountsL . accountsMapL
76
- dReps =
77
- -- Reset all delegations in order to remove any inconsistencies
78
- -- Delegations will be reset accordingly below.
79
- Map. map (\ dRepState -> dRepState {drepDelegs = Set. empty}) $
80
- certState ^. certVStateL . vsDRepsL
81
- (dRepsWithDelegations, accountsWithoutUnknownDRepDelegations) =
82
- Map. mapAccumWithKey adjustDelegations dReps accountsMap
83
- adjustDelegations ds stakeCred accountState =
84
- case accountState ^. dRepDelegationAccountStateL of
85
- Just (DRepCredential dRep) ->
86
- let addDelegation _ dRepState =
87
- Just $ dRepState {drepDelegs = Set. insert stakeCred (drepDelegs dRepState)}
88
- in case Map. updateLookupWithKey addDelegation dRep ds of
89
- (Nothing , _) -> (ds, accountState & dRepDelegationAccountStateL .~ Nothing )
90
- (Just _, ds') -> (ds', accountState)
91
- _ -> (ds, accountState)
92
- in certState
93
- -- Remove dangling delegations to non-existent DReps:
94
- & certDStateL . accountsL . accountsMapL .~ accountsWithoutUnknownDRepDelegations
95
- -- Populate DRep delegations with delegatees
96
- & certVStateL . vsDRepsL .~ dRepsWithDelegations
97
- else pure epochState
70
+ let update
71
+ | pvMajor newPv == natVersion @ 10 =
72
+ esLStateL . lsCertStateL %~ updateDRepDelegations
73
+ | otherwise = id
74
+ pure $ update epochState
75
+
76
+ updateDRepDelegations :: ConwayEraCertState era => CertState era -> CertState era
77
+ updateDRepDelegations certState =
78
+ let accountsMap = certState ^. certDStateL . accountsL . accountsMapL
79
+ dReps =
80
+ -- Reset all delegations in order to remove any inconsistencies
81
+ -- Delegations will be reset accordingly below.
82
+ Map. map (\ dRepState -> dRepState {drepDelegs = Set. empty}) $
83
+ certState ^. certVStateL . vsDRepsL
84
+ (dRepsWithDelegations, accountsWithoutUnknownDRepDelegations) =
85
+ Map. mapAccumWithKey adjustDelegations dReps accountsMap
86
+ adjustDelegations ds stakeCred accountState =
87
+ case accountState ^. dRepDelegationAccountStateL of
88
+ Just (DRepCredential dRep) ->
89
+ let addDelegation _ dRepState =
90
+ Just $ dRepState {drepDelegs = Set. insert stakeCred (drepDelegs dRepState)}
91
+ in case Map. updateLookupWithKey addDelegation dRep ds of
92
+ (Nothing , _) -> (ds, accountState & dRepDelegationAccountStateL .~ Nothing )
93
+ (Just _, ds') -> (ds', accountState)
94
+ _ -> (ds, accountState)
95
+ in certState
96
+ -- Remove dangling delegations to non-existent DReps:
97
+ & certDStateL . accountsL . accountsMapL .~ accountsWithoutUnknownDRepDelegations
98
+ -- Populate DRep delegations with delegatees
99
+ & certVStateL . vsDRepsL .~ dRepsWithDelegations
0 commit comments