Skip to content

Commit c721b2a

Browse files
authored
Merge pull request #3363 from input-output-hk/lehins/move-tpraos-utils
Move tpraos utils
2 parents 93ff7ea + 9dbcc1f commit c721b2a

File tree

44 files changed

+832
-1735
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+832
-1735
lines changed

cabal.project

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ package cardano-ledger-core
7474
package cardano-ledger-shelley
7575
flags: +asserts
7676

77-
-- Always write GHC env files, because they are needed by the doctests.
77+
-- Always write GHC env files, because they are needed by for repl and doctest.
7878
write-ghc-environment-files: always
7979

8080
-- Always build tests and benchmarks.

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Bbody.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import Cardano.Ledger.Block (Block (..))
3333
import Cardano.Ledger.Core
3434
import qualified Cardano.Ledger.Era as Era
3535
import Cardano.Ledger.Keys (DSignable, Hash, coerceKeyRole)
36-
import Cardano.Ledger.Shelley.BlockChain (bBodySize, incrBlocks)
36+
import Cardano.Ledger.Shelley.BlockChain (incrBlocks)
3737
import Cardano.Ledger.Shelley.LedgerState (LedgerState)
3838
import Cardano.Ledger.Shelley.Rules (
3939
BbodyEnv (..),

eras/shelley/impl/src/Cardano/Ledger/Shelley/BlockChain.hs

-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import qualified Cardano.Crypto.Hash.Class as Hash
3333
import Cardano.Ledger.BaseTypes (
3434
BlocksMade (..),
3535
Nonce (..),
36-
ProtVer (..),
3736
StrictMaybe (..),
3837
mkNonceFromNumber,
3938
strictMaybeToMaybe,
@@ -48,7 +47,6 @@ import Cardano.Ledger.Binary (
4847
encodeFoldableMapEncoder,
4948
encodePreEncoded,
5049
serialize,
51-
serialize',
5250
withSlice,
5351
)
5452
import Cardano.Ledger.Core
@@ -60,7 +58,6 @@ import Cardano.Ledger.Shelley.Tx (ShelleyTx, segwitTx)
6058
import Cardano.Ledger.Slot (SlotNo (..))
6159
import Control.Monad (unless)
6260
import Data.ByteString (ByteString)
63-
import qualified Data.ByteString.Char8 as BS
6461
import qualified Data.ByteString.Lazy as BSL
6562
import Data.Coerce (coerce)
6663
import Data.Map.Strict (Map)
@@ -248,9 +245,6 @@ txSeqDecoder lax = do
248245
instance EraTx era => DecCBOR (Annotator (ShelleyTxSeq era)) where
249246
decCBOR = txSeqDecoder False
250247

251-
bBodySize :: forall era. EraSegWits era => ProtVer -> TxSeq era -> Int
252-
bBodySize (ProtVer v _) = BS.length . serialize' v . encCBORGroup
253-
254248
slotToNonce :: SlotNo -> Nonce
255249
slotToNonce (SlotNo s) = mkNonceFromNumber s
256250

eras/shelley/impl/src/Cardano/Ledger/Shelley/Rules/Bbody.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import Cardano.Ledger.BaseTypes (BlocksMade, ShelleyBase, epochInfoPure)
2727
import Cardano.Ledger.Block (Block (..))
2828
import Cardano.Ledger.Core
2929
import Cardano.Ledger.Keys (DSignable, Hash, coerceKeyRole)
30-
import Cardano.Ledger.Shelley.BlockChain (bBodySize, incrBlocks)
30+
import Cardano.Ledger.Shelley.BlockChain (incrBlocks)
3131
import Cardano.Ledger.Shelley.Era (ShelleyBBODY)
3232
import Cardano.Ledger.Shelley.LedgerState (
3333
AccountState,

eras/shelley/test-suite/bench/Cardano/Ledger/Shelley/Bench/Rewards.hs

+7-6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import Test.Cardano.Ledger.Shelley.Generator.Core (
5353
AllIssuerKeys (..),
5454
GenEnv (..),
5555
ScriptSpace (..),
56+
VRFKeyPair (..),
5657
geConstants,
5758
geKeySpace,
5859
ksStakePools,
@@ -136,12 +137,12 @@ genChainInEpoch epoch = do
136137
ShelleyGenesisStaking
137138
{ sgsPools =
138139
LM.ListMap
139-
[ (hk, pp)
140-
| (AllIssuerKeys {vrf, hk}, (owner : _)) <- stakeMap
140+
[ (aikColdKeyHash, pp)
141+
| (AllIssuerKeys {aikVrf, aikColdKeyHash}, (owner : _)) <- stakeMap
141142
, let pp =
142143
PoolParams
143-
{ ppId = hk
144-
, ppVrf = hashVerKeyVRF $ snd vrf
144+
{ ppId = aikColdKeyHash
145+
, ppVrf = hashVerKeyVRF $ vrfVerKey aikVrf
145146
, ppPledge = Coin 1
146147
, ppCost = Coin 1
147148
, ppMargin = minBound
@@ -153,8 +154,8 @@ genChainInEpoch epoch = do
153154
]
154155
, sgsStake =
155156
LM.ListMap
156-
[ (dlg, hk)
157-
| (AllIssuerKeys {hk}, dlgs) <- stakeMap
157+
[ (dlg, aikColdKeyHash)
158+
| (AllIssuerKeys {aikColdKeyHash}, dlgs) <- stakeMap
158159
, dlg <- dlgs
159160
]
160161
}

eras/shelley/test-suite/cardano-ledger-shelley-test.cabal

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ source-repository head
2121

2222
library
2323
exposed-modules:
24-
Test.Cardano.Crypto.VRF.Fake
2524
Test.Cardano.Ledger.TerseTools
2625
Test.Cardano.Ledger.Shelley.Address.Bootstrap
2726
Test.Cardano.Ledger.Shelley.BenchmarkFunctions
@@ -169,7 +168,7 @@ test-suite cardano-ledger-shelley-test
169168
cardano-ledger-pretty,
170169
cardano-ledger-shelley:{cardano-ledger-shelley, testlib},
171170
cardano-ledger-shelley-test >=1.1,
172-
cardano-protocol-tpraos,
171+
cardano-protocol-tpraos:{cardano-protocol-tpraos, testlib},
173172
cardano-slotting,
174173
cborg,
175174
containers,

eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/BenchmarkFunctions.hs

+4-3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ import qualified Test.Cardano.Ledger.Shelley.ConcreteCryptoTypes as Original (
8989
C_Crypto,
9090
)
9191
import Test.Cardano.Ledger.Shelley.Generator.Core (
92+
VRFKeyPair (..),
9293
genesisCoins,
9394
)
9495
import Test.Cardano.Ledger.Shelley.Generator.EraGen (genesisId)
@@ -394,18 +395,18 @@ firstStakePoolKeyHash :: KeyHash 'StakePool B_Crypto
394395
firstStakePoolKeyHash = mkPoolKeyHash firstStakePool
395396

396397
vrfKeyHash :: Hash B_Crypto (VerKeyVRF B_Crypto)
397-
vrfKeyHash = hashVerKeyVRF . snd . mkVRFKeyPair $ RawSeed 0 0 0 0 0
398+
vrfKeyHash = hashVerKeyVRF . vrfVerKey . mkVRFKeyPair @B_Crypto $ RawSeed 0 0 0 0 0
398399

399400
mkPoolParameters :: KeyPair 'StakePool B_Crypto -> PoolParams B_Crypto
400401
mkPoolParameters keys =
401402
PoolParams
402-
{ ppId = (hashKey . vKey) keys
403+
{ ppId = hashKey (vKey keys)
403404
, ppVrf = vrfKeyHash
404405
, ppPledge = Coin 0
405406
, ppCost = Coin 0
406407
, ppMargin = unsafeBoundRational 0
407408
, ppRewardAcnt = RewardAcnt Testnet firstStakeKeyCred
408-
, ppOwners = Set.singleton $ (hashKey . vKey) stakeKeyOne
409+
, ppOwners = Set.singleton $ hashKey (vKey stakeKeyOne)
409410
, ppRelays = StrictSeq.empty
410411
, ppMetadata = SNothing
411412
}

eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/ConcreteCryptoTypes.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import Cardano.Ledger.BaseTypes (Seed)
2424
import Cardano.Ledger.Crypto
2525
import Cardano.Ledger.Shelley (ShelleyEra)
2626
import Cardano.Protocol.TPraos.API (PraosCrypto)
27-
import Test.Cardano.Crypto.VRF.Fake (FakeVRF)
27+
import Test.Cardano.Protocol.Crypto.VRF.Fake (FakeVRF)
2828

2929
-- | Mocking constraints used in generators
3030
type Mock c =

eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Examples/Cast.hs

+36-34
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import Cardano.Ledger.Credential (
5151
Ptr (..),
5252
StakeReference (..),
5353
)
54-
import qualified Cardano.Ledger.Crypto as CC (Crypto)
54+
import Cardano.Ledger.Crypto (Crypto)
5555
import Cardano.Ledger.Keys (
5656
Hash,
5757
KeyRole (..),
@@ -67,12 +67,14 @@ import Cardano.Ledger.Shelley.TxBody (
6767
import Cardano.Ledger.Slot (SlotNo (..))
6868
import Cardano.Protocol.TPraos.OCert (KESPeriod (..))
6969
import qualified Data.ByteString.Char8 as BS (pack)
70+
import qualified Data.List.NonEmpty as NE
7071
import Data.Maybe (fromJust)
7172
import qualified Data.Sequence.Strict as StrictSeq
7273
import qualified Data.Set as Set
7374
import Test.Cardano.Ledger.Core.KeyPair (KeyPair (..), mkAddr)
7475
import Test.Cardano.Ledger.Shelley.Generator.Core (
7576
AllIssuerKeys (..),
77+
VRFKeyPair (..),
7678
)
7779
import Test.Cardano.Ledger.Shelley.Utils (
7880
RawSeed (..),
@@ -83,50 +85,50 @@ import Test.Cardano.Ledger.Shelley.Utils (
8385
)
8486

8587
-- | Alice's payment key pair
86-
alicePay :: CC.Crypto c => KeyPair 'Payment c
88+
alicePay :: Crypto c => KeyPair 'Payment c
8789
alicePay = KeyPair vk sk
8890
where
8991
(sk, vk) = mkKeyPair (RawSeed 0 0 0 0 0)
9092

9193
-- | Alice's stake key pair
92-
aliceStake :: CC.Crypto c => KeyPair 'Staking c
94+
aliceStake :: Crypto c => KeyPair 'Staking c
9395
aliceStake = KeyPair vk sk
9496
where
9597
(sk, vk) = mkKeyPair (RawSeed 1 1 1 1 1)
9698

9799
-- | Alice's stake pool keys (cold keys, VRF keys, hot KES keys)
98-
alicePoolKeys :: CC.Crypto c => AllIssuerKeys c 'StakePool
100+
alicePoolKeys :: Crypto c => AllIssuerKeys c 'StakePool
99101
alicePoolKeys =
100102
AllIssuerKeys
101103
(KeyPair vkCold skCold)
102104
(mkVRFKeyPair (RawSeed 1 0 0 0 2))
103-
[(KESPeriod 0, mkKESKeyPair (RawSeed 1 0 0 0 3))]
105+
((KESPeriod 0, mkKESKeyPair (RawSeed 1 0 0 0 3)) NE.:| [])
104106
(hashKey vkCold)
105107
where
106108
(skCold, vkCold) = mkKeyPair (RawSeed 1 0 0 0 1)
107109

108110
-- | Alice's base address
109-
aliceAddr :: CC.Crypto c => Addr c
111+
aliceAddr :: Crypto c => Addr c
110112
aliceAddr = mkAddr (alicePay, aliceStake)
111113

112114
-- | Alice's payment credential
113-
alicePHK :: CC.Crypto c => Credential 'Payment c
115+
alicePHK :: Crypto c => Credential 'Payment c
114116
alicePHK = (KeyHashObj . hashKey . vKey) alicePay
115117

116118
-- | Alice's stake credential
117-
aliceSHK :: CC.Crypto c => Credential 'Staking c
119+
aliceSHK :: Crypto c => Credential 'Staking c
118120
aliceSHK = (KeyHashObj . hashKey . vKey) aliceStake
119121

120122
-- | Alice's base address
121-
alicePtrAddr :: CC.Crypto c => Addr c
123+
alicePtrAddr :: Crypto c => Addr c
122124
alicePtrAddr = Addr Testnet alicePHK (StakeRefPtr $ Ptr (SlotNo 10) minBound minBound)
123125

124126
-- | Alice's stake pool parameters
125-
alicePoolParams :: forall c. CC.Crypto c => PoolParams c
127+
alicePoolParams :: forall c. Crypto c => PoolParams c
126128
alicePoolParams =
127129
PoolParams
128-
{ ppId = (hashKey . vKey . cold) alicePoolKeys
129-
, ppVrf = hashVerKeyVRF . snd $ vrf (alicePoolKeys @c)
130+
{ ppId = hashKey . vKey $ aikCold alicePoolKeys
131+
, ppVrf = hashVerKeyVRF . vrfVerKey $ aikVrf (alicePoolKeys @c)
130132
, ppPledge = Coin 1
131133
, ppCost = Coin 5
132134
, ppMargin = unsafeBoundRational 0.1
@@ -144,99 +146,99 @@ alicePoolParams =
144146
-- | Alice's VRF key hash
145147
aliceVRFKeyHash ::
146148
forall c.
147-
CC.Crypto c =>
149+
Crypto c =>
148150
Hash c (VerKeyVRF c)
149-
aliceVRFKeyHash = hashVerKeyVRF (snd $ vrf (alicePoolKeys @c))
151+
aliceVRFKeyHash = hashVerKeyVRF (vrfVerKey $ aikVrf (alicePoolKeys @c))
150152

151153
-- | Bob's payment key pair
152-
bobPay :: CC.Crypto c => KeyPair 'Payment c
154+
bobPay :: Crypto c => KeyPair 'Payment c
153155
bobPay = KeyPair vk sk
154156
where
155157
(sk, vk) = mkKeyPair (RawSeed 2 2 2 2 2)
156158

157159
-- | Bob's stake key pair
158-
bobStake :: CC.Crypto c => KeyPair 'Staking c
160+
bobStake :: Crypto c => KeyPair 'Staking c
159161
bobStake = KeyPair vk sk
160162
where
161163
(sk, vk) = mkKeyPair (RawSeed 3 3 3 3 3)
162164

163165
-- | Bob's address
164-
bobAddr :: CC.Crypto c => Addr c
166+
bobAddr :: Crypto c => Addr c
165167
bobAddr = mkAddr (bobPay, bobStake)
166168

167169
-- | Bob's stake credential
168-
bobSHK :: CC.Crypto c => Credential 'Staking c
170+
bobSHK :: Crypto c => Credential 'Staking c
169171
bobSHK = (KeyHashObj . hashKey . vKey) bobStake
170172

171173
-- | Bob's stake pool keys (cold keys, VRF keys, hot KES keys)
172-
bobPoolKeys :: CC.Crypto c => AllIssuerKeys c 'StakePool
174+
bobPoolKeys :: Crypto c => AllIssuerKeys c 'StakePool
173175
bobPoolKeys =
174176
AllIssuerKeys
175177
(KeyPair vkCold skCold)
176178
(mkVRFKeyPair (RawSeed 2 0 0 0 2))
177-
[(KESPeriod 0, mkKESKeyPair (RawSeed 2 0 0 0 3))]
179+
((KESPeriod 0, mkKESKeyPair (RawSeed 2 0 0 0 3)) NE.:| [])
178180
(hashKey vkCold)
179181
where
180182
(skCold, vkCold) = mkKeyPair (RawSeed 2 0 0 0 1)
181183

182184
-- | Bob's stake pool parameters
183-
bobPoolParams :: forall c. CC.Crypto c => PoolParams c
185+
bobPoolParams :: forall c. Crypto c => PoolParams c
184186
bobPoolParams =
185187
PoolParams
186-
{ ppId = (hashKey . vKey . cold) bobPoolKeys
187-
, ppVrf = hashVerKeyVRF . snd $ vrf (bobPoolKeys @c)
188+
{ ppId = hashKey . vKey $ aikCold bobPoolKeys
189+
, ppVrf = hashVerKeyVRF . vrfVerKey $ aikVrf (bobPoolKeys @c)
188190
, ppPledge = Coin 2
189191
, ppCost = Coin 1
190192
, ppMargin = unsafeBoundRational 0.1
191193
, ppRewardAcnt = RewardAcnt Testnet bobSHK
192-
, ppOwners = Set.singleton $ (hashKey . vKey) bobStake
194+
, ppOwners = Set.singleton $ hashKey (vKey bobStake)
193195
, ppRelays = StrictSeq.empty
194196
, ppMetadata = SNothing
195197
}
196198

197199
-- | Bob's VRF key hash
198200
bobVRFKeyHash ::
199201
forall c.
200-
CC.Crypto c =>
202+
Crypto c =>
201203
Hash c (VerKeyVRF c)
202-
bobVRFKeyHash = hashVerKeyVRF (snd $ vrf (bobPoolKeys @c))
204+
bobVRFKeyHash = hashVerKeyVRF (vrfVerKey $ aikVrf (bobPoolKeys @c))
203205

204206
-- Carl's payment key pair
205-
carlPay :: CC.Crypto c => KeyPair 'Payment c
207+
carlPay :: Crypto c => KeyPair 'Payment c
206208
carlPay = KeyPair vk sk
207209
where
208210
(sk, vk) = mkKeyPair (RawSeed 4 4 4 4 4)
209211

210212
-- | Carl's stake key pair
211-
carlStake :: CC.Crypto c => KeyPair 'Staking c
213+
carlStake :: Crypto c => KeyPair 'Staking c
212214
carlStake = KeyPair vk sk
213215
where
214216
(sk, vk) = mkKeyPair (RawSeed 5 5 5 5 5)
215217

216218
-- | Carl's address
217-
carlAddr :: CC.Crypto c => Addr c
219+
carlAddr :: Crypto c => Addr c
218220
carlAddr = mkAddr (carlPay, carlStake)
219221

220222
-- | Carl's stake credential
221-
carlSHK :: CC.Crypto c => Credential 'Staking c
223+
carlSHK :: Crypto c => Credential 'Staking c
222224
carlSHK = (KeyHashObj . hashKey . vKey) carlStake
223225

224226
-- | Daria's payment key pair
225-
dariaPay :: CC.Crypto c => KeyPair 'Payment c
227+
dariaPay :: Crypto c => KeyPair 'Payment c
226228
dariaPay = KeyPair vk sk
227229
where
228230
(sk, vk) = mkKeyPair (RawSeed 6 6 6 6 6)
229231

230232
-- | Daria's stake key pair
231-
dariaStake :: CC.Crypto c => KeyPair 'Staking c
233+
dariaStake :: Crypto c => KeyPair 'Staking c
232234
dariaStake = KeyPair vk sk
233235
where
234236
(sk, vk) = mkKeyPair (RawSeed 7 7 7 7 7)
235237

236238
-- | Daria's address
237-
dariaAddr :: CC.Crypto c => Addr c
239+
dariaAddr :: Crypto c => Addr c
238240
dariaAddr = mkAddr (dariaPay, dariaStake)
239241

240242
-- | Daria's stake credential
241-
dariaSHK :: CC.Crypto c => Credential 'Staking c
243+
dariaSHK :: Crypto c => Credential 'Staking c
242244
dariaSHK = (KeyHashObj . hashKey . vKey) dariaStake

0 commit comments

Comments
 (0)