@@ -250,36 +250,37 @@ poolDelegationTransition = do
250250 , mismatchExpected = minPoolCost
251251 }
252252 let mbStakePoolState = Map. lookup ppId psStakePools
253- let hasMatchingVRF = ((^. spsVrfL) <$> mbStakePoolState) == Just ppVrf
254- when (hardforkConwayDisallowDuplicatedVRFKeys pv) $ do
255- -- if the VRF key is not associated with this pool (either because the pool is not registered
256- -- or because the VRF key is different from the one registered for this pool),
257- -- then we check that this VRF key is not already in use
258- hasMatchingVRF
259- || Set. notMember ppVrf psVRFKeyHashes
260- ?! VRFKeyHashAlreadyRegistered ppId ppVrf
261253 case mbStakePoolState of
254+ -- register new, Pool-Reg
262255 Nothing -> do
263- -- register new, Pool-Reg
256+ when (hardforkConwayDisallowDuplicatedVRFKeys pv) $ do
257+ Set. notMember ppVrf psVRFKeyHashes ?! VRFKeyHashAlreadyRegistered ppId ppVrf
258+ let updateVRFKeyHash
259+ | hardforkConwayDisallowDuplicatedVRFKeys pv = Set. insert ppVrf
260+ | otherwise = id
264261 tellEvent $ RegisterPool ppId
265262 pure $
266263 payPoolDeposit ppId pp $
267264 ps
268265 & psStakePoolsL %~ Map. insert ppId (mkStakePoolState poolParams)
269- & psVRFKeyHashesL %~ Set. insert ppVrf
270- Just _ -> do
271- -- re-register Pool
272-
273- -- If a pool re-registers with a fresh VRF, we have to add it to the list,
274- -- but also remove the previous VRFHashKey potentially stored in previous re-registration within the same epoch,
275- -- which we can retrieve from futureStakePools. We first delete and then insert the new one,
276- -- so in case they are the same, it will still end up in the set.
277- let updateVRFs
278- | hasMatchingVRF = id
279- | otherwise = psVRFKeyHashesL %~ (Set. insert ppVrf . withoutFutureVrf)
280- where
281- withoutFutureVrf s = maybe s (`Set.delete` s) futureVrf
282- futureVrf = (^. spsVrfL) <$> Map. lookup ppId psFutureStakePools
266+ & psVRFKeyHashesL %~ updateVRFKeyHash
267+ -- re-register Pool
268+ Just stakePoolState -> do
269+ when (hardforkConwayDisallowDuplicatedVRFKeys pv) $ do
270+ ppVrf == stakePoolState ^. spsVrfL
271+ || Set. notMember ppVrf psVRFKeyHashes ?! VRFKeyHashAlreadyRegistered ppId ppVrf
272+ let updateFutureVRFKeyHash
273+ | hardforkConwayDisallowDuplicatedVRFKeys pv =
274+ -- If a pool re-registers with a fresh VRF, we have to add it to the list,
275+ -- but also remove the previous VRFHashKey potentially stored in previous re-registration within the same epoch,
276+ -- which we retrieve from futureStakePools.
277+ case Map. lookup ppId psFutureStakePools of
278+ Nothing -> Set. insert ppVrf
279+ Just futureStakePoolState
280+ | futureStakePoolState ^. spsVrfL /= ppVrf ->
281+ Set. insert ppVrf . Set. delete (futureStakePoolState ^. spsVrfL)
282+ | otherwise -> id
283+ | otherwise = id
283284 tellEvent $ ReregisterPool ppId
284285 -- hk is already registered, so we want to reregister it. That means adding it
285286 -- to the Future pool params (if it is not there already), and overriding the
@@ -294,7 +295,7 @@ poolDelegationTransition = do
294295 ps
295296 & psFutureStakePoolsL %~ Map. insert ppId (mkStakePoolState poolParams)
296297 & psRetiringL %~ Map. delete ppId
297- & updateVRFs
298+ & psVRFKeyHashesL %~ updateFutureVRFKeyHash
298299 RetirePool ppId e -> do
299300 Map. member ppId psStakePools ?! StakePoolNotRegisteredOnKeyPOOL ppId
300301 let maxEpoch = pp ^. ppEMaxL
0 commit comments