Skip to content

Commit 02bacd7

Browse files
committed
Implement suggested changes for predicate failure and state update
1 parent b1454d1 commit 02bacd7

File tree

2 files changed

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

2 files changed

+28
-25
lines changed

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

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,9 @@ 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+
pv <- getsPParams ppProtocolVersionL
347+
unless (pvMajor pv < natVersion @11) $
348+
(^. psVRFKeyHashesL) <$> getPState `shouldReturn` vrfs
347349
poolParams kh vrf = do
348350
pps <- registerRewardAccount >>= freshPoolParams kh
349351
pure $ pps & ppVrfL .~ vrf

0 commit comments

Comments
 (0)