def msg_confirmed_tx(self, msg: ConfirmedTxMessage) -> None:
        tx_hash = msg.tx_hash()
        transaction_key = self.node.get_tx_service().get_transaction_key(
            tx_hash)
        tx_contents = msg.tx_val()

        # shouldn't ever happen, but just in case
        if tx_contents == ConfirmedTxMessage.EMPTY_TX_VAL:
            tx_contents = cast(
                Optional[memoryview],
                self.node.get_tx_service().get_transaction_by_key(
                    transaction_key))
            if tx_contents is None:
                transaction_feed_stats_service.log_pending_transaction_missing_contents(
                )
                return

        self.node.feed_manager.publish_to_feed(
            FeedKey(EthPendingTransactionFeed.NAME),
            EthRawTransaction(tx_hash,
                              tx_contents,
                              FeedSource.BDN_SOCKET,
                              local_region=True))

        transaction_feed_stats_service.log_pending_transaction_from_internal(
            tx_hash)
Пример #2
0
    def test_msg_confirmed_tx(self):
        self.node.feed_manager.publish_to_feed = MagicMock()

        tx_hash = helpers.generate_object_hash()
        message = ConfirmedTxMessage(tx_hash)
        self.connection.msg_confirmed_tx(message)
        self.node.feed_manager.publish_to_feed.assert_not_called()

        tx_hash = helpers.generate_object_hash()
        message = ConfirmedTxMessage(
            tx_hash, rlp.encode(mock_eth_messages.get_dummy_transaction(1)))
        self.connection.msg_confirmed_tx(message)
        self.node.feed_manager.publish_to_feed.assert_called_once()
Пример #3
0
    def test_message_preview_success_all_gateway_types(self):
        self.get_message_preview_successfully(
            GatewayHelloMessage(123, 1, "127.0.0.1", 40000, 1),
            GatewayMessageType.HELLO,
            GatewayHelloMessage.PAYLOAD_LENGTH,
        )
        self.get_message_preview_successfully(
            BlockReceivedMessage(self.HASH),
            GatewayMessageType.BLOCK_RECEIVED,
            BlockReceivedMessage.PAYLOAD_LENGTH,
        )
        self.get_message_preview_successfully(
            BlockPropagationRequestMessage(self.BLOCK),
            GatewayMessageType.BLOCK_PROPAGATION_REQUEST,
            len(self.BLOCK) + constants.CONTROL_FLAGS_LEN,
        )
        self.get_message_preview_successfully(
            BlockHoldingMessage(self.HASH, network_num=123),
            BloxrouteMessageType.BLOCK_HOLDING,
            BlockHoldingMessage.PAYLOAD_LENGTH,
        )
        self.get_message_preview_successfully(
            ConfirmedTxMessage(self.HASH, self.TX_VAL),
            GatewayMessageType.CONFIRMED_TX,
            ConfirmedTxMessage.PAYLOAD_LENGTH + len(self.TX_VAL),
        )
        self.get_message_preview_successfully(
            RequestTxStreamMessage(),
            GatewayMessageType.REQUEST_TX_STREAM,
            constants.CONTROL_FLAGS_LEN,
        )

        hash_val = BtcObjectHash(buf=crypto.double_sha256(b"123"),
                                 length=crypto.SHA256_HASH_LEN)
        blockchain_message = GetBlocksBtcMessage(12345, 23456, [hash_val],
                                                 hash_val).rawbytes()
        self.get_message_preview_successfully(
            BlockchainSyncRequestMessage(GetBlocksBtcMessage.MESSAGE_TYPE,
                                         blockchain_message),
            BlockchainSyncRequestMessage.MESSAGE_TYPE,
            MSG_TYPE_LEN + len(blockchain_message),
        )
        self.get_message_preview_successfully(
            BlockchainSyncResponseMessage(GetBlocksBtcMessage.MESSAGE_TYPE,
                                          blockchain_message),
            BlockchainSyncResponseMessage.MESSAGE_TYPE,
            MSG_TYPE_LEN + len(blockchain_message),
        )
Пример #4
0
    def test_create_message_success_all_gateway_types(self):
        hello_message = self.create_message_successfully(
            GatewayHelloMessage(123, 1, "127.0.0.1", 40001, 1),
            GatewayHelloMessage)
        self.assertEqual(123, hello_message.protocol_version())
        self.assertEqual(1, hello_message.network_num())
        self.assertEqual("127.0.0.1", hello_message.ip())
        self.assertEqual(40001, hello_message.port())
        self.assertEqual(1, hello_message.ordering())

        block_recv_message = self.create_message_successfully(
            BlockReceivedMessage(self.HASH), BlockReceivedMessage)
        self.assertEqual(self.HASH, block_recv_message.block_hash())

        block_holding_message = self.create_message_successfully(
            BlockHoldingMessage(self.HASH, network_num=123),
            BlockHoldingMessage)
        self.assertEqual(self.HASH, block_holding_message.block_hash())

        block_propagation_request_message = self.create_message_successfully(
            BlockPropagationRequestMessage(self.BLOCK),
            BlockPropagationRequestMessage)
        self.assertEqual(self.BLOCK, block_propagation_request_message.blob())

        hash_val = BtcObjectHash(buf=crypto.double_sha256(b"123"),
                                 length=crypto.SHA256_HASH_LEN)
        blockchain_message_in = GetBlocksBtcMessage(12345, 23456, [hash_val],
                                                    hash_val).rawbytes()
        sync_request_message = self.create_message_successfully(
            BlockchainSyncRequestMessage(GetBlocksBtcMessage.MESSAGE_TYPE,
                                         blockchain_message_in),
            BlockchainSyncRequestMessage,
        )
        blockchain_message_out = GetBlocksBtcMessage(
            buf=sync_request_message.payload())
        self.assertEqual(12345, blockchain_message_out.magic())
        self.assertEqual(23456, blockchain_message_out.version())
        self.assertEqual(1, blockchain_message_out.hash_count())
        self.assertEqual(hash_val, blockchain_message_out.hash_stop())

        self.create_message_successfully(
            BlockchainSyncResponseMessage(GetBlocksBtcMessage.MESSAGE_TYPE,
                                          blockchain_message_in),
            BlockchainSyncResponseMessage,
        )

        blockchain_message_out = GetBlocksBtcMessage(
            buf=sync_request_message.payload())
        self.assertEqual(12345, blockchain_message_out.magic())
        self.assertEqual(23456, blockchain_message_out.version())
        self.assertEqual(1, blockchain_message_out.hash_count())
        self.assertEqual(hash_val, blockchain_message_out.hash_stop())

        confirmed_tx = self.create_message_successfully(
            ConfirmedTxMessage(self.HASH, self.TX_VAL), ConfirmedTxMessage)
        self.assertEqual(self.HASH, confirmed_tx.tx_hash())
        self.assertEqual(self.TX_VAL, confirmed_tx.tx_val())

        confirmed_tx_no_content = self.create_message_successfully(
            ConfirmedTxMessage(self.HASH), ConfirmedTxMessage)
        self.assertEqual(self.HASH, confirmed_tx_no_content.tx_hash())
        self.assertEqual(TxMessage.EMPTY_TX_VAL,
                         confirmed_tx_no_content.tx_val())

        self.create_message_successfully(RequestTxStreamMessage(),
                                         RequestTxStreamMessage)