beacon.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import threading
  2. from ouroboros.clock import SynchedNTPClock
  3. from ouroboros.vrf import VRF
  4. from ouroboros.logger import Logger
  5. '''
  6. \class TrustedBeacon
  7. the trusted beacon is decentralized, such that at the onset of the Epoch,
  8. the leader of the first slot generated the signed seed, and release the signature,
  9. proof, and base to the ge nesis block.
  10. #TODO implement trustedbeacon as a node
  11. '''
  12. class TrustedBeacon(SynchedNTPClock, threading.Thread):
  13. def __init__(self, epoch_length, genesis_time):
  14. SynchedNTPClock.__init__(self, epoch_length)
  15. threading.Thread.__init__(self)
  16. self.daemon=True
  17. self.current_slot = self.slot
  18. self.log = Logger(self, genesis_time)
  19. self.bb=0 # epoch counts since genesis (big bang)
  20. self.proofs_epoch=-1
  21. def __repr__(self):
  22. return f"trustedbeacon"
  23. def run(self):
  24. self.log.highlight("thread [start]")
  25. prev_slot = self.slot
  26. self.__callback()
  27. while True:
  28. if not self.slot == prev_slot:
  29. prev_slot = self.slot
  30. self.__callback()
  31. def next_epoch_seeds(self, vrf):
  32. rands = {}
  33. for i in range(self.epoch_length):
  34. slot_idx = self.current_slot+i
  35. y, pi = vrf.sign(slot_idx)
  36. rands[slot_idx] = (y,pi)
  37. return rands
  38. '''
  39. def verify(self, y, pi, pk_raw, g):
  40. return VRF.verify(self.current_slot, y, pi, pk_raw, g)
  41. '''