Exemple #1
0
    def test_message_tracked_correctly_when_framed(self):
        block_stats.add_block_event_by_block_hash = MagicMock()

        # send the handshake message
        self.node.on_bytes_sent(self.connection_fileno, 307)
        self.node.on_bytes_written_to_socket(self.connection_fileno, 307)

        block_message = NewBlockEthProtocolMessage(
            None,
            mock_eth_messages.get_dummy_block(
                1,
                mock_eth_messages.get_dummy_block_header(5, int(time.time()))),
            10)
        block_message.serialize()

        self.connection.enqueue_msg(block_message)
        message_length = self.connection.outputbuf.length
        for message in self.connection.message_tracker.messages:
            print(message.length)
        block_stats.add_block_event_by_block_hash.assert_not_called()
        self.assertEqual(message_length,
                         self.connection.message_tracker.messages[0].length)

        self.node.on_bytes_sent(self.connection_fileno, message_length)
        self.node.on_bytes_written_to_socket(self.connection_fileno,
                                             message_length)
        block_stats.add_block_event_by_block_hash.assert_called_once()
Exemple #2
0
    def test_bdn_stats_block_new_from_bdn_ignore_from_node(self):
        block_msg = NewBlockEthProtocolMessage(
            None,
            _block_with_timestamp(time.time() + 1 - (
                self.node.opts.blockchain_ignore_block_interval_count *
                self.node.opts.blockchain_block_interval)), 10)

        internal_new_block_msg = InternalEthBlockInfo.from_new_block_msg(
            block_msg)
        msg_bytes, block_info = self.node.message_converter.block_to_bx_block(
            internal_new_block_msg, self.node._tx_service, True,
            self.node.network.min_tx_age_seconds)
        msg_hash = Sha256Hash(crypto.double_sha256(msg_bytes))
        broadcast_msg = BroadcastMessage(message_hash=msg_hash,
                                         network_num=1,
                                         is_encrypted=False,
                                         blob=msg_bytes)
        self.relay_connection.msg_broadcast(broadcast_msg)

        block_msg.serialize()
        self.block_blockchain_connection_protocol.msg_block(block_msg)

        self.assertEqual(
            3,
            len(gateway_bdn_performance_stats_service.interval_data.
                blockchain_node_to_bdn_stats))
        for stats in gateway_bdn_performance_stats_service.interval_data.blockchain_node_to_bdn_stats.values(
        ):
            self.assertEqual(1, stats.new_blocks_received_from_bdn)
            self.assertEqual(0, stats.new_blocks_received_from_blockchain_node)
Exemple #3
0
    def test_bdn_stats_block_new_from_node_ignore_duplicate(self):
        block_msg = NewBlockEthProtocolMessage(
            None,
            _block_with_timestamp(
                time.time() + 1 -
                self.node.opts.blockchain_ignore_block_interval_count *
                self.node.opts.blockchain_block_interval), 10)
        block_msg.serialize()
        self.block_blockchain_connection_protocol.msg_block(block_msg)
        self.block_blockchain_connection_protocol.msg_block(block_msg)

        self.assertEqual(
            3,
            len(gateway_bdn_performance_stats_service.interval_data.
                blockchain_node_to_bdn_stats))
        node_1_stats = gateway_bdn_performance_stats_service.interval_data.blockchain_node_to_bdn_stats[
            self.node_1_endpoint]
        for endpoint, stats in gateway_bdn_performance_stats_service.interval_data.blockchain_node_to_bdn_stats.items(
        ):
            if endpoint == self.node_1_endpoint:
                continue
            self.assertEqual(1, stats.new_blocks_received_from_bdn)

        self.assertEqual(1,
                         node_1_stats.new_blocks_received_from_blockchain_node)
Exemple #4
0
 def generate_new_eth_block(self) -> NewBlockEthProtocolMessage:
     block_message = NewBlockEthProtocolMessage(
         None,
         mock_eth_messages.get_dummy_block(1, mock_eth_messages.get_dummy_block_header(5, int(time.time()))),
         10
     )
     block_message.serialize()
     return block_message
 def test_msg_block_too_old(self):
     message = NewBlockEthProtocolMessage(
         None,
         _block_with_timestamp(
             time.time() - 1 - self.node.opts.blockchain_ignore_block_interval_count * self.node.opts.blockchain_block_interval
         ),
         10
     )
     message.serialize()
     self.sut.msg_block(message)
     self.node.block_processing_service.queue_block_for_processing.assert_not_called()
Exemple #6
0
 def generate_new_eth_block(self, block_number=10) -> InternalEthBlockInfo:
     block_message = NewBlockEthProtocolMessage(
         None,
         mock_eth_messages.get_dummy_block(
             1,
             mock_eth_messages.get_dummy_block_header(
                 5, int(time.time()), block_number=block_number)), 10)
     block_message.serialize()
     internal_block_message = InternalEthBlockInfo.from_new_block_msg(
         block_message)
     return internal_block_message