diff --git a/bigchaindb/core.py b/bigchaindb/core.py index ea4b2576..dc7d5d69 100644 --- a/bigchaindb/core.py +++ b/bigchaindb/core.py @@ -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 diff --git a/bigchaindb/voter.py b/bigchaindb/voter.py index 3e1e6cd3..2123204f 100644 --- a/bigchaindb/voter.py +++ b/bigchaindb/voter.py @@ -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):