Exemple #1
0
    def end_block(self, height):
        """Calculate block hash using transaction ids and previous block
        hash to be stored in the next block.

        Args:
            height (int): new height of the chain."""

        self.new_height = height
        block_txn_hash = calculate_hash(self.block_txn_ids)
        block = self.bigchaindb.get_latest_block()

        if self.block_txn_ids:
            self.block_txn_hash = calculate_hash(
                [block['app_hash'], block_txn_hash])
        else:
            self.block_txn_hash = block['app_hash']

        validator_updates = self.bigchaindb.get_validator_update()
        validator_updates = [encode_validator(v) for v in validator_updates]

        # set sync status to true
        self.bigchaindb.delete_validator_update()

        # NOTE: interface for `ResponseEndBlock` has be changed in the latest
        # version of py-abci i.e. the validator updates should be return
        # as follows:
        # ResponseEndBlock(validator_updates=validator_updates)
        return ResponseEndBlock(diffs=validator_updates)
Exemple #2
0
    def end_block(self, request_end_block):
        """Calculate block hash using transaction ids and previous block
        hash to be stored in the next block.

        Args:
            height (int): new height of the chain.
        """

        self.abort_if_abci_chain_is_not_synced()

        chain_shift = 0 if self.chain is None else self.chain['height']

        height = request_end_block.height + chain_shift
        self.new_height = height
        block_txn_hash = calculate_hash(self.block_txn_ids)
        block = self.bigchaindb.get_latest_block()

        if self.block_txn_ids:
            self.block_txn_hash = calculate_hash(
                [block['app_hash'], block_txn_hash])
        else:
            self.block_txn_hash = block['app_hash']

        validator_update = Election.process_block(self.bigchaindb,
                                                  self.new_height,
                                                  self.block_transactions)

        # Store pre-commit state to recover in case there is a crash  during `commit`
        pre_commit_state = PreCommitState(commit_id=PRE_COMMIT_ID,
                                          height=self.new_height,
                                          transactions=self.block_txn_ids)
        logger.debug('Updating PreCommitState: %s', self.new_height)
        self.bigchaindb.store_pre_commit_state(pre_commit_state._asdict())
        return ResponseEndBlock(validator_updates=validator_update)
Exemple #3
0
    def end_block(self, request_end_block):
        """Calculate block hash using transaction ids and previous block
        hash to be stored in the next block.

        Args:
            height (int): new height of the chain.
        """

        height = request_end_block.height
        self.new_height = height
        block_txn_hash = calculate_hash(self.block_txn_ids)
        block = self.bigchaindb.get_latest_block()

        if self.block_txn_ids:
            self.block_txn_hash = calculate_hash(
                [block['app_hash'], block_txn_hash])
        else:
            self.block_txn_hash = block['app_hash']

        # TODO: calculate if an election has concluded
        # NOTE: ensure the local validator set is updated
        # validator_updates = self.bigchaindb.get_validator_update()
        # validator_updates = [encode_validator(v) for v in validator_updates]
        validator_updates = []

        # Store pre-commit state to recover in case there is a crash
        # during `commit`
        pre_commit_state = PreCommitState(commit_id=PRE_COMMIT_ID,
                                          height=self.new_height,
                                          transactions=self.block_txn_ids)
        logger.debug('Updating PreCommitState: %s', self.new_height)
        self.bigchaindb.store_pre_commit_state(pre_commit_state._asdict())
        return ResponseEndBlock(validator_updates=validator_updates)
Exemple #4
0
    def end_block(self, height):
        """Calculate block hash using transaction ids and previous block
        hash to be stored in the next block.

        Args:
            height (int): new height of the chain."""
        self.new_height = height
        block_txn_hash = calculate_hash(self.block_txn_ids)
        block = self.bigchaindb.get_latest_block()

        if self.block_txn_ids:
            self.block_txn_hash = calculate_hash(
                [block['app_hash'], block_txn_hash])
        else:
            self.block_txn_hash = block['app_hash']

        validator_updates = self.bigchaindb.get_validator_update()
        validator_updates = [encode_validator(v) for v in validator_updates]

        # set sync status to true
        self.bigchaindb.delete_validator_update()

        # Store pre-commit state to recover in case there is a crash
        # during `commit`
        pre_commit_state = PreCommitState(commit_id=PRE_COMMIT_ID,
                                          height=self.new_height,
                                          transactions=self.block_txn_ids)
        logger.debug('Updating PreCommitState: %s', self.new_height)
        self.bigchaindb.store_pre_commit_state(pre_commit_state._asdict())

        # NOTE: interface for `ResponseEndBlock` has be changed in the latest
        # version of py-abci i.e. the validator updates should be return
        # as follows:
        # ResponseEndBlock(validator_updates=validator_updates)
        return ResponseEndBlock(validator_updates=validator_updates)
Exemple #5
0
    def end_block(self, request_end_block):
        """Calculate block hash using transaction ids and previous block
        hash to be stored in the next block.

        Args:
            height (int): new height of the chain.
        """

        height = request_end_block.height
        self.new_height = height
        block_txn_hash = calculate_hash(self.block_txn_ids)
        block = self.bigchaindb.get_latest_block()

        if self.block_txn_ids:
            self.block_txn_hash = calculate_hash([block['app_hash'], block_txn_hash])
        else:
            self.block_txn_hash = block['app_hash']

        # Check if the current block concluded any validator elections and
        # update the locally tracked validator set
        validator_updates = ValidatorElection.get_validator_update(self.bigchaindb,
                                                                   self.new_height,
                                                                   self.block_transactions)

        # Store pre-commit state to recover in case there is a crash
        # during `commit`
        pre_commit_state = PreCommitState(commit_id=PRE_COMMIT_ID,
                                          height=self.new_height,
                                          transactions=self.block_txn_ids)
        logger.debug('Updating PreCommitState: %s', self.new_height)
        self.bigchaindb.store_pre_commit_state(pre_commit_state._asdict())
        return ResponseEndBlock(validator_updates=validator_updates)
Exemple #6
0
    def end_block(self, height):
        """Called at the end of processing. If this is a stateful application
        you can use the height from here to record the last_block_height"""

        self.db.set_block_height(increment=True)
        if self.new_block_txs:  # Change app hash only if there any new txns
            self.db.set_block_app_hash(utils.get_merkle_root(self.new_block_txs))

        return ResponseEndBlock()
Exemple #7
0
    def end_block(self, height):
        """Calculate block hash using transaction ids and previous block
        hash to be stored in the next block.

        Args:
            height (int): new height of the chain."""

        self.new_height = height
        block_txn_hash = calculate_hash(self.block_txn_ids)
        block = self.bigchaindb.get_latest_block()

        if self.block_txn_ids:
            self.block_txn_hash = calculate_hash(
                [block['app_hash'], block_txn_hash])
        else:
            self.block_txn_hash = block['app_hash']

        return ResponseEndBlock()
Exemple #8
0
 def end_block(self, height):
     """Called at the end of processing. If this is a stateful application
     you can use the height from here to record the last_block_height"""
     self.last_block_height = height
     return ResponseEndBlock()
Exemple #9
0
 def end_block(self, req):
     return ResponseEndBlock(validator_updates=self.validators)