Skip to content

Commit

Permalink
Adjust drep expiry set on registration
Browse files Browse the repository at this point in the history
to subtract the added number of dormant epochs from the total
  • Loading branch information
teodanciu committed Aug 14, 2024
1 parent 39672a1 commit f3e6c09
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
25 changes: 24 additions & 1 deletion eras/conway/impl/src/Cardano/Ledger/Conway/Rules/GovCert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import Cardano.Ledger.Credential (Credential)
import Cardano.Ledger.Crypto (Crypto)
import Cardano.Ledger.DRep (DRepState (..), drepAnchorL, drepDepositL, drepExpiryL)
import Cardano.Ledger.Keys (KeyRole (ColdCommitteeRole, DRepRole))
import qualified Cardano.Ledger.Shelley.HardForks as HF (bootstrapPhase)
import Cardano.Slotting.Slot (EpochInterval, binOpEpochNo)
import Control.DeepSeq (NFData)
import Control.State.Transition.Extended (
Expand Down Expand Up @@ -235,7 +236,15 @@ conwayGovCertTransition = do
{ vsDReps =
Map.insert
cred
(DRepState (addEpochInterval cgceCurrentEpoch ppDRepActivity) mAnchor ppDRepDeposit)
( DRepState
( computeDRepExpiryVersioned
cgcePParams
cgceCurrentEpoch
(vState ^. vsNumDormantEpochsL)
)
mAnchor
ppDRepDeposit
)
vsDReps
}
ConwayUnRegDRep cred refund -> do
Expand Down Expand Up @@ -274,6 +283,20 @@ conwayGovCertTransition = do
UpdateCommittee _ _ newMembers _ -> Map.member coldCred newMembers
_ -> False

computeDRepExpiryVersioned ::
ConwayEraPParams era =>
PParams era ->
-- | Current epoch
EpochNo ->
-- | The count of the dormant epochs
EpochNo ->
EpochNo
computeDRepExpiryVersioned pp currentEpoch numDormantEpochs
| HF.bootstrapPhase (pp ^. ppProtocolVersionL) =
addEpochInterval currentEpoch (pp ^. ppDRepActivityL)
| otherwise =
computeDRepExpiry (pp ^. ppDRepActivityL) currentEpoch numDormantEpochs

computeDRepExpiry ::
-- | DRepActivity PParam
EpochInterval ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Cardano.Ledger.Core
import Cardano.Ledger.Credential (Credential (KeyHashObj))
import Cardano.Ledger.DRep
import Cardano.Ledger.Keys (KeyRole (..))
import qualified Cardano.Ledger.Shelley.HardForks as HF
import Cardano.Ledger.Shelley.LedgerState
import Data.Default (def)
import Data.Foldable (Foldable (..))
Expand Down Expand Up @@ -70,6 +71,33 @@ spec = do
expectActualDRepExpiry drep $
addEpochInterval curEpochNo $
EpochInterval (drepActivity + fromIntegral n)

it "dRep registered when there are dormant epochs" $ do
let drepActivity = 3
modifyPParams $ ppDRepActivityL .~ EpochInterval drepActivity
let n = 2
passNEpochs n
expectNumDormantEpochs $ EpochNo (fromIntegral n)
(drep, _, _) <- setupSingleDRep 1_000_000

let expectedExpiry = do
epochNo <- getsNES nesELL
let tot = addEpochInterval epochNo (EpochInterval drepActivity)
pv <- getProtVer
pure $
if HF.bootstrapPhase pv
then binOpEpochNo (+) tot (fromIntegral n)
else tot

expectedExpiry >>= expectActualDRepExpiry drep

nes <- getsNES id
void $ submitParameterChange SNothing $ def & ppuMinFeeAL .~ SJust (Coin 3000)

expectedExpiry >>= expectDRepExpiry drep
drepState <- drepStateFromQuery drep nes
expectedExpiry >>= shouldBe (drepState ^. drepExpiryL)

it "proposals are made and numDormantEpochs are added" $ do
curEpochNo <- getsNES nesELL
let drepActivity = 3
Expand Down

0 comments on commit f3e6c09

Please sign in to comment.