Skip to content

Commit

Permalink
Improve stability of futurePParams prediction:
Browse files Browse the repository at this point in the history
Ensure that every Conway Epoch begins with a correct prediction for
`futurePParams`. The problem that this commit fixes has to do with the
fact that `futurePParams` where correctly predicted on the very first
`TICK`. However, if there are no blocks prior to point-of-no-return,
which can't happen on a normal running chain, there would be no `TICK`,
thus there would be no prediction. So, regardless if there was a correct
prediciton after the point-of-no-return, `PParamUpdate` would be simply
ignored, since `futurePParams` would be already set to `NoPParamUpdate`.

Despite the fact that this can't really happen on mainnet, we can fix
this quite easily by predicting `futurePParams` during DRepPulser
initialization, which is exactly what being imlemented in this commit.
  • Loading branch information
lehins committed Jun 20, 2024
1 parent 45534b0 commit 86ae8a3
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -464,29 +464,30 @@ setFreshDRepPulsingState epochNo stakePoolDistr epochState = do
umap = dsUnified dState
umapSize = Map.size $ umElems umap
pulseSize = max 1 (umapSize `div` (fromIntegral :: Word64 -> Int) (4 * k))
epochState' =
epochState
& epochStateGovStateL . cgsDRepPulsingStateL
.~ DRPulsing
( DRepPulser
{ dpPulseSize = pulseSize
, dpUMap = dsUnified dState
, dpIndex = 0 -- used as the index of the remaining UMap
, dpStakeDistr = stakeDistr -- used as part of the snapshot
, dpStakePoolDistr = stakePoolDistr
, dpDRepDistr = Map.empty -- The partial result starts as the empty map
, dpDRepState = vsDReps vState
, dpCurrentEpoch = epochNo
, dpCommitteeState = vsCommitteeState vState
, dpEnactState =
mkEnactState govState
& ensTreasuryL .~ epochState ^. epochStateTreasuryL
, dpProposals = proposalsActions props
, dpProposalDeposits = proposalsDeposits props
, dpGlobals = globals
}
)
pure epochState'
govState' =
predictFuturePParams $
govState
& cgsDRepPulsingStateL
.~ DRPulsing
( DRepPulser
{ dpPulseSize = pulseSize
, dpUMap = dsUnified dState
, dpIndex = 0 -- used as the index of the remaining UMap
, dpStakeDistr = stakeDistr -- used as part of the snapshot
, dpStakePoolDistr = stakePoolDistr
, dpDRepDistr = Map.empty -- The partial result starts as the empty map
, dpDRepState = vsDReps vState
, dpCurrentEpoch = epochNo
, dpCommitteeState = vsCommitteeState vState
, dpEnactState =
mkEnactState govState
& ensTreasuryL .~ epochState ^. epochStateTreasuryL
, dpProposals = proposalsActions props
, dpProposalDeposits = proposalsDeposits props
, dpGlobals = globals
}
)
pure $ epochState & epochStateGovStateL .~ govState'

-- | Force computation of DRep stake distribution and figure out the next enact
-- state. This operation is useful in cases when access to new EnactState or DRep stake
Expand Down

0 comments on commit 86ae8a3

Please sign in to comment.