Skip to content

TP hangs up too quickly (before fully sending SetupConnection.Error) #84

@plebhash

Description

@plebhash

Is there an existing issue for this?

  • I have searched the existing issues

Current behaviour

the following Integration Test made me realize that TP doesn't respond with a SetupConnection.Error

#[tokio::test]
async fn debug_test() {
    start_tracing();
    use roles_logic_sv2::common_messages_sv2::{SetupConnection, Protocol};
    use roles_logic_sv2::parsers::{AnyMessage, CommonMessages};
    use integration_tests_sv2::start_sniffer;
    use integration_tests_sv2::start_tracing;
    use integration_tests_sv2::sniffer::{MessageDirection, ReplaceMessage};
    use const_sv2::MESSAGE_TYPE_SETUP_CONNECTION;
    use const_sv2::MESSAGE_TYPE_SETUP_CONNECTION_ERROR;
    use std::convert::TryInto;

    // start TemplateProvider
    let (_tp, tp_addr) = integration_tests_sv2::start_template_provider(None);

    // message we are going to replace on the request from Pool
    let setup_connection = SetupConnection {
        protocol: Protocol::MiningProtocol, // not supported by a TP
        min_version: 2,
        max_version: 2,
        flags: 0,
        endpoint_host: "0.0.0.0".to_string().into_bytes().try_into().unwrap(),
        endpoint_port: 8081,
        vendor: "".to_string().into_bytes().try_into().unwrap(),
        hardware_version: "".to_string().into_bytes().try_into().unwrap(),
        firmware: "".to_string().into_bytes().try_into().unwrap(),
        device_id: "".to_string().into_bytes().try_into().unwrap(),
    };

    let message_replacement = AnyMessage::Common(CommonMessages::SetupConnection(setup_connection));
    let intercept = ReplaceMessage::new(
        MessageDirection::ToUpstream,
        MESSAGE_TYPE_SETUP_CONNECTION,
        message_replacement,
    );

    // sniffer that will be used to intercept the Pool's request and replace it with one that contains an unsupported protocol
    let (sniffer_a, sniffer_a_addr) =
        start_sniffer("A".to_string(), tp_addr, false, Some(intercept.into())).await;

    // start pool
    let _ = integration_tests_sv2::start_pool(Some(sniffer_a_addr)).await;

    // prints None
    println!("response from TP {:?}", sniffer_a.next_message_from_upstream());

    // hangs until timeout
    sniffer_a.wait_for_message_type(MessageDirection::ToDownstream, MESSAGE_TYPE_SETUP_CONNECTION_ERROR).await;
}

According to the spec, I would expect it to return a SetupConnection.Error with error_code = unsupported-protocol

Expected behaviour

#[tokio::test]
async fn debug_test() {
    start_tracing();
    use roles_logic_sv2::common_messages_sv2::{SetupConnection, Protocol};
    use roles_logic_sv2::parsers::{AnyMessage, CommonMessages};
    use integration_tests_sv2::start_sniffer;
    use integration_tests_sv2::start_tracing;
    use integration_tests_sv2::sniffer::{MessageDirection, ReplaceMessage};
    use const_sv2::MESSAGE_TYPE_SETUP_CONNECTION;
    use const_sv2::MESSAGE_TYPE_SETUP_CONNECTION_ERROR;
    use std::convert::TryInto;

    // start TemplateProvider
    let (_tp, tp_addr) = integration_tests_sv2::start_template_provider(None);

    // message we are going to replace on the request from Pool
    let setup_connection = SetupConnection {
        protocol: Protocol::MiningProtocol, // not supported by a TP
        min_version: 2,
        max_version: 2,
        flags: 0,
        endpoint_host: "0.0.0.0".to_string().into_bytes().try_into().unwrap(),
        endpoint_port: 8081,
        vendor: "".to_string().into_bytes().try_into().unwrap(),
        hardware_version: "".to_string().into_bytes().try_into().unwrap(),
        firmware: "".to_string().into_bytes().try_into().unwrap(),
        device_id: "".to_string().into_bytes().try_into().unwrap(),
    };

    let message_replacement = AnyMessage::Common(CommonMessages::SetupConnection(setup_connection));
    let intercept = ReplaceMessage::new(
        MessageDirection::ToUpstream,
        MESSAGE_TYPE_SETUP_CONNECTION,
        message_replacement,
    );

    // sniffer that will be used to intercept the Pool's request and replace it with one that contains an unsupported protocol
    let (sniffer_a, sniffer_a_addr) =
        start_sniffer("A".to_string(), tp_addr, false, Some(intercept.into())).await;

    // start pool
    let _ = integration_tests_sv2::start_pool(Some(sniffer_a_addr)).await;

    // prints Some(SetupConnectionError)
    println!("response from TP {:?}", sniffer_a.next_message_from_upstream());

    // returns without error
    sniffer_a.wait_for_message_type(MessageDirection::ToDownstream, MESSAGE_TYPE_SETUP_CONNECTION_ERROR).await;
}

Steps to reproduce

Integration Tests described above

Relevant log output

No response

How did you obtain Bitcoin Core

Other

What version of Bitcoin Core are you using?

0.1.13

Operating system and version

MacOS Sonoma Version 14.4.1 (23E224)

Machine specifications

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions