-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocol.py
53 lines (42 loc) · 1.79 KB
/
protocol.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
from committee import Committee
class Protocol:
def __init__(self, committeeSize, validators, delegators, rounds, setup, reward):
self.committeeSize = committeeSize
self.validators = validators
self.delegators = delegators
self.rounds = rounds
self.blockchain = []
self.setup = setup
self.reward = reward
def selectCommittee(self):
committee = Committee(self.committeeSize, self.setup)
self.setup.selectCommittee(committee, self.validators)
return committee
def calculateRewards(self, committee):
committee.calculateRewards(self.reward)
def calculateValidatorsScores(self):
#total = 0
#for validator in self.validators:
#total+= validator.totalReward
total_rewards = sum(validator.totalReward for validator in self.validators)
total_stake = sum(validator.votingPower for validator in self.validators)
for validator in self.validators:
if validator.count == 0:
validator.score = 10000000
else:
validator.score = ((validator.totalReward / total_rewards) / (validator.votingPower * validator.count)) * 10000000
def updateDelegations(self):
for delegator in self.delegators:
delegator.changeValidator(self.validators)
def run(self):
#committee = self.selectCommittee()
#self.updateDelegations(committee)
for i in range(self.rounds):
print(i)
self.updateDelegations()
committee = self.selectCommittee()
newBlock = committee.round()
if newBlock is not None:
self.blockchain.append(newBlock)
self.calculateRewards(committee)
self.calculateValidatorsScores()