'Given a list of eligible votes, (votes from known nodes that are listed
as voters), produce the number that say valid and the number that say
invalid. Votes must agree on previous block, otherwise they become invalid.'

@classmethod
def count_votes(cls, by_voter):

    prev_blocks = collections.Counter()
    malformed = []
    for vote in by_voter.values():
        if (not cls.verify_vote_schema(vote)):
            malformed.append(vote)
            continue
        if (vote['vote']['is_block_valid'] is True):
            prev_blocks[vote['vote']['previous_block']] += 1
    n_valid = 0
    prev_block = None
    if prev_blocks:
        (prev_block, n_valid) = prev_blocks.most_common()[0]
        del prev_blocks[prev_block]
    return {'counts': {'n_valid': n_valid, 'n_invalid': (len(by_voter) - n_valid)}, 'malformed': malformed, 'previous_block': prev_block, 'other_previous_block': dict(prev_blocks)}
