Skip to content

Commit a5e8010

Browse files
committed
Implement suggested changes for predicate failure and state update
1 parent 3804cae commit a5e8010

File tree

2 files changed

+28
-27
lines changed
  • eras/shelley/impl

2 files changed

+28
-27
lines changed

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

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -249,37 +249,37 @@ poolDelegationTransition = do
249249
{ mismatchSupplied = ppCost
250250
, mismatchExpected = minPoolCost
251251
}
252-
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
261-
case mbStakePoolState of
252+
case Map.lookup ppId psStakePools of
253+
-- register new, Pool-Reg
262254
Nothing -> do
263-
-- register new, Pool-Reg
255+
when (hardforkConwayDisallowDuplicatedVRFKeys pv) $ do
256+
Set.notMember ppVrf psVRFKeyHashes ?! VRFKeyHashAlreadyRegistered ppId ppVrf
257+
let updateVRFKeyHash
258+
| hardforkConwayDisallowDuplicatedVRFKeys pv = Set.insert ppVrf
259+
| otherwise = id
264260
tellEvent $ RegisterPool ppId
265261
pure $
266262
payPoolDeposit ppId pp $
267263
ps
268264
& 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
265+
& psVRFKeyHashesL %~ updateVRFKeyHash
266+
-- re-register Pool
267+
Just stakePoolState -> do
268+
when (hardforkConwayDisallowDuplicatedVRFKeys pv) $ do
269+
ppVrf == stakePoolState ^. spsVrfL
270+
|| Set.notMember ppVrf psVRFKeyHashes ?! VRFKeyHashAlreadyRegistered ppId ppVrf
271+
let updateFutureVRFKeyHash
272+
| hardforkConwayDisallowDuplicatedVRFKeys pv =
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 retrieve from futureStakePools.
276+
case Map.lookup ppId psFutureStakePools of
277+
Nothing -> Set.insert ppVrf
278+
Just futureStakePoolState
279+
| futureStakePoolState ^. spsVrfL /= ppVrf ->
280+
Set.insert ppVrf . Set.delete (futureStakePoolState ^. spsVrfL)
281+
| otherwise -> id
282+
| otherwise = id
283283
tellEvent $ ReregisterPool ppId
284284
-- hk is already registered, so we want to reregister it. That means adding it
285285
-- to the Future pool params (if it is not there already), and overriding the
@@ -294,7 +294,7 @@ poolDelegationTransition = do
294294
ps
295295
& psFutureStakePoolsL %~ Map.insert ppId (mkStakePoolState poolParams)
296296
& psRetiringL %~ Map.delete ppId
297-
& updateVRFs
297+
& psVRFKeyHashesL %~ updateFutureVRFKeyHash
298298
RetirePool ppId e -> do
299299
Map.member ppId psStakePools ?! StakePoolNotRegisteredOnKeyPOOL ppId
300300
let maxEpoch = pp ^. ppEMaxL

eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/Imp/PoolSpec.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,8 @@ spec = describe "POOL" $ do
343343
("Expected 'retiring' status of: " <> show poolKh <> " to be: " <> show isRetiring)
344344
$ Map.member poolKh retiring == isRetiring
345345
expectVRFs vrfs = do
346-
(^. psVRFKeyHashesL) <$> getPState `shouldReturn` vrfs
346+
whenMajorVersionAtLeast @11 $
347+
psVRFKeyHashes <$> getPState `shouldReturn` vrfs
347348
poolParams kh vrf = do
348349
pps <- registerRewardAccount >>= freshPoolParams kh
349350
pure $ pps & ppVrfL .~ vrf

0 commit comments

Comments
 (0)