Skip to content

Commit a5543c1

Browse files
committed
Update HardFork rule to populate VRF key hashes
1 parent 505717d commit a5543c1

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-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+
spsVrf
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: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
-- Since we're testing the HardFork to 11, the test only makes sense for protocol version 10
29+
whenMajorVersion @10 $ do
30+
(kh1, vrf1) <- (,) <$> freshKeyHash <*> freshKeyHashVRF
31+
registerStakePool kh1 vrf1
32+
(kh2, vrf2) <- (,) <$> freshKeyHash <*> freshKeyHashVRF
33+
registerStakePool kh2 vrf2
34+
vrf3 <- freshKeyHashVRF
35+
-- re-register with a new key, so vrf1 should not be present after the hard fork
36+
registerStakePool kh1 vrf3
37+
-- register a new pool with an existing vrf
38+
kh3 <- freshKeyHash
39+
registerStakePool kh3 vrf2
40+
-- register and retire a pool before the hard fork, so vrf4 should not be present after the hard fork
41+
(kh4, vrf4) <- (,) <$> freshKeyHash <*> freshKeyHashVRF
42+
registerStakePool kh4 vrf4
43+
retireStakePool kh4 (EpochInterval 1)
44+
-- register and schedule retirement for after the hard fork, so vrf5 should be present after the hard fork
45+
(kh5, vrf5) <- (,) <$> freshKeyHash <*> freshKeyHashVRF
46+
registerStakePool kh5 vrf5
47+
retireStakePool kh5 (EpochInterval 5)
48+
49+
expectVRFs [] -- VRF keyhashes in PState is not yet populated
50+
enactHardForkV11
51+
expectVRFs [vrf2, vrf3, vrf5]
52+
where
53+
enactHardForkV11 = do
54+
modifyPParams $ \pp ->
55+
pp
56+
& ppDRepVotingThresholdsL . dvtHardForkInitiationL .~ 0 %! 1
57+
& ppPoolVotingThresholdsL . pvtHardForkInitiationL .~ 0 %! 1
58+
let pv11 = ProtVer (natVersion @11) 0
59+
committee <- registerInitialCommittee
60+
govActionId <- submitGovAction $ HardForkInitiation SNothing pv11
61+
submitYesVoteCCs_ committee govActionId
62+
passNEpochs 2
63+
getProtVer `shouldReturn` pv11
64+
registerStakePool kh vrf = do
65+
pps <- registerRewardAccount >>= freshPoolParams kh
66+
submitTx_ $
67+
mkBasicTx mkBasicTxBody
68+
& bodyTxL . certsTxBodyL .~ [RegPoolTxCert $ pps & ppVrfL .~ vrf]
69+
retireStakePool kh retirementInterval = do
70+
curEpochNo <- getsNES nesELL
71+
let retirement = addEpochInterval curEpochNo retirementInterval
72+
submitTx_ $
73+
mkBasicTx mkBasicTxBody
74+
& bodyTxL . certsTxBodyL .~ [RetirePoolTxCert kh retirement]
75+
expectVRFs vrfs =
76+
psVRFKeyHashes <$> getPState `shouldReturn` Set.fromList vrfs
77+
getPState = getsNES @era $ nesEsL . esLStateL . lsCertStateL . certPStateL

0 commit comments

Comments
 (0)