Change ProtocolId to U64. yolo3x spec (#271)
* Change ProtocolId to U64 and make it support variable subprotocol names* * Add yolo3x testnet
This commit is contained in:
@@ -37,7 +37,7 @@ use ethcore::{
|
||||
client::{BlockChainClient, ChainMessageType, ChainNotify, NewBlocks},
|
||||
snapshot::SnapshotService,
|
||||
};
|
||||
use ethereum_types::{H256, H512, U256};
|
||||
use ethereum_types::{H256, H512, U256, U64};
|
||||
use ethkey::Secret;
|
||||
use io::TimerToken;
|
||||
use network::IpFilter;
|
||||
@@ -55,9 +55,9 @@ use types::{
|
||||
};
|
||||
|
||||
/// OpenEthereum sync protocol
|
||||
pub const PAR_PROTOCOL: ProtocolId = *b"par";
|
||||
pub const PAR_PROTOCOL: ProtocolId = U64([0x706172]); // hexadecimal number of "par";
|
||||
/// Ethereum sync protocol
|
||||
pub const ETH_PROTOCOL: ProtocolId = *b"eth";
|
||||
pub const ETH_PROTOCOL: ProtocolId = U64([0x657468]); // hexadecimal number of "eth";
|
||||
|
||||
/// Determine warp sync status.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -104,7 +104,7 @@ pub struct SyncConfig {
|
||||
/// Network ID
|
||||
pub network_id: u64,
|
||||
/// Main "eth" subprotocol name.
|
||||
pub subprotocol_name: [u8; 3],
|
||||
pub subprotocol_name: ProtocolId,
|
||||
/// Fork block to check
|
||||
pub fork_block: Option<(BlockNumber, H256)>,
|
||||
/// Enable snapshot sync
|
||||
@@ -230,7 +230,7 @@ pub struct EthSync {
|
||||
/// Main (eth/par) protocol handler
|
||||
eth_handler: Arc<SyncProtocolHandler>,
|
||||
/// The main subprotocol name
|
||||
subprotocol_name: [u8; 3],
|
||||
subprotocol_name: ProtocolId,
|
||||
/// Priority tasks notification channel
|
||||
priority_tasks: Mutex<mpsc::Sender<PriorityTask>>,
|
||||
}
|
||||
|
||||
@@ -669,8 +669,8 @@ impl SyncHandler {
|
||||
.next()
|
||||
.ok_or(rlp::DecoderError::RlpIsTooShort)?
|
||||
.as_val()?;
|
||||
let _eth_protocol_version = io.protocol_version(Ð_PROTOCOL, peer_id);
|
||||
let warp_protocol_version = io.protocol_version(&PAR_PROTOCOL, peer_id);
|
||||
let _eth_protocol_version = io.protocol_version(ETH_PROTOCOL, peer_id);
|
||||
let warp_protocol_version = io.protocol_version(PAR_PROTOCOL, peer_id);
|
||||
let warp_protocol = warp_protocol_version != 0;
|
||||
|
||||
let network_id = r_iter
|
||||
|
||||
@@ -1272,8 +1272,8 @@ impl ChainSync {
|
||||
|
||||
/// Send Status message
|
||||
fn send_status(&mut self, io: &mut dyn SyncIo, peer: PeerId) -> Result<(), network::Error> {
|
||||
let eth_protocol_version = io.protocol_version(Ð_PROTOCOL, peer);
|
||||
let warp_protocol_version = io.protocol_version(&PAR_PROTOCOL, peer);
|
||||
let eth_protocol_version = io.protocol_version(ETH_PROTOCOL, peer);
|
||||
let warp_protocol_version = io.protocol_version(PAR_PROTOCOL, peer);
|
||||
let warp_protocol = warp_protocol_version != 0;
|
||||
let protocol = if warp_protocol {
|
||||
warp_protocol_version
|
||||
|
||||
@@ -47,7 +47,7 @@ pub trait SyncIo {
|
||||
/// Returns information on p2p session
|
||||
fn peer_session_info(&self, peer_id: PeerId) -> Option<SessionInfo>;
|
||||
/// Maximum mutually supported version of a gien protocol.
|
||||
fn protocol_version(&self, protocol: &ProtocolId, peer_id: PeerId) -> u8;
|
||||
fn protocol_version(&self, protocol: ProtocolId, peer_id: PeerId) -> u8;
|
||||
/// Returns if the chain block queue empty
|
||||
fn is_chain_queue_empty(&self) -> bool {
|
||||
self.chain().is_queue_empty()
|
||||
@@ -121,9 +121,9 @@ impl<'s> SyncIo for NetSyncIo<'s> {
|
||||
self.network.is_expired()
|
||||
}
|
||||
|
||||
fn protocol_version(&self, protocol: &ProtocolId, peer_id: PeerId) -> u8 {
|
||||
fn protocol_version(&self, protocol: ProtocolId, peer_id: PeerId) -> u8 {
|
||||
self.network
|
||||
.protocol_version(*protocol, peer_id)
|
||||
.protocol_version(protocol, peer_id)
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
|
||||
@@ -168,8 +168,8 @@ where
|
||||
None
|
||||
}
|
||||
|
||||
fn protocol_version(&self, protocol: &ProtocolId, _peer_id: PeerId) -> u8 {
|
||||
if protocol == &PAR_PROTOCOL {
|
||||
fn protocol_version(&self, protocol: ProtocolId, _peer_id: PeerId) -> u8 {
|
||||
if protocol == PAR_PROTOCOL {
|
||||
PAR_PROTOCOL_VERSION_2.0
|
||||
} else {
|
||||
ETH_PROTOCOL_VERSION_64.0
|
||||
|
||||
Reference in New Issue
Block a user