mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 06:17:56 +00:00
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:
committed by
Gavin Wood
parent
b61b3095ee
commit
bc3d283e78
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user