Skip to content

Commit 65eba70

Browse files
committed
test(p2p/webrtc): signaling discovery and exchange
re: #772
1 parent a4ca4e2 commit 65eba70

File tree

5 files changed

+81
-1
lines changed

5 files changed

+81
-1
lines changed

.github/workflows/ci.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ jobs:
284284
needs:
285285
- k8s-peers
286286
- build-tests
287-
# - build-tests-webrtc
287+
- build-tests-webrtc
288288
runs-on: ubuntu-20.04
289289
container:
290290
image: minaprotocol/mina-daemon:3.0.0-dc6bf78-focal-devnet
@@ -309,6 +309,7 @@ jobs:
309309
- connection_discovery_rust_as_seed
310310
- connection_discovery_rust_to_ocaml_via_seed
311311
- connection_discovery_rust_to_ocaml
312+
- webrtc_p2p_signaling
312313
# - webrtc_single_node
313314
# - webrtc_multi_node
314315
fail-fast: false
@@ -331,6 +332,12 @@ jobs:
331332
with:
332333
pattern: tests*
333334
merge-multiple: true
335+
336+
- name: Download tests
337+
uses: actions/download-artifact@v4
338+
with:
339+
pattern: tests-webrtc*
340+
merge-multiple: true
334341

335342
- name: Setup permissions
336343
run: |

node/testing/src/scenarios/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub mod p2p;
1818

1919
mod driver;
2020
pub use driver::*;
21+
use p2p::signaling::P2pSignaling;
2122

2223
pub use crate::cluster::runner::*;
2324

@@ -66,6 +67,7 @@ pub enum Scenarios {
6667
SimulationSmall(SimulationSmall),
6768
SimulationSmallForeverRealTime(SimulationSmallForeverRealTime),
6869
P2pReceiveBlock(P2pReceiveBlock),
70+
P2pSignaling(P2pSignaling),
6971
MultiNodePubsubPropagateBlock(MultiNodePubsubPropagateBlock),
7072
RecordReplayBootstrap(RecordReplayBootstrap),
7173
RecordReplayBlockProduction(RecordReplayBlockProduction),
@@ -90,6 +92,7 @@ impl Scenarios {
9092
Self::SimulationSmall(_) => true,
9193
Self::SimulationSmallForeverRealTime(_) => true,
9294
Self::MultiNodePubsubPropagateBlock(_) => true, // in progress
95+
Self::P2pSignaling(_) => cfg!(feature = "p2p-webrtc"),
9396
_ => false,
9497
}
9598
}
@@ -148,6 +151,7 @@ impl Scenarios {
148151
Self::SimulationSmall(_) => SimulationSmall::DOCS,
149152
Self::SimulationSmallForeverRealTime(_) => SimulationSmallForeverRealTime::DOCS,
150153
Self::P2pReceiveBlock(_) => P2pReceiveBlock::DOCS,
154+
Self::P2pSignaling(_) => P2pSignaling::DOCS,
151155
Self::MultiNodePubsubPropagateBlock(_) => MultiNodePubsubPropagateBlock::DOCS,
152156
Self::RecordReplayBootstrap(_) => RecordReplayBootstrap::DOCS,
153157
Self::RecordReplayBlockProduction(_) => RecordReplayBlockProduction::DOCS,
@@ -184,6 +188,7 @@ impl Scenarios {
184188
Self::SimulationSmall(v) => v.run(runner).await,
185189
Self::SimulationSmallForeverRealTime(v) => v.run(runner).await,
186190
Self::P2pReceiveBlock(v) => v.run(runner).await,
191+
Self::P2pSignaling(v) => v.run(runner).await,
187192
Self::MultiNodePubsubPropagateBlock(v) => v.run(runner).await,
188193
Self::RecordReplayBootstrap(v) => v.run(runner).await,
189194
Self::RecordReplayBlockProduction(v) => v.run(runner).await,

node/testing/src/scenarios/p2p/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ pub mod basic_incoming_connections;
33
pub mod basic_outgoing_connections;
44
pub mod kademlia;
55
pub mod pubsub;
6+
pub mod signaling;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
use std::{collections::BTreeSet, time::Duration};
2+
3+
use node::{
4+
p2p::{P2pPeerAction, PeerId},
5+
Action, P2pAction,
6+
};
7+
8+
use crate::{
9+
node::RustNodeTestingConfig,
10+
scenarios::{ClusterRunner, DynEffectsData, RunCfg},
11+
};
12+
13+
/// Makes sure that when using WebRTC only nodes, peers can discover
14+
/// each other and connect to each other via p2p signaling.
15+
#[derive(documented::Documented, Default, Clone, Copy)]
16+
pub struct P2pSignaling;
17+
18+
impl P2pSignaling {
19+
pub async fn run(self, mut runner: ClusterRunner<'_>) {
20+
const NODES_N: usize = 4;
21+
22+
let seed_config = RustNodeTestingConfig::devnet_default();
23+
let seed = runner.add_rust_node(seed_config.clone());
24+
25+
let node_config = seed_config.initial_peers(vec![seed.into()]);
26+
let _node_1 = runner.add_rust_node(node_config.clone());
27+
let _node_2 = runner.add_rust_node(node_config.clone());
28+
let _node_3 = runner.add_rust_node(node_config.clone());
29+
30+
let node_peers: [_; NODES_N] = std::array::from_fn(|_| BTreeSet::<PeerId>::new());
31+
let node_peers = DynEffectsData::new(node_peers);
32+
33+
runner
34+
.run(
35+
RunCfg::default()
36+
.timeout(Duration::from_secs(60))
37+
.advance_time(1..=100)
38+
.action_handler(move |node_id, _state, _, action| {
39+
if action.action().kind().to_string().contains("Signaling") {
40+
let me = _state.p2p.my_id();
41+
let me_pk = me.to_public_key().unwrap();
42+
dbg!((me, me_pk, action.action()));
43+
}
44+
match action.action() {
45+
Action::P2p(P2pAction::Peer(P2pPeerAction::Ready {
46+
peer_id, ..
47+
})) => {
48+
node_peers.inner()[node_id.index()].insert(*peer_id);
49+
dbg!(node_peers.inner())
50+
.iter()
51+
.all(|v| v.len() == NODES_N - 1)
52+
}
53+
_ => false,
54+
}
55+
}),
56+
)
57+
.await
58+
.expect("peers didn't discover each other");
59+
}
60+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![cfg(feature = "p2p-webrtc")]
2+
3+
use openmina_node_testing::scenarios::p2p::signaling::P2pSignaling;
4+
5+
mod common;
6+
7+
scenario_test!(p2p_signaling, P2pSignaling, P2pSignaling, true);

0 commit comments

Comments
 (0)