This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Allow to broadcast network messages in parallel #7542
Open
vstakhov
wants to merge
18
commits into
master
Choose a base branch
from
vstakhov-network-bridge-small-refactor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ffd9329
Add network bridge messages metrics
vstakhov 5c6d1c4
Propagate network messages in parallel
vstakhov 228b601
Update orchestra from crates
vstakhov 8faef86
Merge branch 'master' into vstakhov-network-bridge-small-refactor
vstakhov 20aae17
Regenerate lock file
vstakhov f540d45
Add some explanations of the logic
vstakhov cf453cc
Merge branch 'master' into vstakhov-network-bridge-small-refactor
vstakhov 289522c
Some lock file conflicts
vstakhov a1113e3
Simplify by using BoxFuture
vstakhov 1b576a8
Use orchestra fix branch to test stuff
vstakhov fbfc8cd
Fix test overseer trait
vstakhov ffca86e
Temporary fix malus node try_send implementation
vstakhov 60ace99
Sync metered
vstakhov 242348a
Remove garbage
vstakhov 0770f4f
Reintroduce const for tests
vstakhov c37ce36
Fix malus node after orchestra update
vstakhov 27b9a69
Switch from using a git version
vstakhov eab2277
Merge remote-tracking branch 'origin/master' into vstakhov-network-br…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,10 @@ use super::*; | |
|
||
use always_assert::never; | ||
use bytes::Bytes; | ||
use futures::stream::BoxStream; | ||
use futures::{ | ||
stream::{BoxStream, FuturesUnordered, StreamExt}, | ||
Future, | ||
}; | ||
use parity_scale_codec::{Decode, DecodeAll}; | ||
|
||
use sc_network::Event as NetworkEvent; | ||
|
@@ -55,6 +58,7 @@ pub use polkadot_node_network_protocol::peer_set::{peer_sets_info, IsAuthority}; | |
use std::{ | ||
collections::{hash_map, HashMap}, | ||
iter::ExactSizeIterator, | ||
pin::Pin, | ||
}; | ||
|
||
use super::validator_discovery; | ||
|
@@ -890,21 +894,55 @@ fn dispatch_collation_event_to_all_unbounded( | |
} | ||
} | ||
|
||
fn try_send_validation_event<E>( | ||
event: E, | ||
sender: &mut (impl overseer::NetworkBridgeRxSenderTrait + overseer::SubsystemSender<E>), | ||
delayed_queue: &FuturesUnordered<Pin<Box<dyn Future<Output = ()> + Send>>>, | ||
) where | ||
E: Send + 'static, | ||
{ | ||
match sender.try_send_message(event) { | ||
Ok(()) => {}, | ||
Err(overseer::TrySendError::Full(event)) => { | ||
let mut sender = sender.clone(); | ||
delayed_queue.push(Box::pin(async move { | ||
sender.send_message(event).await; | ||
})); | ||
}, | ||
Err(overseer::TrySendError::Closed(_)) => { | ||
panic!( | ||
"NetworkBridgeRxSender is closed when trying to send event of type: {}", | ||
std::any::type_name::<E>() | ||
); | ||
}, | ||
} | ||
} | ||
|
||
async fn dispatch_validation_events_to_all<I>( | ||
events: I, | ||
sender: &mut impl overseer::NetworkBridgeRxSenderTrait, | ||
) where | ||
I: IntoIterator<Item = NetworkBridgeEvent<net_protocol::VersionedValidationProtocol>>, | ||
I::IntoIter: Send, | ||
{ | ||
let delayed_messages: FuturesUnordered<Pin<Box<dyn Future<Output = ()> + Send>>> = | ||
FuturesUnordered::new(); | ||
for event in events { | ||
sender | ||
.send_messages(event.focus().map(StatementDistributionMessage::from)) | ||
.await; | ||
sender.send_messages(event.focus().map(BitfieldDistributionMessage::from)).await; | ||
sender.send_messages(event.focus().map(ApprovalDistributionMessage::from)).await; | ||
sender.send_messages(event.focus().map(GossipSupportMessage::from)).await; | ||
if let Ok(msg) = event.focus().map(StatementDistributionMessage::from) { | ||
try_send_validation_event(msg, sender, &delayed_messages); | ||
} | ||
if let Ok(msg) = event.focus().map(BitfieldDistributionMessage::from) { | ||
try_send_validation_event(msg, sender, &delayed_messages); | ||
} | ||
if let Ok(msg) = event.focus().map(ApprovalDistributionMessage::from) { | ||
try_send_validation_event(msg, sender, &delayed_messages); | ||
} | ||
if let Ok(msg) = event.focus().map(GossipSupportMessage::from) { | ||
try_send_validation_event(msg, sender, &delayed_messages); | ||
} | ||
} | ||
|
||
let _: Vec<()> = delayed_messages.collect().await; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. technically the bridge is still stopped until all futures complete here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but other subsystems have a chance to receive updates if some other subsystem is slow. That's the goal of this PR technically. |
||
} | ||
|
||
async fn dispatch_collation_events_to_all<I>( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it ok to ignore a possible error?