Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only send transactions to peers with open substream #2717

Merged
merged 3 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion bin/light-base/src/network_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,12 @@ impl<TPlat: Platform> NetworkService<TPlat> {
let mut guarded = self.shared.guarded.lock().await;

// TODO: collecting in a Vec :-/
for peer in guarded.network.peers_list().cloned().collect::<Vec<_>>() {
for peer in guarded
.network
.opened_transactions_substream(chain_index)
.cloned()
.collect::<Vec<_>>()
{
if guarded
.network
.announce_transaction(&peer, chain_index, transaction)
Expand Down
1 change: 1 addition & 0 deletions bin/wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Fix occasional panic when connecting to a parachain with forks and/or missed slots. ([#2703](https://github.com/paritytech/smoldot/pull/2703))
- Fix parachain initialization unnecessarily waiting for its corresponding relay chain initialization to be finished. ([#2705](https://github.com/paritytech/smoldot/pull/2705))
- Fix panic when broadcasting a transaction to a peer while its connection is shutting down.

## 0.6.31 - 2022-08-30

Expand Down
14 changes: 14 additions & 0 deletions src/libp2p/peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,20 @@ where
)
}

/// Returns the list of peers for which we have a fully established notifications protocol of
/// the given protocol.
pub fn opened_out_notifications(
&'_ self,
notifications_protocol_index: usize,
) -> impl Iterator<Item = &'_ PeerId> + '_ {
// TODO: this is O(n)
self.peers_notifications_out
.iter()
.filter(move |((_, idx), _)| *idx == notifications_protocol_index)
.filter(|(_, state)| matches!(state.open, NotificationsOutOpenState::Open(_)))
.map(|((peer_idx, _), _)| &self.peers[*peer_idx].peer_id)
}

/// Returns the state of the given connection.
///
/// # Panic
Expand Down
10 changes: 10 additions & 0 deletions src/network/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,16 @@ where
)
}

/// Returns the list of peers for which we have a fully established notifications protocol of
/// the given protocol.
pub fn opened_transactions_substream(
&'_ self,
chain_index: usize,
) -> impl Iterator<Item = &'_ PeerId> + '_ {
self.inner
.opened_out_notifications(chain_index * NOTIFICATIONS_PROTOCOLS_PER_CHAIN + 1)
}

///
///
/// Must be passed the SCALE-encoded transaction.
Expand Down