move quorum check to core

This commit is contained in:
ryan
2016-04-26 13:33:10 +02:00
parent 74c098a0cd
commit 3cd256a797
2 changed files with 18 additions and 6 deletions

View File

@@ -475,3 +475,18 @@ class Bigchain(object):
unvoted.pop(0)
return unvoted
def block_voted_invalid(self, block):
"""
Checks if block has enough invalid votes to make a decision
"""
n_voters = len(block['block']['voters'])
vote_list = [vote['vote']['is_block_valid'] for vote in block['votes']]
n_invalid_votes = vote_list.count(False)
if n_invalid_votes >= int(n_voters/2):
return True
else:
return False

View File

@@ -208,15 +208,12 @@ class Election(object):
"""
Checks if block has enough invalid votes to make a decision
"""
b = Bigchain()
while True:
next_block = self.q_block_new_vote.get()
n_voters = len(next_block['block']['voters'])
vote_list = [vote['vote']['is_block_valid'] for vote in next_block['votes']]
n_invalid_votes = vote_list.count(False)
if n_invalid_votes >= int(n_voters/2):
if b.block_voted_invalid(next_block):
self.q_invalid_blocks.put(next_block)
def requeue_transactions(self):