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
+6 -2
View File
@@ -85,6 +85,7 @@ pub fn dummy_overseer_builder<'a, Spawner, SupportsParachains>(
DummySubsystem,
DummySubsystem,
DummySubsystem,
DummySubsystem,
>,
SubsystemError,
>
@@ -126,6 +127,7 @@ pub fn one_for_all_overseer_builder<'a, Spawner, SupportsParachains, Sub>(
Sub,
Sub,
Sub,
Sub,
>,
SubsystemError,
>
@@ -143,7 +145,8 @@ where
+ Subsystem<OverseerSubsystemContext<ChainApiMessage>, SubsystemError>
+ Subsystem<OverseerSubsystemContext<CollationGenerationMessage>, SubsystemError>
+ Subsystem<OverseerSubsystemContext<CollatorProtocolMessage>, SubsystemError>
+ Subsystem<OverseerSubsystemContext<NetworkBridgeMessage>, SubsystemError>
+ Subsystem<OverseerSubsystemContext<NetworkBridgeRxMessage>, SubsystemError>
+ Subsystem<OverseerSubsystemContext<NetworkBridgeTxMessage>, SubsystemError>
+ Subsystem<OverseerSubsystemContext<ProvisionerMessage>, SubsystemError>
+ Subsystem<OverseerSubsystemContext<RuntimeApiMessage>, SubsystemError>
+ Subsystem<OverseerSubsystemContext<StatementDistributionMessage>, SubsystemError>
@@ -169,7 +172,8 @@ where
.chain_api(subsystem.clone())
.collation_generation(subsystem.clone())
.collator_protocol(subsystem.clone())
.network_bridge(subsystem.clone())
.network_bridge_tx(subsystem.clone())
.network_bridge_rx(subsystem.clone())
.provisioner(subsystem.clone())
.runtime_api(subsystem.clone())
.statement_distribution(subsystem.clone())
+20 -16
View File
@@ -83,8 +83,8 @@ use polkadot_node_subsystem_types::messages::{
BitfieldSigningMessage, CandidateBackingMessage, CandidateValidationMessage, ChainApiMessage,
ChainSelectionMessage, CollationGenerationMessage, CollatorProtocolMessage,
DisputeCoordinatorMessage, DisputeDistributionMessage, GossipSupportMessage,
NetworkBridgeMessage, ProvisionerMessage, PvfCheckerMessage, RuntimeApiMessage,
StatementDistributionMessage,
NetworkBridgeRxMessage, NetworkBridgeTxMessage, ProvisionerMessage, PvfCheckerMessage,
RuntimeApiMessage, StatementDistributionMessage,
};
pub use polkadot_node_subsystem_types::{
errors::{SubsystemError, SubsystemResult},
@@ -108,9 +108,9 @@ use parity_util_mem::MemoryAllocationTracker;
pub use orchestra as gen;
pub use orchestra::{
contextbounds, orchestra, subsystem, FromOrchestra, MapSubsystem, MessagePacket,
SignalsReceived, Spawner, Subsystem, SubsystemContext, SubsystemIncomingMessages,
SubsystemInstance, SubsystemMeterReadouts, SubsystemMeters, SubsystemSender, TimeoutExt,
ToOrchestra,
OrchestraError as OverseerError, SignalsReceived, Spawner, Subsystem, SubsystemContext,
SubsystemIncomingMessages, SubsystemInstance, SubsystemMeterReadouts, SubsystemMeters,
SubsystemSender, TimeoutExt, ToOrchestra,
};
/// Store 2 days worth of blocks, not accounting for forks,
@@ -389,7 +389,7 @@ pub async fn forward_events<P: BlockchainEvents<Block>>(client: Arc<P>, mut hand
/// # };
/// # use polkadot_node_subsystem_types::messages::{
/// # CandidateValidationMessage, CandidateBackingMessage,
/// # NetworkBridgeMessage,
/// # NetworkBridgeTxMessage,
/// # };
///
/// struct ValidationSubsystem;
@@ -477,7 +477,7 @@ pub struct Overseer<SupportsParachains> {
candidate_backing: CandidateBacking,
#[subsystem(StatementDistributionMessage, sends: [
NetworkBridgeMessage,
NetworkBridgeTxMessage,
CandidateBackingMessage,
RuntimeApiMessage,
])]
@@ -488,12 +488,12 @@ pub struct Overseer<SupportsParachains> {
AvailabilityRecoveryMessage,
ChainApiMessage,
RuntimeApiMessage,
NetworkBridgeMessage,
NetworkBridgeTxMessage,
])]
availability_distribution: AvailabilityDistribution,
#[subsystem(AvailabilityRecoveryMessage, sends: [
NetworkBridgeMessage,
NetworkBridgeTxMessage,
RuntimeApiMessage,
AvailabilityStoreMessage,
])]
@@ -508,7 +508,7 @@ pub struct Overseer<SupportsParachains> {
#[subsystem(BitfieldDistributionMessage, sends: [
RuntimeApiMessage,
NetworkBridgeMessage,
NetworkBridgeTxMessage,
ProvisionerMessage,
])]
bitfield_distribution: BitfieldDistribution,
@@ -530,7 +530,7 @@ pub struct Overseer<SupportsParachains> {
])]
availability_store: AvailabilityStore,
#[subsystem(NetworkBridgeMessage, sends: [
#[subsystem(NetworkBridgeRxMessage, sends: [
BitfieldDistributionMessage,
StatementDistributionMessage,
ApprovalDistributionMessage,
@@ -539,7 +539,10 @@ pub struct Overseer<SupportsParachains> {
CollationGenerationMessage,
CollatorProtocolMessage,
])]
network_bridge: NetworkBridge,
network_bridge_rx: NetworkBridgeRx,
#[subsystem(NetworkBridgeTxMessage, sends: [])]
network_bridge_tx: NetworkBridgeTx,
#[subsystem(blocking, ChainApiMessage, sends: [])]
chain_api: ChainApi,
@@ -551,14 +554,14 @@ pub struct Overseer<SupportsParachains> {
collation_generation: CollationGeneration,
#[subsystem(CollatorProtocolMessage, sends: [
NetworkBridgeMessage,
NetworkBridgeTxMessage,
RuntimeApiMessage,
CandidateBackingMessage,
])]
collator_protocol: CollatorProtocol,
#[subsystem(ApprovalDistributionMessage, sends: [
NetworkBridgeMessage,
NetworkBridgeTxMessage,
ApprovalVotingMessage,
])]
approval_distribution: ApprovalDistribution,
@@ -575,7 +578,8 @@ pub struct Overseer<SupportsParachains> {
approval_voting: ApprovalVoting,
#[subsystem(GossipSupportMessage, sends: [
NetworkBridgeMessage,
NetworkBridgeTxMessage,
NetworkBridgeRxMessage, // TODO <https://github.com/paritytech/polkadot/issues/5626>
RuntimeApiMessage,
ChainSelectionMessage,
])]
@@ -594,7 +598,7 @@ pub struct Overseer<SupportsParachains> {
#[subsystem(DisputeDistributionMessage, sends: [
RuntimeApiMessage,
DisputeCoordinatorMessage,
NetworkBridgeMessage,
NetworkBridgeTxMessage,
])]
dispute_distribution: DisputeDistribution,
+24 -9
View File
@@ -29,7 +29,7 @@ use polkadot_node_subsystem_types::{
ActivatedLeaf, LeafStatus,
};
use polkadot_primitives::v2::{
CandidateHash, CandidateReceipt, CollatorPair, InvalidDisputeStatementKind,
CandidateHash, CandidateReceipt, CollatorPair, InvalidDisputeStatementKind, SessionIndex,
ValidDisputeStatementKind, ValidatorIndex,
};
@@ -864,8 +864,16 @@ fn test_availability_store_msg() -> AvailabilityStoreMessage {
AvailabilityStoreMessage::QueryAvailableData(CandidateHash(Default::default()), sender)
}
fn test_network_bridge_msg() -> NetworkBridgeMessage {
NetworkBridgeMessage::ReportPeer(PeerId::random(), UnifiedReputationChange::BenefitMinor(""))
fn test_network_bridge_tx_msg() -> NetworkBridgeTxMessage {
NetworkBridgeTxMessage::ReportPeer(PeerId::random(), UnifiedReputationChange::BenefitMinor(""))
}
fn test_network_bridge_rx_msg() -> NetworkBridgeRxMessage {
NetworkBridgeRxMessage::NewGossipTopology {
session: SessionIndex::from(0_u32),
our_neighbors_x: HashMap::new(),
our_neighbors_y: HashMap::new(),
}
}
fn test_approval_distribution_msg() -> ApprovalDistributionMessage {
@@ -913,7 +921,7 @@ fn test_chain_selection_msg() -> ChainSelectionMessage {
// Checks that `stop`, `broadcast_signal` and `broadcast_message` are implemented correctly.
#[test]
fn overseer_all_subsystems_receive_signals_and_messages() {
const NUM_SUBSYSTEMS: usize = 21;
const NUM_SUBSYSTEMS: usize = 22;
// -4 for BitfieldSigning, GossipSupport, AvailabilityDistribution and PvfCheckerSubsystem.
const NUM_SUBSYSTEMS_MESSAGED: usize = NUM_SUBSYSTEMS - 4;
@@ -980,7 +988,10 @@ fn overseer_all_subsystems_receive_signals_and_messages() {
.send_msg_anon(AllMessages::AvailabilityStore(test_availability_store_msg()))
.await;
handle
.send_msg_anon(AllMessages::NetworkBridge(test_network_bridge_msg()))
.send_msg_anon(AllMessages::NetworkBridgeTx(test_network_bridge_tx_msg()))
.await;
handle
.send_msg_anon(AllMessages::NetworkBridgeRx(test_network_bridge_rx_msg()))
.await;
handle.send_msg_anon(AllMessages::ChainApi(test_chain_api_msg())).await;
handle
@@ -1042,7 +1053,8 @@ fn context_holds_onto_message_until_enough_signals_received() {
let (provisioner_bounded_tx, _) = metered::channel(CHANNEL_CAPACITY);
let (runtime_api_bounded_tx, _) = metered::channel(CHANNEL_CAPACITY);
let (availability_store_bounded_tx, _) = metered::channel(CHANNEL_CAPACITY);
let (network_bridge_bounded_tx, _) = metered::channel(CHANNEL_CAPACITY);
let (network_bridge_rx_bounded_tx, _) = metered::channel(CHANNEL_CAPACITY);
let (network_bridge_tx_bounded_tx, _) = metered::channel(CHANNEL_CAPACITY);
let (chain_api_bounded_tx, _) = metered::channel(CHANNEL_CAPACITY);
let (collator_protocol_bounded_tx, _) = metered::channel(CHANNEL_CAPACITY);
let (collation_generation_bounded_tx, _) = metered::channel(CHANNEL_CAPACITY);
@@ -1064,7 +1076,8 @@ fn context_holds_onto_message_until_enough_signals_received() {
let (provisioner_unbounded_tx, _) = metered::unbounded();
let (runtime_api_unbounded_tx, _) = metered::unbounded();
let (availability_store_unbounded_tx, _) = metered::unbounded();
let (network_bridge_unbounded_tx, _) = metered::unbounded();
let (network_bridge_tx_unbounded_tx, _) = metered::unbounded();
let (network_bridge_rx_unbounded_tx, _) = metered::unbounded();
let (chain_api_unbounded_tx, _) = metered::unbounded();
let (collator_protocol_unbounded_tx, _) = metered::unbounded();
let (collation_generation_unbounded_tx, _) = metered::unbounded();
@@ -1087,7 +1100,8 @@ fn context_holds_onto_message_until_enough_signals_received() {
provisioner: provisioner_bounded_tx.clone(),
runtime_api: runtime_api_bounded_tx.clone(),
availability_store: availability_store_bounded_tx.clone(),
network_bridge: network_bridge_bounded_tx.clone(),
network_bridge_tx: network_bridge_tx_bounded_tx.clone(),
network_bridge_rx: network_bridge_rx_bounded_tx.clone(),
chain_api: chain_api_bounded_tx.clone(),
collator_protocol: collator_protocol_bounded_tx.clone(),
collation_generation: collation_generation_bounded_tx.clone(),
@@ -1109,7 +1123,8 @@ fn context_holds_onto_message_until_enough_signals_received() {
provisioner_unbounded: provisioner_unbounded_tx.clone(),
runtime_api_unbounded: runtime_api_unbounded_tx.clone(),
availability_store_unbounded: availability_store_unbounded_tx.clone(),
network_bridge_unbounded: network_bridge_unbounded_tx.clone(),
network_bridge_tx_unbounded: network_bridge_tx_unbounded_tx.clone(),
network_bridge_rx_unbounded: network_bridge_rx_unbounded_tx.clone(),
chain_api_unbounded: chain_api_unbounded_tx.clone(),
collator_protocol_unbounded: collator_protocol_unbounded_tx.clone(),
collation_generation_unbounded: collation_generation_unbounded_tx.clone(),