Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve resilience of future PParams #4433

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eras/conway/impl/cardano-ledger-conway.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ library
cardano-ledger-babbage ^>=1.8,
cardano-ledger-core ^>=1.13,
cardano-ledger-mary ^>=1.6,
cardano-ledger-shelley ^>=1.12.1,
cardano-ledger-shelley ^>=1.12.2,
cardano-slotting,
cardano-strict-containers,
containers,
Expand Down
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 @@ -467,29 +467,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 $
lehins marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ relevantDuringBootstrapSpec ::
relevantDuringBootstrapSpec = do
actionPrioritySpec
hardForkInitiationNoDRepsSpec
pparamPredictionSpec

treasuryWithdrawalsSpec ::
forall era.
Expand Down Expand Up @@ -241,6 +242,27 @@ hardForkInitiationNoDRepsSpec =
passNEpochs 2
getProtVer `shouldReturn` nextProtVer

pparamPredictionSpec :: ConwayEraImp era => SpecWith (ImpTestState era)
pparamPredictionSpec =
it "futurePParams" $ do
committeeMembers' <- registerInitialCommittee
modifyPParams $ ppPoolVotingThresholdsL . pvtHardForkInitiationL .~ 2 %! 3
whenPostBootstrap (modifyPParams $ ppDRepVotingThresholdsL . dvtHardForkInitiationL .~ def)
_ <- setupPoolWithStake $ Coin 22_000_000
(stakePoolId1, _, _) <- setupPoolWithStake $ Coin 22_000_000
(stakePoolId2, _, _) <- setupPoolWithStake $ Coin 22_000_000
curProtVer <- getProtVer
nextMajorVersion <- succVersion $ pvMajor curProtVer
let nextProtVer = curProtVer {pvMajor = nextMajorVersion}
govActionId <- submitGovAction $ HardForkInitiation SNothing nextProtVer
submitYesVoteCCs_ committeeMembers' govActionId
submitYesVote_ (StakePoolVoter stakePoolId1) govActionId
submitYesVote_ (StakePoolVoter stakePoolId2) govActionId
passEpoch
advanceToPointOfNoReturn
passEpoch
getProtVer `shouldReturn` nextProtVer

noConfidenceSpec :: forall era. ConwayEraImp era => SpecWith (ImpTestState era)
noConfidenceSpec =
it "NoConfidence" $ do
Expand Down
6 changes: 5 additions & 1 deletion eras/shelley/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Version history for `cardano-ledger-shelley`

## 1.12.1.1
## 1.12.2.0

*

### `testlib`

* Add `advanceToPointOfNoReturn`

## 1.12.1.0

*
Expand Down
2 changes: 1 addition & 1 deletion eras/shelley/impl/cardano-ledger-shelley.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: cardano-ledger-shelley
version: 1.12.1.0
version: 1.12.2.0
license: Apache-2.0
maintainer: [email protected]
author: IOHK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ module Test.Cardano.Ledger.Shelley.ImpTest (
impKeyPairsG,
impNativeScriptsG,
produceScript,
advanceToPointOfNoReturn,
) where

import qualified Cardano.Chain.Common as Byron
Expand Down Expand Up @@ -180,6 +181,7 @@ import Cardano.Ledger.Shelley.Scripts (
pattern RequireMOf,
pattern RequireSignature,
)
import Cardano.Ledger.Slot (getTheSlotOfNoReturn)
import Cardano.Ledger.Tools (calcMinFeeTxNativeScriptWits, integralToByteStringN)
import Cardano.Ledger.TxIn (TxId (..), TxIn (..))
import Cardano.Ledger.UMap as UMap
Expand Down Expand Up @@ -751,8 +753,10 @@ runImpTestM mQCSize impState (ImpTestM m) = do
endState <- readIORef ioRef
pure (res, endState)

runShelleyBase :: Globals -> ShelleyBase a -> a
runShelleyBase globals act = runIdentity $ runReaderT act globals
runShelleyBase :: ShelleyBase a -> ImpTestM era a
runShelleyBase act = do
globals <- use impGlobalsL
pure $ runIdentity $ runReaderT act globals

getRewardAccountAmount :: RewardAccount (EraCrypto era) -> ImpTestM era Coin
getRewardAccountAmount rewardAcount = do
Expand Down Expand Up @@ -1016,15 +1020,14 @@ tryRunImpRule ::
)
tryRunImpRule stsEnv stsState stsSignal = do
let trc = TRC (stsEnv, stsState, stsSignal)
globals <- use impGlobalsL
let
stsOpts =
ApplySTSOpts
{ asoValidation = ValidateAll
, asoEvents = EPReturn
, asoAssertions = AssertionsAll
}
pure $ runShelleyBase globals (applySTSOptsEither @(EraRule rule era) stsOpts trc)
runShelleyBase (applySTSOptsEither @(EraRule rule era) stsOpts trc)

runImpRule ::
forall rule era.
Expand Down Expand Up @@ -1546,3 +1549,9 @@ produceScript scriptHash = do
mkBasicTx mkBasicTxBody
& bodyTxL . outputsTxBodyL .~ SSeq.singleton (mkBasicTxOut addr (inject (Coin 10)))
txInAt (0 :: Int) <$> submitTx tx

advanceToPointOfNoReturn :: ImpTestM era ()
advanceToPointOfNoReturn = do
impLastTick <- gets impLastTick
(_, slotOfNoReturn, _) <- runShelleyBase $ getTheSlotOfNoReturn impLastTick
impLastTickL .= slotOfNoReturn