Пример #1
0
    def complete_vote(self, blocknum, txnlist):
        """Close the current vote.

        This is called by the QuorumVote object after the last ballot has been
        closed. The specified transactions can be safely added to journal.

        Args:
            blocknum (int): The block identifier.
            txnlist (list): A list of transactions that nodes voted to
                include in the block.
        """

        logger.debug('complete the vote for block based on %s',
                     self.MostRecentCommitedBlockID)

        if blocknum != self.MostRecentCommitedBlock.BlockNumber + 1:
            logger.warn(
                'attempt complete vote on block %d, expecting block %d',
                blocknum, self.MostRecentCommitedBlock.BlockNumber + 1)
            return

        nblock = quorum_transaction_block.QuorumTransactionBlock()
        nblock.BlockNumber = blocknum
        nblock.PreviousBlockID = self.MostRecentCommitedBlockID
        nblock.TransactionIDs = txnlist[:]
        nblock.sign_from_node(self.LocalNode)

        logger.info('commit: %s', nblock.dump())

        self.commit_transaction_block(nblock)

        self.CurrentQuorumVote = None
        self.NextVoteTime = self._nextvotetime()
        self.NextBallotTime = 0
Пример #2
0
    def build_transaction_block(self, force=False):
        """Builds the next transaction block for the journal.

        Note:
            For the voting journal this operation is meaningful only
            for the initial block. All other blocks are created after
            voting completes.

        Args:
            force (boolean): Force creation of the initial block.

        Returns:
            QuorumTransactionBlock: The created transaction block.
        """

        logger.debug('build transaction block')

        if force:
            block = quorum_transaction_block.QuorumTransactionBlock()
            block.BlockNumber = 0
            return block

        return None