Rework priority groups, take 2 (#7700)

* Rework priority groups

* Broken tests fix

* Fix warning causing CI to fail

* [Hack] Try restore backwards-compatibility

* Fix peerset bug

* Doc fixes and clean up

* Error on state mismatch

* Try debug CI

* CI debugging

* [CI debug] Can I please see this line

* Revert "[CI debug] Can I please see this line"

This reverts commit 4b7cf7c1511f579cd818b21d46bd11642dfac5cb.

* Revert "CI debugging"

This reverts commit 9011f1f564b860386dc7dd6ffa9fc34ea7107623.

* Fix error! which isn't actually an error

* Fix Ok() returned when actually Err()

* Tweaks and fixes

* Fix build

* Peerset bugfix

* [Debug] Try outbound GrandPa slots

* Another bugfix

* Revert "[Debug] Try outbound GrandPa slots"

This reverts commit d175b9208c088faad77d9f0ce36ff6f48bd92dd3.

* [Debug] Try outbound GrandPa slots

* Apply suggestions from code review

Co-authored-by: Max Inden <mail@max-inden.de>

* Use consts for hardcoded peersets

* Revert "Try debug CI"

This reverts commit 62c4ad5e79c03d561c714a008022ecac463a597e.

* Renames

* Line widths

* Add doc

Co-authored-by: Max Inden <mail@max-inden.de>
This commit is contained in:
Pierre Krieger
2021-01-07 14:52:39 +01:00
committed by GitHub
parent 94bb119ef9
commit 779c4f8616
30 changed files with 2742 additions and 2293 deletions
+30 -56
View File
@@ -24,7 +24,6 @@ use crate::{
};
use bytes::Bytes;
use codec::Encode as _;
use futures::channel::oneshot;
use libp2p::NetworkBehaviour;
use libp2p::core::{Multiaddr, PeerId, PublicKey};
@@ -157,6 +156,12 @@ pub enum BehaviourOut<B: BlockT> {
messages: Vec<(Cow<'static, str>, Bytes)>,
},
/// Now connected to a new peer for syncing purposes.
SyncConnected(PeerId),
/// No longer connected to a peer for syncing purposes.
SyncDisconnected(PeerId),
/// Events generated by a DHT as a response to get_value or put_value requests as well as the
/// request duration.
Dht(DhtEvent, Duration),
@@ -242,35 +247,6 @@ impl<B: BlockT, H: ExHashT> Behaviour<B, H> {
self.request_responses.send_request(target, protocol, request, pending_response)
}
/// Registers a new notifications protocol.
///
/// Please call `event_stream` before registering a protocol, otherwise you may miss events
/// about the protocol that you have registered.
///
/// You are very strongly encouraged to call this method very early on. Any connection open
/// will retain the protocols that were registered then, and not any new one.
pub fn register_notifications_protocol(
&mut self,
protocol: impl Into<Cow<'static, str>>,
) {
let protocol = protocol.into();
// This is the message that we will send to the remote as part of the initial handshake.
// At the moment, we force this to be an encoded `Roles`.
let handshake_message = Roles::from(&self.role).encode();
let list = self.substrate.register_notifications_protocol(protocol.clone(), handshake_message);
for (remote, roles, notifications_sink) in list {
let role = reported_roles_to_observed_role(&self.role, remote, roles);
self.events.push_back(BehaviourOut::NotificationStreamOpened {
remote: remote.clone(),
protocol: protocol.clone(),
role,
notifications_sink: notifications_sink.clone(),
});
}
}
/// Returns a shared reference to the user protocol.
pub fn user_protocol(&self) -> &Protocol<B, H> {
&self.substrate
@@ -343,38 +319,36 @@ Behaviour<B, H> {
&target, &self.block_request_protocol_name, buf, pending_response,
);
},
CustomMessageOutcome::NotificationStreamOpened { remote, protocols, roles, notifications_sink } => {
CustomMessageOutcome::NotificationStreamOpened { remote, protocol, roles, notifications_sink } => {
let role = reported_roles_to_observed_role(&self.role, &remote, roles);
for protocol in protocols {
self.events.push_back(BehaviourOut::NotificationStreamOpened {
remote: remote.clone(),
protocol,
role: role.clone(),
notifications_sink: notifications_sink.clone(),
});
}
self.events.push_back(BehaviourOut::NotificationStreamOpened {
remote,
protocol,
role: role.clone(),
notifications_sink: notifications_sink.clone(),
});
},
CustomMessageOutcome::NotificationStreamReplaced { remote, protocols, notifications_sink } =>
for protocol in protocols {
self.events.push_back(BehaviourOut::NotificationStreamReplaced {
remote: remote.clone(),
protocol,
notifications_sink: notifications_sink.clone(),
});
},
CustomMessageOutcome::NotificationStreamClosed { remote, protocols } =>
for protocol in protocols {
self.events.push_back(BehaviourOut::NotificationStreamClosed {
remote: remote.clone(),
protocol,
});
},
CustomMessageOutcome::NotificationStreamReplaced { remote, protocol, notifications_sink } =>
self.events.push_back(BehaviourOut::NotificationStreamReplaced {
remote,
protocol,
notifications_sink,
}),
CustomMessageOutcome::NotificationStreamClosed { remote, protocol } =>
self.events.push_back(BehaviourOut::NotificationStreamClosed {
remote,
protocol,
}),
CustomMessageOutcome::NotificationsReceived { remote, messages } => {
self.events.push_back(BehaviourOut::NotificationsReceived { remote, messages });
},
CustomMessageOutcome::PeerNewBest(peer_id, number) => {
self.light_client_handler.update_best_block(&peer_id, number);
}
CustomMessageOutcome::SyncConnected(peer_id) =>
self.events.push_back(BehaviourOut::SyncConnected(peer_id)),
CustomMessageOutcome::SyncDisconnected(peer_id) =>
self.events.push_back(BehaviourOut::SyncDisconnected(peer_id)),
CustomMessageOutcome::None => {}
}
}
@@ -425,7 +399,7 @@ impl<B: BlockT, H: ExHashT> NetworkBehaviourEventProcess<peer_info::PeerInfoEven
for addr in listen_addrs {
self.discovery.add_self_reported_address(&peer_id, protocols.iter(), addr);
}
self.substrate.add_discovered_nodes(iter::once(peer_id));
self.substrate.add_default_set_discovered_nodes(iter::once(peer_id));
}
}
@@ -440,7 +414,7 @@ impl<B: BlockT, H: ExHashT> NetworkBehaviourEventProcess<DiscoveryOut>
// implementation for `PeerInfoEvent`.
}
DiscoveryOut::Discovered(peer_id) => {
self.substrate.add_discovered_nodes(iter::once(peer_id));
self.substrate.add_default_set_discovered_nodes(iter::once(peer_id));
}
DiscoveryOut::ValueFound(results, duration) => {
self.events.push_back(BehaviourOut::Dht(DhtEvent::ValueFound(results), duration));