Merge pull request #7040 from paritytech/squashed_network_error_chain
squashed ethcore-network changes which introduce error-chain
This commit is contained in:
@@ -19,7 +19,7 @@ use std::collections::{HashMap, BTreeMap};
|
||||
use std::io;
|
||||
use bytes::Bytes;
|
||||
use network::{NetworkProtocolHandler, NetworkService, NetworkContext, HostInfo, PeerId, ProtocolId,
|
||||
NetworkConfiguration as BasicNetworkConfiguration, NonReservedPeerMode, NetworkError, ConnectionFilter};
|
||||
NetworkConfiguration as BasicNetworkConfiguration, NonReservedPeerMode, Error, ErrorKind, ConnectionFilter};
|
||||
use bigint::prelude::U256;
|
||||
use bigint::hash::{H256, H512};
|
||||
use io::{TimerToken};
|
||||
@@ -207,7 +207,7 @@ pub struct EthSync {
|
||||
|
||||
impl EthSync {
|
||||
/// Creates and register protocol with the network service
|
||||
pub fn new(params: Params, connection_filter: Option<Arc<ConnectionFilter>>) -> Result<Arc<EthSync>, NetworkError> {
|
||||
pub fn new(params: Params, connection_filter: Option<Arc<ConnectionFilter>>) -> Result<Arc<EthSync>, Error> {
|
||||
const MAX_LIGHTSERV_LOAD: f64 = 0.5;
|
||||
|
||||
let pruning_info = params.chain.pruning_info();
|
||||
@@ -397,8 +397,8 @@ impl ChainNotify for EthSync {
|
||||
}
|
||||
|
||||
fn start(&self) {
|
||||
match self.network.start() {
|
||||
Err(NetworkError::StdIo(ref e)) if e.kind() == io::ErrorKind::AddrInUse => warn!("Network port {:?} is already in use, make sure that another instance of an Ethereum client is not running or change the port using the --port option.", self.network.config().listen_address.expect("Listen address is not set.")),
|
||||
match self.network.start().map_err(Into::into) {
|
||||
Err(ErrorKind::Io(ref e)) if e.kind() == io::ErrorKind::AddrInUse => warn!("Network port {:?} is already in use, make sure that another instance of an Ethereum client is not running or change the port using the --port option.", self.network.config().listen_address.expect("Listen address is not set.")),
|
||||
Err(err) => warn!("Error starting network: {}", err),
|
||||
_ => {},
|
||||
}
|
||||
@@ -675,7 +675,7 @@ pub struct LightSync {
|
||||
|
||||
impl LightSync {
|
||||
/// Create a new light sync service.
|
||||
pub fn new<L>(params: LightSyncParams<L>) -> Result<Self, NetworkError>
|
||||
pub fn new<L>(params: LightSyncParams<L>) -> Result<Self, Error>
|
||||
where L: AsLightClient + Provider + Sync + Send + 'static
|
||||
{
|
||||
use light_sync::LightSync as SyncHandler;
|
||||
@@ -752,8 +752,10 @@ impl ManageNetwork for LightSync {
|
||||
}
|
||||
|
||||
fn start_network(&self) {
|
||||
match self.network.start() {
|
||||
Err(NetworkError::StdIo(ref e)) if e.kind() == io::ErrorKind::AddrInUse => warn!("Network port {:?} is already in use, make sure that another instance of an Ethereum client is not running or change the port using the --port option.", self.network.config().listen_address.expect("Listen address is not set.")),
|
||||
match self.network.start().map_err(Into::into) {
|
||||
Err(ErrorKind::Io(ref e)) if e.kind() == io::ErrorKind::AddrInUse => {
|
||||
warn!("Network port {:?} is already in use, make sure that another instance of an Ethereum client is not running or change the port using the --port option.", self.network.config().listen_address.expect("Listen address is not set."))
|
||||
}
|
||||
Err(err) => warn!("Error starting network: {}", err),
|
||||
_ => {},
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ use bigint::hash::H256;
|
||||
use triehash::ordered_trie_root;
|
||||
use bytes::Bytes;
|
||||
use rlp::*;
|
||||
use network::NetworkError;
|
||||
use network;
|
||||
use ethcore::header::Header as BlockHeader;
|
||||
|
||||
known_heap_size!(0, HeaderId);
|
||||
@@ -341,7 +341,7 @@ impl BlockCollection {
|
||||
self.downloading_headers.contains(hash) || self.downloading_bodies.contains(hash)
|
||||
}
|
||||
|
||||
fn insert_body(&mut self, b: Bytes) -> Result<(), NetworkError> {
|
||||
fn insert_body(&mut self, b: Bytes) -> Result<(), network::Error> {
|
||||
let header_id = {
|
||||
let body = UntrustedRlp::new(&b);
|
||||
let tx = body.at(0)?;
|
||||
@@ -365,18 +365,18 @@ impl BlockCollection {
|
||||
},
|
||||
None => {
|
||||
warn!("Got body with no header {}", h);
|
||||
Err(NetworkError::BadProtocol)
|
||||
Err(network::ErrorKind::BadProtocol.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
trace!(target: "sync", "Ignored unknown/stale block body. tx_root = {:?}, uncles = {:?}", header_id.transactions_root, header_id.uncles);
|
||||
Err(NetworkError::BadProtocol)
|
||||
Err(network::ErrorKind::BadProtocol.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn insert_receipt(&mut self, r: Bytes) -> Result<(), NetworkError> {
|
||||
fn insert_receipt(&mut self, r: Bytes) -> Result<(), network::Error> {
|
||||
let receipt_root = {
|
||||
let receipts = UntrustedRlp::new(&r);
|
||||
ordered_trie_root(receipts.iter().map(|r| r.as_raw().to_vec())) //TODO: get rid of vectors here
|
||||
@@ -392,7 +392,7 @@ impl BlockCollection {
|
||||
},
|
||||
None => {
|
||||
warn!("Got receipt with no header {}", h);
|
||||
return Err(NetworkError::BadProtocol)
|
||||
return Err(network::ErrorKind::BadProtocol.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -400,7 +400,7 @@ impl BlockCollection {
|
||||
}
|
||||
_ => {
|
||||
trace!(target: "sync", "Ignored unknown/stale block receipt {:?}", receipt_root);
|
||||
Err(NetworkError::BadProtocol)
|
||||
Err(network::ErrorKind::BadProtocol.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ use bigint::hash::{H256, H256FastMap};
|
||||
use parking_lot::RwLock;
|
||||
use bytes::Bytes;
|
||||
use rlp::*;
|
||||
use network::*;
|
||||
use network::{self, PeerId, PacketId};
|
||||
use ethcore::header::{BlockNumber, Header as BlockHeader};
|
||||
use ethcore::client::{BlockChainClient, BlockStatus, BlockId, BlockChainInfo, BlockImportError, BlockQueueInfo};
|
||||
use ethcore::error::*;
|
||||
@@ -1493,7 +1493,7 @@ impl ChainSync {
|
||||
}
|
||||
|
||||
/// Send Status message
|
||||
fn send_status(&mut self, io: &mut SyncIo, peer: PeerId) -> Result<(), NetworkError> {
|
||||
fn send_status(&mut self, io: &mut SyncIo, peer: PeerId) -> Result<(), network::Error> {
|
||||
let warp_protocol_version = io.protocol_version(&WARP_SYNC_PROTOCOL_ID, peer);
|
||||
let warp_protocol = warp_protocol_version != 0;
|
||||
let protocol = if warp_protocol { warp_protocol_version } else { PROTOCOL_VERSION_63 };
|
||||
@@ -1705,7 +1705,7 @@ impl ChainSync {
|
||||
|
||||
fn return_rlp<FRlp, FError>(io: &mut SyncIo, rlp: &UntrustedRlp, peer: PeerId, rlp_func: FRlp, error_func: FError) -> Result<(), PacketDecodeError>
|
||||
where FRlp : Fn(&SyncIo, &UntrustedRlp, PeerId) -> RlpResponseResult,
|
||||
FError : FnOnce(NetworkError) -> String
|
||||
FError : FnOnce(network::Error) -> String
|
||||
{
|
||||
let response = rlp_func(io, rlp, peer);
|
||||
match response {
|
||||
|
||||
@@ -72,7 +72,7 @@ mod api;
|
||||
|
||||
pub use api::*;
|
||||
pub use chain::{SyncStatus, SyncState};
|
||||
pub use network::{validate_node_url, NonReservedPeerMode, NetworkError, ConnectionFilter, ConnectionDirection};
|
||||
pub use network::{validate_node_url, NonReservedPeerMode, Error, ErrorKind, ConnectionFilter, ConnectionDirection};
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) type Address = bigint::hash::H160;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use network::{NetworkContext, PeerId, PacketId, NetworkError, SessionInfo, ProtocolId};
|
||||
use network::{NetworkContext, PeerId, PacketId, Error, SessionInfo, ProtocolId};
|
||||
use bytes::Bytes;
|
||||
use ethcore::client::BlockChainClient;
|
||||
use ethcore::header::BlockNumber;
|
||||
@@ -31,11 +31,11 @@ pub trait SyncIo {
|
||||
/// Disconnect peer
|
||||
fn disconnect_peer(&mut self, peer_id: PeerId);
|
||||
/// Respond to current request with a packet. Can be called from an IO handler for incoming packet.
|
||||
fn respond(&mut self, packet_id: PacketId, data: Vec<u8>) -> Result<(), NetworkError>;
|
||||
fn respond(&mut self, packet_id: PacketId, data: Vec<u8>) -> Result<(), Error>;
|
||||
/// Send a packet to a peer.
|
||||
fn send(&mut self, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), NetworkError>;
|
||||
fn send(&mut self, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), Error>;
|
||||
/// Send a packet to a peer using specified protocol.
|
||||
fn send_protocol(&mut self, protocol: ProtocolId, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), NetworkError>;
|
||||
fn send_protocol(&mut self, protocol: ProtocolId, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), Error>;
|
||||
/// Get the blockchain
|
||||
fn chain(&self) -> &BlockChainClient;
|
||||
/// Get the snapshot service.
|
||||
@@ -92,15 +92,15 @@ impl<'s, 'h> SyncIo for NetSyncIo<'s, 'h> {
|
||||
self.network.disconnect_peer(peer_id);
|
||||
}
|
||||
|
||||
fn respond(&mut self, packet_id: PacketId, data: Vec<u8>) -> Result<(), NetworkError>{
|
||||
fn respond(&mut self, packet_id: PacketId, data: Vec<u8>) -> Result<(), Error>{
|
||||
self.network.respond(packet_id, data)
|
||||
}
|
||||
|
||||
fn send(&mut self, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), NetworkError>{
|
||||
fn send(&mut self, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), Error>{
|
||||
self.network.send(peer_id, packet_id, data)
|
||||
}
|
||||
|
||||
fn send_protocol(&mut self, protocol: ProtocolId, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), NetworkError>{
|
||||
fn send_protocol(&mut self, protocol: ProtocolId, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), Error>{
|
||||
self.network.send_protocol(protocol, peer_id, packet_id, data)
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ use std::sync::Arc;
|
||||
use bigint::hash::H256;
|
||||
use parking_lot::RwLock;
|
||||
use bytes::Bytes;
|
||||
use network::*;
|
||||
use network::{self, PeerId, ProtocolId, PacketId, SessionInfo};
|
||||
use tests::snapshot::*;
|
||||
use ethcore::client::{TestBlockChainClient, BlockChainClient, Client as EthcoreClient, ClientConfig, ChainNotify};
|
||||
use ethcore::header::BlockNumber;
|
||||
@@ -90,7 +90,7 @@ impl<'p, C> SyncIo for TestIo<'p, C> where C: FlushingBlockChainClient, C: 'p {
|
||||
false
|
||||
}
|
||||
|
||||
fn respond(&mut self, packet_id: PacketId, data: Vec<u8>) -> Result<(), NetworkError> {
|
||||
fn respond(&mut self, packet_id: PacketId, data: Vec<u8>) -> Result<(), network::Error> {
|
||||
self.packets.push(TestPacket {
|
||||
data: data,
|
||||
packet_id: packet_id,
|
||||
@@ -99,7 +99,7 @@ impl<'p, C> SyncIo for TestIo<'p, C> where C: FlushingBlockChainClient, C: 'p {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn send(&mut self, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), NetworkError> {
|
||||
fn send(&mut self, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), network::Error> {
|
||||
self.packets.push(TestPacket {
|
||||
data: data,
|
||||
packet_id: packet_id,
|
||||
@@ -108,7 +108,7 @@ impl<'p, C> SyncIo for TestIo<'p, C> where C: FlushingBlockChainClient, C: 'p {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn send_protocol(&mut self, _protocol: ProtocolId, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), NetworkError> {
|
||||
fn send_protocol(&mut self, _protocol: ProtocolId, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), network::Error> {
|
||||
self.send(peer_id, packet_id, data)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user