Skip to content

Commit 66d6026

Browse files
committed
Update HardFork rule to populate VRF key hashes
1 parent 4f30247 commit 66d6026

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

eras/conway/impl/cardano-ledger-conway.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ library testlib
146146
Test.Cardano.Ledger.Conway.Imp.EpochSpec
147147
Test.Cardano.Ledger.Conway.Imp.GovCertSpec
148148
Test.Cardano.Ledger.Conway.Imp.GovSpec
149+
Test.Cardano.Ledger.Conway.Imp.HardForkSpec
149150
Test.Cardano.Ledger.Conway.Imp.LedgerSpec
150151
Test.Cardano.Ledger.Conway.Imp.RatifySpec
151152
Test.Cardano.Ledger.Conway.Imp.UtxoSpec

eras/conway/impl/src/Cardano/Ledger/Conway/Rules/HardFork.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ hardforkTransition = do
7070
let update
7171
| pvMajor newPv == natVersion @10 =
7272
esLStateL . lsCertStateL %~ updateDRepDelegations
73+
| pvMajor newPv == natVersion @11 =
74+
esLStateL . lsCertStateL . certPStateL %~ populateVRFKeyHashes
7375
| otherwise = id
7476
pure $ update epochState
7577

@@ -97,3 +99,11 @@ updateDRepDelegations certState =
9799
& certDStateL . accountsL . accountsMapL .~ accountsWithoutUnknownDRepDelegations
98100
-- Populate DRep delegations with delegatees
99101
& certVStateL . vsDRepsL .~ dRepsWithDelegations
102+
103+
populateVRFKeyHashes :: PState era -> PState era
104+
populateVRFKeyHashes pState =
105+
let allVRFKeyHashes =
106+
(^. spsVrfL)
107+
<$> Map.elems (pState ^. psStakePoolsL)
108+
<> Map.elems (pState ^. psFutureStakePoolsL)
109+
in pState & psVRFKeyHashesL .~ Set.fromList allVRFKeyHashes

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import qualified Test.Cardano.Ledger.Conway.Imp.EnactSpec as Enact
5353
import qualified Test.Cardano.Ledger.Conway.Imp.EpochSpec as Epoch
5454
import qualified Test.Cardano.Ledger.Conway.Imp.GovCertSpec as GovCert
5555
import qualified Test.Cardano.Ledger.Conway.Imp.GovSpec as Gov
56+
import qualified Test.Cardano.Ledger.Conway.Imp.HardForkSpec as HardFork
5657
import qualified Test.Cardano.Ledger.Conway.Imp.LedgerSpec as Ledger
5758
import qualified Test.Cardano.Ledger.Conway.Imp.RatifySpec as Ratify
5859
import qualified Test.Cardano.Ledger.Conway.Imp.UtxoSpec as Utxo
@@ -139,6 +140,7 @@ conwaySpec = do
139140
describe "GOV" Gov.spec
140141
describe "GOVCERT" GovCert.spec
141142
describe "LEDGER" Ledger.spec
143+
describe "HARDFORK" HardFork.spec
142144
describe "RATIFY" Ratify.spec
143145
describe "UTXO" Utxo.spec
144146
describe "UTXOS" Utxos.spec
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{-# LANGUAGE BangPatterns #-}
2+
{-# LANGUAGE DataKinds #-}
3+
{-# LANGUAGE FlexibleContexts #-}
4+
{-# LANGUAGE OverloadedLists #-}
5+
{-# LANGUAGE ScopedTypeVariables #-}
6+
{-# LANGUAGE TypeApplications #-}
7+
{-# LANGUAGE TypeFamilies #-}
8+
9+
module Test.Cardano.Ledger.Conway.Imp.HardForkSpec (spec) where
10+
11+
import Cardano.Ledger.BaseTypes
12+
import Cardano.Ledger.Conway.Core
13+
import Cardano.Ledger.Conway.Governance
14+
import Cardano.Ledger.Conway.PParams
15+
import Cardano.Ledger.Conway.State
16+
import Cardano.Ledger.Shelley.LedgerState
17+
import qualified Data.Set as Set
18+
import Lens.Micro
19+
import Test.Cardano.Ledger.Conway.ImpTest
20+
import Test.Cardano.Ledger.Core.Rational
21+
import Test.Cardano.Ledger.Imp.Common
22+
23+
spec ::
24+
forall era.
25+
ConwayEraImp era => SpecWith (ImpInit (LedgerSpec era))
26+
spec = do
27+
it "VRF Keyhashes get populated at v11 HardFork" $ do
28+
pv <- getProtVer
29+
-- Since we're testing the HardFork to 11, the test only makes sense for protocol version 10
30+
when (pvMajor pv == natVersion @10) $ do
31+
(kh1, vrf1) <- (,) <$> freshKeyHash <*> freshKeyHashVRF
32+
registerStakePool kh1 vrf1
33+
(kh2, vrf2) <- (,) <$> freshKeyHash <*> freshKeyHashVRF
34+
registerStakePool kh2 vrf2
35+
vrf3 <- freshKeyHashVRF
36+
-- re-register with a new key, so vrf1 should not be present after the hard fork
37+
registerStakePool kh1 vrf3
38+
-- register a new pool with an existing vrf
39+
kh3 <- freshKeyHash
40+
registerStakePool kh3 vrf2
41+
-- register and retire a pool before the hard fork, so vrf4 should not be present after the hard fork
42+
(kh4, vrf4) <- (,) <$> freshKeyHash <*> freshKeyHashVRF
43+
registerStakePool kh4 vrf4
44+
retireStakePool kh4 (EpochInterval 1)
45+
-- register and schedule retirement for after the hard fork, so vrf5 should be present after the hard fork
46+
(kh5, vrf5) <- (,) <$> freshKeyHash <*> freshKeyHashVRF
47+
registerStakePool kh5 vrf5
48+
retireStakePool kh5 (EpochInterval 5)
49+
50+
expectVRFs [] -- VRF keyhashes in PState is not yet populated
51+
enactHardForkV11
52+
expectVRFs [vrf2, vrf3, vrf5]
53+
where
54+
enactHardForkV11 = do
55+
modifyPParams $ \pp ->
56+
pp
57+
& ppDRepVotingThresholdsL . dvtHardForkInitiationL .~ 0 %! 1
58+
& ppPoolVotingThresholdsL . pvtHardForkInitiationL .~ 0 %! 1
59+
let pv11 = ProtVer (natVersion @11) 0
60+
committee <- registerInitialCommittee
61+
govActionId <- submitGovAction $ HardForkInitiation SNothing pv11
62+
submitYesVoteCCs_ committee govActionId
63+
passNEpochs 2
64+
getProtVer `shouldReturn` pv11
65+
registerStakePool kh vrf = do
66+
pps <- registerRewardAccount >>= freshPoolParams kh
67+
submitTx_ $
68+
mkBasicTx mkBasicTxBody
69+
& bodyTxL . certsTxBodyL .~ [RegPoolTxCert $ pps & ppVrfL .~ vrf]
70+
retireStakePool kh retirementInterval = do
71+
curEpochNo <- getsNES nesELL
72+
let retirement = addEpochInterval curEpochNo retirementInterval
73+
submitTx_ $
74+
mkBasicTx mkBasicTxBody
75+
& bodyTxL . certsTxBodyL .~ [RetirePoolTxCert kh retirement]
76+
expectVRFs vrfs =
77+
(^. psVRFKeyHashesL) <$> getPState `shouldReturn` Set.fromList vrfs
78+
getPState = getsNES @era $ nesEsL . esLStateL . lsCertStateL . certPStateL

0 commit comments

Comments
 (0)