Skip to content

Commit

Permalink
Fix PParams update in the Conway's TICKF fule
Browse files Browse the repository at this point in the history
One of the most important tasks of the `TICKF` rule is to accurately
forecast the PParams that will be in the future.
  • Loading branch information
lehins committed May 7, 2024
1 parent 6f4a286 commit 1cacf79
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
17 changes: 12 additions & 5 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Rules/Tickf.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import Cardano.Ledger.BaseTypes (ShelleyBase, SlotNo, epochInfoPure)
import Cardano.Ledger.Conway.Era
import Cardano.Ledger.Core
import Cardano.Ledger.EpochBoundary (SnapShots (ssStakeMarkPoolDistr))
import Cardano.Ledger.Shelley.Governance
import Cardano.Ledger.Shelley.LedgerState
import Cardano.Ledger.Slot (epochInfoEpoch)
import Control.Monad.Trans.Reader (asks)
import Control.State.Transition
import GHC.Generics (Generic)
import Lens.Micro ((&), (.~), (^.))
import NoThunks.Class (NoThunks (..))

-- ==================================================
Expand Down Expand Up @@ -46,7 +48,7 @@ instance NoThunks (ConwayTickfPredFailure era)
data ConwayTickfEvent era

instance
Era era =>
EraGov era =>
STS (ConwayTICKF era)
where
type State (ConwayTICKF era) = NewEpochState era
Expand Down Expand Up @@ -75,10 +77,17 @@ instance
-- the relevant 'NEWEPOCH' logic
let pd' = ssStakeMarkPoolDistr ss

-- note that the genesis delegates are updated not only on the epoch boundary.
if epoch /= succ (nesEL nes)
then pure nes
else do
let govState = nes ^. newEpochStateGovStateL
-- TICKF is only ever called at most one stability window into the future,
-- which means that `futurePParamsGovStateG` will be known at this point at
-- will be O(1) lookup.
newPParams =
case govState ^. futurePParamsGovStateG of
Nothing -> govState ^. curPParamsGovStateL
Just futurePParams -> futurePParams
-- We can skip 'SNAP'; we already have the equivalent pd'.

-- We can skip 'POOLREAP';
Expand All @@ -88,6 +97,4 @@ instance
-- return value here was used to validate their headers.

pure $!
nes
{ nesPd = pd'
}
nes {nesPd = pd'} & newEpochStateGovStateL . curPParamsGovStateL .~ newPParams
3 changes: 3 additions & 0 deletions libs/cardano-ledger-api/src/Cardano/Ledger/Api/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ module Cardano.Ledger.Api.Governance (
EraGov (GovState),
emptyGovState,
getProposedPPUpdates,
curPParamsGovStateL,
prevPParamsGovStateL,
futurePParamsGovStateG,

-- * Shelley
ShelleyGovState (..),
Expand Down

0 comments on commit 1cacf79

Please sign in to comment.