Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 96 additions & 24 deletions node/network/bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,26 +306,48 @@ where
});

match peer_set {
PeerSet::Validation => dispatch_validation_events_to_all(
vec![
NetworkBridgeEvent::PeerConnected(peer.clone(), role),
NetworkBridgeEvent::PeerViewChange(
peer,
View::default(),
PeerSet::Validation => {
dispatch_validation_events_to_all(
vec![
NetworkBridgeEvent::PeerConnected(peer.clone(), role),
NetworkBridgeEvent::PeerViewChange(
peer.clone(),
View::default(),
),
],
&mut ctx,
).await;

send_message(
&mut bridge.network_service,
vec![peer],
PeerSet::Validation,
WireMessage::<protocol_v1::ValidationProtocol>::ViewUpdate(
local_view.clone()
),
],
&mut ctx,
).await,
PeerSet::Collation => dispatch_collation_events_to_all(
vec![
NetworkBridgeEvent::PeerConnected(peer.clone(), role),
NetworkBridgeEvent::PeerViewChange(
peer,
View::default(),
).await?;
}
PeerSet::Collation => {
dispatch_collation_events_to_all(
vec![
NetworkBridgeEvent::PeerConnected(peer.clone(), role),
NetworkBridgeEvent::PeerViewChange(
peer.clone(),
View::default(),
),
],
&mut ctx,
).await;

send_message(
&mut bridge.network_service,
vec![peer],
PeerSet::Collation,
WireMessage::<protocol_v1::CollationProtocol>::ViewUpdate(
local_view.clone()
),
],
&mut ctx,
).await,
).await?;
}
}
}
}
Expand Down Expand Up @@ -831,6 +853,51 @@ mod tests {
)
}

#[test]
fn send_our_view_upon_connection() {
test_harness(|test_harness| async move {
let TestHarness {
mut network_handle,
mut virtual_overseer,
} = test_harness;

let peer = PeerId::random();

let head = Hash::repeat_byte(1);
virtual_overseer.send(
FromOverseer::Signal(OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate::start_work(head, Arc::new(JaegerSpan::Disabled)),
))
).await;

network_handle.connect_peer(peer.clone(), PeerSet::Validation, ObservedRole::Full).await;
network_handle.connect_peer(peer.clone(), PeerSet::Collation, ObservedRole::Full).await;

let view = view![head];
let actions = network_handle.next_network_actions(2).await;
assert_network_actions_contains(
&actions,
&NetworkAction::WriteNotification(
peer.clone(),
PeerSet::Validation,
WireMessage::<protocol_v1::ValidationProtocol>::ViewUpdate(
view.clone(),
).encode(),
),
);
assert_network_actions_contains(
&actions,
&NetworkAction::WriteNotification(
peer.clone(),
PeerSet::Collation,
WireMessage::<protocol_v1::CollationProtocol>::ViewUpdate(
view.clone(),
).encode(),
),
);
});
}

#[test]
fn sends_view_updates_to_peers() {
test_harness(|test_harness| async move {
Expand Down Expand Up @@ -858,7 +925,7 @@ mod tests {
))
).await;

let actions = network_handle.next_network_actions(2).await;
let actions = network_handle.next_network_actions(4).await;
let wire_message = WireMessage::<protocol_v1::ValidationProtocol>::ViewUpdate(
view![hash_a]
).encode();
Expand Down Expand Up @@ -920,7 +987,7 @@ mod tests {
))
).await;

let actions = network_handle.next_network_actions(2).await;
let actions = network_handle.next_network_actions(4).await;
let wire_message = WireMessage::<protocol_v1::ValidationProtocol>::ViewUpdate(
View { heads: vec![hash_a], finalized_number: 5 }
).encode();
Expand Down Expand Up @@ -1110,7 +1177,7 @@ mod tests {
))
).await;

let actions = network_handle.next_network_actions(1).await;
let actions = network_handle.next_network_actions(3).await;
let wire_message = WireMessage::<protocol_v1::ValidationProtocol>::ViewUpdate(
view![hash_a]
).encode();
Expand Down Expand Up @@ -1181,7 +1248,7 @@ mod tests {
WireMessage::ProtocolMessage(message.clone()).encode(),
).await;

let actions = network_handle.next_network_actions(1).await;
let actions = network_handle.next_network_actions(3).await;
assert_network_actions_contains(
&actions,
&NetworkAction::ReputationChange(
Expand Down Expand Up @@ -1302,7 +1369,7 @@ mod tests {
))
).await;

let actions = network_handle.next_network_actions(1).await;
let actions = network_handle.next_network_actions(2).await;
let wire_message = WireMessage::<protocol_v1::ValidationProtocol>::ViewUpdate(
View {
heads: vec![hash_b],
Expand Down Expand Up @@ -1350,7 +1417,7 @@ mod tests {
).encode(),
).await;

let actions = network_handle.next_network_actions(1).await;
let actions = network_handle.next_network_actions(2).await;
assert_network_actions_contains(
&actions,
&NetworkAction::ReputationChange(
Expand Down Expand Up @@ -1399,6 +1466,11 @@ mod tests {
).await;
}

// consume peer view changes
{
let _peer_view_changes = network_handle.next_network_actions(2).await;
}

// send a validation protocol message.

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ We update our view's `finalized_number` to the provided one and delay `ProtocolM

### Network Event: Peer Connected

Issue a `NetworkBridgeEvent::PeerConnected` for each [Event Handler](#event-handlers) of the peer-set and negotiated protocol version of the peer.
Issue a `NetworkBridgeEvent::PeerConnected` for each [Event Handler](#event-handlers) of the peer-set and negotiated protocol version of the peer. Also issue a `NetworkBridgeEvent::PeerViewChange` and send the peer our current view.

### Network Event: Peer Disconnected

Expand Down