def msg_compressed_block_txs(self, msg: CompressedBlockTxsMessage):
        start_time = time.time()

        self.msg_txs(msg.to_txs_message(),
                     RecoveredTxsSource.COMPRESSED_BLOCK_TXS_RECEIVED)

        block_stats.add_block_event_by_block_hash(
            msg.block_hash(),
            BlockStatEventType.ENC_BLOCK_COMPRESSED_TXS_RECEIVED_BY_GATEWAY,
            network_num=msg.network_num(),
            peers=[self],
            more_info="{}. processing time: {}".format(
                stats_format.connection(self),
                stats_format.timespan(start_time, time.time())))
예제 #2
0
    def test_compressed_block_txs_message_to_txs_message(self):
        block_hash = Sha256Hash(helpers.generate_bytearray(32))
        txs_info = [
            TransactionInfo(Sha256Hash(helpers.generate_bytearray(32)),
                            helpers.generate_bytearray(200), 111),
            TransactionInfo(Sha256Hash(helpers.generate_bytearray(32)),
                            helpers.generate_bytearray(300), 222),
            TransactionInfo(Sha256Hash(helpers.generate_bytearray(32)),
                            helpers.generate_bytearray(400), 333)
        ]

        block_txs_message = CompressedBlockTxsMessage(self.NETWORK_NUM,
                                                      block_hash, txs_info)
        txs_message = block_txs_message.to_txs_message()

        self.assertEqual(TxsMessage.MESSAGE_TYPE, txs_message.msg_type())

        parsed_txs = txs_message.get_txs()

        self.assertEqual(len(parsed_txs), len(parsed_txs))

        for index in range(len(txs_info)):
            self.assertEqual(parsed_txs[index].short_id,
                             txs_info[index].short_id)
            self.assertEqual(parsed_txs[index].contents,
                             txs_info[index].contents)
            self.assertEqual(parsed_txs[index].hash, txs_info[index].hash)

        raw_bytes = txs_message.rawbytes()

        self.assertEqual(raw_bytes[:constants.STARTING_SEQUENCE_BYTES_LEN],
                         constants.STARTING_SEQUENCE_BYTES)
        self.assertIsNotNone(txs_message.payload())
        self.assertIsNotNone(txs_message.payload_len())
        # control flag check
        self.assertEqual(raw_bytes[-1], 1)