Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
algorand
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nilak
algorand
Commits
b5a476fc
Commit
b5a476fc
authored
May 03, 2019
by
UNHALE NILESH ARUN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stable algorand - deleted link - memory leak by link messages queues emptying
parent
2b3e6ec8
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
78 additions
and
54 deletions
+78
-54
Link.py
Link.py
+2
-1
Node.py
Node.py
+1
-1
OverlayNode.py
OverlayNode.py
+72
-49
Utility.py
Utility.py
+2
-2
start.sh
start.sh
+1
-1
No files found.
Link.py
View file @
b5a476fc
...
...
@@ -78,8 +78,9 @@ class Link(SystemEntity):
'''
#todo process messages in queue
# generate tasks for todolist based on messges
for
message
in
self
.
messageQueue
:
for
message
in
list
(
self
.
messageQueue
)
:
self
.
scheduleMessageDelievery
(
message
[
0
],
message
[
1
])
self
.
dequeMessage
()
# TODO : perform task from todolist which are relevant for current tick
...
...
Node.py
View file @
b5a476fc
...
...
@@ -115,7 +115,7 @@ class Node(SystemEntity):
yield "resume",timeafter_which_to_resume
'''
if
ResumeOut
and
ResumeOut
[
0
]
==
"resume"
:
self
.
logger
.
info
(
"resume has been called"
)
#
self.logger.info("resume has been called")
self
.
ResumeTasks
[
str
(
int
(
time
)
+
int
(
ResumeOut
[
1
]))]
.
append
((
"nextOn"
,
self
.
startNodeLifeCycleGenerator
,))
except
KeyError
as
ke
:
# not task pending at this time
...
...
OverlayNode.py
View file @
b5a476fc
...
...
@@ -13,6 +13,9 @@ genesisBlock = ("I am the first block")
# def __init__(self):
# self.role =
class
OverlayNode
(
Node
):
def
__init__
(
self
,
id
,
network
,
weight
):
Node
.
__init__
(
self
,
id
,
network
,
weight
)
...
...
@@ -34,11 +37,18 @@ class OverlayNode(Node):
self
.
ResumeTasks
[
'1'
]
.
append
((
"nextOn"
,
self
.
startNodeLifeCycleGenerator
,))
self
.
commands
.
update
({})
def
printStats
(
self
):
print
(
'----------------------------------------------------------------------------------------------------------------'
)
print
(
Config
.
BLOCK_PROPOSAL_MSG_type
,
" : counts : {}"
.
format
(
len
(
self
.
uniqueReceivedMessages
[
Config
.
BLOCK_PROPOSAL_MSG_type
])))
print
(
Config
.
COMMITTEE_VOTE_MSG_type
,
" : counts : {}"
.
format
(
len
(
self
.
uniqueReceivedMessages
[
Config
.
COMMITTEE_VOTE_MSG_type
])))
print
(
Config
.
TENTATIVE_BLOCK_msg_type
,
" : counts : {}"
.
format
(
len
(
self
.
uniqueReceivedMessages
[
Config
.
TENTATIVE_BLOCK_msg_type
])))
print
(
Config
.
FINALIZED_BLOCK_msg_type
,
" : counts : {}"
.
format
(
len
(
self
.
uniqueReceivedMessages
[
Config
.
FINALIZED_BLOCK_msg_type
])))
print
(
"MESSAGES TILL NOW :COUNT : {}"
.
format
(
len
(
self
.
messagesTillNow
)))
print
(
'----------------------------------------------------------------------------------------------------------------'
)
# def processMessage(self,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
):
...
...
@@ -73,13 +83,13 @@ class OverlayNode(Node):
try
:
pk
.
verify
(
sign
,
bytes
(
str
(
payload
)
.
encode
(
'UTF8'
))
)
except
BadSignatureError
as
badSign
:
print
(
"bad signature"
)
##
print("bad signature")
return
0
,
None
,
None
round
,
step
,
sorthash
,
proof
,
previousblockHash
,
value
=
payload
if
previousblockHash
!=
hashlib
.
sha256
(
self
.
blockchain
[
-
1
]
.
encode
(
'utf-8'
))
.
hexdigest
()
:
print
(
"not in the right chain"
)
##
print("not in the right chain")
return
0
,
None
,
None
...
...
@@ -91,33 +101,33 @@ class OverlayNode(Node):
self
.
logger
.
info
(
"outpusts of veifysort : {}"
.
format
(
votes
))
if
votes
:
self
.
logger
.
info
(
"THese are valid committee votes with votes : "
+
str
(
votes
))
print
(
votes
,
"
\t
"
,
value
,
"
\t
"
,
sorthash
)
##
print(votes,"\t",value,"\t",sorthash)
return
votes
,
value
,
sorthash
pass
def
partOfCountVotes
(
self
,
round
,
step
,
start
,
counts
,
voters
,
T
,
tou
):
msgs
=
self
.
uniqueReceivedMessages
.
pop
(
Config
.
COMMITTEE_VOTE_MSG_type
)
print
(
"-------------msgs , "
,
self
.
id
)
print
(
msgs
)
##
print("-------------msgs , ", self.id)
#
print(msgs)
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
]
# print(round, " # ",step )
#
##
print(round, " # ",step )
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
)
if
msg_pk
in
voters
or
votes
==
0
:
print
(
self
.
id
+
" continuing"
)
##
print(self.id + " continuing")
continue
voters
.
append
(
msg_pk
)
print
(
"yup its wrong here"
)
##
print("yup its wrong here")
counts
[
value
]
=
counts
.
get
(
value
,
votes
)
print
(
'--------------counts-------------'
,
self
.
id
)
print
(
counts
)
##
print('--------------counts-------------',self.id)
##
print(counts)
if
counts
[
value
]
>
T
*
tou
:
print
(
"returning value"
)
##
print("returning value")
return
value
pass
...
...
@@ -255,13 +265,13 @@ class OverlayNode(Node):
except
Exception
as
e
:
self
.
logger
.
error
(
e
)
# print(blockForBA)
#
#
print(blockForBA)
hashof_blockForBA
=
Utility
.
pseudoRandomGenerator
(
blockForBA
)
######### END : Performing selection of block BA* ############################
self
.
printStats
()
''' START : REDUCTION ALGORITHM '''
''' COmmitte vote reduction step 1'''
...
...
@@ -282,7 +292,7 @@ class OverlayNode(Node):
self
.
broadcast
(
self
.
network
.
time
,
committeeVoteMsg
)
self
.
logger
.
info
(
"Broadcasting commitee messgae : {}"
.
format
(
committeeVoteMsg
))
# print(self.uniqueReceivedMessages[Config.COMMITTEE_VOTE_MSG_type])
#
##
print(self.uniqueReceivedMessages[Config.COMMITTEE_VOTE_MSG_type])
yield
"resume"
,
Config
.
lambda_block
+
Config
.
lambda_step
######## count votes for hblock1 ###########
...
...
@@ -300,24 +310,26 @@ class OverlayNode(Node):
while
True
:
if
not
self
.
uniqueReceivedMessages
[
Config
.
COMMITTEE_VOTE_MSG_type
]
:
if
int
(
self
.
network
.
time
)
>
start
+
countVote_lmbda
:
print
(
self
.
id
+
"Timing out"
)
##
print(self.id + "Timing out")
hblock1
=
Config
.
TIMEOUT
break
pass
else
:
temp_return
=
self
.
partOfCountVotes
(
countVote_round
,
countVote_reduct_step_1
,
start
,
counts
,
voters
,
Config
.
T
,
Config
.
tou_step
)
print
(
"temp_retiurn "
,
temp_return
)
##
print("temp_retiurn " ,temp_return)
if
temp_return
:
hblock1
=
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
(
"returning from first count values with return value : {}"
.
format
(
hblock1
))
print
(
"returning from first count values with return value"
,
hblock1
)
##
print("returning from first count values with return value",hblock1)
self
.
logger
.
info
(
"votes count reduction step 1 : {}"
.
format
(
counts
))
######## END : count votes for hblock1 ###########
self
.
printStats
()
self
.
uniqueReceivedMessages
[
Config
.
COMMITTEE_VOTE_MSG_type
]
.
clear
()
yield
'resume'
,
50
''' END : COmmitte vote reduction step 1'''
''' Start : COmmitte vote reduction step 2 '''
...
...
@@ -351,7 +363,7 @@ class OverlayNode(Node):
variables_reduct_step_2
[
'role'
],
self
.
weight
,
self
.
network
.
badaW
,
self
.
pk
)
# print("Reduction algo " + self.id," : ",reduct_j)
#
##
print("Reduction algo " + self.id," : ",reduct_j)
if
variables_reduct_step_2
[
'j'
]
>
0
:
self
.
logger
.
info
(
"selection for VOTING COMMITEE with J ="
+
str
(
variables_reduct_step_2
[
'j'
]))
...
...
@@ -386,7 +398,7 @@ class OverlayNode(Node):
if
not
self
.
uniqueReceivedMessages
[
Config
.
COMMITTEE_VOTE_MSG_type
]:
if
int
(
self
.
network
.
time
)
>
CountVotes_step2
[
'start'
]
+
CountVotes_step2
[
'countVote_lmbda'
]:
print
(
self
.
id
+
"Timing out"
)
##
print(self.id + "Timing out")
CountVotes_step2
[
'hblock2'
]
=
Config
.
TIMEOUT
break
pass
...
...
@@ -395,31 +407,32 @@ class OverlayNode(Node):
CountVotes_step2
[
'countVote_round'
],
CountVotes_step2
[
'countVote_step'
],
CountVotes_step2
[
'start'
],
CountVotes_step2
[
'counts'
],
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'
]:
CountVotes_step2
[
'hblock2'
]
=
CountVotes_step2
[
'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
(
"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 ###########
var_BBA_star
=
{}
print
(
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
)
#
print('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
if
CountVotes_step2
[
'hblock2'
]
==
Config
.
TIMEOUT
:
var_BBA_star
[
'block_hash'
]
=
empty_hash
else
:
var_BBA_star
[
'block_hash'
]
=
CountVotes_step2
[
'hblock2'
]
print
(
"I am culprit "
)
print
(
var_BBA_star
[
'block_hash'
])
#print("I am culprit " )
#print(var_BBA_star['block_hash'])
self
.
printStats
()
# self.uniqueReceivedMessages[Config.COMMITTEE_VOTE_MSG_type].clear()
yield
'resume'
,
50
''' END : COmmitte vote reduction step 2 '''
yield
"resume"
,
9
''' END : REDUCTION ALGORITHM '''
...
...
@@ -462,7 +475,7 @@ class OverlayNode(Node):
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"
)
#
print(self.id + "Timing out")
CountVotes_BBA_CASE_1
[
'return_block_hash'
]
=
Config
.
TIMEOUT
break
pass
...
...
@@ -471,16 +484,18 @@ class OverlayNode(Node):
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'
])
#
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'
])
#
print("CountVotes_BBA_CASE_1", CountVotes_BBA_CASE_1['return_block_hash'])
var_BBA_star
[
'r'
]
=
CountVotes_BBA_CASE_1
[
'return_block_hash'
]
self
.
printStats
()
# self.uniqueReceivedMessages[Config.COMMITTEE_VOTE_MSG_type].clear()
yield
'resume'
,
50
######## END : count votes for CountVotes_BBA_CASE_1 ###########
if
var_BBA_star
[
'r'
]
==
Config
.
TIMEOUT
:
...
...
@@ -508,8 +523,7 @@ class OverlayNode(Node):
pass
var_BBA_star
[
'step'
]
+=
1
self
.
printStats
()
''' START : BBAstar_case 2'''
''' COmmitte vote BBA_CASE_2 : BBA_CASE_2'''
...
...
@@ -538,7 +552,7 @@ class OverlayNode(Node):
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"
)
#
print(self.id + "Timing out")
CountVotes_BBA_CASE_2
[
'return_block_hash'
]
=
Config
.
TIMEOUT
break
pass
...
...
@@ -547,13 +561,13 @@ class OverlayNode(Node):
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'
])
#
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'
])
#
print("CountVotes_BBA_CASE_2", CountVotes_BBA_CASE_2['return_block_hash'])
var_BBA_star
[
'r'
]
=
CountVotes_BBA_CASE_2
[
'return_block_hash'
]
...
...
@@ -575,7 +589,9 @@ class OverlayNode(Node):
pass
var_BBA_star
[
'step'
]
+=
1
self
.
printStats
()
# self.uniqueReceivedMessages[Config.COMMITTEE_VOTE_MSG_type].clear()
yield
'resume'
,
50
''' END : BBAstar_case 2'''
'''START : BBAStar case 3'''
...
...
@@ -605,7 +621,7 @@ class OverlayNode(Node):
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"
)
#
print(self.id + "Timing out")
CountVotes_BBA_CASE_3
[
'return_block_hash'
]
=
Config
.
TIMEOUT
break
pass
...
...
@@ -614,13 +630,13 @@ class OverlayNode(Node):
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'
])
#
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'
])
#
print("CountVotes_BBA_CASE_3", CountVotes_BBA_CASE_3['return_block_hash'])
var_BBA_star
[
'r'
]
=
CountVotes_BBA_CASE_3
[
'return_block_hash'
]
...
...
@@ -641,7 +657,9 @@ class OverlayNode(Node):
pass
var_BBA_star
[
'step'
]
+=
1
self
.
printStats
()
# self.uniqueReceivedMessages[Config.COMMITTEE_VOTE_MSG_type].clear()
yield
'resume'
,
50
'''END : BBAStar case 3'''
...
...
@@ -649,6 +667,7 @@ class OverlayNode(Node):
if
var_BBA_star
[
'step'
]
==
Config
.
MAXSTEP
:
yield
"resume"
,
40120000
# hang forever
exit
(
0
)
''' END : BBA* ALGORITHM '''
...
...
@@ -670,7 +689,7 @@ class OverlayNode(Node):
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"
)
##
print(self.id + "Timing out")
CountVotes_FINAL
[
'return_block_hash'
]
=
Config
.
TIMEOUT
break
pass
...
...
@@ -679,13 +698,13 @@ class OverlayNode(Node):
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'
])
##
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'
])
##
print("CountVotes_FINAL", CountVotes_FINAL['return_block_hash'])
######## END : count votes for CountVotes_FINAL ###########
...
...
@@ -701,9 +720,13 @@ class OverlayNode(Node):
self
.
tentativeblockchain
.
append
(
str
((
self
.
currentPreviousHash
,
hblockSTAR
)))
self
.
logger
.
info
(
"BLOCKCHAIN : {}"
.
format
(
self
.
blockchain
))
self
.
printStats
()
self
.
uniqueReceivedMessages
[
Config
.
COMMITTEE_VOTE_MSG_type
]
.
clear
()
self
.
messagesTillNow
.
clear
()
# self.messageQueue.clear()
yield
'resume'
,
50
# self.logger.info(self.uniqueReceivedMessages)
yield
"resume"
,
40
...
...
@@ -775,12 +798,12 @@ if __name__ == '__main__':
value
=
5
d
[
key
]
=
d
.
get
(
key
,
value
)
print
(
d
[
2
])
##
print(d[2])
v
=
7
d
[
key
]
=
d
.
get
(
key
,
v
)
print
(
d
[
2
])
##
print(d[2])
...
...
Utility.py
View file @
b5a476fc
...
...
@@ -140,8 +140,8 @@ def verifySort(pk,hash,proof,seed,rolecount,role,w,badaW):
break
j
=
j
+
1
if
j
:
print
(
"Verification success : J :"
,
j
,
role
)
#
if j :
#
print("Verification success : J :",j,role)
return
j
...
...
start.sh
View file @
b5a476fc
#!/usr/bin/env bash
python3 filegen.py 30
#
python3 filegen.py 30
rm
-rf
ASim.log
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment