Skip to content

Commit

Permalink
Minor cleanup and simplification. Change `StakePoolRetirementWrongEpo…
Browse files Browse the repository at this point in the history
…chPOOL`:

Change types in `StakePoolRetirementWrongEpochPOOL` from `Word64` to `EpochNo`
  • Loading branch information
lehins committed Mar 18, 2023
1 parent 20c8f99 commit 1c6564b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
1 change: 1 addition & 0 deletions eras/shelley/impl/CHANGELOG.md
Expand Up @@ -31,6 +31,7 @@
* Change `totalCertsDeposits` to accept a function that checks for registered pools,
rather than the `DPState`. Use `totalCertsDepositsDPState` for the previous behavior
* Added `getProducedValue` and `totalCertsDepositsDPState`.
* Change types in `StakePoolRetirementWrongEpochPOOL` from `Word64` to `EpochNo`

### `testlib`

Expand Down
9 changes: 4 additions & 5 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/Rules/Epoch.hs
Expand Up @@ -21,7 +21,6 @@ module Cardano.Ledger.Shelley.Rules.Epoch (
) where

import Cardano.Ledger.BaseTypes (ShelleyBase)
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.EpochBoundary (SnapShots)
import Cardano.Ledger.Shelley.Core
import Cardano.Ledger.Shelley.Era (ShelleyEPOCH)
Expand Down Expand Up @@ -209,10 +208,10 @@ epochTransition = do
-- kept (dsUnified of DState and psDeposits of PState) are adjusted by
-- the rules, So we can recompute the utxosDeposited field using adjustedDPState
-- since we have the invariant that: obligationDPState dpstate == utxosDeposited utxostate
Coin oblgNew = obligationDPState adjustedDPstate
Coin reserves = asReserves acnt'
utxoSt''' = utxoSt'' {utxosDeposited = Coin oblgNew}
acnt'' = acnt' {asReserves = Coin reserves}
oblgNew = obligationDPState adjustedDPstate
reserves = asReserves acnt'
utxoSt''' = utxoSt'' {utxosDeposited = oblgNew}
acnt'' = acnt' {asReserves = reserves}
pure $
epochState'
{ esAccountState = acnt''
Expand Down
24 changes: 10 additions & 14 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/Rules/Pool.hs
Expand Up @@ -67,7 +67,7 @@ import Control.State.Transition (
(?!),
)
import qualified Data.ByteString as BS
import Data.Word (Word64, Word8)
import Data.Word (Word8)
import GHC.Generics (Generic)
import Lens.Micro ((^.))
import NoThunks.Class (NoThunks (..))
Expand All @@ -83,9 +83,9 @@ data ShelleyPoolPredFailure era
= StakePoolNotRegisteredOnKeyPOOL
!(KeyHash 'StakePool (EraCrypto era)) -- KeyHash which cannot be retired since it is not registered
| StakePoolRetirementWrongEpochPOOL
!Word64 -- Current Epoch
!Word64 -- The epoch listed in the Pool Retirement Certificate
!Word64 -- The first epoch that is too far out for retirement
!EpochNo -- Current Epoch
!EpochNo -- The epoch listed in the Pool Retirement Certificate
!EpochNo -- The first epoch that is too far out for retirement
| WrongCertificateTypePOOL
!Word8 -- The disallowed certificate (this case should never happen)
| StakePoolCostTooLowPOOL
Expand Down Expand Up @@ -206,7 +206,7 @@ poolDelegationTransition = do
tellEvent $ ReregisterPool hk
-- hk is already registered, so we want to reregister it. That means adding it to the
-- Future pool params (if it is not there already), and overriding the range with the new 'poolParam',
-- if it is (using ⨃ ). We must also unretire it, if it has been schedule for retirement.
-- if it is (using ⨃ ). We must also unretire it, if it has been scheduled for retirement.
-- The deposit does not change. One pays the deposit just once. Only if it is fully retired
-- (i.e. it's deposit has been refunded, and it has been removed from the registered pools).
-- does it need to pay a new deposit (at the current deposit amount). But of course,
Expand All @@ -216,21 +216,17 @@ poolDelegationTransition = do
{ psFutureStakePoolParams = eval (psFutureStakePoolParams ps singleton hk poolParam)
, psRetiring = eval (setSingleton hk psRetiring ps)
}
DCertPool (RetirePool hk (EpochNo e)) -> do
DCertPool (RetirePool hk e) -> do
-- note that pattern match is used instead of cwitness, as in the spec
eval (hk dom stpools) ?! StakePoolNotRegisteredOnKeyPOOL hk
EpochNo cepoch <- liftSTS $ do
cepoch <- liftSTS $ do
ei <- asks epochInfoPure
epochInfoEpoch ei slot
let EpochNo maxEpoch = pp ^. ppEMaxL
cepoch
< e
&& e
<= cepoch
+ maxEpoch
let maxEpoch = pp ^. ppEMaxL
(cepoch < e && e <= cepoch + maxEpoch)
?! StakePoolRetirementWrongEpochPOOL cepoch e (cepoch + maxEpoch)
-- We just schedule it for retirement. When it is retired we refund the deposit (see POOLREAP)
pure $ ps {psRetiring = eval (psRetiring ps singleton hk (EpochNo e))}
pure $ ps {psRetiring = eval (psRetiring ps singleton hk e)}
DCertDeleg _ -> do
failBecause $ WrongCertificateTypePOOL 0
pure ps
Expand Down
Expand Up @@ -130,8 +130,8 @@ poolReapTransition = do
Map.partitionWithKey
(\k _ -> UM.member k (rewards ds)) -- (k ∈ dom (rewards ds))
(Map.mapKeys getRwdCred rewardAcnts')
refunded = fold $ Map.elems refunds
unclaimed = fold $ Map.elems mRefunds
refunded = fold refunds
unclaimed = fold mRefunds

tellEvent $
let rewardAcntsWithPool =
Expand Down

0 comments on commit 1c6564b

Please sign in to comment.