def has_previous_vote(self, block_id, voters): """Check for previous votes from this node Args: block_id (str): the id of the block to check voters (list(str)): the voters of the block to check Returns: bool: :const:`True` if this block already has a valid vote from this node, :const:`False` otherwise. Raises: ImproperVoteError: If there is already a vote, but the vote is invalid. """ votes = list( self.backend.get_votes_by_block_id_and_voter(block_id, self.me)) if len(votes) > 1: raise exceptions.MultipleVotesError( 'Block {block_id} has {n_votes} votes from public key {me}'. format(block_id=block_id, n_votes=str(len(votes)), me=self.me)) has_previous_vote = False if votes: if util.verify_vote_signature(voters, votes[0]): has_previous_vote = True else: raise exceptions.ImproperVoteError( 'Block {block_id} already has an incorrectly signed vote ' 'from public key {me}'.format(block_id=block_id, me=self.me)) return has_previous_vote
def verify_vote_signature(voters, signed_vote): """Verify the signature of a vote. Refer to the documentation of :func:`bigchaindb.util.verify_signature`. """ return verify_vote_signature(voters, signed_vote)
def has_previous_vote(self, block_id, voters): """Check for previous votes from this node Args: block_id (str): the id of the block to check voters (list(str)): the voters of the block to check Returns: bool: :const:`True` if this block already has a valid vote from this node, :const:`False` otherwise. Raises: ImproperVoteError: If there is already a vote, but the vote is invalid. """ votes = list(backend.query.get_votes_by_block_id_and_voter(self.connection, block_id, self.me)) if len(votes) > 1: raise exceptions.MultipleVotesError('Block {block_id} has {n_votes} votes from public key {me}' .format(block_id=block_id, n_votes=str(len(votes)), me=self.me)) has_previous_vote = False if votes: if util.verify_vote_signature(voters, votes[0]): has_previous_vote = True else: raise exceptions.ImproperVoteError('Block {block_id} already has an incorrectly signed vote ' 'from public key {me}'.format(block_id=block_id, me=self.me)) return has_previous_vote
def verify_vote_signature(block, signed_vote): """Verify the signature of a vote. Refer to the documentation of ``bigchaindb.util.verify_signature`` """ return util.verify_vote_signature(block, signed_vote)
def has_previous_vote(self, block): """Check for previous votes from this node Args: block (dict): block to check. Returns: bool: :const:`True` if this block already has a valid vote from this node, :const:`False` otherwise. Raises: ImproperVoteError: If there is already a vote, but the vote is invalid. """ votes = list(r.table('votes').get_all([block['id'], self.me], index='block_and_voter').run(self.conn)) if len(votes) > 1: raise exceptions.MultipleVotesError('Block {block_id} has {n_votes} votes from public key {me}' .format(block_id=block['id'], n_votes=str(len(votes)), me=self.me)) has_previous_vote = False if votes: if util.verify_vote_signature(block, votes[0]): has_previous_vote = True else: raise exceptions.ImproperVoteError('Block {block_id} already has an incorrectly signed vote ' 'from public key {me}'.format(block_id=block['id'], me=self.me)) return has_previous_vote
def has_previous_vote(self, block): """Check for previous votes from this node Args: block (dict): block to check. Returns: bool: :const:`True` if this block already has a valid vote from this node, :const:`False` otherwise. Raises: ImproperVoteError: If there is already a vote, but the vote is invalid. """ votes = list(r.table('votes', read_mode=self.read_mode)\ .get_all([block['id'], self.me], index='block_and_voter').run(self.conn)) if len(votes) > 1: raise exceptions.MultipleVotesError('Block {block_id} has {n_votes} votes from public key {me}' .format(block_id=block['id'], n_votes=str(len(votes)), me=self.me)) has_previous_vote = False if votes: if util.verify_vote_signature(block, votes[0]): has_previous_vote = True else: raise exceptions.ImproperVoteError('Block {block_id} already has an incorrectly signed vote ' 'from public key {me}'.format(block_id=block['id'], me=self.me)) return has_previous_vote
def verify_vote(voters, signed_vote): """Verify the signature of a vote. Refer to the documentation of :func:`bigchaindb.util.verify_signature`. """ if verify_vote_signature(voters, signed_vote): try: validate_vote_schema(signed_vote) return True except SchemaValidationError as exc: logger.warning(exc) else: logger.warning("Vote failed signature verification: " "%s with voters: %s", signed_vote, voters) return False
def verify_vote(voters, signed_vote): """Verify the signature of a vote. Refer to the documentation of :func:`bigchaindb.util.verify_signature`. """ if verify_vote_signature(voters, signed_vote): try: validate_vote_schema(signed_vote) return True except SchemaValidationError as exc: logger.warning(exc) else: logger.warning( "Vote failed signature verification: " "%s with voters: %s", signed_vote, voters) return False
def has_previous_vote(self, block): """Check for previous votes from this node Args: block (dict): block to check. Returns: True if this block already has a valid vote from this node, False otherwise. If there is already a vote, but the vote is invalid, raises an ImproperVoteError """ if block['votes']: for vote in block['votes']: if vote['node_pubkey'] == self.me: if util.verify_vote_signature(block, vote): return True else: raise ImproperVoteError('Block {block_id} already has an incorrectly signed vote ' 'from public key {me}').format(block_id=block['id'], me=self.me) return False
def has_previous_vote(self, block): """Check for previous votes from this node Args: block (dict): block to check. Returns: True if this block already has a valid vote from this node, False otherwise. If there is already a vote, but the vote is invalid, raises an ImproperVoteError """ if block['votes']: for vote in block['votes']: if vote['node_pubkey'] == self.me: if util.verify_vote_signature(block, vote): return True else: raise ImproperVoteError( 'Block {block_id} already has an incorrectly signed vote ' 'from public key {me}').format( block_id=block['id'], me=self.me) return False
def has_previous_vote(self, block): """Check for previous votes from this node Args: block (dict): block to check. Returns: bool: :const:`True` if this block already has a valid vote from this node, :const:`False` otherwise. Raises: ImproperVoteError: If there is already a vote, but the vote is invalid. """ if block['votes']: for vote in block['votes']: if vote['node_pubkey'] == self.me: if not util.verify_vote_signature(block, vote): raise exceptions.ImproperVoteError( 'Block {} already has an incorrectly signed vote from public key {}' ).format(block['id'], self.me) return True return False