split NetworkBridge into two subsystems (#5616)

* foo

* rolling session window

* fixup

* remove use statemetn

* fmt

* split NetworkBridge into two subsystems

Pending cleanup

* split

* chore: reexport OrchestraError as OverseerError

* chore: silence warnings

* fixup tests

* chore: add default timenout of 30s to subsystem test helper ctx handle

* single item channel

* fixins

* fmt

* cleanup

* remove dead code

* remove sync bounds again

* wire up shared state

* deal with some FIXMEs

* use distinct tags

Co-authored-by: Andrei Sandu <54316454+sandreim@users.noreply.github.com>

* use tag

Co-authored-by: Andrei Sandu <54316454+sandreim@users.noreply.github.com>

* address naming

tx and rx are common in networking and also have an implicit meaning regarding networking
compared to incoming and outgoing which are already used with subsystems themselvesq

* remove unused sync oracle

* remove unneeded state

* fix tests

* chore: fmt

* do not try to register twice

* leak Metrics type

Co-authored-by: Andrei Sandu <54316454+sandreim@users.noreply.github.com>
Co-authored-by: Andronik <write@reusable.software>
This commit is contained in:
Bernhard Schuster
2022-07-12 18:22:36 +02:00
committed by GitHub
parent c11c1f38f4
commit 3240cb5e4d
40 changed files with 1880 additions and 1429 deletions
@@ -39,7 +39,7 @@ use polkadot_node_subsystem_util::{self as util, rand, MIN_GOSSIP_PEERS};
use polkadot_node_subsystem::{
jaeger,
messages::{
CandidateBackingMessage, NetworkBridgeEvent, NetworkBridgeMessage,
CandidateBackingMessage, NetworkBridgeEvent, NetworkBridgeTxMessage,
StatementDistributionMessage,
},
overseer, ActiveLeavesUpdate, FromOrchestra, OverseerSignal, PerLeafSpan, SpawnedSubsystem,
@@ -1083,7 +1083,7 @@ async fn circulate_statement<'a, Context>(
statement = ?stored.statement,
"Sending statement",
);
ctx.send_message(NetworkBridgeMessage::SendValidationMessage(
ctx.send_message(NetworkBridgeTxMessage::SendValidationMessage(
peers_to_send.iter().map(|(p, _)| p.clone()).collect(),
payload,
))
@@ -1123,8 +1123,11 @@ async fn send_statements_about<Context>(
statement = ?statement.statement,
"Sending statement",
);
ctx.send_message(NetworkBridgeMessage::SendValidationMessage(vec![peer.clone()], payload))
.await;
ctx.send_message(NetworkBridgeTxMessage::SendValidationMessage(
vec![peer.clone()],
payload,
))
.await;
metrics.on_statement_distributed();
}
@@ -1155,8 +1158,11 @@ async fn send_statements<Context>(
statement = ?statement.statement,
"Sending statement"
);
ctx.send_message(NetworkBridgeMessage::SendValidationMessage(vec![peer.clone()], payload))
.await;
ctx.send_message(NetworkBridgeTxMessage::SendValidationMessage(
vec![peer.clone()],
payload,
))
.await;
metrics.on_statement_distributed();
}
@@ -1167,7 +1173,7 @@ async fn report_peer(
peer: PeerId,
rep: Rep,
) {
sender.send_message(NetworkBridgeMessage::ReportPeer(peer, rep)).await
sender.send_message(NetworkBridgeTxMessage::ReportPeer(peer, rep)).await
}
/// If message contains a statement, then retrieve it, otherwise fork task to fetch it.
@@ -1926,7 +1932,7 @@ impl<R: rand::Rng> StatementDistributionSubsystem<R> {
}
},
RequesterMessage::SendRequest(req) => {
ctx.send_message(NetworkBridgeMessage::SendRequests(
ctx.send_message(NetworkBridgeTxMessage::SendRequests(
vec![req],
IfDisconnected::ImmediateError,
))
@@ -33,7 +33,7 @@ use polkadot_node_subsystem::{
ActivatedLeaf, LeafStatus,
};
use polkadot_node_subsystem_test_helpers::mock::make_ferdie_keystore;
use polkadot_primitives::v2::{Hash, SessionInfo, ValidationCode};
use polkadot_primitives::v2::{Hash, Id as ParaId, SessionInfo, ValidationCode};
use polkadot_primitives_test_helpers::{
dummy_committed_candidate_receipt, dummy_hash, AlwaysZeroRng,
};
@@ -383,7 +383,7 @@ fn peer_view_update_sends_messages() {
let candidate = {
let mut c = dummy_committed_candidate_receipt(dummy_hash());
c.descriptor.relay_parent = hash_c;
c.descriptor.para_id = 1.into();
c.descriptor.para_id = ParaId::from(1_u32);
c
};
let candidate_hash = candidate.hash();
@@ -549,7 +549,7 @@ fn peer_view_update_sends_messages() {
assert_matches!(
message,
AllMessages::NetworkBridge(NetworkBridgeMessage::SendValidationMessage(
AllMessages::NetworkBridgeTx(NetworkBridgeTxMessage::SendValidationMessage(
to,
payload,
)) => {
@@ -570,7 +570,7 @@ fn circulated_statement_goes_to_all_peers_with_view() {
let candidate = {
let mut c = dummy_committed_candidate_receipt(dummy_hash());
c.descriptor.relay_parent = hash_b;
c.descriptor.para_id = 1.into();
c.descriptor.para_id = ParaId::from(1_u32);
c
};
@@ -680,7 +680,7 @@ fn circulated_statement_goes_to_all_peers_with_view() {
let message = handle.recv().await;
assert_matches!(
message,
AllMessages::NetworkBridge(NetworkBridgeMessage::SendValidationMessage(
AllMessages::NetworkBridgeTx(NetworkBridgeTxMessage::SendValidationMessage(
to,
payload,
)) => {
@@ -847,8 +847,8 @@ fn receiving_from_one_sends_to_another_and_to_candidate_backing() {
assert_matches!(
handle.recv().await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::ReportPeer(p, r)
AllMessages::NetworkBridgeTx(
NetworkBridgeTxMessage::ReportPeer(p, r)
) if p == peer_a && r == BENEFIT_VALID_STATEMENT_FIRST => {}
);
@@ -861,8 +861,8 @@ fn receiving_from_one_sends_to_another_and_to_candidate_backing() {
assert_matches!(
handle.recv().await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::SendValidationMessage(
AllMessages::NetworkBridgeTx(
NetworkBridgeTxMessage::SendValidationMessage(
recipients,
Versioned::V1(protocol_v1::ValidationProtocol::StatementDistribution(
protocol_v1::StatementDistributionMessage::Statement(r, s)
@@ -1090,8 +1090,8 @@ fn receiving_large_statement_from_one_sends_to_another_and_to_candidate_backing(
assert_matches!(
handle.recv().await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::SendRequests(
AllMessages::NetworkBridgeTx(
NetworkBridgeTxMessage::SendRequests(
mut reqs, IfDisconnected::ImmediateError
)
) => {
@@ -1143,8 +1143,8 @@ fn receiving_large_statement_from_one_sends_to_another_and_to_candidate_backing(
// Let c fail once too:
assert_matches!(
handle.recv().await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::SendRequests(
AllMessages::NetworkBridgeTx(
NetworkBridgeTxMessage::SendRequests(
mut reqs, IfDisconnected::ImmediateError
)
) => {
@@ -1163,8 +1163,8 @@ fn receiving_large_statement_from_one_sends_to_another_and_to_candidate_backing(
// a fails again:
assert_matches!(
handle.recv().await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::SendRequests(
AllMessages::NetworkBridgeTx(
NetworkBridgeTxMessage::SendRequests(
mut reqs, IfDisconnected::ImmediateError
)
) => {
@@ -1184,8 +1184,8 @@ fn receiving_large_statement_from_one_sends_to_another_and_to_candidate_backing(
// Send invalid response (all other peers have been tried now):
assert_matches!(
handle.recv().await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::SendRequests(
AllMessages::NetworkBridgeTx(
NetworkBridgeTxMessage::SendRequests(
mut reqs, IfDisconnected::ImmediateError
)
) => {
@@ -1211,16 +1211,16 @@ fn receiving_large_statement_from_one_sends_to_another_and_to_candidate_backing(
// Should get punished and never tried again:
assert_matches!(
handle.recv().await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::ReportPeer(p, r)
AllMessages::NetworkBridgeTx(
NetworkBridgeTxMessage::ReportPeer(p, r)
) if p == peer_bad && r == COST_WRONG_HASH => {}
);
// a is tried again (retried in reverse order):
assert_matches!(
handle.recv().await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::SendRequests(
AllMessages::NetworkBridgeTx(
NetworkBridgeTxMessage::SendRequests(
mut reqs, IfDisconnected::ImmediateError
)
) => {
@@ -1240,8 +1240,8 @@ fn receiving_large_statement_from_one_sends_to_another_and_to_candidate_backing(
// c succeeds now:
assert_matches!(
handle.recv().await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::SendRequests(
AllMessages::NetworkBridgeTx(
NetworkBridgeTxMessage::SendRequests(
mut reqs, IfDisconnected::ImmediateError
)
) => {
@@ -1262,22 +1262,22 @@ fn receiving_large_statement_from_one_sends_to_another_and_to_candidate_backing(
assert_matches!(
handle.recv().await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::ReportPeer(p, r)
AllMessages::NetworkBridgeTx(
NetworkBridgeTxMessage::ReportPeer(p, r)
) if p == peer_a && r == COST_FETCH_FAIL => {}
);
assert_matches!(
handle.recv().await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::ReportPeer(p, r)
AllMessages::NetworkBridgeTx(
NetworkBridgeTxMessage::ReportPeer(p, r)
) if p == peer_c && r == BENEFIT_VALID_RESPONSE => {}
);
assert_matches!(
handle.recv().await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::ReportPeer(p, r)
AllMessages::NetworkBridgeTx(
NetworkBridgeTxMessage::ReportPeer(p, r)
) if p == peer_a && r == BENEFIT_VALID_STATEMENT_FIRST => {}
);
@@ -1291,8 +1291,8 @@ fn receiving_large_statement_from_one_sends_to_another_and_to_candidate_backing(
// Now messages should go out:
assert_matches!(
handle.recv().await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::SendValidationMessage(
AllMessages::NetworkBridgeTx(
NetworkBridgeTxMessage::SendValidationMessage(
mut recipients,
Versioned::V1(protocol_v1::ValidationProtocol::StatementDistribution(
protocol_v1::StatementDistributionMessage::LargeStatement(meta)
@@ -1638,8 +1638,8 @@ fn share_prioritizes_backing_group() {
// Messages should go out:
assert_matches!(
handle.recv().await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::SendValidationMessage(
AllMessages::NetworkBridgeTx(
NetworkBridgeTxMessage::SendValidationMessage(
mut recipients,
Versioned::V1(protocol_v1::ValidationProtocol::StatementDistribution(
protocol_v1::StatementDistributionMessage::LargeStatement(meta)
@@ -1843,7 +1843,7 @@ fn peer_cant_flood_with_large_statements() {
let mut punished = false;
for _ in 0..2 {
match handle.recv().await {
AllMessages::NetworkBridge(NetworkBridgeMessage::SendRequests(
AllMessages::NetworkBridgeTx(NetworkBridgeTxMessage::SendRequests(
mut reqs,
IfDisconnected::ImmediateError,
)) => {
@@ -1860,7 +1860,7 @@ fn peer_cant_flood_with_large_statements() {
requested = true;
},
AllMessages::NetworkBridge(NetworkBridgeMessage::ReportPeer(p, r))
AllMessages::NetworkBridgeTx(NetworkBridgeTxMessage::ReportPeer(p, r))
if p == peer_a && r == COST_APPARENT_FLOOD =>
{
punished = true;
@@ -2088,8 +2088,8 @@ fn handle_multiple_seconded_statements() {
assert_matches!(
handle.recv().await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::ReportPeer(p, r)
AllMessages::NetworkBridgeTx(
NetworkBridgeTxMessage::ReportPeer(p, r)
) => {
assert_eq!(p, peer_a);
assert_eq!(r, BENEFIT_VALID_STATEMENT_FIRST);
@@ -2109,8 +2109,8 @@ fn handle_multiple_seconded_statements() {
assert_matches!(
handle.recv().await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::SendValidationMessage(
AllMessages::NetworkBridgeTx(
NetworkBridgeTxMessage::SendValidationMessage(
recipients,
Versioned::V1(protocol_v1::ValidationProtocol::StatementDistribution(
protocol_v1::StatementDistributionMessage::Statement(r, s)
@@ -2140,8 +2140,8 @@ fn handle_multiple_seconded_statements() {
assert_matches!(
handle.recv().await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::ReportPeer(p, r)
AllMessages::NetworkBridgeTx(
NetworkBridgeTxMessage::ReportPeer(p, r)
) => {
assert_eq!(p, peer_b);
assert_eq!(r, BENEFIT_VALID_STATEMENT);
@@ -2191,8 +2191,8 @@ fn handle_multiple_seconded_statements() {
assert_matches!(
handle.recv().await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::ReportPeer(p, r)
AllMessages::NetworkBridgeTx(
NetworkBridgeTxMessage::ReportPeer(p, r)
) => {
assert_eq!(p, peer_a);
assert_eq!(r, BENEFIT_VALID_STATEMENT_FIRST);
@@ -2211,8 +2211,8 @@ fn handle_multiple_seconded_statements() {
assert_matches!(
handle.recv().await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::SendValidationMessage(
AllMessages::NetworkBridgeTx(
NetworkBridgeTxMessage::SendValidationMessage(
recipients,
Versioned::V1(protocol_v1::ValidationProtocol::StatementDistribution(
protocol_v1::StatementDistributionMessage::Statement(r, s)
@@ -2244,8 +2244,8 @@ fn handle_multiple_seconded_statements() {
// the first when sending `Seconded`
assert_matches!(
handle.recv().await,
AllMessages::NetworkBridge(
NetworkBridgeMessage::ReportPeer(p, r)
AllMessages::NetworkBridgeTx(
NetworkBridgeTxMessage::ReportPeer(p, r)
) => {
assert_eq!(p, peer_b);
assert_eq!(r, BENEFIT_VALID_STATEMENT);