Commit badde1b9 authored by UNHALE NILESH ARUN's avatar UNHALE NILESH ARUN

completed algorand implementation

parent 24319984
...@@ -2,7 +2,7 @@ lambda_proposer = 30# wait time for priority messages to be received ...@@ -2,7 +2,7 @@ lambda_proposer = 30# wait time for priority messages to be received
tou_proposer = 20 # proposer rolecount tou_proposer = 20 # proposer rolecount
ROLE_BLOCK_PROPOSER = 'BLOCK_PROPOSER' ROLE_BLOCK_PROPOSER = 'BLOCK_PROPOSER'
tou_step = 20 # tou is expected number of users that sortition selects for committee tou_step = 28 # tou is expected number of users that sortition selects for committee
ROLE_COMMITEE_FOR_VOTE = 'committee' ROLE_COMMITEE_FOR_VOTE = 'committee'
lambda_block = 300 #seconds lambda_block = 300 #seconds
...@@ -13,7 +13,16 @@ BLOCK_PROPOSAL_MSG_type = 'BLOCK_PROPOSAL_MSGs' ...@@ -13,7 +13,16 @@ BLOCK_PROPOSAL_MSG_type = 'BLOCK_PROPOSAL_MSGs'
PRIORITY_MSG_type = 'PRIORITY_MSG' PRIORITY_MSG_type = 'PRIORITY_MSG'
COMMITTEE_VOTE_MSG_type = "COMMITTEE_VOTE" COMMITTEE_VOTE_MSG_type = "COMMITTEE_VOTE"
TIMEOUT = "TIMEOUT" TIMEOUT = "TIMEOUT"
T = 2/3 # T isa a fraction of expected committee size that defines BA*`s voting thershold T = 0.001 # 2/3 # T isa a fraction of expected committee size that defines BA*`s voting thershold
NUMBER_OF_NODES_IN_NETWORK = 50 T_FINAL = 0.001
tou_FINAL = 28
FINALIZED_BLOCK_msg_type = "FINALIZED_BLOCK"
TENTATIVE_BLOCK_msg_type = "TENTATIVE_BLOCK"
NUMBER_OF_NODES_IN_NETWORK = 30
MAXSTEP = 15
FINAL_STEP = 9999999999
0 21 0 19
0 39 0 24
1 32 0 27
1 29 1 2
2 34 1 20
2 44 1 19
3 16 2 6
3 25 3 22
3 42 3 12
3 35 4 16
4 18 4 7
4 37 4 25
4 43 5 28
4 30 5 15
5 37 6 8
5 11 6 26
5 23
6 41
6 46
7 14
7 47
7 28 7 28
8 15 7 23
8 44 8 13
8 35 8 18
9 27 9 22
9 46 9 24
9 13 10 21
9 49 10 16
10 27 11 19
10 48
10 35
11 29
11 23 11 23
12 22 12 22
12 42 12 17
13 26 13 29
13 33 14 25
14 24 14 15
14 27 14 26
14 39 15 29
15 40 16 20
16 22 17 24
16 40 18 23
16 42 18 21
17 23 18 22
17 45 23 27
18 48 25 28
19 27
19 31
20 46
20 45
20 38
21 24
21 37
21 30
23 42
25 29
26 41
28 34
29 49
30 31
30 38
31 36
31 34
32 35
32 39
33 47
36 43
37 38
39 47
40 47
41 46
41 49
0 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
...@@ -33,7 +33,11 @@ class Network(): ...@@ -33,7 +33,11 @@ class Network():
:return: :return:
''' '''
w = randint(1, 51, Config.NUMBER_OF_NODES_IN_NETWORK) # 51 is excluded - range (1,50) w = randint(1, 51, Config.NUMBER_OF_NODES_IN_NETWORK) # 51 is excluded - range (1,50)
print('Stakes that are given to the nodes are : \n')
print(w)
print('\n')
self.badaW = np.sum(w) self.badaW = np.sum(w)
print(self.badaW)
i = 0 i = 0
with open('Nodes1.dat', 'r') as f: with open('Nodes1.dat', 'r') as f:
reader = csv.reader(f) reader = csv.reader(f)
......
...@@ -28,23 +28,3 @@ ...@@ -28,23 +28,3 @@
27 27
28 28
29 29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
...@@ -24,6 +24,8 @@ class OverlayNode(Node): ...@@ -24,6 +24,8 @@ class OverlayNode(Node):
self.currentRoleCount = 20 self.currentRoleCount = 20
self.currentRole = "BLOCK_PROPOSER" self.currentRole = "BLOCK_PROPOSER"
self.currentSeed = None self.currentSeed = None
self.currentPreviousHash = None
self.seenBlocksHashTOBLOCK_MAP = {}
self.startNodeLifeCycleGenerator = self.startNodeLifeCycle() self.startNodeLifeCycleGenerator = self.startNodeLifeCycle()
# adding initial task of bootstraping node.and it only contains ba* resume tasks # adding initial task of bootstraping node.and it only contains ba* resume tasks
...@@ -36,6 +38,32 @@ class OverlayNode(Node): ...@@ -36,6 +38,32 @@ class OverlayNode(Node):
# def processMessage(self,time,payload): # def processMessage(self,time,payload):
# super(OverlayNode, self).processMessage(time,payload) # super(OverlayNode, self).processMessage(time,payload)
# print("from overlay node : "+str(payload)) # print("from overlay node : "+str(payload))
def committeeVote(self,seed ,round,step,tou,value,fromwhere_it_is_called):
role = (Config.ROLE_COMMITEE_FOR_VOTE, round, step)
sorthash, proof, j = Utility.sortition(self.sk, seed,
tou,
role,
self.weight, self.network.badaW,
self.pk)
if j > 0:
self.logger.info("selection for VOTING COMMITEE :[ "+ str(fromwhere_it_is_called)+" ] with J = {}".format(j))
payload = (
self.currentRound, step,sorthash,
proof, self.currentPreviousHash, value)
committeeVoteMsg = (Config.COMMITTEE_VOTE_MSG_type,
(self.pk, payload,
self.sk.sign(bytes(
str(payload).encode(
'UTF8')))))
self.broadcast(self.network.time, committeeVoteMsg)
self.logger.info(
"Broadcasting commitee messgae : ["+fromwhere_it_is_called+" : {}".format(committeeVoteMsg))
pass
def algo_processMsg(self,msg,tou): def algo_processMsg(self,msg,tou):
pk = msg[1][0] pk = msg[1][0]
sign = msg[1][2] sign = msg[1][2]
...@@ -62,7 +90,6 @@ class OverlayNode(Node): ...@@ -62,7 +90,6 @@ class OverlayNode(Node):
self.logger.info("outpusts of veifysort : {}".format(votes)) self.logger.info("outpusts of veifysort : {}".format(votes))
if votes : if votes :
self.logger.info("THese are valid committee votes with votes : "+str(votes)) self.logger.info("THese are valid committee votes with votes : "+str(votes))
print("why votes be zero :",role)
print(votes,"\t",value,"\t",sorthash) print(votes,"\t",value,"\t",sorthash)
return votes,value,sorthash return votes,value,sorthash
pass pass
...@@ -97,6 +124,32 @@ class OverlayNode(Node): ...@@ -97,6 +124,32 @@ class OverlayNode(Node):
self.uniqueReceivedMessages[Config.COMMITTEE_VOTE_MSG_type].append(msg) self.uniqueReceivedMessages[Config.COMMITTEE_VOTE_MSG_type].append(msg)
pass pass
pass pass
def commonCoin(self,round,step,tou):
msgs = self.uniqueReceivedMessages.pop(Config.COMMITTEE_VOTE_MSG_type)
minhash = 2**256
for msg in msgs:
msg_round = msg[1][1][0]
msg_step = msg[1][1][1]
payload = msg[1][1]
msg_pk = msg[1][0]
if msg_round== round and msg_step==step : #check if message belong to current round and current step or not
votes,value,sorthash = self.algo_processMsg(msg,tou)
for i in range(1,votes):
input_to_SHA256 = (sorthash, i)
temp = hashlib.sha256((str(input_to_SHA256)).encode('utf-8')).hexdigest()
h = int(temp,16)
if h < minhash :
minhash = h
else:
self.uniqueReceivedMessages[Config.COMMITTEE_VOTE_MSG_type].append(msg)
pass
return minhash % 2
pass
def startNodeLifeCycle(self): def startNodeLifeCycle(self):
'''THis is monolithic algorand algorithm for a NOde''' '''THis is monolithic algorand algorithm for a NOde'''
self.logger.info("Life cycle started") self.logger.info("Life cycle started")
...@@ -108,6 +161,7 @@ class OverlayNode(Node): ...@@ -108,6 +161,7 @@ class OverlayNode(Node):
blockForBA = None blockForBA = None
# Checking if I am a Block Propser # Checking if I am a Block Propser
previousHash = hashlib.sha256(self.blockchain[-1].encode('utf-8')).hexdigest() previousHash = hashlib.sha256(self.blockchain[-1].encode('utf-8')).hexdigest()
self.currentPreviousHash = previousHash
seed = ( previousHash,self.currentRound,0) seed = ( previousHash,self.currentRound,0)
self.currentSeed= (previousHash, self.currentRound, 0) self.currentSeed= (previousHash, self.currentRound, 0)
self.logger.info("priority sortiion ip : {}".format((self.sk,seed,Config.tou_proposer, Config.ROLE_BLOCK_PROPOSER, self.weight, self.network.badaW, self.pk))) self.logger.info("priority sortiion ip : {}".format((self.sk,seed,Config.tou_proposer, Config.ROLE_BLOCK_PROPOSER, self.weight, self.network.badaW, self.pk)))
...@@ -154,7 +208,10 @@ class OverlayNode(Node): ...@@ -154,7 +208,10 @@ class OverlayNode(Node):
''' '''
BLOCK_PROPOSAL_MSG_to_broadcast : ("BLOCK_PROPOSAL_MSG", previousblockhash,A random string as txns,Nod`s priority payload) BLOCK_PROPOSAL_MSG_to_broadcast : ("BLOCK_PROPOSAL_MSG", previousblockhash,A random string as txns,Nod`s priority payload)
''' '''
BLOCK_PROPOSAL_MSG_to_broadcast = (Config.BLOCK_PROPOSAL_MSG_type, previousHash,Utility.pseudoRandomGenerator(random.randint(0,1000)),priority_msg_to_broadcast[1:]) BLOCK_PROPOSAL_MSG_to_broadcast = (Config.BLOCK_PROPOSAL_MSG_type,
previousHash,
Utility.pseudoRandomGenerator(random.randint(0,1000)),
priority_msg_to_broadcast[1:])
self.logger.info("broadcsting BLOCK Proposal Message : {}".format(BLOCK_PROPOSAL_MSG_to_broadcast)) self.logger.info("broadcsting BLOCK Proposal Message : {}".format(BLOCK_PROPOSAL_MSG_to_broadcast))
self.broadcast(self.network.time, BLOCK_PROPOSAL_MSG_to_broadcast) self.broadcast(self.network.time, BLOCK_PROPOSAL_MSG_to_broadcast)
blockForBA = (previousHash,BLOCK_PROPOSAL_MSG_to_broadcast[2]) blockForBA = (previousHash,BLOCK_PROPOSAL_MSG_to_broadcast[2])
...@@ -280,90 +337,377 @@ class OverlayNode(Node): ...@@ -280,90 +337,377 @@ class OverlayNode(Node):
''' COmmitte vote reduction step2 : reduct_step2_block_to_vote''' ''' COmmitte vote reduction step2 : reduct_step2_block_to_vote'''
#
# variables_reduct_step_2 = {} variables_reduct_step_2 = {}
#
# variables_reduct_step_2['step'] = 2 variables_reduct_step_2['step'] = 2
# # variables_reduct_step_2['seed'] = (previousHash, self.currentRound, variables_reduct_step_2['step']) # variables_reduct_step_2['seed'] = (previousHash, self.currentRound, variables_reduct_step_2['step'])
# variables_reduct_step_2['seed'] = self.currentSeed variables_reduct_step_2['seed'] = self.currentSeed
# variables_reduct_step_2['role'] = ( variables_reduct_step_2['role'] = (
# Config.ROLE_COMMITEE_FOR_VOTE, self.currentRound, variables_reduct_step_2['step']) Config.ROLE_COMMITEE_FOR_VOTE, self.currentRound, variables_reduct_step_2['step'])
# variables_reduct_step_2['sorthash'], variables_reduct_step_2['proof'], variables_reduct_step_2[ variables_reduct_step_2['sorthash'], variables_reduct_step_2['proof'], variables_reduct_step_2[
# 'j'] = Utility.sortition(self.sk, variables_reduct_step_2['seed'], 'j'] = Utility.sortition(self.sk, variables_reduct_step_2['seed'],
# Config.tou_step, Config.tou_step,
# variables_reduct_step_2['role'], variables_reduct_step_2['role'],
# self.weight, self.network.badaW, self.weight, self.network.badaW,
# self.pk) self.pk)
# # print("Reduction algo " + self.id," : ",reduct_j) # print("Reduction algo " + self.id," : ",reduct_j)
#
# if variables_reduct_step_2['j'] > 0: if variables_reduct_step_2['j'] > 0:
# self.logger.info("selection for VOTING COMMITEE with J =" + str(variables_reduct_step_2['j'])) self.logger.info("selection for VOTING COMMITEE with J =" + str(variables_reduct_step_2['j']))
# variables_reduct_step_2['payload'] = ( variables_reduct_step_2['payload'] = (
# self.currentRound, variables_reduct_step_2['step'], variables_reduct_step_2['sorthash'], self.currentRound, variables_reduct_step_2['step'], variables_reduct_step_2['sorthash'],
# variables_reduct_step_2['proof'], previousHash, reduct_step2_block_to_vote) variables_reduct_step_2['proof'], previousHash, reduct_step2_block_to_vote)
# variables_reduct_step_2['committeeVoteMsg'] = (Config.COMMITTEE_VOTE_MSG_type, variables_reduct_step_2['committeeVoteMsg'] = (Config.COMMITTEE_VOTE_MSG_type,
# (self.pk, variables_reduct_step_2['payload'], (self.pk, variables_reduct_step_2['payload'],
# self.sk.sign(bytes( self.sk.sign(bytes(
# str(variables_reduct_step_2['payload']).encode( str(variables_reduct_step_2['payload']).encode(
# 'UTF8'))))) 'UTF8')))))
# self.broadcast(self.network.time, variables_reduct_step_2['committeeVoteMsg']) self.broadcast(self.network.time, variables_reduct_step_2['committeeVoteMsg'])
# self.logger.info("Broadcasting commitee messgae" + str(variables_reduct_step_2['committeeVoteMsg'])) self.logger.info("Broadcasting commitee messgae" + str(variables_reduct_step_2['committeeVoteMsg']))
#
# # yield "resume", Config.lambda_block + Config.lambda_step # yield "resume", Config.lambda_block + Config.lambda_step
#
# ''' COmmitte vote reduction step2 : reduct_step2_block_to_vote''' ''' COmmitte vote reduction step2 : reduct_step2_block_to_vote'''
#
# ######## count votes for hblock1 ########### ######## count votes for hblock1 ###########
# CountVotes_step2 = {} CountVotes_step2 = {}
# CountVotes_step2['countVote_round'] = self.currentRound CountVotes_step2['countVote_round'] = self.currentRound
# CountVotes_step2['countVote_step'] = 2 CountVotes_step2['countVote_step'] = 2
# # Config.T # Config.T
# # Config.tou_step # Config.tou_step
# CountVotes_step2['countVote_lmbda'] = Config.lambda_block + Config.lambda_step CountVotes_step2['countVote_lmbda'] = Config.lambda_block + Config.lambda_step
#
# CountVotes_step2['start'] = int(self.network.time) CountVotes_step2['start'] = int(self.network.time)
# CountVotes_step2['counts'] = {} CountVotes_step2['counts'] = {}
# CountVotes_step2['voters'] = [] CountVotes_step2['voters'] = []
# CountVotes_step2['hblock2'] = None CountVotes_step2['hblock2'] = None
# while True: while True:
# if not self.uniqueReceivedMessages[Config.COMMITTEE_VOTE_MSG_type]: if not self.uniqueReceivedMessages[Config.COMMITTEE_VOTE_MSG_type]:
# if int(self.network.time) > CountVotes_step2['start'] + CountVotes_step2[ if int(self.network.time) > CountVotes_step2['start'] + CountVotes_step2[
# 'countVote_lmbda']: 'countVote_lmbda']:
# print(self.id + "Timing out") print(self.id + "Timing out")
# CountVotes_step2['hblock2'] = Config.TIMEOUT CountVotes_step2['hblock2'] = Config.TIMEOUT
# break break
# pass pass
# else: else:
# CountVotes_step2['temp_return'] = self.partOfCountVotes( CountVotes_step2['temp_return'] = self.partOfCountVotes(
# CountVotes_step2['countVote_round'], CountVotes_step2['countVote_step'], CountVotes_step2['countVote_round'], CountVotes_step2['countVote_step'],
# CountVotes_step2['start'], CountVotes_step2['counts'], CountVotes_step2['start'], CountVotes_step2['counts'],
# CountVotes_step2['voters'], Config.T, Config.tou_step) CountVotes_step2['voters'], Config.T, Config.tou_step)
# print("CountVotes_step2",CountVotes_step2['temp_return']) print("CountVotes_step2",CountVotes_step2['temp_return'])
# if CountVotes_step2['temp_return']: if CountVotes_step2['temp_return']:
# CountVotes_step2['hblock2'] = CountVotes_step2['temp_return'] CountVotes_step2['hblock2'] = CountVotes_step2['temp_return']
# break break
# yield "resume", 1 # this is to allow other nodes to be simulated and not get this node into infinite waiting on single node yield "resume", 1 # this is to allow other nodes to be simulated and not get this node into infinite waiting on single node
# self.logger.info( self.logger.info(
# "returning from first count values with return value : " + str(CountVotes_step2['hblock2'])) "returning from first count values with return value : " + str(CountVotes_step2['hblock2']))
# print("CountVotes_step2",CountVotes_step2['hblock2']) print("CountVotes_step2",CountVotes_step2['hblock2'])
#
# ######## END : count votes for hblock1 ########### ######## END : count votes for hblock1 ###########
#
# var_BBA_star = {} var_BBA_star = {}
# print('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
# if CountVotes_step2['hblock2'] == Config.TIMEOUT: if CountVotes_step2['hblock2'] == Config.TIMEOUT:
# var_BBA_star['block_hash']= empty_hash var_BBA_star['block_hash']= empty_hash
# else: else:
# var_BBA_star['block_hash'] = CountVotes_step2['hblock2'] var_BBA_star['block_hash'] = CountVotes_step2['hblock2']
#
#
# print("I am culprit " ,var_BBA_star['hblock2']) print("I am culprit " )
# ''' END : COmmitte vote reduction step 2 ''' print(var_BBA_star['block_hash'])
''' END : COmmitte vote reduction step 2 '''
yield "resume", 9 yield "resume", 9
# self.logger.info(self.uniqueReceivedMessages)
yield "resume",40000
''' END : REDUCTION ALGORITHM ''' ''' END : REDUCTION ALGORITHM '''
''' START : BBA* ALGORITHM '''
var_BBA_star['step'] = 1
var_BBA_star['r'] = var_BBA_star['block_hash']
var_BBA_star['empty_hash'] = Utility.pseudoRandomGenerator((previousHash, "Empty"))
while var_BBA_star['step'] < Config.MAXSTEP :
''' COmmitte vote BBA_CASE_1 : BBA_CASE_1'''
self.committeeVote(self.currentSeed,
self.currentRound,
var_BBA_star['step'],
Config.tou_step,
var_BBA_star['r'],
'BBA_CASE_1')
''' COmmitte vote BBA_CASE_1 :BBA_CASE_1'''
######## count votes for CountVotes_BBA_CASE_1 ###########
CountVotes_BBA_CASE_1 = {}
CountVotes_BBA_CASE_1['countVote_round'] = self.currentRound
CountVotes_BBA_CASE_1['countVote_step'] = var_BBA_star['step']
# Config.T
# Config.tou_step
CountVotes_BBA_CASE_1['countVote_lmbda'] = Config.lambda_step
CountVotes_BBA_CASE_1['start'] = int(self.network.time)
CountVotes_BBA_CASE_1['counts'] = {}
CountVotes_BBA_CASE_1['voters'] = []
CountVotes_BBA_CASE_1['return_block_hash'] = None
while True:
if not self.uniqueReceivedMessages[Config.COMMITTEE_VOTE_MSG_type]:
if int(self.network.time) > CountVotes_BBA_CASE_1['start'] + CountVotes_BBA_CASE_1[
'countVote_lmbda']:
print(self.id + "Timing out")
CountVotes_BBA_CASE_1['return_block_hash'] = Config.TIMEOUT
break
pass
else:
CountVotes_BBA_CASE_1['temp_return'] = self.partOfCountVotes(
CountVotes_BBA_CASE_1['countVote_round'], CountVotes_BBA_CASE_1['countVote_step'],
CountVotes_BBA_CASE_1['start'], CountVotes_BBA_CASE_1['counts'],
CountVotes_BBA_CASE_1['voters'], Config.T, Config.tou_step)
print("CountVotes_BBA_CASE_1", CountVotes_BBA_CASE_1['temp_return'])
if CountVotes_BBA_CASE_1['temp_return']:
CountVotes_BBA_CASE_1['return_block_hash'] = CountVotes_BBA_CASE_1['temp_return']
break
yield "resume", 1 # this is to allow other nodes to be simulated and not get this node into infinite waiting on single node
self.logger.info("CountVotes_BBA_CASE_1 o/p : {}".format( CountVotes_BBA_CASE_1['return_block_hash']))
print("CountVotes_BBA_CASE_1", CountVotes_BBA_CASE_1['return_block_hash'])
var_BBA_star['r'] = CountVotes_BBA_CASE_1['return_block_hash']
######## END : count votes for CountVotes_BBA_CASE_1 ###########
if var_BBA_star['r'] == Config.TIMEOUT :
var_BBA_star['r'] = var_BBA_star['block_hash']
elif var_BBA_star['r'] != var_BBA_star['empty_hash'] :
for i in range(1,4):
self.committeeVote(self.currentSeed,
self.currentRound,
var_BBA_star['step']+i,
Config.tou_step,
var_BBA_star['r'],
'BBA_CASE_1_if_not_emptyhashCase')
if var_BBA_star['step'] == 1:
self.committeeVote(self.currentSeed,
self.currentRound,
Config.FINAL_STEP,
Config.tou_step,
var_BBA_star['r'],
'BBA_CASE_1_Reached final consensu in step 1')
var_BBA_star['return_value'] = var_BBA_star['r']
break
pass
var_BBA_star['step'] += 1
''' START : BBAstar_case 2'''
''' COmmitte vote BBA_CASE_2 : BBA_CASE_2'''
self.committeeVote(self.currentSeed,
self.currentRound,
var_BBA_star['step'],
Config.tou_step,
var_BBA_star['r'],
'BBA_CASE_2')
''' COmmitte vote BBA_CASE_2 :BBA_CASE_2'''
######## count votes for CountVotes_BBA_CASE_2 ###########
CountVotes_BBA_CASE_2 = {}
CountVotes_BBA_CASE_2['countVote_round'] = self.currentRound
CountVotes_BBA_CASE_2['countVote_step'] = var_BBA_star['step']
# Config.T
# Config.tou_step
CountVotes_BBA_CASE_2['countVote_lmbda'] = Config.lambda_step
CountVotes_BBA_CASE_2['start'] = int(self.network.time)
CountVotes_BBA_CASE_2['counts'] = {}
CountVotes_BBA_CASE_2['voters'] = []
CountVotes_BBA_CASE_2['return_block_hash'] = None
while True:
if not self.uniqueReceivedMessages[Config.COMMITTEE_VOTE_MSG_type]:
if int(self.network.time) > CountVotes_BBA_CASE_2['start'] + CountVotes_BBA_CASE_2[
'countVote_lmbda']:
print(self.id + "Timing out")
CountVotes_BBA_CASE_2['return_block_hash'] = Config.TIMEOUT
break
pass
else:
CountVotes_BBA_CASE_2['temp_return'] = self.partOfCountVotes(
CountVotes_BBA_CASE_2['countVote_round'], CountVotes_BBA_CASE_2['countVote_step'],
CountVotes_BBA_CASE_2['start'], CountVotes_BBA_CASE_2['counts'],
CountVotes_BBA_CASE_2['voters'], Config.T, Config.tou_step)
print("CountVotes_BBA_CASE_2", CountVotes_BBA_CASE_2['temp_return'])
if CountVotes_BBA_CASE_2['temp_return']:
CountVotes_BBA_CASE_2['return_block_hash'] = CountVotes_BBA_CASE_2['temp_return']
break
yield "resume", 1 # this is to allow other nodes to be simulated and not get this node into infinite waiting on single node
self.logger.info("CountVotes_BBA_CASE_2 o/p : {}".format(CountVotes_BBA_CASE_2['return_block_hash']))
print("CountVotes_BBA_CASE_2", CountVotes_BBA_CASE_2['return_block_hash'])
var_BBA_star['r'] = CountVotes_BBA_CASE_2['return_block_hash']
######## END : count votes for CountVotes_BBA_CASE_2 ###########
if var_BBA_star['r'] == Config.TIMEOUT:
var_BBA_star['r'] = var_BBA_star['block_hash']
elif var_BBA_star['r'] != var_BBA_star['empty_hash']:
for i in range(1, 4):
self.committeeVote(self.currentSeed,
self.currentRound,
var_BBA_star['step'] + i,
Config.tou_step,
var_BBA_star['r'],
'BBA_CASE_2_if_not_emptyhashCase')
pass
var_BBA_star['return_value'] = var_BBA_star['r']
break
pass
var_BBA_star['step'] += 1
''' END : BBAstar_case 2'''
'''START : BBAStar case 3'''
''' COmmitte vote BBA_CASE_3 : BBA_CASE_3'''
self.committeeVote(self.currentSeed,
self.currentRound,
var_BBA_star['step'],
Config.tou_step,
var_BBA_star['r'],
'BBA_CASE_3')
''' COmmitte vote BBA_CASE_3 :BBA_CASE_3'''
######## count votes for CountVotes_BBA_CASE_3 ###########
CountVotes_BBA_CASE_3 = {}
CountVotes_BBA_CASE_3['countVote_round'] = self.currentRound
CountVotes_BBA_CASE_3['countVote_step'] = var_BBA_star['step']
# Config.T
# Config.tou_step
CountVotes_BBA_CASE_3['countVote_lmbda'] = Config.lambda_step
CountVotes_BBA_CASE_3['start'] = int(self.network.time)
CountVotes_BBA_CASE_3['counts'] = {}
CountVotes_BBA_CASE_3['voters'] = []
CountVotes_BBA_CASE_3['return_block_hash'] = None
while True:
if not self.uniqueReceivedMessages[Config.COMMITTEE_VOTE_MSG_type]:
if int(self.network.time) > CountVotes_BBA_CASE_3['start'] + CountVotes_BBA_CASE_3[
'countVote_lmbda']:
print(self.id + "Timing out")
CountVotes_BBA_CASE_3['return_block_hash'] = Config.TIMEOUT
break
pass
else:
CountVotes_BBA_CASE_3['temp_return'] = self.partOfCountVotes(
CountVotes_BBA_CASE_3['countVote_round'], CountVotes_BBA_CASE_3['countVote_step'],
CountVotes_BBA_CASE_3['start'], CountVotes_BBA_CASE_3['counts'],
CountVotes_BBA_CASE_3['voters'], Config.T, Config.tou_step)
print("CountVotes_BBA_CASE_3", CountVotes_BBA_CASE_3['temp_return'])
if CountVotes_BBA_CASE_3['temp_return']:
CountVotes_BBA_CASE_3['return_block_hash'] = CountVotes_BBA_CASE_3['temp_return']
break
yield "resume", 1 # this is to allow other nodes to be simulated and not get this node into infinite waiting on single node
self.logger.info("CountVotes_BBA_CASE_3 o/p : {}".format(CountVotes_BBA_CASE_3['return_block_hash']))
print("CountVotes_BBA_CASE_3", CountVotes_BBA_CASE_3['return_block_hash'])
var_BBA_star['r'] = CountVotes_BBA_CASE_3['return_block_hash']
######## END : count votes for CountVotes_BBA_CASE_3 ###########
if var_BBA_star['r'] == Config.TIMEOUT:
if self.commonCoin(self.currentRound,var_BBA_star['step'],Config.tou_step) :
var_BBA_star['r'] = var_BBA_star['block_hash']
else :
var_BBA_star['r'] = var_BBA_star['empty_hash']
pass
var_BBA_star['step'] += 1
'''END : BBAStar case 3'''
yield "resume",1
if var_BBA_star['step'] == Config.MAXSTEP :
yield "resume", 40120000 # hang forever
''' END : BBA* ALGORITHM '''
hblockSTAR = var_BBA_star['return_value']
######## count votes for CountVotes_FINAL ###########
CountVotes_FINAL = {}
CountVotes_FINAL['countVote_round'] = self.currentRound
CountVotes_FINAL['countVote_step'] = Config.FINAL_STEP
# Config.T
# Config.tou_step
CountVotes_FINAL['countVote_lmbda'] = Config.lambda_step
CountVotes_FINAL['start'] = int(self.network.time)
CountVotes_FINAL['counts'] = {}
CountVotes_FINAL['voters'] = []
CountVotes_FINAL['return_block_hash'] = None
while True:
if not self.uniqueReceivedMessages[Config.COMMITTEE_VOTE_MSG_type]:
if int(self.network.time) > CountVotes_FINAL['start'] + CountVotes_FINAL[
'countVote_lmbda']:
print(self.id + "Timing out")
CountVotes_FINAL['return_block_hash'] = Config.TIMEOUT
break
pass
else:
CountVotes_FINAL['temp_return'] = self.partOfCountVotes(
CountVotes_FINAL['countVote_round'], CountVotes_FINAL['countVote_step'],
CountVotes_FINAL['start'], CountVotes_FINAL['counts'],
CountVotes_FINAL['voters'], Config.T_FINAL, Config.tou_FINAL)
print("CountVotes_FINAL", CountVotes_FINAL['temp_return'])
if CountVotes_FINAL['temp_return']:
CountVotes_FINAL['return_block_hash'] = CountVotes_FINAL['temp_return']
break
yield "resume", 1 # this is to allow other nodes to be simulated and not get this node into infinite waiting on single node
self.logger.info("CountVotes_FINAL o/p : {}".format(CountVotes_FINAL['return_block_hash']))
print("CountVotes_FINAL", CountVotes_FINAL['return_block_hash'])
######## END : count votes for CountVotes_FINAL ###########
if hblockSTAR == CountVotes_FINAL['return_block_hash']:
FNALIZED_BLOCK_msg = (
Config.FINALIZED_BLOCK_msg_type,hblockSTAR )
self.logger.info("broadcsting FINALIZED BLOCK : {}".format(FNALIZED_BLOCK_msg))
self.broadcast(self.network.time, FNALIZED_BLOCK_msg)
else:
TENTATIVE_BLOCK_msg = (Config.TENTATIVE_BLOCK_msg_type, hblockSTAR)
self.logger.info("broadcsting FINALIZED BLOCK : {}".format(TENTATIVE_BLOCK_msg))
self.broadcast(self.network.time, TENTATIVE_BLOCK_msg)
# self.logger.info(self.uniqueReceivedMessages)
yield "resume", 40000
''' '''
TODo check if node is selected as BLOCK_PROPOSER TODo check if node is selected as BLOCK_PROPOSER
if yes if yes
......
...@@ -64,6 +64,7 @@ def sortition(sk,seed,rolecount,role,w,badaW,pk): ...@@ -64,6 +64,7 @@ def sortition(sk,seed,rolecount,role,w,badaW,pk):
newseed = (seed,role) newseed = (seed,role)
hash,proof = VRF(sk, newseed, pk) hash,proof = VRF(sk, newseed, pk)
p = rolecount/badaW p = rolecount/badaW
# p = 0.5
j=0 j=0
#simplifying the computation : hash/(2**hashlen) #simplifying the computation : hash/(2**hashlen)
...@@ -88,6 +89,12 @@ def sortition(sk,seed,rolecount,role,w,badaW,pk): ...@@ -88,6 +89,12 @@ def sortition(sk,seed,rolecount,role,w,badaW,pk):
break break
j = j+1 j = j+1
# added by nilesh
if j > 0 :
print('\n')
print('===============> The j value is >>>' , j)
print('\n')
return (hash,proof,j) return (hash,proof,j)
...@@ -256,7 +263,7 @@ def tester(): ...@@ -256,7 +263,7 @@ def tester():
roleCount = 26 roleCount = 26
role = "LEAD" role = "LEAD"
# w= randint(1,100000,10) # w= randint(1,100000,10)
w = [ 1, 10,100, 500, 1000,5000, 8000, 10000 ] w = randint(1, 51, 50)
w.sort() w.sort()
print(w) print(w)
# w = 20 # w = 20
......
import hashlib
h1 = hashlib.sha256((str('asda')).encode('utf-8'))
h1hex = h1.hexdigest()
print(int(h1hex,16)% 2)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment