Clean-ups in the network-gossip crate (#4542)

* Remove usage of sc_network::Context trait

* Remove Context::send_consensus

* Pass &mut dyn Network instead of &dyn Network

* Move Validator traits and related to separate module
This commit is contained in:
Pierre Krieger
2020-01-09 19:24:51 +01:00
committed by Gavin Wood
parent b61b3095ee
commit bc3d283e78
5 changed files with 159 additions and 235 deletions
-34
View File
@@ -80,8 +80,6 @@ pub(crate) const MIN_VERSION: u32 = 3;
// Maximum allowed entries in `BlockResponse`
const MAX_BLOCK_DATA_RESPONSE: u32 = 128;
// Maximum allowed entries in `ConsensusBatch`
const MAX_CONSENSUS_MESSAGES: usize = 256;
/// When light node connects to the full node and the full node is behind light node
/// for at least `LIGHT_MAXIMAL_BLOCKS_DIFFERENCE` blocks, we consider it unuseful
/// and disconnect to free connection slot.
@@ -327,9 +325,6 @@ pub trait Context<B: BlockT> {
/// Force disconnecting from a peer. Use this when a peer misbehaved.
fn disconnect_peer(&mut self, who: PeerId);
/// Send a consensus message to a peer.
fn send_consensus(&mut self, who: PeerId, messages: Vec<ConsensusMessage>);
/// Send a chain-specific message to a peer.
fn send_chain_specific(&mut self, who: PeerId, message: Vec<u8>);
}
@@ -360,35 +355,6 @@ impl<'a, B: BlockT + 'a, H: ExHashT + 'a> Context<B> for ProtocolContext<'a, B,
self.behaviour.disconnect_peer(&who)
}
fn send_consensus(&mut self, who: PeerId, messages: Vec<ConsensusMessage>) {
if self.context_data.peers.get(&who).map_or(false, |peer| peer.info.protocol_version > 4) {
let mut batch = Vec::new();
let len = messages.len();
for (index, message) in messages.into_iter().enumerate() {
batch.reserve(MAX_CONSENSUS_MESSAGES);
batch.push(message);
if batch.len() == MAX_CONSENSUS_MESSAGES || index == len - 1 {
send_message::<B> (
self.behaviour,
&mut self.context_data.stats,
&who,
GenericMessage::ConsensusBatch(std::mem::replace(&mut batch, Vec::new())),
)
}
}
} else {
// Backwards compatibility
for message in messages {
send_message::<B> (
self.behaviour,
&mut self.context_data.stats,
&who,
GenericMessage::Consensus(message)
)
}
}
}
fn send_chain_specific(&mut self, who: PeerId, message: Vec<u8>) {
send_message::<B> (
self.behaviour,