step 1.5.6 : Block proposal sent out and receveid by others

parent 5dc86966
lambda_proposer = 3 # wait time for priority messages to be received
tou_proposer = 20 # proposer rolecount
ROLE_BLOCK_PROPOSER = 'BLOCK_PROPOSER'
\ No newline at end of file
......@@ -110,6 +110,10 @@ class Node(SystemEntity):
for ResumeTask in ResumeTasks:
command = self.commands.get(ResumeTask[0])
ResumeOut = command(time,ResumeTask[1:])
'''
synatx for proper return commands
yield "resume",timeafter_which_to_resume
'''
if ResumeOut and ResumeOut[0] == "resume":
self.logger.info("resume has been called")
self.ResumeTasks[str(int(time)+int(ResumeOut[1]))].append(("nextOn", self.startNodeLifeCycleGenerator,))
......
......@@ -2,6 +2,8 @@ from Node import Node
import logging
import Utility
import hashlib
import Config
import random
genesisBlock = ("I am the first block")
#
......@@ -43,9 +45,10 @@ class OverlayNode(Node):
# Checking if I am a Block Propser
previousHash = hashlib.sha256(self.blockchain[-1].encode('utf-8')).hexdigest()
seed = ( previousHash,self.currentRound,0)
hash, proof, j = Utility.sortition(self.sk,seed,20, 'BLOCK_PROPOSER', self.weight, self.network.badaW, self.pk)
hash, proof, j = Utility.sortition(self.sk,seed,Config.tou_proposer, Config.ROLE_BLOCK_PROPOSER, self.weight, self.network.badaW, self.pk)
print("I am the mighty J =",j)
if j > 0 :
if j > 0 : # only the block proposer commity mebers can enter here
min_sha_priority = None
# min_sub_user_index = None
# msg_to_broadcast = ( currentRound, hash , min_sub_user_index , min_sha_priority )
......@@ -65,8 +68,25 @@ class OverlayNode(Node):
self.logger.info("broadcsting priority message : "+str(priority_msg_to_broadcast))
self.broadcast(self.network.time, priority_msg_to_broadcast)
print("i am before yield 1",self.id)
yield "resume",7
self.logger.info("WAITING FOR PRIORITY MESSAGES from others")
yield "resume",Config.lambda_proposer
greater_flag = True
for priority_msg_other in self.uniqueReceivedMessages:
if min_sha_priority > priority_msg_other[4]:
greater_flag = False
if greater_flag :
self.logger.info("I am the block proposer")
'''
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", previousHash,Utility.pseudoRandomGenerator(random.randint(0,1000)),priority_msg_to_broadcast[1:])
self.logger.info("broadcsting BLOCK Proposal Message : " + str(BLOCK_PROPOSAL_MSG_to_broadcast))
self.broadcast(self.network.time, BLOCK_PROPOSAL_MSG_to_broadcast)
yield "resume", 9
self.logger.info(self.uniqueReceivedMessages)
yield "resume",40
......
......@@ -12,7 +12,7 @@ class TimeSimulator(object):
return "Time : "+ str(self._systemTime)
def startTicking(self,callback):
for i in range(15):
for i in range(25):
self._systemTime = self._systemTime + 1
logger.info(self)
callback(str(self._systemTime))
......
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