Correct internal par protocol nomenclature

This commit is contained in:
Artem Vorotnikov 2020-08-13 14:52:54 +03:00
parent a75ba3620c
commit 2ab8c72ce3
No known key found for this signature in database
GPG Key ID: E0148C3F2FBB7A20
5 changed files with 18 additions and 24 deletions

View File

@ -62,7 +62,7 @@ use types::{pruning_info::PruningInfo, transaction::UnverifiedTransaction, Block
use super::light_sync::SyncInfo;
/// Parity sync protocol
pub const WARP_SYNC_PROTOCOL_ID: ProtocolId = *b"par";
pub const PAR_PROTOCOL: ProtocolId = *b"par";
/// Ethereum sync protocol
pub const ETH_PROTOCOL: ProtocolId = *b"eth";
/// Ethereum light protocol
@ -449,7 +449,7 @@ struct SyncProtocolHandler {
impl NetworkProtocolHandler for SyncProtocolHandler {
fn initialize(&self, io: &dyn NetworkContext) {
if io.subprotocol_name() != WARP_SYNC_PROTOCOL_ID {
if io.subprotocol_name() != PAR_PROTOCOL {
io.register_timer(PEERS_TIMER, Duration::from_millis(700))
.expect("Error registering peers timer");
io.register_timer(MAINTAIN_SYNC_TIMER, Duration::from_millis(1100))
@ -476,11 +476,8 @@ impl NetworkProtocolHandler for SyncProtocolHandler {
fn connected(&self, io: &dyn NetworkContext, peer: &PeerId) {
trace_time!("sync::connected");
// If warp protocol is supported only allow warp handshake
let warp_protocol = io
.protocol_version(WARP_SYNC_PROTOCOL_ID, *peer)
.unwrap_or(0)
!= 0;
let warp_context = io.subprotocol_name() == WARP_SYNC_PROTOCOL_ID;
let warp_protocol = io.protocol_version(PAR_PROTOCOL, *peer).unwrap_or(0) != 0;
let warp_context = io.subprotocol_name() == PAR_PROTOCOL;
if warp_protocol == warp_context {
self.sync.write().on_peer_connected(
&mut NetSyncIo::new(io, &*self.chain, &*self.snapshot_service, &self.overlay),
@ -491,7 +488,7 @@ impl NetworkProtocolHandler for SyncProtocolHandler {
fn disconnected(&self, io: &dyn NetworkContext, peer: &PeerId) {
trace_time!("sync::disconnected");
if io.subprotocol_name() != WARP_SYNC_PROTOCOL_ID {
if io.subprotocol_name() != PAR_PROTOCOL {
self.sync.write().on_peer_aborting(
&mut NetSyncIo::new(io, &*self.chain, &*self.snapshot_service, &self.overlay),
*peer,
@ -598,7 +595,7 @@ impl ChainNotify for EthSync {
self.network
.register_protocol(
self.eth_handler.clone(),
WARP_SYNC_PROTOCOL_ID,
PAR_PROTOCOL,
&[
PAR_PROTOCOL_VERSION_1,
PAR_PROTOCOL_VERSION_2,
@ -625,7 +622,7 @@ impl ChainNotify for EthSync {
}
fn broadcast(&self, message_type: ChainMessageType) {
self.network.with_context(WARP_SYNC_PROTOCOL_ID, |context| {
self.network.with_context(PAR_PROTOCOL, |context| {
let mut sync_io = NetSyncIo::new(
context,
&*self.eth_handler.chain,
@ -827,7 +824,7 @@ impl NetworkConfiguration {
max_peers: self.max_peers,
min_peers: self.min_peers,
max_handshakes: self.max_pending_peers,
reserved_protocols: hash_map![WARP_SYNC_PROTOCOL_ID => self.snapshot_peers],
reserved_protocols: hash_map![PAR_PROTOCOL => self.snapshot_peers],
reserved_nodes: self.reserved_nodes,
ip_filter: self.ip_filter,
non_reserved_mode: if self.allow_non_reserved {
@ -859,10 +856,7 @@ impl From<BasicNetworkConfiguration> for NetworkConfiguration {
max_peers: other.max_peers,
min_peers: other.min_peers,
max_pending_peers: other.max_handshakes,
snapshot_peers: *other
.reserved_protocols
.get(&WARP_SYNC_PROTOCOL_ID)
.unwrap_or(&0),
snapshot_peers: *other.reserved_protocols.get(&PAR_PROTOCOL).unwrap_or(&0),
reserved_nodes: other.reserved_nodes,
ip_filter: other.ip_filter,
allow_non_reserved: match other.non_reserved_mode {

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
use api::WARP_SYNC_PROTOCOL_ID;
use api::PAR_PROTOCOL;
use block_sync::{BlockDownloaderImportError as DownloaderImportError, DownloadAction};
use bytes::Bytes;
use enum_primitive::FromPrimitive;
@ -659,7 +659,7 @@ impl SyncHandler {
) -> Result<(), DownloaderImportError> {
sync.handshaking_peers.remove(&peer_id);
let protocol_version: u8 = r.val_at(0)?;
let warp_protocol_version = io.protocol_version(&WARP_SYNC_PROTOCOL_ID, peer_id);
let warp_protocol_version = io.protocol_version(&PAR_PROTOCOL, peer_id);
let warp_protocol = warp_protocol_version != 0;
let private_tx_protocol = warp_protocol_version >= PAR_PROTOCOL_VERSION_3.0;
let peer = PeerInfo {

View File

@ -94,7 +94,7 @@ mod supplier;
pub mod sync_packet;
use super::{SyncConfig, WarpSync};
use api::{EthProtocolInfo as PeerInfoDigest, PriorityTask, WARP_SYNC_PROTOCOL_ID};
use api::{EthProtocolInfo as PeerInfoDigest, PriorityTask, PAR_PROTOCOL};
use block_sync::{BlockDownloader, DownloadAction};
use bytes::Bytes;
use ethcore::{
@ -1206,7 +1206,7 @@ impl ChainSync {
/// Send Status message
fn send_status(&mut self, io: &mut dyn SyncIo, peer: PeerId) -> Result<(), network::Error> {
let warp_protocol_version = io.protocol_version(&WARP_SYNC_PROTOCOL_ID, peer);
let warp_protocol_version = io.protocol_version(&PAR_PROTOCOL, peer);
let warp_protocol = warp_protocol_version != 0;
let private_tx_protocol = warp_protocol_version >= PAR_PROTOCOL_VERSION_3.0;
let protocol = if warp_protocol {

View File

@ -24,7 +24,7 @@
#![allow(unused_doc_comments)]
use api::{ETH_PROTOCOL, WARP_SYNC_PROTOCOL_ID};
use api::{ETH_PROTOCOL, PAR_PROTOCOL};
use network::{PacketId, ProtocolId};
// An enum that defines all known packet ids in the context of
@ -93,7 +93,7 @@ impl PacketInfo for SyncPacket {
| SnapshotDataPacket
| ConsensusDataPacket
| PrivateTransactionPacket
| SignedPrivateTransactionPacket => WARP_SYNC_PROTOCOL_ID,
| SignedPrivateTransactionPacket => PAR_PROTOCOL,
}
}
@ -132,6 +132,6 @@ mod tests {
#[test]
fn when_consensus_data_packet_then_id_and_protocol_match() {
assert_eq!(ConsensusDataPacket.id(), ConsensusDataPacket as PacketId);
assert_eq!(ConsensusDataPacket.protocol(), WARP_SYNC_PROTOCOL_ID);
assert_eq!(ConsensusDataPacket.protocol(), PAR_PROTOCOL);
}
}

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
use api::WARP_SYNC_PROTOCOL_ID;
use api::PAR_PROTOCOL;
use bytes::Bytes;
use chain::{
sync_packet::{
@ -176,7 +176,7 @@ where
}
fn protocol_version(&self, protocol: &ProtocolId, peer_id: PeerId) -> u8 {
if protocol == &WARP_SYNC_PROTOCOL_ID {
if protocol == &PAR_PROTOCOL {
PAR_PROTOCOL_VERSION_3.0
} else {
self.eth_protocol_version(peer_id)