Skip to content

Commit d6fa6b0

Browse files
committed
Remove dangling VRFs from set of known VRFs in PoolReap
1 parent 3b4a01a commit d6fa6b0

File tree

1 file changed

+17
-1
lines changed
  • eras/shelley/impl/src/Cardano/Ledger/Shelley/Rules

1 file changed

+17
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import Control.State.Transition (
4848
)
4949
import Data.Default (Default, def)
5050
import Data.Foldable (fold)
51+
import qualified Data.Map.Merge.Strict as Map
5152
import qualified Data.Map.Strict as Map
5253
import Data.Set (Set)
5354
import qualified Data.Set as Set
@@ -128,6 +129,20 @@ poolReapTransition = do
128129
TRC (_, PoolreapState us a cs0, e) <- judgmentContext
129130
let
130131
ps0 = cs0 ^. certPStateL
132+
-- find the set of VRF keys that are no longer relevant, since they have been overwritten
133+
-- via pool re-registration
134+
danglingVrfs =
135+
Set.fromList $
136+
Map.elems $
137+
Map.merge
138+
Map.dropMissing
139+
Map.dropMissing
140+
( Map.zipWithMaybeMatched $ \_ sps spsF ->
141+
if sps ^. spsVrfL /= spsF ^. spsVrfL then Just (sps ^. spsVrfL) else Nothing
142+
)
143+
(ps0 ^. psStakePoolsL)
144+
(ps0 ^. psFutureStakePoolsL)
145+
131146
-- activate future stakePools
132147
ps =
133148
ps0
@@ -202,7 +217,8 @@ poolReapTransition = do
202217
& certPStateL . psStakePoolsL %~ (`Map.withoutKeys` retired)
203218
& certPStateL . psRetiringL %~ (`Map.withoutKeys` retired)
204219
& certPStateL . psDepositsCompactL .~ remainingDeposits
205-
& certPStateL . psVRFKeyHashesL %~ (`Set.difference` retiredVRFs)
220+
& certPStateL . psVRFKeyHashesL
221+
%~ (\s -> (s `Set.difference` retiredVRFs) `Set.difference` danglingVrfs)
206222
)
207223

208224
renderPoolReapViolation ::

0 commit comments

Comments
 (0)