-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpoolLeaderLogs.py
550 lines (471 loc) · 23.4 KB
/
poolLeaderLogs.py
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
542
543
544
545
546
547
548
549
550
#!/bin/env python3
import requests
import urllib.request
from urllib.request import urlopen
import math
import binascii
import json
import pytz
import hashlib
import re
import readchar
from ctypes import *
from os import system, path
from datetime import datetime, timezone
from sys import exit, platform
### ADA Unicode symbol, Percent and Lovelaces ###
ada = " \u20B3"
lovelaces = 1000000
percent = " %"
### Def Colors ###
class col:
red = '\033[31m'
green = '\033[92m'
endcl = '\033[0m'
### Clear Screen ###
def ClearScreen():
command ='clear'
system(command)
### Loading Data Message ###
ClearScreen()
print()
print(col.green + f'Loading Data from Koios...')
print()
### Set your own timezone -----------------------------------------###
### Example: local_tz = pytz.timezone('Europe/Berlin') ###
local_tz = pytz.timezone('/')
### Set These Variables ###
PoolId = ""
PoolIdBech = ""
PoolTicker = ""
VrfKeyFile = '<PATH_TO>/vrf.skey'
### Example:
# PoolId = "342350284fd76ba9dbd7fd4ed579b2a2058d5ee558f8872b37817b28"
# PoolIdBech = "pool1xs34q2z06a46nk7hl48d27dj5gzc6hh9trugw2ehs9ajsevqffx"
# PoolTicker = "SNAKE"
# VrfKeyFile = '/home/user/cardano/vrf.skey'
### Koios Headers and BaseURL ###
# Uncomment this and comment koiosHeaders on line 62 if you use Koios Auth Token
# koiosToken = "yourKoiosAuthToken"
# koiosHeaders = { 'Accept': 'application/json', 'Authorization': f'Bearer {koiosToken}' }
### Koios Headers and BaseURL ###
koiosHeaders = {'content-type': 'application/json'}
koiosBaseUrl = "https://api.koios.rest/api/v0/"
### Current Current Epoch, Epoch Slot and Total Epoch Slots ###
koiosTipUrl = koiosBaseUrl+"tip"
request = urllib.request.Request(koiosTipUrl, headers=koiosHeaders)
response = urllib.request.urlopen(request).read()
tipData = json.loads(response.decode('utf-8'))
epoch = int(tipData[0]['epoch_no'])
epochSlot = int(tipData[0]['epoch_slot'])
epochSlotFormat = "{:,}".format(epochSlot)
### Genesis Info ###
koiosGenesisUrl = koiosBaseUrl+"genesis"
request = urllib.request.Request(koiosGenesisUrl, headers=koiosHeaders)
response = urllib.request.urlopen(request).read()
genesisData = json.loads(response.decode('utf-8'))
epochLength = int(genesisData[0]['epochlength'])
slotLength = int(genesisData[0]['slotlength'])
remainingSlots = epochLength - epochSlot
remainingSlots = "{:,}".format(remainingSlots)
### Network Active Stake ###
koiosEpochInfoUrl = koiosBaseUrl+"epoch_info?_epoch_no="+str(epoch)
request = urllib.request.Request(koiosEpochInfoUrl, headers=koiosHeaders)
response = urllib.request.urlopen(request).read()
epochInfoData = json.loads(response.decode('utf-8'))
nStake = int(epochInfoData[0]['active_stake'])
nStakeToFormat = math.trunc(int(nStake) / lovelaces)
nStakeFormat = "{:,}".format(nStakeToFormat)
#nStakePerf = nStakeFormat
### Current Epoch Nonce ###
koiosEpochParamUrl = koiosBaseUrl+"epoch_params?_epoch_no="+str(epoch)
request = urllib.request.Request(koiosEpochParamUrl, headers=koiosHeaders)
response = urllib.request.urlopen(request).read()
epochParamData = json.loads(response.decode('utf-8'))
eta0 = epochParamData[0]['nonce']
### Pool Stats ###
poolInfoUrl = koiosBaseUrl+"pool_info"
poolPostData = {"_pool_bech32_ids":[PoolIdBech]}
poolinfo = requests.post(poolInfoUrl, data=json.dumps(poolPostData))
poolinfo = poolinfo.text
poolinfo = json.loads(poolinfo)
poolPledge = int(poolinfo[0]['pledge']) / lovelaces
poolPledge = math.trunc(poolPledge)
poolPledge = "{:,}".format(poolPledge)
poolMargin = poolinfo[0]['margin']
poolFixedCost = int(poolinfo[0]['fixed_cost']) / lovelaces
poolFixedCost = math.trunc(poolFixedCost)
poolDelegators = poolinfo[0]['live_delegators']
blocksLifetime = poolinfo[0]['block_count']
poolSaturation = poolinfo[0]['live_saturation']
poolLiveStake = int(poolinfo[0]['live_stake']) / lovelaces
poolLiveStake = math.trunc(poolLiveStake)
poolLiveStake = "{:,}".format(poolLiveStake)
pStake = int(poolinfo[0]['active_stake'])
pStakeInt = int(poolinfo[0]['active_stake']) / lovelaces
poolActiveStake = math.trunc(pStakeInt)
poolActiveStake = "{:,}".format(poolActiveStake)
pStakePerf = poolActiveStake
sigma = poolinfo[0]['sigma']
### Other Pool Stats from cexplorer.io ###
PoolIdBechStr = PoolIdBech+".json"
cexplorer_headers = {'content-type': 'application/json', 'User-Agent': 'Mozilla/5.0'}
poolUrl = "https://js.cexplorer.io/api-static/pool/"+PoolIdBechStr
request = urllib.request.Request(poolUrl, headers=cexplorer_headers)
response = urllib.request.urlopen(request).read()
poolDat = json.loads(response.decode('utf-8'))
luckLifetime = float(poolDat['data']['luck_lifetime']) * 100
luckLifetime = round(luckLifetime,2)
roaShort = float(poolDat['data']['roa_short'])
roaShort = round(roaShort, 1)
roaLifetime = (poolDat['data']['roa_lifetime'])
poolRanking = (poolDat['data']['position'])
### Global Cardano Stats from cexplorer.io ###
statsUrl = "https://js.cexplorer.io/api-static/basic/global.json"
request = urllib.request.Request(statsUrl, headers=cexplorer_headers)
response = urllib.request.urlopen(request).read()
statsDat = json.loads(response.decode('utf-8'))
circSupply = int(statsDat['data']['supply']['now'] / lovelaces)
circSupplyFormat = "{:,}".format(circSupply)
stakePools = int(statsDat['data']['stats']['pools'])
stakePools = "{:,}".format(stakePools)
delegators = int(statsDat['data']['stats']['delegators'])
delegators = "{:,}".format(delegators)
stakedPercent = (nStakeToFormat * 100 / circSupply)
stakedPercent = str(round(stakedPercent, 2))
### Next Epoch Nonce, Next Pool Sigma and Next Pool Active Stake ###
koiosPoolSnapshotUrl = koiosBaseUrl+"pool_stake_snapshot?_pool_bech32="+PoolIdBech
request = urllib.request.Request(koiosPoolSnapshotUrl, headers=koiosHeaders)
response = urllib.request.urlopen(request).read()
poolStakeSnapData = json.loads(response.decode('utf-8'))
nextEpochNonce = str(poolStakeSnapData[2]['nonce'])
nextPoolActiveStake = (poolStakeSnapData[2]['pool_stake'])
nextPoolActiveStakeFormat = int(nextPoolActiveStake) / lovelaces
nextPoolActiveStakeFormat = math.trunc(nextPoolActiveStakeFormat)
nextPoolActiveStakeFormat = "{:,}".format(nextPoolActiveStakeFormat)
nextNetActiveStake = (poolStakeSnapData[2]['active_stake'])
nextNetActiveStakeFormat = int(nextNetActiveStake) / lovelaces
nextNetActiveStakeFormat = math.trunc(nextNetActiveStakeFormat)
nextNetActiveStakeFormat = "{:,}".format(nextNetActiveStakeFormat)
nextPoolSigma = int(nextPoolActiveStake) / int(nextNetActiveStake)
### Pool Estimated Blocks ###
koiosGenesisUrl = koiosBaseUrl+"genesis"
request = urllib.request.Request(koiosGenesisUrl, headers=koiosHeaders)
response = urllib.request.urlopen(request).read()
networkGenesisData = json.loads(response.decode('utf-8'))
epochlength = int(networkGenesisData[0]['epochlength'])
activeSlotCoeff = float(networkGenesisData[0]['activeslotcoeff'])
blocksInEpoch = math.trunc(epochlength * activeSlotCoeff)
nextPoolActiveInt = int(nextPoolActiveStake) / lovelaces
nextNetActiveInt = int(nextNetActiveStake) / lovelaces
blocksEstimated = int(blocksInEpoch * nextPoolActiveInt) / (nextNetActiveInt)
blocksEstimated = round(blocksEstimated,2)
### User Prompt ###
ClearScreen()
print()
print(col.green + f'Leader Logs Checker for Cardano SPOs. ')
print()
print(col.green + f'Check Scheduled Blocks in Next, Current and Previous Epochs.')
print(col.endcl)
print(col.endcl)
print(col.green + f'Current Cardano Epoch ' + col.endcl +str(epoch))
print(col.green + f'Epoch Slot ' + col.endcl +str(epochSlotFormat))
print(col.green + f'Remaining Slots ' + col.endcl +str(remainingSlots))
print(col.endcl)
print(col.green + f'Circulating Supply ' + col.endcl +str(circSupplyFormat) +str(ada))
print(col.green + f'Total Staked ' + col.endcl +str(nStakeFormat) +str(ada))
print(col.green + f'Staked percent ' + col.endcl +str(stakedPercent) +str(percent))
print(col.endcl)
print(col.green + f'Stakepools ' + col.endcl +str(stakePools))
print(col.green + f'Delegators ' + col.endcl +str(delegators))
print(col.endcl)
print(col.endcl)
### newEpochNonce Availability ###
if epochSlot >= 302400:
epochNonce = print(col.green + f'New epochNonce Available' + col.endcl)
print()
if epochSlot < 302400:
epochNonce = print(col.red + f'New epochNonce Not Available' + col.endcl)
print()
print(f'(n) to Check Next Epoch Leader Logs')
print(col.endcl)
print(f'(c) to Check Current Epoch Leader Logs')
print(col.endcl)
print(f'(p) to Check Previous Epochs Leader Logs')
print(col.endcl)
print(f'(any other key) to Exit')
### Read Keyboard keys ###
key = readchar.readkey()
if(key == 'n'):
ClearScreen()
epoch = int(epoch + 1)
### Check Next Epoch Leader Logs ###
### Koios new epoch nonce available at 09:50am UTC on fourth epoch day.
### 36 hours before epoch end.
### from https://api.koios.rest/api/v1/pool_stake_snapshot
### we update "epochSlot >= 302400:" to epochSlot >= 302700:
if epochSlot >= 302700:
eta0 = nextEpochNonce
sigma = nextPoolSigma
pStake = int(nextPoolActiveStake)
nStake = int(nextNetActiveStake)
### Message ###
print()
print(f'Checking Leader Logs for Stakepool: ' + (col.green + PoolTicker + col.endcl))
print()
print(f'Pool Id: ' + (col.green + PoolId + col.endcl))
print()
print(f' Live Stake: ' + (col.green + poolLiveStake + col.endcl) + ada)
print(f' Active Stake: ' + (col.green + nextPoolActiveStakeFormat + col.endcl) + ada)
print(f' Pledge: ' + (col.green + poolPledge + col.endcl) + ada)
print(f' Pool Margin: ' + (col.green + str(poolMargin) + col.endcl) + percent)
print(f' Pool FixedCost: ' + (col.green + str(poolFixedCost) + col.endcl) + ada)
print(f' Delegators: ' + (col.green + str(poolDelegators) + col.endcl))
print(f' Estimated Blocks: ' + (col.green + str(blocksEstimated) + col.endcl))
print(f' Lifetime Blocks: ' + (col.green + str(blocksLifetime) + col.endcl))
print()
print(f'Next Epoch: ' + col.green + str(epoch) + col.endcl)
print()
print(f'Nonce: ' + col.green + str(eta0) + col.endcl)
print()
print(f'Network Active Stake in Epoch ' + str(epoch) + ": " + col.green + str(nextNetActiveStakeFormat) + col.endcl + ada + col.endcl)
print()
print(f'Pool Active Stake in Epoch ' + str(epoch) + ": " + col.green + str(nextPoolActiveStakeFormat) + col.endcl + ada + col.endcl)
print()
if epochSlot < 302700:
print()
print(f'New epochNonce Not Yet Available for Epoch: ' + str(epoch))
print()
print(f'Please come back at epochSlot 302700.')
print()
print(f'Current epochSlot '+ str(epochSlot) + '.')
print()
exit()
### Check Current Epoch Leader Logs ###
if(key == 'c'):
ClearScreen()
### Message ###
print()
print(f'Checking Leader Logs for Stakepool: ' + (col.green + PoolTicker + col.endcl))
print()
print(f'Pool Id: ' + (col.green + PoolId + col.endcl))
print()
print(f' Live Stake: ' + (col.green + poolLiveStake + col.endcl) + ada)
print(f' Active Stake: ' + (col.green + poolActiveStake + col.endcl) + ada)
print(f' Pledge: ' + (col.green + poolPledge + col.endcl) + ada)
print(f' Pool Margin: ' + (col.green + str(poolMargin) + col.endcl) + percent)
print(f' Pool FixedCost: ' + (col.green + str(poolFixedCost) + col.endcl) + ada)
print(f' Estimated Blocks: ' + (col.green + str(blocksEstimated) + col.endcl))
print(f' Delegators: ' + (col.green + str(poolDelegators) + col.endcl))
print(f' Lifetime Blocks: ' + (col.green + str(blocksLifetime) + col.endcl))
print(f' Lifetime Luck: ' + (col.green + str(luckLifetime) + col.endcl) + percent)
print(f' Last Roa: ' + (col.green + str(roaShort) + col.endcl) + percent)
print(f' Lifetime Roa: ' + (col.green + roaLifetime + col.endcl) + percent)
print(f' Saturation: ' + (col.green + str(poolSaturation) + col.endcl) + percent)
print(f' Rank: ' + (col.green + poolRanking + col.endcl))
print()
print(f'Epoch: ' + col.green + str(epoch) + col.endcl)
print()
print(f'Nonce: ' + col.green + str(eta0) + col.endcl)
print()
print(f'Network Active Stake in Epoch ' + str(epoch) + ": " + col.green + str(nStakeFormat) + col.endcl + ada + col.endcl)
print()
print(f'Pool Active Stake in Epoch ' + str(epoch) + ": " + col.green + str(poolActiveStake) + col.endcl + ada + col.endcl)
print()
### Check Previous Epochs Leader Logs ###
if(key == 'p'):
ClearScreen()
print()
Epoch = input("Enter Previous Epoch Number: " + col.green)
print(col.endcl)
### Historical Network and Pool Data ###
histEpochParamsUrl = koiosBaseUrl+"epoch_params?_epoch_no="+Epoch
request = urllib.request.Request(histEpochParamsUrl, headers=koiosHeaders)
response = urllib.request.urlopen(request).read()
histEpochParamsData = json.loads(response.decode('utf-8'))
epoch = histEpochParamsData[0]['epoch_no']
eta0 = histEpochParamsData[0]['nonce']
histNetEpochInfoUrl = koiosBaseUrl+"epoch_info?_epoch_no="+Epoch
request = urllib.request.Request(histNetEpochInfoUrl, headers=koiosHeaders)
response = urllib.request.urlopen(request).read()
histNetEpochInfoData = json.loads(response.decode('utf-8'))
nStake = int(histNetEpochInfoData[0]['active_stake'])
nStakeInt = int(histNetEpochInfoData[0]['active_stake']) / lovelaces
nStakeFormat = math.trunc(nStakeInt)
nStakeFormat = "{:,}".format(nStakeFormat)
histPoolEpochInfoUrl = koiosBaseUrl+"pool_history?_pool_bech32="+PoolIdBech+"&_epoch_no="+Epoch
request = urllib.request.Request(histPoolEpochInfoUrl, headers=koiosHeaders)
response = urllib.request.urlopen(request).read()
histPoolEpochInfoData = json.loads(response.decode('utf-8'))
pStake = int(histPoolEpochInfoData[0]['active_stake'])
pStakeInt = int(histPoolEpochInfoData[0]['active_stake']) / lovelaces
poolActiveStake = math.trunc(pStakeInt)
poolActiveStake = "{:,}".format(poolActiveStake)
sigma = pStake / nStake
### Message ###
print(f'Checking Leader Logs for Stakepool: ' + (col.green + PoolTicker + col.endcl))
print()
print(f'Pool Id: ' + (col.green + PoolId + col.endcl))
print()
print(f'Epoch: ' + col.green + Epoch + col.endcl)
print()
print(f'Nonce: ' + col.green + str(eta0) + col.endcl)
print()
print(f'Network Active Stake in Epoch ' + Epoch + ": " + col.green + str(nStakeFormat) + col.endcl + ada + col.endcl)
print()
print(f'Pool Active Stake in Epoch ' + Epoch + ": " + col.green + str(poolActiveStake) + col.endcl + ada + col.endcl)
print()
### ######################################### ###
if(key != 'n') and (key != 'c') and (key != 'p'):
ClearScreen()
exit(0)
### Leader Logs Computation: ###
# https://github.com/papacarp/pooltool.io/blob/master/leaderLogs/leaderLogs.py
# leader logs proof of concept - all credit goes to
# @andrewwestberg of BCSH
# @AC8998 (Antonio) of CSP
# @iiLap (Pal Dorogi) of UNDR
# for the algo extraction from cardano-node
### Opening vrf.skey file ####
with open(VrfKeyFile) as f:
skey = json.load(f)
pool_vrf_skey = skey['cborHex'][4:]
### Load libsodium library from /usr/local/lib/ ###
libsodium = cdll.LoadLibrary("/usr/local/lib/libsodium.so")
libsodium.sodium_init()
### Epoch211FirstSlot ###
firstShelleyBlockHash = "33a28456a44277cbfb3457082467e56f16554932eb2a9eb7ceca97740bd4f4db"
blockInfoUrl = koiosBaseUrl+"block_info"
postData = {"_block_hashes":[firstShelleyBlockHash]}
blockInfo = requests.post(blockInfoUrl, data=json.dumps(postData))
blockInfo = blockInfo.text
blockInfo = json.loads(blockInfo)
firstSlot = blockInfo[0]['abs_slot']
### calculate first slot of target epoch ###
firstSlotOfEpoch = (firstSlot) + (epoch - 211)*epochLength
# Determine if our pool is a slot leader for this given slot
# @param slot The slot to check
# @param activeSlotCoeff The activeSlotsCoeff value from protocol params
# @param sigma The controlled stake proportion for the pool
# @param eta0 The epoch nonce value
# @param pool_vrf_skey The vrf signing key for the pool
from decimal import *
getcontext().prec = 9
getcontext().rounding = ROUND_HALF_UP
def mk_seed(slot, eta0):
h = hashlib.blake2b(digest_size=32)
h.update(slot.to_bytes(8, byteorder='big') + binascii.unhexlify(eta0))
slotToSeedBytes = h.digest()
return slotToSeedBytes
def vrf_eval_certified(seed, praosCanBeLeaderSignKeyVRF):
if isinstance(seed, bytes) and isinstance(praosCanBeLeaderSignKeyVRF, bytes):
proof = create_string_buffer(libsodium.crypto_vrf_ietfdraft03_proofbytes())
libsodium.crypto_vrf_prove(proof, praosCanBeLeaderSignKeyVRF, seed, len(seed))
proof_hash = create_string_buffer(libsodium.crypto_vrf_outputbytes())
libsodium.crypto_vrf_proof_to_hash(proof_hash, proof)
return proof_hash.raw
else:
print("Error. Feed me bytes")
exit()
def vrf_leader_value(vrfCert):
h = hashlib.blake2b(digest_size=32)
h.update(str.encode("L"))
h.update(vrfCert)
vrfLeaderValueBytes = h.digest()
return int.from_bytes(vrfLeaderValueBytes, byteorder="big", signed=False)
def isOverlaySlot(firstSlotOfEpoch, currentSlot, decentralizationParam):
diff_slot = float(currentSlot - firstSlotOfEpoch)
left = Decimal(diff_slot) * Decimal(decentralizationParam)
right = Decimal(diff_slot + 1) * Decimal(decentralizationParam)
if math.ceil(left) < math.ceil(right):
return True
return False
### Epoch Assigned Performance or Luck ###
def get_performance(nStake, pStake):
blocksEpoch = 21600
epoch_luck = int(( 100 * slotcount) / (blocksEpoch * pStake / nStake / lovelaces))
epoch_luck = epoch_luck / lovelaces
print()
print(f'Assigned Luck: ' + str(format(epoch_luck, ".2f")) + ' %' )
print()
if slotcount == 0:
print()
print("No SlotLeader Schedules Found for Epoch: " +str(epoch))
print()
exit
### For Epochs inside Praos Time ###
if float(epoch) >= 364:
def is_slot_leader(slot, activeSlotsCoeff, sigma, eta0, pool_vrf_skey):
seed = mk_seed(slot, eta0)
praosCanBeLeaderSignKeyVRFb = binascii.unhexlify(pool_vrf_skey)
cert = vrf_eval_certified(seed, praosCanBeLeaderSignKeyVRFb)
certLeaderVrf = vrf_leader_value(cert)
certNatMax = math.pow(2, 256)
denominator = certNatMax - certLeaderVrf
q = certNatMax / denominator
c = math.log(1.0 - activeSlotsCoeff)
sigmaOfF = math.exp(-sigma * c)
return q <= sigmaOfF
slotcount=0
for slot in range(firstSlotOfEpoch,epochLength+firstSlotOfEpoch):
slotLeader = is_slot_leader(slot, activeSlotCoeff, sigma, eta0, pool_vrf_skey)
seed = mk_seed(slot, eta0)
praosCanBeLeaderSignKeyVRFb = binascii.unhexlify(pool_vrf_skey)
cert = vrf_eval_certified(seed,praosCanBeLeaderSignKeyVRFb)
certLeaderVrf = vrf_leader_value(cert)
certNatMax = math.pow(2,256)
denominator = certNatMax - certLeaderVrf
q = certNatMax / denominator
c = math.log(1.0 - activeSlotCoeff)
sigmaOfF = math.exp(-sigma * c)
if slotLeader:
pass
timestamp = datetime.fromtimestamp(slot + 1591566291, tz=local_tz)
slotcount+=1
print("Epoch: " + str(epoch) + " - Local Time: " + str(timestamp.strftime('%Y-%m-%d %H:%M:%S') + " - Absolute Slot: " + str(slot) + " - Epoch Slot: " + str(slot-firstSlotOfEpoch)))
print()
print("Total Scheduled Blocks: " + str(slotcount))
get_performance(nStake, pStake)
### For old Epochs inside TPraos Time (before Current Ouroboros Praos) ###
else:
def mkSeed(slot, eta0):
h = hashlib.blake2b(digest_size=32)
h.update(bytearray([0,0,0,0,0,0,0,1])) #neutral nonce
seedLbytes=h.digest()
h = hashlib.blake2b(digest_size=32)
h.update(slot.to_bytes(8,byteorder='big') + binascii.unhexlify(eta0))
slotToSeedBytes = h.digest()
seed = [x ^ slotToSeedBytes[i] for i,x in enumerate(seedLbytes)]
return bytes(seed)
def vrfEvalCertified(seed, tpraosCanBeLeaderSignKeyVRF):
if isinstance(seed, bytes) and isinstance(tpraosCanBeLeaderSignKeyVRF, bytes):
proof = create_string_buffer(libsodium.crypto_vrf_ietfdraft03_proofbytes())
libsodium.crypto_vrf_prove(proof, tpraosCanBeLeaderSignKeyVRF,seed, len(seed))
proofHash = create_string_buffer(libsodium.crypto_vrf_outputbytes())
libsodium.crypto_vrf_proof_to_hash(proofHash,proof)
return proofHash.raw
else:
print("error. Feed me bytes")
exit()
def isSlotLeader(slot,activeSlotCoeff,sigma,eta0,pool_vrf_skey):
seed = mkSeed(slot, eta0)
tpraosCanBeLeaderSignKeyVRFb = binascii.unhexlify(pool_vrf_skey)
cert=vrfEvalCertified(seed,tpraosCanBeLeaderSignKeyVRFb)
certNat = int.from_bytes(cert, byteorder="big", signed=False)
certNatMax = math.pow(2,512)
denominator = certNatMax - certNat
q = certNatMax / denominator
c = math.log(1.0 - activeSlotCoeff)
sigmaOfF = math.exp(-sigma * c)
return q <= sigmaOfF
slotcount=0
for slot in range(firstSlotOfEpoch,epochLength+firstSlotOfEpoch):
slotLeader = isSlotLeader(slot, activeSlotCoeff, sigma, eta0, pool_vrf_skey)
if slotLeader:
pass
timestamp = datetime.fromtimestamp(slot + 1591566291, tz=local_tz)
slotcount+=1
print("Epoch: " + str(epoch) + " - Local Time: " + str(timestamp.strftime('%Y-%m-%d %H:%M:%S') + " - Absolute Slot: " + str(slot) + " - Epoch Slot: " + str(slot-firstSlotOfEpoch)))
print()
print("Total Scheduled Blocks: " + str(slotcount))
get_performance(nStake, pStake)