-
Notifications
You must be signed in to change notification settings - Fork 155
/
BenchmarkFunctions.hs
541 lines (475 loc) · 18.7 KB
/
BenchmarkFunctions.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Test.Cardano.Ledger.Shelley.BenchmarkFunctions (
ledgerSpendOneUTxO,
ledgerSpendOneGivenUTxO,
initUTxO, -- How to precompute env for the UTxO transactions
ledgerEnv,
ledgerRegisterStakeKeys,
ledgerDeRegisterStakeKeys,
ledgerRewardWithdrawals,
ledgerStateWithNregisteredKeys, -- How to precompute env for the StakeKey transactions
ledgerRegisterStakePools,
ledgerReRegisterStakePools,
ledgerRetireStakePools,
ledgerStateWithNregisteredPools, -- How to precompute env for the Stake Pool transactions
ledgerDelegateManyKeysOnePool,
ledgerStateWithNkeysMpools, -- How to precompute env for the Stake Delegation transactions
B, -- Era instance for Benchmarking
B_Crypto, -- Crypto instance for Benchmarking
)
where
import Cardano.Crypto.Hash.Blake2b (Blake2b_256)
import Cardano.Ledger.Address (Addr)
import Cardano.Ledger.BaseTypes (Network (..), StrictMaybe (..), TxIx, mkTxIxPartial)
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Credential (Credential (..))
import Cardano.Ledger.Crypto (Crypto (..))
import Cardano.Ledger.Keys (
Hash,
KeyHash,
KeyRole (..),
VerKeyVRF,
asWitness,
hashKey,
hashVerKeyVRF,
)
import Cardano.Ledger.SafeHash (hashAnnotated)
import Cardano.Ledger.Shelley (ShelleyEra)
import Cardano.Ledger.Shelley.Core
import Cardano.Ledger.Shelley.Delegation.Certificates (DelegCert (..))
import Cardano.Ledger.Shelley.LedgerState (
AccountState (..),
LedgerState (..),
UTxOState (..),
)
import Cardano.Ledger.Shelley.Rules (LedgerEnv (..), ShelleyLEDGER)
import Cardano.Ledger.Shelley.Tx (ShelleyTx (..))
import Cardano.Ledger.Shelley.TxBody (
DCert (..),
Delegation (..),
PoolCert (..),
PoolParams (..),
RewardAcnt (..),
ShelleyTxBody (..),
ShelleyTxOut (..),
ppCost,
ppId,
ppMargin,
ppMetadata,
ppOwners,
ppPledge,
ppRelays,
ppRewardAcnt,
ppVrf,
)
import Cardano.Ledger.Shelley.TxWits (addrWits)
import Cardano.Ledger.Slot (EpochNo (..), SlotNo (..))
import Cardano.Ledger.TxIn (TxIn (..), mkTxInPartial)
import Cardano.Ledger.Val (Val (inject))
import Cardano.Protocol.TPraos.API (PraosCrypto)
import Control.State.Transition.Extended (TRC (..), applySTS)
import Data.Default.Class (def)
import qualified Data.Map.Strict as Map
import Data.Sequence.Strict (StrictSeq)
import qualified Data.Sequence.Strict as StrictSeq
import qualified Data.Set as Set
import Data.Word (Word64)
import GHC.Stack
import Lens.Micro ((&), (.~))
import Test.Cardano.Ledger.Core.KeyPair (KeyPair (..), mkAddr, mkWitnessesVKey, vKey)
import qualified Test.Cardano.Ledger.Shelley.ConcreteCryptoTypes as Original (
C_Crypto,
)
import Test.Cardano.Ledger.Shelley.Generator.Core (
genesisCoins,
)
import Test.Cardano.Ledger.Shelley.Generator.EraGen (genesisId)
import Test.Cardano.Ledger.Shelley.Generator.ShelleyEraGen ()
import Test.Cardano.Ledger.Shelley.Utils (
RawSeed (..),
mkKeyPair,
mkKeyPair',
mkVRFKeyPair,
runShelleyBase,
unsafeBoundRational,
)
-- ===============================================
-- A special Era to run the Benchmarks in
type B = ShelleyEra B_Crypto
data B_Crypto
instance Cardano.Ledger.Crypto.Crypto B_Crypto where
type KES B_Crypto = KES Original.C_Crypto
type VRF B_Crypto = VRF Original.C_Crypto
type DSIGN B_Crypto = DSIGN Original.C_Crypto
type HASH B_Crypto = Blake2b_256
type ADDRHASH B_Crypto = Blake2b_256
instance PraosCrypto B_Crypto
-- =========================================================
aliceStake :: KeyPair 'Staking B_Crypto
aliceStake = KeyPair vk sk
where
(sk, vk) = mkKeyPair (RawSeed 0 0 0 0 1)
alicePay :: KeyPair 'Payment B_Crypto
alicePay = KeyPair vk sk
where
(sk, vk) = mkKeyPair (RawSeed 0 0 0 0 0)
aliceAddr :: Addr B_Crypto
aliceAddr = mkAddr (alicePay, aliceStake)
-- ==========================================================
injcoins :: Integer -> [ShelleyTxOut B]
injcoins n = fmap (\_ -> ShelleyTxOut aliceAddr (inject $ Coin 100)) [0 .. n]
-- Cretae an initial UTxO set with n-many transaction outputs
initUTxO :: Integer -> UTxOState B
initUTxO n =
UTxOState
(genesisCoins genesisId (injcoins n))
(Coin 0)
(Coin 0)
def
mempty
-- Protocal Parameters used for the benchmarknig tests.
-- Note that the fees and deposits are set to zero for
-- ease of creating transactions.
ppsBench :: (EraPParams era, ProtVerAtMost era 4, ProtVerAtMost era 6) => PParams era
ppsBench =
emptyPParams
& ppMaxBBSizeL .~ 50000
& ppDL .~ unsafeBoundRational 0.5
& ppEMaxL .~ EpochNo 10000
& ppKeyDepositL .~ Coin 0
& ppMaxBHSizeL .~ 10000
& ppMaxTxSizeL .~ 1000000000
& ppMinFeeAL .~ Coin 0
& ppMinFeeBL .~ Coin 0
& ppMinUTxOValueL .~ Coin 10
& ppPoolDepositL .~ Coin 0
& ppRhoL .~ unsafeBoundRational 0.0021
& ppTauL .~ unsafeBoundRational 0.2
ledgerEnv :: (EraPParams era, ProtVerAtMost era 4, ProtVerAtMost era 6) => LedgerEnv era
ledgerEnv = LedgerEnv (SlotNo 0) minBound ppsBench (AccountState (Coin 0) (Coin 0))
testLEDGER ::
LedgerState B ->
ShelleyTx B ->
LedgerEnv B ->
()
testLEDGER initSt tx env = do
let st = runShelleyBase $ applySTS @(ShelleyLEDGER B) (TRC (env, initSt, tx))
case st of
Right _ -> ()
Left e -> error $ show e
txbSpendOneUTxO :: ShelleyTxBody B
txbSpendOneUTxO =
ShelleyTxBody
(Set.fromList [TxIn genesisId minBound])
( StrictSeq.fromList
[ ShelleyTxOut aliceAddr (inject $ Coin 10)
, ShelleyTxOut aliceAddr (inject $ Coin 89)
]
)
StrictSeq.empty
(Withdrawals Map.empty)
(Coin 1)
(SlotNo 10)
SNothing
SNothing
txSpendOneUTxO :: ShelleyTx B
txSpendOneUTxO =
ShelleyTx
txbSpendOneUTxO
mempty
{ addrWits = mkWitnessesVKey (hashAnnotated txbSpendOneUTxO) [asWitness alicePay]
}
SNothing
ledgerSpendOneUTxO :: Integer -> ()
ledgerSpendOneUTxO n = testLEDGER (initLedgerState n) txSpendOneUTxO ledgerEnv
ledgerSpendOneGivenUTxO :: UTxOState B -> ()
ledgerSpendOneGivenUTxO state = testLEDGER (LedgerState state def) txSpendOneUTxO ledgerEnv
-- ===========================================================================
--
-- Register a stake keys when there are a lot of registered stake keys
--
-- Create stake key pairs, corresponding to seeds
-- (RawSeed start 0 0 0 0) through (RawSeed end 0 0 0 0)
stakeKeys :: Word64 -> Word64 -> [KeyPair 'Staking B_Crypto]
stakeKeys start end = fmap (\w -> mkKeyPair' (RawSeed w 0 0 0 0)) [start .. end]
stakeKeyOne :: KeyPair 'Staking B_Crypto
stakeKeyOne = mkKeyPair' (RawSeed 1 0 0 0 0)
stakeKeyToCred :: KeyPair 'Staking B_Crypto -> Credential 'Staking B_Crypto
stakeKeyToCred = KeyHashObj . hashKey . vKey
firstStakeKeyCred :: Credential 'Staking B_Crypto
firstStakeKeyCred = stakeKeyToCred stakeKeyOne
-- Create stake key registration certificates
stakeKeyRegistrations :: [KeyPair 'Staking B_Crypto] -> StrictSeq (DCert B_Crypto)
stakeKeyRegistrations keys =
StrictSeq.fromList $
fmap (DCertDeleg . RegKey . (KeyHashObj . hashKey . vKey)) keys
-- Create a transaction body given a sequence of certificates.
-- It spends the genesis coin given by the index ix.
txbFromCerts :: TxIx -> StrictSeq (DCert B_Crypto) -> ShelleyTxBody B
txbFromCerts ix regCerts =
ShelleyTxBody
(Set.fromList [TxIn genesisId ix])
(StrictSeq.fromList [ShelleyTxOut aliceAddr (inject $ Coin 100)])
regCerts
(Withdrawals Map.empty)
(Coin 0)
(SlotNo 10)
SNothing
SNothing
makeSimpleTx ::
ShelleyTxBody B ->
[KeyPair 'Witness B_Crypto] ->
ShelleyTx B
makeSimpleTx txbody keysAddr =
ShelleyTx
txbody
mempty
{ addrWits = mkWitnessesVKey (hashAnnotated txbody) keysAddr
}
SNothing
-- Create a transaction that registers stake credentials.
txRegStakeKeys :: TxIx -> [KeyPair 'Staking B_Crypto] -> ShelleyTx B
txRegStakeKeys ix keys =
makeSimpleTx
(txbFromCerts ix $ stakeKeyRegistrations keys)
[asWitness alicePay]
initLedgerState :: Integer -> LedgerState B
initLedgerState n = LedgerState (initUTxO n) def
makeLEDGERState :: HasCallStack => LedgerState B -> ShelleyTx B -> LedgerState B
makeLEDGERState start tx =
let st = applySTS @(ShelleyLEDGER B) (TRC (ledgerEnv, start, tx))
in case runShelleyBase st of
Right st' -> st'
Left e -> error $ show e
-- Create a ledger state that has registered stake credentials that
-- are seeded with (RawSeed n 0 0 0 0) to (RawSeed m 0 0 0 0).
-- It is pre-populated with 2 genesis injcoins.
ledgerStateWithNregisteredKeys :: Word64 -> Word64 -> LedgerState B
ledgerStateWithNregisteredKeys n m =
makeLEDGERState (initLedgerState 1) $ txRegStakeKeys minBound (stakeKeys n m)
-- ===========================================================
-- Stake Key Registration example
-- Given a ledger state, presumably created by ledgerStateWithNregisteredKeys n m,
-- so that keys (RawSeed n 0 0 0 0) through (RawSeed m 0 0 0 0) are already registered,
-- register new keys (RawSeed x 0 0 0 0) through (RawSeed y 0 0 0 0).
-- Note that [n, m] must be disjoint from [x, y].
ledgerRegisterStakeKeys :: Word64 -> Word64 -> LedgerState B -> ()
ledgerRegisterStakeKeys x y state =
testLEDGER
state
(txRegStakeKeys (mkTxIxPartial 1) (stakeKeys x y))
ledgerEnv
-- ===========================================================
-- Deregistration example
-- Create a transaction body that de-registers stake credentials,
-- corresponding to the keys seeded with (RawSeed x 0 0 0 0) to (RawSeed y 0 0 0 0)
txbDeRegStakeKey :: Word64 -> Word64 -> ShelleyTxBody B
txbDeRegStakeKey x y =
ShelleyTxBody
(Set.fromList [mkTxInPartial genesisId 1])
(StrictSeq.fromList [ShelleyTxOut aliceAddr (inject $ Coin 100)])
( StrictSeq.fromList $
fmap (DCertDeleg . DeRegKey . stakeKeyToCred) (stakeKeys x y)
)
(Withdrawals Map.empty)
(Coin 0)
(SlotNo 10)
SNothing
SNothing
-- Create a transaction that deregisters stake credentials numbered x through y.
-- It spends the genesis coin indexed by 1.
txDeRegStakeKeys :: Word64 -> Word64 -> ShelleyTx B
txDeRegStakeKeys x y =
makeSimpleTx
(txbDeRegStakeKey x y)
(asWitness alicePay : fmap asWitness (stakeKeys x y))
-- Given a ledger state, presumably created by ledgerStateWithNregisteredKeys n m,
-- so that keys (RawSeed n 0 0 0 0) through (RawSeed m 0 0 0 0) are already registered,
-- deregister keys (RawSeed x 0 0 0 0) through (RawSeed y 0 0 0 0).
-- Note that [x, y] must be contained in [n, m].
ledgerDeRegisterStakeKeys :: Word64 -> Word64 -> LedgerState B -> ()
ledgerDeRegisterStakeKeys x y state =
testLEDGER
state
(txDeRegStakeKeys x y)
ledgerEnv
-- ===========================================================
-- Reward Withdrawal example
-- Create a transaction body that withdrawals from reward accounts,
-- corresponding to the keys seeded with (RawSeed x 0 0 0 0) to (RawSeed y 0 0 0 0).
txbWithdrawals :: Word64 -> Word64 -> ShelleyTxBody B
txbWithdrawals x y =
ShelleyTxBody
(Set.fromList [mkTxInPartial genesisId 1])
(StrictSeq.fromList [ShelleyTxOut aliceAddr (inject $ Coin 100)])
StrictSeq.empty
( Withdrawals $
Map.fromList $
fmap (\ks -> (RewardAcnt Testnet (stakeKeyToCred ks), Coin 0)) (stakeKeys x y)
)
(Coin 0)
(SlotNo 10)
SNothing
SNothing
-- Create a transaction that withdrawals from a reward accounts.
-- It spends the genesis coin indexed by 1.
txWithdrawals :: Word64 -> Word64 -> ShelleyTx B
txWithdrawals x y =
makeSimpleTx
(txbWithdrawals x y)
(asWitness alicePay : fmap asWitness (stakeKeys x y))
-- Given a ledger state, presumably created by ledgerStateWithNregisteredKeys n m,
-- so that keys (RawSeed n 0 0 0 0) through (RawSeed m 0 0 0 0) are already registered,
-- make reward withdrawals for keys (RawSeed x 0 0 0 0) through (RawSeed y 0 0 0 0).
-- Note that [x, y] must be contained in [n, m].
ledgerRewardWithdrawals :: Word64 -> Word64 -> LedgerState B -> ()
ledgerRewardWithdrawals x y state = testLEDGER state (txWithdrawals x y) ledgerEnv
-- ===========================================================================
--
-- Register a stake pool when there are a lot of registered stake pool
--
-- Create stake pool key pairs, corresponding to seeds
-- (RawSeed start 0 0 0 0) through (RawSeed end 0 0 0 0)
poolColdKeys :: Word64 -> Word64 -> [KeyPair 'StakePool B_Crypto]
poolColdKeys start end = fmap (\w -> mkKeyPair' (RawSeed w 1 0 0 0)) [start .. end]
firstStakePool :: KeyPair 'StakePool B_Crypto
firstStakePool = mkKeyPair' (RawSeed 1 1 0 0 0)
mkPoolKeyHash :: KeyPair 'StakePool B_Crypto -> KeyHash 'StakePool B_Crypto
mkPoolKeyHash = hashKey . vKey
firstStakePoolKeyHash :: KeyHash 'StakePool B_Crypto
firstStakePoolKeyHash = mkPoolKeyHash firstStakePool
vrfKeyHash :: Hash B_Crypto (VerKeyVRF B_Crypto)
vrfKeyHash = hashVerKeyVRF . snd . mkVRFKeyPair $ RawSeed 0 0 0 0 0
mkPoolParameters :: KeyPair 'StakePool B_Crypto -> PoolParams B_Crypto
mkPoolParameters keys =
PoolParams
{ ppId = (hashKey . vKey) keys
, ppVrf = vrfKeyHash
, ppPledge = Coin 0
, ppCost = Coin 0
, ppMargin = unsafeBoundRational 0
, ppRewardAcnt = RewardAcnt Testnet firstStakeKeyCred
, ppOwners = Set.singleton $ (hashKey . vKey) stakeKeyOne
, ppRelays = StrictSeq.empty
, ppMetadata = SNothing
}
-- Create stake pool registration certs
poolRegCerts :: [KeyPair 'StakePool B_Crypto] -> StrictSeq (DCert B_Crypto)
poolRegCerts = StrictSeq.fromList . fmap (DCertPool . RegPool . mkPoolParameters)
-- Create a transaction that registers stake pools.
txRegStakePools :: TxIx -> [KeyPair 'StakePool B_Crypto] -> ShelleyTx B
txRegStakePools ix keys =
makeSimpleTx
(txbFromCerts ix $ poolRegCerts keys)
([asWitness alicePay, asWitness stakeKeyOne] ++ fmap asWitness keys)
-- Create a ledger state that has n registered stake pools.
-- The keys are seeded with (RawSeed n 1 0 0 0) to (RawSeed m 1 0 0 0)
-- It is pre-populated with 2 genesis injcoins.
ledgerStateWithNregisteredPools :: Word64 -> Word64 -> LedgerState B
ledgerStateWithNregisteredPools n m =
makeLEDGERState (initLedgerState 1) $ txRegStakePools minBound (poolColdKeys n m)
-- ===========================================================
-- Stake Pool Registration example
-- Given a ledger state, presumably created by ledgerStateWithNregisteredPools n m,
-- so that pool keys (RawSeed n 1 0 0 0) through (RawSeed m 1 0 0 0) are already registered,
-- register new pools (RawSeed x 0 0 0 0) through (RawSeed y 0 0 0 0).
-- Note that [n, m] must be disjoint from [x, y].
ledgerRegisterStakePools :: Word64 -> Word64 -> LedgerState B -> ()
ledgerRegisterStakePools x y state =
testLEDGER
state
(txRegStakePools (mkTxIxPartial 1) (poolColdKeys x y))
ledgerEnv
-- ===========================================================
-- Stake Pool Re-Registration/Update example
-- Given a ledger state, presumably created by ledgerStateWithNregisteredPools n m,
-- so that pool keys (RawSeed n 1 0 0 0) through (RawSeed m 1 0 0 0) are already registered,
-- re-register pools (RawSeed x 0 0 0 0) through (RawSeed y 0 0 0 0).
-- Note that [n, m] must be contained in [x, y].
ledgerReRegisterStakePools :: Word64 -> Word64 -> LedgerState B -> ()
ledgerReRegisterStakePools x y state =
testLEDGER
state
(txRegStakePools (mkTxIxPartial 1) (poolColdKeys x y))
ledgerEnv
-- ===========================================================
-- Stake Pool Retirement example
-- Create a transaction body that retires stake pools,
-- corresponding to the keys seeded with (RawSeed x 1 0 0 0) to (RawSeed y 1 0 0 0)
txbRetireStakePool :: Word64 -> Word64 -> ShelleyTxBody B
txbRetireStakePool x y =
ShelleyTxBody
(Set.fromList [mkTxInPartial genesisId 1])
(StrictSeq.fromList [ShelleyTxOut aliceAddr (inject $ Coin 100)])
( StrictSeq.fromList $
fmap
(\ks -> DCertPool $ RetirePool (mkPoolKeyHash ks) (EpochNo 1))
(poolColdKeys x y)
)
(Withdrawals Map.empty)
(Coin 0)
(SlotNo 10)
SNothing
SNothing
-- Create a transaction that retires stake pools x through y.
-- It spends the genesis coin indexed by 1.
txRetireStakePool :: Word64 -> Word64 -> ShelleyTx B
txRetireStakePool x y =
makeSimpleTx
(txbRetireStakePool x y)
(asWitness alicePay : fmap asWitness (poolColdKeys x y))
-- Given a ledger state, presumably created by ledgerStateWithNregisteredPools n m,
-- so that pool keys (RawSeed n 1 0 0 0) through (RawSeed m 1 0 0 0) are already registered,
-- retire pools (RawSeed x 0 0 0 0) through (RawSeed y 0 0 0 0).
-- Note that [n, m] must be contained in [x, y].
ledgerRetireStakePools :: Word64 -> Word64 -> LedgerState B -> ()
ledgerRetireStakePools x y state = testLEDGER state (txRetireStakePool x y) ledgerEnv
-- ===========================================================================
--
-- Delegate Stake Credentials when many stake keys and stake pools are registered.
--
-- Create a ledger state that has n registered stake keys and m stake pools.
-- The stake keys are seeded with (RawSeed 1 0 0 0 0) to (RawSeed n 0 0 0 0)
-- The stake pools are seeded with (RawSeed 1 1 0 0 0) to (RawSeed m 1 0 0 0)
-- It is pre-populated with 3 genesis injcoins.
ledgerStateWithNkeysMpools :: Word64 -> Word64 -> LedgerState B
ledgerStateWithNkeysMpools n m =
makeLEDGERState
(makeLEDGERState (initLedgerState 2) $ txRegStakeKeys minBound (stakeKeys 1 n))
(txRegStakePools (mkTxIxPartial 1) (poolColdKeys 1 m))
-- Create a transaction body that delegates several keys to ONE stake pool,
-- corresponding to the keys seeded with (RawSeed n 0 0 0 0) to (RawSeed m 0 0 0 0)
txbDelegate :: Word64 -> Word64 -> ShelleyTxBody B
txbDelegate n m =
ShelleyTxBody
(Set.fromList [mkTxInPartial genesisId 2])
(StrictSeq.fromList [ShelleyTxOut aliceAddr (inject $ Coin 100)])
( StrictSeq.fromList $
fmap
(\ks -> DCertDeleg $ Delegate (Delegation (stakeKeyToCred ks) firstStakePoolKeyHash))
(stakeKeys n m)
)
(Withdrawals Map.empty)
(Coin 0)
(SlotNo 10)
SNothing
SNothing
-- Create a transaction that delegates stake.
txDelegate :: Word64 -> Word64 -> ShelleyTx B
txDelegate n m =
makeSimpleTx
(txbDelegate n m)
(asWitness alicePay : fmap asWitness (stakeKeys n m))
-- Given a ledger state, presumably created by ledgerStateWithNkeysMpools n m,
-- so that stake keys (RawSeed 1 0 0 0 0) through (RawSeed n 0 0 0 0) are already registered
-- and pool keys (RawSeed 1 1 0 0 0) through (RawSeed m 1 0 0 0) are already registered,
-- delegate stake keys (RawSeed x 0 0 0 0) through (RawSeed y 0 0 0 0) to ONE pool.
-- Note that [x, y] must be contained in [1, n].
ledgerDelegateManyKeysOnePool :: Word64 -> Word64 -> LedgerState B -> ()
ledgerDelegateManyKeysOnePool x y state = testLEDGER state (txDelegate x y) ledgerEnv