This pull request includes an addition of new test cases for the network module which adds comprehensive peer-to-peer (P2P) protocol tests.
Testing Enhancements:
Added a new test module in sdk/src/network/mod.rs to test P2P protocol with multiple nodes, including setup functions and detailed round-based messaging tests.
However, this test does not pass because of a bug in our networking layer, I've added this test mainly for @tbraun96 to be able to debug the networking layer better. This test simulate N nodes working together on a protocol. This protocol contains 3 rounds (Broadcast, P2P, Broadcast) which reflects our mostly used MPC protocols. Getting this fixed would allow for a lot of real-world applications like my blueprint here: https://github.com/tangle-network/frost-blueprint which currently is broken because of our networking implementation.
Running the test
To run the test:
cargo test -p gadget-sdk network::tests::p2p -- --nocapture
You will get a similar log to mine:
running 1 test
DEBUG Checking if all nodes are connected to each other NODE_COUNT=3 max_retries=90 retry=0
DEBUG Connected peers node=0 peers=0
ERROR network_worker:network_service:handle_outgoing_connection_error: Outgoing connection error: Failed to negotiate transport protocol(s): [(/ip4/172.22.0.1/tcp/34393/p2p/12D3KooWL8JyGMH951VHpV2e4iwZMyJuaVjQVEUCFxQyA6MusSqr: : Connection refused (os error 111): Connection refused (os error 111): Connection refused (os error 111))] _connection_id=ConnectionId(36) _peer_id=Some(PeerId("12D3KooWL8JyGMH951VHpV2e4iwZMyJuaVjQVEUCFxQyA6MusSqr"))
ERROR network_worker:network_service:handle_outgoing_connection_error: Outgoing connection error: Failed to negotiate transport protocol(s): [(/ip4/192.168.1.123/tcp/34393/p2p/12D3KooWL8JyGMH951VHpV2e4iwZMyJuaVjQVEUCFxQyA6MusSqr: : Connection refused (os error 111): Connection refused (os error 111): Connection refused (os error 111))] _connection_id=ConnectionId(2) _peer_id=Some(PeerId("12D3KooWL8JyGMH951VHpV2e4iwZMyJuaVjQVEUCFxQyA6MusSqr"))
ERROR network_worker:network_service:handle_outgoing_connection_error: Outgoing connection error: Failed to negotiate transport protocol(s): [(/ip4/192.168.1.123/tcp/34393/p2p/12D3KooWL8JyGMH951VHpV2e4iwZMyJuaVjQVEUCFxQyA6MusSqr: : Connection refused (os error 111): Connection refused (os error 111): Connection refused (os error 111))] _connection_id=ConnectionId(10) _peer_id=Some(PeerId("12D3KooWL8JyGMH951VHpV2e4iwZMyJuaVjQVEUCFxQyA6MusSqr"))
ERROR network_worker:network_service:handle_outgoing_connection_error: Outgoing connection error: Failed to negotiate transport protocol(s): [(/ip4/172.22.0.1/tcp/34393/p2p/12D3KooWL8JyGMH951VHpV2e4iwZMyJuaVjQVEUCFxQyA6MusSqr: : Connection refused (os error 111): Connection refused (os error 111): Connection refused (os error 111))] _connection_id=ConnectionId(26) _peer_id=Some(PeerId("12D3KooWL8JyGMH951VHpV2e4iwZMyJuaVjQVEUCFxQyA6MusSqr"))
ERROR network_worker:network_worker:network_service:handle_outgoing_connection_error: Outgoing connection error: Failed to negotiate transport protocol(s): [(/ip4/172.22.0.1/tcp/38301/p2p/12D3KooWFwe9qf7ETLJhVbq237nkzEKG2zNp2UREVEeTX7SLTGBt: : Connection refused (os error 111): Connection refused (os error 111): Connection refused (os error 111))] _connection_id=ConnectionId(18) _peer_id=Some(PeerId("12D3KooWFwe9qf7ETLJhVbq237nkzEKG2zNp2UREVEeTX7SLTGBt"))
ERROR network_worker:network_service:handle_outgoing_connection_error: Outgoing connection error: Failed to negotiate transport protocol(s): [(/ip4/172.22.0.1/tcp/38301/p2p/12D3KooWFwe9qf7ETLJhVbq237nkzEKG2zNp2UREVEeTX7SLTGBt: : Connection refused (os error 111): Connection refused (os error 111): Connection refused (os error 111))] _connection_id=ConnectionId(42) _peer_id=Some(PeerId("12D3KooWFwe9qf7ETLJhVbq237nkzEKG2zNp2UREVEeTX7SLTGBt"))
DEBUG network_worker:network_service:handle_p2p: Sent response to peer: 12D3KooWL8JyGMH951VHpV2e4iwZMyJuaVjQVEUCFxQyA6MusSqr with request_id: 1
DEBUG network_worker:network_worker:network_service:handle_p2p: Sent response to peer: 12D3KooWFwe9qf7ETLJhVbq237nkzEKG2zNp2UREVEeTX7SLTGBt with request_id: 2
DEBUG network_worker:network_worker:network_service:handle_p2p: Sent response to peer: 12D3KooWSBXPgnkWqK6JWvqEFiQgNrBj7uxspeb2mmS9mphmAZ6P with request_id: 1
DEBUG network_worker:network_service:handle_p2p: Sent response to peer: 12D3KooWSBXPgnkWqK6JWvqEFiQgNrBj7uxspeb2mmS9mphmAZ6P with request_id: 2
DEBUG network_worker:network_service:handle_p2p: Sent response to peer: 12D3KooWL8JyGMH951VHpV2e4iwZMyJuaVjQVEUCFxQyA6MusSqr with request_id: 1
DEBUG network_worker:network_service:handle_p2p: Sent response to peer: 12D3KooWFwe9qf7ETLJhVbq237nkzEKG2zNp2UREVEeTX7SLTGBt with request_id: 2
DEBUG Checking if all nodes are connected to each other NODE_COUNT=3 max_retries=90 retry=1
DEBUG Connected peers node=0 peers=2
DEBUG Connected peers node=1 peers=2
DEBUG Connected peers node=2 peers=2
DEBUG All nodes are connected to each other
DEBUG Round 1: Broadcast Message node=0
DEBUG network_worker:network_worker:Round 1: Broadcast Message node=1
DEBUG Round 1: Broadcast Message node=2
DEBUG Round 1: Received message from=0 m=Round1(Round1Msg { power: 0, hitpoints: 50, armor: 2, name: "Player 0" }) node=2
DEBUG network_worker:network_worker:Round 1: Received message from=0 m=Round1(Round1Msg { power: 0, hitpoints: 50, armor: 2, name: "Player 0" }) node=1
DEBUG Round 1: Received message from=2 m=Round1(Round1Msg { power: 200, hitpoints: 150, armor: 4, name: "Player 2" }) node=0
DEBUG network_worker: Received message from=2 m=Round1(Round1Msg { power: 200, hitpoints: 150, armor: 4, name: "Player 2" })
DEBUG network_worker: Done
DEBUG network_worker:Round 2: Send P2P Message to=0 node=1
DEBUG network_worker:Round 2: Send P2P Message to=2 node=1
DEBUG Round 1: Received message from=1 m=Round1(Round1Msg { power: 100, hitpoints: 100, armor: 3, name: "Player 1" }) node=2
DEBUG Round 1: Done node=2
DEBUG Round 2: Send P2P Message to=0 node=2
DEBUG Round 2: Send P2P Message to=1 node=2
DEBUG Round 1: Received message from=1 m=Round2(Round2Msg { x: 10, y: 40, z: 3 }) node=0
DEBUG Round 1: Received message from=1 m=Round2(Round2Msg { x: 10, y: 40, z: 3 }) node=0
thread 'tokio-runtime-worker' panicked at sdk/src/network/mod.rs:343:13:
Duplicate message from node 1
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
DEBUG network_worker:network_worker:Round 1: Received message from=1 m=Round1(Round1Msg { power: 100, hitpoints: 100, armor: 3, name: "Player 1" }) node=1
DEBUG network_worker:network_worker:Round 1: Done node=1
DEBUG network_worker:network_worker:Round 1:Round 2: Send P2P Message to=1 node=1 node=0
DEBUG network_worker:network_worker:Round 1:Round 2: Send P2P Message to=2 node=1 node=0
thread 'DEBUG network_worker:network_worker:Round 1:Round 2: Received message from=2 m=Round2(Round2Msg { x: 20, y: 60, z: 4 }) node=1 node=0
network::tests::p2p' panicked at sdk/src/network/mod.rs:231:14:
Failed to run protocol: JoinError::Panic(Id(118), "Duplicate message from node 1", ...)
DEBUG network_worker:network_worker:Round 1:Round 2: Received message from=1 m=Round2(Round2Msg { x: 10, y: 40, z: 3 }) node=1 node=0
DEBUG network_worker:network_worker:Round 1:Round 2: Done node=1 node=0
DEBUG network_worker:network_worker:Round 1:Round 3: Broadcast Message node=1 node=0
DEBUG network_worker:network_worker:Round 1:Round 3: Received message from=2 m=Round2(Round2Msg { x: 20, y: 60, z: 4 }) node=1 node=0
thread 'tokio-runtime-worker' panicked at sdk/src/network/mod.rs:390:13:
Expected Round3 message but got Round2(Round2Msg { x: 20, y: 60, z: 4 }) from node 2
ERROR network_worker:network_service:handle_gossip:handle_gossip_message: Failed to send message to worker: channel closed _message_id=313244334b6f6f574c384a79474d483935315648705632653469775a4d794a7561566a51564555434678517941364d757353717231373330383936393432323034393438383538 _propagation_source=12D3KooWL8JyGMH951VHpV2e4iwZMyJuaVjQVEUCFxQyA6MusSqr source=Some(PeerId("12D3KooWL8JyGMH951VHpV2e4iwZMyJuaVjQVEUCFxQyA6MusSqr"))
ERROR network_worker:network_service:handle_gossip:handle_gossip_message: Failed to send message to worker: channel closed _message_id=313244334b6f6f574c384a79474d483935315648705632653469775a4d794a7561566a51564555434678517941364d757353717231373330383936393432323034393438383539 _propagation_source=12D3KooWL8JyGMH951VHpV2e4iwZMyJuaVjQVEUCFxQyA6MusSqr source=Some(PeerId("12D3KooWL8JyGMH951VHpV2e4iwZMyJuaVjQVEUCFxQyA6MusSqr"))
test network::tests::p2p ... FAILED
failures:
failures:
network::tests::p2p
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 10 filtered out; finished in 0.35s
Please note that since this networking, some logs are not in the same order as your run would be.
This pull request includes an addition of new test cases for the
network
module which adds comprehensive peer-to-peer (P2P) protocol tests.Testing Enhancements:
sdk/src/network/mod.rs
to test P2P protocol with multiple nodes, including setup functions and detailed round-based messaging tests.However, this test does not pass because of a bug in our networking layer, I've added this test mainly for @tbraun96 to be able to debug the networking layer better. This test simulate
N
nodes working together on a protocol. This protocol contains 3 rounds (Broadcast, P2P, Broadcast) which reflects our mostly used MPC protocols. Getting this fixed would allow for a lot of real-world applications like my blueprint here: https://github.com/tangle-network/frost-blueprint which currently is broken because of our networking implementation.Running the test
To run the test:
You will get a similar log to mine: