Exemplo n.º 1
0
    def _new_block_procedure(self, block: BlockContender, txs: List[bytes]):
        self.log.notice("Masternode attempting to store a new block")

        # Attempt to store block
        try:
            block_hash = BlockStorageDriver.store_block(
                block_contender=block,
                raw_transactions=txs,
                publisher_sk=self.parent.signing_key)
            self.log.important2(
                "Masternode successfully stored new block with {} total transactiosn and block hash {}"
                .format(len(txs), block_hash))
        except BlockStorageException as e:
            self.log.error("Error storing block!\nError = {}".format(e))
            self._try_next_block()
            return

        # Notify delegates that a new block was published
        self.log.info(
            "Masternode sending NewBlockNotification to TESTNET_DELEGATES with new block hash {} "
            .format(block_hash))
        notif = NewBlockNotification.create(
            **BlockStorageDriver.get_latest_block(include_number=False))
        self.parent.composer.send_pub_msg(filter=MASTERNODE_DELEGATE_FILTER,
                                          message=notif,
                                          port=MN_NEW_BLOCK_PUB_PORT)
Exemplo n.º 2
0
    def _new_block_procedure(self, block: BlockContender, txs: List[bytes]):
        self.log.notice("Masternode attempting to store a new block")
        # self.log.debugv("DONE COLLECTING BLOCK DATA FROM LEAVES. Storing new "
        #                 "block with...\ncontender={}\nraw txs={}".format(block, txs))

        # Attempt to store block
        try:
            block_hash = BlockStorageDriver.store_block(block_contender=block, raw_transactions=txs, publisher_sk=self.parent.signing_key)
            self.log.important2("Masternode successfully stored new block with {} total transactiosn and block hash {}"
                                .format(len(txs), block_hash))
        except BlockStorageException as e:
            self.log.error("Error storing block!\nError = {}".format(e))
            self._try_next_block()
            return

        # Notify delegates of new block
        self.log.info("Masternode sending NewBlockNotification to delegates with new block hash {} ".format(block_hash))
        notif = NewBlockNotification.create(**BlockStorageDriver.get_latest_block(include_number=False))
        self.parent.composer.send_pub_msg(filter=masternode_delegate, message=notif)