Exemplo n.º 1
0
    def check_for_quorum(self, next_vote):
        """
        Checks if block has enough invalid votes to make a decision

        Args:
            next_vote: The next vote.

        """
        try:
            block_id = next_vote['vote']['voting_for_block']
            node = next_vote['node_pubkey']
        except KeyError:
            return

        next_block = self.bigchain.get_block(block_id)

        result = self.bigchain.block_election(next_block)
        self.handle_block_events(result, block_id)
        if result['status'] == self.bigchain.BLOCK_INVALID:
            return Block.from_dict(next_block)

        # Log the result
        if result['status'] != self.bigchain.BLOCK_UNDECIDED:
            msg = 'node:%s block:%s status:%s' % \
                (node, block_id, result['status'])
            # Extra data can be accessed via the log formatter.
            # See logging.dictConfig.
            logger_results.debug(msg, extra={
                'current_vote': next_vote,
                'election_result': result,
            })
Exemplo n.º 2
0
    def check_for_quorum(self, next_vote):
        """
        Checks if block has enough invalid votes to make a decision

        Args:
            next_vote: The next vote.

        """
        next_block = self.bigchain.get_block(
            next_vote['vote']['voting_for_block'])

        block_status = self.bigchain.block_election_status(next_block['id'],
                                                           next_block['block']['voters'])
        if block_status == self.bigchain.BLOCK_INVALID:
            return Block.from_dict(next_block)
Exemplo n.º 3
0
 def validate_block(self, block):
     if not self.bigchain.has_previous_vote(block['id']):
         try:
             block = Block.from_dict(block)
         except (exceptions.InvalidHash):
             # XXX: if a block is invalid we should skip the `validate_tx`
             # step, but since we are in a pipeline we cannot just jump to
             # another function. Hackish solution: generate an invalid
             # transaction and propagate it to the next steps of the
             # pipeline.
             return block['id'], [self.invalid_dummy_tx]
         try:
             block._validate_block(self.bigchain)
         except exceptions.ValidationError:
             # XXX: if a block is invalid we should skip the `validate_tx`
             # step, but since we are in a pipeline we cannot just jump to
             # another function. Hackish solution: generate an invalid
             # transaction and propagate it to the next steps of the
             # pipeline.
             return block.id, [self.invalid_dummy_tx]
         return block.id, block.transactions
Exemplo n.º 4
0
 def validate_block(self, block):
     if not self.bigchain.has_previous_vote(block['id'],
                                            block['block']['voters']):
         try:
             block = Block.from_dict(block)
         except (exceptions.InvalidHash, exceptions.InvalidSignature):
             # XXX: if a block is invalid we should skip the `validate_tx`
             # step, but since we are in a pipeline we cannot just jump to
             # another function. Hackish solution: generate an invalid
             # transaction and propagate it to the next steps of the
             # pipeline.
             return block['id'], [self.invalid_dummy_tx]
         try:
             self.consensus.validate_block(self.bigchain, block)
         except (exceptions.InvalidHash, exceptions.OperationError,
                 exceptions.InvalidSignature):
             # XXX: if a block is invalid we should skip the `validate_tx`
             # step, but since we are in a pipeline we cannot just jump to
             # another function. Hackish solution: generate an invalid
             # transaction and propagate it to the next steps of the
             # pipeline.
             return block.id, [self.invalid_dummy_tx]
         return block.id, block.transactions
Exemplo n.º 5
0
    def test_block_deserialization(self, b, alice):
        from bigchaindb.common.crypto import hash_data
        from bigchaindb.common.utils import gen_timestamp, serialize
        from bigchaindb.models import Block, Transaction

        transaction = Transaction.create([alice.public_key],
                                         [([alice.public_key], 1)])
        transaction.sign([alice.private_key])
        timestamp = gen_timestamp()
        expected = Block([transaction], alice.public_key, timestamp)

        block = {
            'timestamp': timestamp,
            'transactions': [transaction.to_dict()],
            'node_pubkey': alice.public_key,
        }

        block_body = {
            'id': hash_data(serialize(block)),
            'block': block,
            'signature': None,
        }

        assert expected == Block.from_dict(block_body)
Exemplo n.º 6
0
    def test_block_deserialization(self, b):
        from bigchaindb.common.crypto import hash_data
        from bigchaindb.common.utils import gen_timestamp, serialize
        from bigchaindb.models import Block, Transaction

        transactions = [Transaction.create([b.me], [([b.me], 1)])]
        timestamp = gen_timestamp()
        voters = ['Qaaa', 'Qbbb']
        expected = Block(transactions, b.me, timestamp, voters)

        block = {
            'timestamp': timestamp,
            'transactions': [tx.to_dict() for tx in transactions],
            'node_pubkey': b.me,
            'voters': voters,
        }

        block_body = {
            'id': hash_data(serialize(block)),
            'block': block,
            'signature': None,
        }

        assert expected == Block.from_dict(block_body)
Exemplo n.º 7
0
    def get_last_voted_block(self):
        """Returns the last block that this node voted on."""

        return Block.from_dict(self.backend.get_last_voted_block(self.me))
Exemplo n.º 8
0
    def get_last_voted_block(self):
        """Returns the last block that this node voted on."""

        return Block.from_dict(
            backend.query.get_last_voted_block(self.connection, self.me))
Exemplo n.º 9
0
    def get_last_voted_block(self):
        """Returns the last block that this node voted on."""

        return Block.from_dict(backend.query.get_last_voted_block(self.connection, self.me))