From 7bdd33da7c445ea8bf3a3532192f38ac87b4b6ac Mon Sep 17 00:00:00 2001 From: Andrew Westberg Date: Sun, 15 Sep 2024 13:05:33 +0000 Subject: [PATCH] 638-Allow next leadership-schedule at 4k/f --- cardano-api/internal/Cardano/Api/LedgerState.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cardano-api/internal/Cardano/Api/LedgerState.hs b/cardano-api/internal/Cardano/Api/LedgerState.hs index ee68ce1d8c..654dc4077d 100644 --- a/cardano-api/internal/Cardano/Api/LedgerState.hs +++ b/cardano-api/internal/Cardano/Api/LedgerState.hs @@ -1792,14 +1792,19 @@ nextEpochEligibleLeadershipSlots sbe sGen serCurrEpochState ptclState poolid (Vr Slot.epochInfoRange eInfo (currentEpoch `Slot.addEpochInterval` Slot.EpochInterval 1) -- First we check if we are within 3k/f slots of the end of the current epoch. + -- In Conway era onwards, we use 4k/f slots instead of 3k/f slots. + -- see: https://ouroboros-consensus.cardano.intersectmbo.org/docs/for-developers/Glossary#epoch-structure -- Why? Because the stake distribution is stable at this point. -- k is the security parameter -- f is the active slot coefficient let stabilityWindowR :: Rational - stabilityWindowR = fromIntegral (3 * sgSecurityParam sGen) / Ledger.unboundRational (sgActiveSlotsCoeff sGen) + stabilityWindowR = + fromIntegral (stabilityWindowConst * sgSecurityParam sGen) + / Ledger.unboundRational (sgActiveSlotsCoeff sGen) stabilityWindowSlots :: SlotNo stabilityWindowSlots = fromIntegral @Word64 $ floor $ fromRational @Double stabilityWindowR stableStakeDistribSlot = currentEpochLastSlot - stabilityWindowSlots + stabilityWindowConst = caseShelleyToBabbageOrConwayEraOnwards (const 3) (const 4) sbe case cTip of ChainTipAtGenesis -> Left LeaderErrGenesisSlot