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:
rakita 2021-02-19 12:52:24 +01:00 committed by GitHub
parent d8ce175846
commit 98563b0a45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 59 additions and 50 deletions

View File

@ -34,7 +34,7 @@ use ethcore::{
};
use ethcore_logger::{Config as LogConfig, RotatingLogger};
use ethcore_service::ClientService;
use ethereum_types::H256;
use ethereum_types::{H256, U64};
use helpers::{execute_upgrades, passwords_from_files, to_client_config};
use informant::{FullNodeInformantData, Informant};
use journaldb::Algorithm;
@ -227,12 +227,10 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<RunningClient
Some(id) => id,
None => spec.network_id(),
};
if spec.subprotocol_name().len() != 3 {
warn!("Your chain specification's subprotocol length is not 3. Ignoring.");
if spec.subprotocol_name().len() > 8 {
warn!("Your chain specification's subprotocol length is more then 8. Ignoring.");
} else {
sync_config
.subprotocol_name
.clone_from_slice(spec.subprotocol_name().as_bytes());
sync_config.subprotocol_name = U64::from(spec.subprotocol_name().as_bytes())
}
sync_config.fork_block = spec.fork_block();

View File

@ -37,13 +37,14 @@
"maxCodeSizeTransition": "0x0",
"maximumExtraDataSize": "0xffff",
"minGasLimit": "0x1388",
"networkID": "133519467574835",
"networkID": "34180983699157880",
"chainID": "34180983699157880",
"registrar": "0xc6d9d2cd449a754c494264e1809c50e34d64562b"
},
"genesis": {
"author": "0x0000000000000000000000000000000000000000",
"difficulty": "0x1",
"extraData": "0x00000000000000000000000000000000000000000000000000000000000000008a37866fd3627c9205a37c8685666f32ec07bb1b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x00000000000000000000000000000000000000000000000000000000000000001041afbcb359d5a8dc58c15b2ff51354ff8a217d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x47b760",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"seal": {
@ -52,7 +53,7 @@
"nonce": "0x0000000000000000"
}
},
"timestamp": "0x60117f8b"
"timestamp": "0x6027dd2e"
},
"nodes": [
"enode://9e1096aa59862a6f164994cb5cb16f5124d6c992cdbf4535ff7dea43ea1512afe5448dca9df1b7ab0726129603f1a3336b631e4d7a1a44c94daddd03241587f9@3.9.20.133:30303"
@ -925,6 +926,9 @@
"0e89e2aedb1cfcdb9424d41a1f218f4132738172": {
"balance": "0x200000000000000000000000000000000000000000000000000000000000000"
},
"1041afbcb359d5a8dc58c15b2ff51354ff8a217d": {
"balance": "0x200000000000000000000000000000000000000000000000000000000000000"
},
"60adc0f89a41af237ce73554ede170d733ec14e0": {
"balance": "0x200000000000000000000000000000000000000000000000000000000000000"
},
@ -942,6 +946,9 @@
},
"b02a2eda1b317fbd16760128836b0ac59b560e9d": {
"balance": "0x200000000000000000000000000000000000000000000000000000000000000"
},
"df0a88b2b68c673713a8ec826003676f272e3573": {
"balance": "0x200000000000000000000000000000000000000000000000000000000000000"
}
}
}

View File

@ -37,7 +37,6 @@ trace-time = "0.1"
triehash-ethereum = {version = "0.2", path = "../../util/triehash-ethereum" }
stats = { path = "../../util/stats" }
[dev-dependencies]
env_logger = "0.5"
ethcore = { path = "..", features = ["test-helpers"] }

View File

@ -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>>,
}

View File

@ -669,8 +669,8 @@ impl SyncHandler {
.next()
.ok_or(rlp::DecoderError::RlpIsTooShort)?
.as_val()?;
let _eth_protocol_version = io.protocol_version(&ETH_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

View File

@ -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(&ETH_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

View File

@ -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)
}

View File

@ -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

View File

@ -95,7 +95,7 @@ pub struct CapabilityInfo {
impl Encodable for CapabilityInfo {
fn rlp_append(&self, s: &mut RlpStream) {
s.begin_list(2);
s.append(&&self.protocol[..]);
s.append(&self.protocol.as_u64());
s.append(&self.version);
}
}

View File

@ -21,27 +21,29 @@
//! ```rust
//! extern crate ethcore_network as net;
//! extern crate ethcore_network_devp2p as devp2p;
//! extern crate ethereum_types as types;
//! use net::*;
//! use devp2p::NetworkService;
//! use std::sync::Arc;
//! use std::time::Duration;
//! use types::U64;
//!
//! struct MyHandler;
//!
//! impl NetworkProtocolHandler for MyHandler {
//! fn initialize(&self, io: &NetworkContext) {
//! fn initialize(&self, io: &dyn NetworkContext) {
//! io.register_timer(0, Duration::from_secs(1));
//! }
//!
//! fn read(&self, io: &NetworkContext, peer: &PeerId, packet_id: u8, data: &[u8]) {
//! fn read(&self, io: &dyn NetworkContext, peer: &PeerId, packet_id: u8, data: &[u8]) {
//! println!("Received {} ({} bytes) from {}", packet_id, data.len(), peer);
//! }
//!
//! fn connected(&self, io: &NetworkContext, peer: &PeerId) {
//! fn connected(&self, io: &dyn NetworkContext, peer: &PeerId) {
//! println!("Connected {}", peer);
//! }
//!
//! fn disconnected(&self, io: &NetworkContext, peer: &PeerId) {
//! fn disconnected(&self, io: &dyn NetworkContext, peer: &PeerId) {
//! println!("Disconnected {}", peer);
//! }
//! }
@ -49,7 +51,7 @@
//! fn main () {
//! let mut service = NetworkService::new(NetworkConfiguration::new_local(), None).expect("Error creating network service");
//! service.start().expect("Error starting service");
//! service.register_protocol(Arc::new(MyHandler), *b"myp", &[(1u8, 1u8)]);
//! service.register_protocol(Arc::new(MyHandler), U64::from(0x000aaa00), &[(1u8, 1u8)]);
//!
//! // Wait for quit condition
//! // ...

View File

@ -87,7 +87,7 @@ pub enum SessionData {
/// Packet data
data: Vec<u8>,
/// Packet protocol ID
protocol: [u8; 3],
protocol: ProtocolId,
/// Zero based packet ID
packet_id: u8,
},
@ -255,7 +255,7 @@ impl Session {
}
/// Checks if peer supports given capability
pub fn have_capability(&self, protocol: [u8; 3]) -> bool {
pub fn have_capability(&self, protocol: ProtocolId) -> bool {
self.info
.capabilities
.iter()
@ -263,7 +263,7 @@ impl Session {
}
/// Checks if peer supports given capability
pub fn capability_version(&self, protocol: [u8; 3]) -> Option<u8> {
pub fn capability_version(&self, protocol: ProtocolId) -> Option<u8> {
self.info
.capabilities
.iter()
@ -313,7 +313,7 @@ impl Session {
pub fn send_packet<Message>(
&mut self,
io: &IoContext<Message>,
protocol: Option<[u8; 3]>,
protocol: Option<ProtocolId>,
packet_id: u8,
data: &[u8],
) -> Result<(), Error>
@ -321,7 +321,7 @@ impl Session {
Message: Send + Sync + Clone,
{
if protocol.is_some() && (self.info.capabilities.is_empty() || !self.had_hello) {
debug!(target: "network", "Sending to unconfirmed session {}, protocol: {:?}, packet: {}", self.token(), protocol.as_ref().map(|p| str::from_utf8(&p[..]).unwrap_or("??")), packet_id);
debug!(target: "network", "Sending to unconfirmed session {}, protocol: {:?}, packet: {}", self.token(), protocol.map(|p| str::from_utf8(&p.as_u64().to_ne_bytes()).unwrap_or("??").to_string()), packet_id);
bail!(ErrorKind::BadProtocol);
}
if self.expired() {

View File

@ -18,12 +18,14 @@ extern crate env_logger;
extern crate ethcore_io as io;
extern crate ethcore_network;
extern crate ethcore_network_devp2p;
extern crate ethereum_types;
extern crate ethkey;
extern crate parity_bytes;
extern crate parking_lot;
use ethcore_network::*;
use ethcore_network_devp2p::NetworkService;
use ethereum_types::U64;
use ethkey::{Generator, Random};
use io::TimerToken;
use parity_bytes::Bytes;
@ -57,7 +59,11 @@ impl TestProtocol {
pub fn register(service: &mut NetworkService, drop_session: bool) -> Arc<TestProtocol> {
let handler = Arc::new(TestProtocol::new(drop_session));
service
.register_protocol(handler.clone(), *b"tst", &[(42u8, 1u8), (43u8, 1u8)])
.register_protocol(
handler.clone(),
U64::from(0x000aaa00),
&[(42u8, 1u8), (43u8, 1u8)],
)
.expect("Error registering test protocol handler");
handler
}
@ -111,7 +117,11 @@ fn net_service() {
.expect("Error creating network service");
service.start().unwrap();
service
.register_protocol(Arc::new(TestProtocol::new(false)), *b"myp", &[(1u8, 1u8)])
.register_protocol(
Arc::new(TestProtocol::new(false)),
U64::from(0x000aff00),
&[(1u8, 1u8)],
)
.unwrap();
}

View File

@ -50,7 +50,7 @@ pub use error::{DisconnectReason, Error, ErrorKind};
pub use io::TimerToken;
use client_version::ClientVersion;
use ethereum_types::H512;
use ethereum_types::{H512, U64};
use ethkey::Secret;
use ipnetwork::{IpNetwork, IpNetworkError};
use rlp::{Decodable, DecoderError, Rlp};
@ -66,7 +66,7 @@ use std::{
/// Protocol handler level packet id
pub type PacketId = u8;
/// Protocol / handler id
pub type ProtocolId = [u8; 3];
pub type ProtocolId = U64;
/// Node public key
pub type NodeId = H512;
@ -136,16 +136,9 @@ pub struct PeerCapabilityInfo {
impl Decodable for PeerCapabilityInfo {
fn decode(rlp: &Rlp) -> Result<Self, DecoderError> {
let p: Vec<u8> = rlp.val_at(0)?;
if p.len() != 3 {
return Err(DecoderError::Custom(
"Invalid subprotocol string length. Should be 3",
));
}
let mut p2: ProtocolId = [0u8; 3];
p2.clone_from_slice(&p);
let p: u64 = rlp.val_at(0)?;
Ok(PeerCapabilityInfo {
protocol: p2,
protocol: U64::from(p),
version: rlp.val_at(1)?,
})
}
@ -155,7 +148,7 @@ impl ToString for PeerCapabilityInfo {
fn to_string(&self) -> String {
format!(
"{}/{}",
str::from_utf8(&self.protocol[..]).unwrap_or("???"),
str::from_utf8(&self.protocol.as_u64().to_ne_bytes()).unwrap_or("???"),
self.version
)
}
@ -163,7 +156,7 @@ impl ToString for PeerCapabilityInfo {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SessionCapabilityInfo {
pub protocol: [u8; 3],
pub protocol: ProtocolId,
pub version: u8,
pub packet_count: u8,
pub id_offset: u8,