Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(starknet_mempool_p2p): test gateway client error on adding tx from p2p #2138

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AlonLStarkWare
Copy link
Contributor

  • test(mempool_p2p): change p2p runner test to use automock for gateway client
  • test(mempool_p2p): test gateway client error on adding tx from p2p

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Contributor

@ShahakShama ShahakShama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 16 unresolved discussions (waiting on @AlonLStarkWare)


crates/starknet_mempool_p2p/src/runner/test.rs line 81 at r2 (raw file):

        mock_register_broadcast_topic().expect("Failed to create mock network");
    let BroadcastTopicChannels { broadcasted_messages_receiver, broadcast_topic_client } =
        subscriber_channels; // used to created our node's p2p runner below, which will listen for incoming txs over broadcasted_messages_receiver.

Same as before, try to reduce the amount of comments


crates/starknet_mempool_p2p/src/runner/test.rs line 92 at r2 (raw file):

    // send an empty message on this channel to indicate that the tx reached the gateway client.
    let (add_tx_indicator_sender, add_tx_indicator_receiver) = futures::channel::oneshot::channel();

You don't need this. You can wait for the peer report instead


crates/starknet_mempool_p2p/src/runner/test.rs line 124 at r2 (raw file):

    // if the runner fails, there was a network issue => panic.
    // if the runner returns successfully, we panic because the runner should never terminate.
    res = tokio::time::timeout(Duration::from_secs(5), mempool_p2p_runner.start()) => {res.expect("Test timed out").expect("Runner failed - network stopped unexpectedly"); panic!("Runner terminated")},

Same as before. newlines and MempoolP2pRunner


crates/starknet_mempool_p2p/src/runner/test.rs line 130 at r2 (raw file):

    res.unwrap();
    // After gateway client fails to add the tx, the p2p runner should have reported the peer.
    let peer_reported = mock_reported_messages_receiver.next().await.expect("Failed to receive message");

As I said before, put this future in the select arm instead


crates/starknet_mempool_p2p/src/runner/test.rs line 130 at r2 (raw file):

    res.unwrap();
    // After gateway client fails to add the tx, the p2p runner should have reported the peer.
    let peer_reported = mock_reported_messages_receiver.next().await.expect("Failed to receive message");

Failed to receive report


crates/starknet_mempool_p2p/src/runner/test.rs line 131 at r2 (raw file):

    // After gateway client fails to add the tx, the p2p runner should have reported the peer.
    let peer_reported = mock_reported_messages_receiver.next().await.expect("Failed to receive message");
    assert_eq!(peer_reported, message_metadata.originator_id.private_get_peer_id())

add a TODO to add this functionality to network manager test utils


crates/starknet_mempool_p2p/src/runner/test.rs line 29 at r1 (raw file):

        mock_register_broadcast_topic().expect("Failed to create mock network");
    let BroadcastTopicChannels { broadcasted_messages_receiver, broadcast_topic_client } =
        subscriber_channels; // used to created our node's p2p runner below, which will listen for incoming txs over broadcasted_messages_receiver.

This comment seems unnecessary


crates/starknet_mempool_p2p/src/runner/test.rs line 33 at r1 (raw file):

        broadcasted_messages_sender: mut mock_broadcasted_messages_sender,
        ..
    } = mock_network; // other node sending tx to our p2p runner

This comment seems unnecessary


crates/starknet_mempool_p2p/src/runner/test.rs line 38 at r1 (raw file):

    let placeholder_network_manager = NetworkManager::new(NetworkConfig::default(), None);

    // send an empty message on this channel to indicate that the tx reached the gateway client.

This comment is incorrect. Change it to "Creating channels for sending ..."


crates/starknet_mempool_p2p/src/runner/test.rs line 42 at r1 (raw file):

    let mut mock_gateway_client = MockGatewayClient::new();
    mock_gateway_client.expect_add_tx().return_once(move |_| {

You should assert that the transaction you've received is the one you've gotten from p2p. You can use automock's with function for that: https://docs.rs/mockall/latest/mockall/index.html#getting-started


crates/starknet_mempool_p2p/src/runner/test.rs line 48 at r1 (raw file):

    let mut mempool_p2p_runner = MempoolP2pRunner::new(
        Some(placeholder_network_manager),
        broadcasted_messages_receiver, // listen to incoming tx

This comment seems unnecessary


crates/starknet_mempool_p2p/src/runner/test.rs line 49 at r1 (raw file):

        Some(placeholder_network_manager),
        broadcasted_messages_receiver, // listen to incoming tx
        broadcast_topic_client,        // broadcast tx or report peer

This comment seems unnecessary


crates/starknet_mempool_p2p/src/runner/test.rs line 64 at r1 (raw file):

    tokio::select! {
        // if the runner takes longer than 5 seconds to start, we panic.

This comment seems unnecessary. You have the expect for that


crates/starknet_mempool_p2p/src/runner/test.rs line 67 at r1 (raw file):

        // if the runner fails, there was a network issue => panic.
        // if the runner returns successfully, we panic because the runner should never terminate.
        res = tokio::time::timeout(Duration::from_secs(5), mempool_p2p_runner.start()) => {res.expect("Test timed out").expect("Runner failed - network stopped unexpectedly"); panic!("Runner terminated")},

Runner -> MempoolP2pRunner


crates/starknet_mempool_p2p/src/runner/test.rs line 67 at r1 (raw file):

        // if the runner fails, there was a network issue => panic.
        // if the runner returns successfully, we panic because the runner should never terminate.
        res = tokio::time::timeout(Duration::from_secs(5), mempool_p2p_runner.start()) => {res.expect("Test timed out").expect("Runner failed - network stopped unexpectedly"); panic!("Runner terminated")},

add newlines after the { and after each ;


crates/starknet_mempool_p2p/src/runner/test.rs line 68 at r1 (raw file):

        // if the runner returns successfully, we panic because the runner should never terminate.
        res = tokio::time::timeout(Duration::from_secs(5), mempool_p2p_runner.start()) => {res.expect("Test timed out").expect("Runner failed - network stopped unexpectedly"); panic!("Runner terminated")},
        // if a message was received on this oneshot channel, the gateway client received the tx.

... and the test succeeded

@AlonLStarkWare AlonLStarkWare force-pushed the alonl/test_p2p_runner_handling_of_gw_error branch from 0864b85 to 9c3f24d Compare November 21, 2024 11:04
Copy link

Artifacts upload triggered. View details here

Copy link

Artifacts upload triggered. View details here

Copy link
Contributor Author

@AlonLStarkWare AlonLStarkWare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 3 files reviewed, 16 unresolved discussions (waiting on @ShahakShama)


crates/starknet_mempool_p2p/src/runner/test.rs line 29 at r1 (raw file):

Previously, ShahakShama wrote…

This comment seems unnecessary

Done.


crates/starknet_mempool_p2p/src/runner/test.rs line 33 at r1 (raw file):

Previously, ShahakShama wrote…

This comment seems unnecessary

Done.


crates/starknet_mempool_p2p/src/runner/test.rs line 38 at r1 (raw file):

Previously, ShahakShama wrote…

This comment is incorrect. Change it to "Creating channels for sending ..."

Done.


crates/starknet_mempool_p2p/src/runner/test.rs line 42 at r1 (raw file):

Previously, ShahakShama wrote…

You should assert that the transaction you've received is the one you've gotten from p2p. You can use automock's with function for that: https://docs.rs/mockall/latest/mockall/index.html#getting-started

Done.


crates/starknet_mempool_p2p/src/runner/test.rs line 48 at r1 (raw file):

Previously, ShahakShama wrote…

This comment seems unnecessary

Done.


crates/starknet_mempool_p2p/src/runner/test.rs line 49 at r1 (raw file):

Previously, ShahakShama wrote…

This comment seems unnecessary

Done.


crates/starknet_mempool_p2p/src/runner/test.rs line 64 at r1 (raw file):

Previously, ShahakShama wrote…

This comment seems unnecessary. You have the expect for that

Done.


crates/starknet_mempool_p2p/src/runner/test.rs line 67 at r1 (raw file):

Previously, ShahakShama wrote…

Runner -> MempoolP2pRunner

Done.


crates/starknet_mempool_p2p/src/runner/test.rs line 67 at r1 (raw file):

Previously, ShahakShama wrote…

add newlines after the { and after each ;

Done.


crates/starknet_mempool_p2p/src/runner/test.rs line 68 at r1 (raw file):

Previously, ShahakShama wrote…

... and the test succeeded

Done.


crates/starknet_mempool_p2p/src/runner/test.rs line 81 at r2 (raw file):

Previously, ShahakShama wrote…

Same as before, try to reduce the amount of comments

Done.


crates/starknet_mempool_p2p/src/runner/test.rs line 92 at r2 (raw file):

Previously, ShahakShama wrote…

You don't need this. You can wait for the peer report instead

Wouldn't we want to know if the gateway received the transaction if it wasn't reported? I think this helps narrow down the potential error.


crates/starknet_mempool_p2p/src/runner/test.rs line 124 at r2 (raw file):

Previously, ShahakShama wrote…

Same as before. newlines and MempoolP2pRunner

Done.


crates/starknet_mempool_p2p/src/runner/test.rs line 130 at r2 (raw file):

Previously, ShahakShama wrote…

As I said before, put this future in the select arm instead

This future can only be resolved after the transaction is received by the gateway, so it should be in this arm, IMO.


crates/starknet_mempool_p2p/src/runner/test.rs line 130 at r2 (raw file):

Previously, ShahakShama wrote…

Failed to receive report

Done.


crates/starknet_mempool_p2p/src/runner/test.rs line 131 at r2 (raw file):

Previously, ShahakShama wrote…

add a TODO to add this functionality to network manager test utils

Done.

@AlonLStarkWare AlonLStarkWare force-pushed the alonl/test_p2p_runner_handling_of_gw_error branch from 9c3f24d to 0691d17 Compare December 16, 2024 13:10
@AlonLStarkWare AlonLStarkWare force-pushed the alonl/test_p2p_runner_handling_of_gw_error branch from 0691d17 to 366fb70 Compare December 16, 2024 13:35
@AlonLStarkWare AlonLStarkWare changed the title test(mempool_p2p): test gateway client error on adding tx from p2p test(starknet_mempool_p2p): test gateway client error on adding tx from p2p Dec 16, 2024
Copy link
Contributor

@ShahakShama ShahakShama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 3 files at r6, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @AlonLStarkWare)


crates/starknet_mempool_p2p/src/runner/test.rs line 92 at r2 (raw file):

Previously, AlonLStarkWare (Alon-Lukatch-Starkware) wrote…

Wouldn't we want to know if the gateway received the transaction if it wasn't reported? I think this helps narrow down the potential error.

ok


crates/starknet_mempool_p2p/src/runner/test.rs line 142 at r6 (raw file):

            // After gateway client fails to add the tx, the p2p runner should have reported the peer.
            let peer_reported = mock_reported_messages_receiver.next().await.expect("Failed to receive report");
            // TODO: add this functionalionality to network manager test utils

spell error in functionalionality

@AlonLStarkWare AlonLStarkWare force-pushed the alonl/test_p2p_runner_handling_of_gw_error branch from 366fb70 to f93b1ae Compare December 19, 2024 14:36
Copy link

Benchmark movements:
tree_computation_flow performance improved 😺
tree_computation_flow time: [34.295 ms 34.411 ms 34.585 ms]
change: [-4.1596% -2.5549% -1.0932%] (p = 0.00 < 0.05)
Performance has improved.
Found 8 outliers among 100 measurements (8.00%)
4 (4.00%) high mild
4 (4.00%) high severe

@AlonLStarkWare AlonLStarkWare force-pushed the alonl/test_p2p_runner_handling_of_gw_error branch from f93b1ae to 25183b9 Compare December 22, 2024 10:02
}
}

// The p2p runner receives a tx from network, and the gateway decalines it, triggering report_peer.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in comment: decalines should be declines

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@ShahakShama ShahakShama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 3 files at r9.
Reviewable status: all files reviewed (commit messages unreviewed), 1 unresolved discussion (waiting on @graphite-app[bot])

}
}

// The p2p runner receives a tx from network, and the gateway decalines it, triggering report_peer.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

@ShahakShama ShahakShama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @graphite-app[bot])

Copy link
Contributor

@ShahakShama ShahakShama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @AlonLStarkWare)

Copy link
Contributor

@ShahakShama ShahakShama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @graphite-app[bot])

@AlonLStarkWare AlonLStarkWare force-pushed the alonl/test_p2p_runner_handling_of_gw_error branch from 25183b9 to 2c6dea4 Compare December 26, 2024 12:40
Copy link
Contributor Author

@AlonLStarkWare AlonLStarkWare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ShahakShama)

}
}

// The p2p runner receives a tx from network, and the gateway decalines it, triggering report_peer.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link

Benchmark movements:
tree_computation_flow performance improved 😺
tree_computation_flow time: [34.015 ms 34.040 ms 34.069 ms]
change: [-4.2229% -2.7171% -1.3983%] (p = 0.00 < 0.05)
Performance has improved.
Found 3 outliers among 100 measurements (3.00%)
2 (2.00%) high mild
1 (1.00%) high severe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants