7bf16cce1b
* Fix light sync with initial validator-set contract (#8528) * Fix #8468 * Use U256::max_value() instead * Fix again * Also change initial transaction gas * Resumable warp-sync / Seed downloaded snapshots (#8544) * Start dividing sync chain : first supplier method * WIP - updated chain sync supplier * Finish refactoring the Chain Sync Supplier * Create Chain Sync Requester * Add Propagator for Chain Sync * Add the Chain Sync Handler * Move tests from mod -> handler * Move tests to propagator * Refactor SyncRequester arguments * Refactoring peer fork header handler * Fix wrong highest block number in snapshot sync * Small refactor... * Resume warp-sync downloaded chunks * Add comments * Refactoring the previous chunks import * Fix tests * Address PR grumbles * Fix not seeding current snapshot * Address PR Grumbles * Address PR grumble * Retry failed CI job * Update SnapshotService readiness check Fix restoration locking issue for previous chunks restoration * Fix tests * Fix tests * Fix test * Early abort importing previous chunks * PR Grumbles * Update Gitlab CI config * SyncState back to Waiting when Manifest peers disconnect * Move fix * Better fix * Revert GitLab CI changes * Fix Warning * Refactor resuming snapshots * Fix string construction * Revert "Refactor resuming snapshots" This reverts commit 75fd4b553a38e4a49dc5d6a878c70e830ff382eb. * Update informant log * Fix string construction * Refactor resuming snapshots * Fix informant * PR Grumbles * Update informant message : show chunks done * PR Grumbles * Fix * Fix Warning * PR Grumbles * Don't open Browser post-install on Mac (#8641) Since we start parity with the UI disabled per default now, opening the browser post installation will show an annoying error message, confusing the user. This patch removes opening the browser to prevent that annoyance. fixes #8194 * Fix not downloading old blocks (#8642) * Fix PoW blockchains sealing notifications in chain_new_blocks (#8656) * Shutdown the Snapshot Service early (#8658) * Shutdown the Snapshot Service when shutting down the runner * Rename `service` to `client_service` * Fix tests * Fix cli signer (#8682) * Update ethereum-types so `{:#x}` applies 0x prefix * Set the request index to that of the current request (#8683) * Set the request index to that of the current request When setting up the chain of (two) requests to look up a block by hash, the second need to refer to the first. This fixes an issue where the back ref was set to the subsequent request, not the current one. When the requests are executed we loop through them in order and ensure the requests that should produce headers all match up. We do this by index so they better be right. In other words: off by one. * network-devp2p: handle UselessPeer disconnect (#8686) * Fix local transactions policy. (#8691) * CI: Fixes for Android Pipeline (#8745) * ci: Remove check for shared libraries in gitlab script * ci: allow android arm build to fail * Custom Error Messages on ENFILE and EMFILE IO Errors (#8744) * Custom Error Messages on ENFILE and EMFILE IO Errors Add custom mapping of ENFILE and EMFILE IO Errors (Failure because of missing system resource) right when chaining ioError into ::util::Network::Error to improve Error Messages given to user Note: Adds libc as a dependency to util/network * Use assert-matches for more readable tests * Fix Wording and consistency * ethcore-sync: fix connection to peers behind chain fork block (#8710)
239 lines
6.2 KiB
Rust
239 lines
6.2 KiB
Rust
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
|
// This file is part of Parity.
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
use std::{io, net, fmt};
|
|
use libc::{ENFILE, EMFILE};
|
|
use io::IoError;
|
|
use {rlp, ethkey, crypto, snappy};
|
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
|
pub enum DisconnectReason
|
|
{
|
|
DisconnectRequested,
|
|
TCPError,
|
|
BadProtocol,
|
|
UselessPeer,
|
|
TooManyPeers,
|
|
DuplicatePeer,
|
|
IncompatibleProtocol,
|
|
NullIdentity,
|
|
ClientQuit,
|
|
UnexpectedIdentity,
|
|
LocalIdentity,
|
|
PingTimeout,
|
|
Unknown,
|
|
}
|
|
|
|
impl DisconnectReason {
|
|
pub fn from_u8(n: u8) -> DisconnectReason {
|
|
match n {
|
|
0 => DisconnectReason::DisconnectRequested,
|
|
1 => DisconnectReason::TCPError,
|
|
2 => DisconnectReason::BadProtocol,
|
|
3 => DisconnectReason::UselessPeer,
|
|
4 => DisconnectReason::TooManyPeers,
|
|
5 => DisconnectReason::DuplicatePeer,
|
|
6 => DisconnectReason::IncompatibleProtocol,
|
|
7 => DisconnectReason::NullIdentity,
|
|
8 => DisconnectReason::ClientQuit,
|
|
9 => DisconnectReason::UnexpectedIdentity,
|
|
10 => DisconnectReason::LocalIdentity,
|
|
11 => DisconnectReason::PingTimeout,
|
|
_ => DisconnectReason::Unknown,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for DisconnectReason {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
use self::DisconnectReason::*;
|
|
|
|
let msg = match *self {
|
|
DisconnectRequested => "disconnect requested",
|
|
TCPError => "TCP error",
|
|
BadProtocol => "bad protocol",
|
|
UselessPeer => "useless peer",
|
|
TooManyPeers => "too many peers",
|
|
DuplicatePeer => "duplicate peer",
|
|
IncompatibleProtocol => "incompatible protocol",
|
|
NullIdentity => "null identity",
|
|
ClientQuit => "client quit",
|
|
UnexpectedIdentity => "unexpected identity",
|
|
LocalIdentity => "local identity",
|
|
PingTimeout => "ping timeout",
|
|
Unknown => "unknown",
|
|
};
|
|
|
|
f.write_str(msg)
|
|
}
|
|
}
|
|
|
|
error_chain! {
|
|
foreign_links {
|
|
SocketIo(IoError) #[doc = "Socket IO error."];
|
|
Decompression(snappy::InvalidInput) #[doc = "Decompression error."];
|
|
}
|
|
|
|
errors {
|
|
#[doc = "Error concerning the network address parsing subsystem."]
|
|
AddressParse {
|
|
description("Failed to parse network address"),
|
|
display("Failed to parse network address"),
|
|
}
|
|
|
|
#[doc = "Error concerning the network address resolution subsystem."]
|
|
AddressResolve(err: Option<io::Error>) {
|
|
description("Failed to resolve network address"),
|
|
display("Failed to resolve network address {}", err.as_ref().map_or("".to_string(), |e| e.to_string())),
|
|
}
|
|
|
|
#[doc = "Authentication failure"]
|
|
Auth {
|
|
description("Authentication failure"),
|
|
display("Authentication failure"),
|
|
}
|
|
|
|
#[doc = "Unrecognised protocol"]
|
|
BadProtocol {
|
|
description("Bad protocol"),
|
|
display("Bad protocol"),
|
|
}
|
|
|
|
#[doc = "Expired message"]
|
|
Expired {
|
|
description("Expired message"),
|
|
display("Expired message"),
|
|
}
|
|
|
|
#[doc = "Peer not found"]
|
|
PeerNotFound {
|
|
description("Peer not found"),
|
|
display("Peer not found"),
|
|
}
|
|
|
|
#[doc = "Peer is disconnected"]
|
|
Disconnect(reason: DisconnectReason) {
|
|
description("Peer disconnected"),
|
|
display("Peer disconnected: {}", reason),
|
|
}
|
|
|
|
#[doc = "Invalid node id"]
|
|
InvalidNodeId {
|
|
description("Invalid node id"),
|
|
display("Invalid node id"),
|
|
}
|
|
|
|
#[doc = "Packet size is over the protocol limit"]
|
|
OversizedPacket {
|
|
description("Packet is too large"),
|
|
display("Packet is too large"),
|
|
}
|
|
|
|
#[doc = "Reached system resource limits for this process"]
|
|
ProcessTooManyFiles {
|
|
description("Too many open files in process."),
|
|
display("Too many open files in this process. Check your resource limits and restart parity"),
|
|
}
|
|
|
|
#[doc = "Reached system wide resource limits"]
|
|
SystemTooManyFiles {
|
|
description("Too many open files on system."),
|
|
display("Too many open files on system. Consider closing some processes/release some file handlers or increas the system-wide resource limits and restart parity."),
|
|
}
|
|
|
|
#[doc = "An unknown IO error occurred."]
|
|
Io(err: io::Error) {
|
|
description("IO Error"),
|
|
display("Unexpected IO error: {}", err),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<io::Error> for Error {
|
|
fn from(err: io::Error) -> Self {
|
|
match err.raw_os_error() {
|
|
Some(ENFILE) => ErrorKind::ProcessTooManyFiles.into(),
|
|
Some(EMFILE) => ErrorKind::SystemTooManyFiles.into(),
|
|
_ => Error::from_kind(ErrorKind::Io(err))
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<rlp::DecoderError> for Error {
|
|
fn from(_err: rlp::DecoderError) -> Self {
|
|
ErrorKind::Auth.into()
|
|
}
|
|
}
|
|
|
|
impl From<ethkey::Error> for Error {
|
|
fn from(_err: ethkey::Error) -> Self {
|
|
ErrorKind::Auth.into()
|
|
}
|
|
}
|
|
|
|
impl From<crypto::Error> for Error {
|
|
fn from(_err: crypto::Error) -> Self {
|
|
ErrorKind::Auth.into()
|
|
}
|
|
}
|
|
|
|
impl From<net::AddrParseError> for Error {
|
|
fn from(_err: net::AddrParseError) -> Self { ErrorKind::AddressParse.into() }
|
|
}
|
|
|
|
#[test]
|
|
fn test_errors() {
|
|
assert_eq!(DisconnectReason::ClientQuit, DisconnectReason::from_u8(8));
|
|
let mut r = DisconnectReason::DisconnectRequested;
|
|
for i in 0 .. 20 {
|
|
r = DisconnectReason::from_u8(i);
|
|
}
|
|
assert_eq!(DisconnectReason::Unknown, r);
|
|
|
|
match *<Error as From<rlp::DecoderError>>::from(rlp::DecoderError::RlpIsTooBig).kind() {
|
|
ErrorKind::Auth => {},
|
|
_ => panic!("Unexpeceted error"),
|
|
}
|
|
|
|
match *<Error as From<crypto::Error>>::from(crypto::Error::InvalidMessage).kind() {
|
|
ErrorKind::Auth => {},
|
|
_ => panic!("Unexpeceted error"),
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn test_io_errors() {
|
|
use libc::{EMFILE, ENFILE};
|
|
|
|
assert_matches!(
|
|
<Error as From<io::Error>>::from(
|
|
io::Error::from_raw_os_error(ENFILE)
|
|
).kind(),
|
|
ErrorKind::ProcessTooManyFiles);
|
|
|
|
assert_matches!(
|
|
<Error as From<io::Error>>::from(
|
|
io::Error::from_raw_os_error(EMFILE)
|
|
).kind(),
|
|
ErrorKind::SystemTooManyFiles);
|
|
|
|
assert_matches!(
|
|
<Error as From<io::Error>>::from(
|
|
io::Error::from_raw_os_error(0)
|
|
).kind(),
|
|
ErrorKind::Io(_));
|
|
}
|