comments on voting logic

This commit is contained in:
ryan 2016-05-03 16:08:10 +02:00
parent dfcdb785f1
commit 4f56ed43e1

View File

@ -504,6 +504,11 @@ class Bigchain(object):
n_valid_votes = sum(vote_list) n_valid_votes = sum(vote_list)
n_invalid_votes = len(vote_list) - n_valid_votes n_invalid_votes = len(vote_list) - n_valid_votes
# The use of ceiling and floor is to account for the case of an
# even number of voters where half the voters have voted 'invalid'
# and half 'valid'. In this case, the block should marked invalid
# to avoid a hung election. In the case of an odd number of voters
# this is not relevant, since one side must be a majority.
if n_invalid_votes >= math.ceil(n_voters / 2): if n_invalid_votes >= math.ceil(n_voters / 2):
return 'invalid' return 'invalid'
elif n_valid_votes > math.floor(n_voters / 2): elif n_valid_votes > math.floor(n_voters / 2):