Esempio n. 1
0
def oneRound():
    global states, procNo
    global myBlock
    global acceptVal, acceptNum
#     global proposed
    global tempBlock
    global started
    global leader
    global balance
    global decideCond
    started = True
    
    
    while leader:
        time.sleep(randomVal())
        res = ElectAsLeader()
        if res == True and leader == True:
            res = transPrepare()
            if res == True:
                
                if tempBlock == paxos_pb2.Block():
                    sendDecide()
                    if myBlock not in states.blockChain:
                        states.blockChain.append(myBlock)
                        balance -= myBlock.amt
                        
                    acceptVal = paxos_pb2.Block()
                    acceptNum = paxos_pb2.BallotNum()
                    myBlock = paxos_pb2.Block()
                    started = False
                    return True
                else:
                    
                    acceptVal = paxos_pb2.Block()
                    acceptNum = paxos_pb2.BallotNum()
                    tempBlock = paxos_pb2.Block()
                    
                leader = True
                
                
                
            else:
                # Wait on decision to be made
                print("Waiting on decision")
                decideCond.acquire()
                decideCond.wait()
                decideCond.release()
                leader = True
#                 print("Accepting phase failed or not original value")
        else:
            # Wait on decision to be made
            print("Waiting on decision")
            decideCond.acquire()
            decideCond.wait()
            decideCond.release()
            leader = True
Esempio n. 2
0
 def __init__(self):
     self.balance = 100
     self.blockChain = []
     self.queue = []
     self.ballot = paxos_pb2.BallotNum()
Esempio n. 3
0
# tes = hashlib.sha256("nihao".encode("utf-8")).hexdigest()
# print(findNonce(tes))
ports = {1: 10001, 2: 10002, 3: 10003, 4: 10004, 5: 10005}
socks = {}
sockLocks = {}
responded = []
myVal = paxos_pb2.Block()
acceptVals = []
promiseCount = 1
PCLock = threading.Lock()
countLock = threading.Lock()

# failed = False
# enough = threading.Condition()
ballot = paxos_pb2.BallotNum()
ballot.num = states.ballot.num
ballot.pid = procNo
ballot.depth = len(states.blockChain)

acceptBallot = paxos_pb2.BallotNum()
acceptCount = 0

started = False

recvConds = {}

for i in range(5):
    socks[i + 1] = -1
    sockLocks[i + 1] = threading.Lock()
    recvConds[i + 1] = threading.Condition()