Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into refactor/hashdb-generic
Browse files Browse the repository at this point in the history
* master:
  Attempt to graceful shutdown in case of panics (#8999)
  simplify kvdb error types (#8924)
  Add option for user to set max size limit for RPC requests (#9010)
  bump ntp to 0.5.0 (#9009)
  Removed duplicate dependency (#9021)
  • Loading branch information
dvdplm committed Jul 2, 2018
2 parents 07dfdc7 + a1a002f commit afbf3a9
Show file tree
Hide file tree
Showing 34 changed files with 262 additions and 219 deletions.
11 changes: 4 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dapps/node-health/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
futures = "0.1"
futures-cpupool = "0.1"
log = "0.3"
ntp = "0.3.0"
ntp = "0.5.0"
parking_lot = "0.5"
serde = "1.0"
serde_derive = "1.0"
Expand Down
16 changes: 7 additions & 9 deletions ethcore/light/src/client/header_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use cht;
use ethcore::block_status::BlockStatus;
use ethcore::encoded;
use ethcore::engines::epoch::{Transition as EpochTransition, PendingTransition as PendingEpochTransition};
use ethcore::error::{Error, ErrorKind, BlockImportError, BlockImportErrorKind, BlockError};
use ethcore::error::{Error, BlockImportError, BlockImportErrorKind, BlockError};
use ethcore::header::Header;
use ethcore::ids::BlockId;
use ethcore::spec::{Spec, SpecHardcodedSync};
Expand Down Expand Up @@ -253,7 +253,7 @@ impl HeaderChain {
let best_block = {
let era = match candidates.get(&curr.best_num) {
Some(era) => era,
None => bail!(ErrorKind::Database("Database corrupt: highest block referenced but no data.".into())),
None => bail!("Database corrupt: highest block referenced but no data."),
};

let best = &era.candidates[0];
Expand Down Expand Up @@ -576,27 +576,25 @@ impl HeaderChain {
} else {
let msg = format!("header of block #{} not found in DB ; database in an \
inconsistent state", h_num);
bail!(ErrorKind::Database(msg.into()));
bail!(msg);
};

let decoded = header.decode().expect("decoding db value failed");

let entry: Entry = {
let bytes = self.db.get(self.col, era_key(h_num).as_bytes())?
.ok_or_else(|| {
let msg = format!("entry for era #{} not found in DB ; database \
in an inconsistent state", h_num);
ErrorKind::Database(msg.into())
format!("entry for era #{} not found in DB ; database \
in an inconsistent state", h_num)
})?;
::rlp::decode(&bytes).expect("decoding db value failed")
};

let total_difficulty = entry.candidates.iter()
.find(|c| c.hash == decoded.hash())
.ok_or_else(|| {
let msg = "no candidate matching block found in DB ; database in an \
inconsistent state";
ErrorKind::Database(msg.into())
"no candidate matching block found in DB ; database in an \
inconsistent state"
})?
.total_difficulty;

Expand Down
5 changes: 2 additions & 3 deletions ethcore/src/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! Blockchain database.
use std::collections::{HashMap, HashSet};
use std::mem;
use std::{mem, io};
use std::path::Path;
use std::sync::Arc;

Expand All @@ -34,7 +34,6 @@ use db::{self, Writable, Readable, CacheUpdatePolicy};
use encoded;
use engines::epoch::{Transition as EpochTransition, PendingTransition as PendingEpochTransition};
use engines::ForkChoice;
use error::Error;
use ethereum_types::{H256, Bloom, BloomRef, U256};
use header::*;
use heapsize::HeapSizeOf;
Expand Down Expand Up @@ -67,7 +66,7 @@ pub trait BlockChainDB: Send + Sync {
/// predefined config.
pub trait BlockChainDBHandler: Send + Sync {
/// Open the predefined key-value database.
fn open(&self, path: &Path) -> Result<Arc<BlockChainDB>, Error>;
fn open(&self, path: &Path) -> io::Result<Arc<BlockChainDB>>;
}

/// Interface for querying blocks by hash and by number.
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ impl Client {
state_db = spec.ensure_db_good(state_db, &factories)?;
let mut batch = DBTransaction::new();
state_db.journal_under(&mut batch, 0, &spec.genesis_header().hash())?;
db.key_value().write(batch).map_err(ClientError::Database)?;
db.key_value().write(batch)?;
}

let gb = spec.genesis_block();
Expand Down Expand Up @@ -821,7 +821,7 @@ impl Client {
}

// ensure buffered changes are flushed.
client.db.read().key_value().flush().map_err(ClientError::Database)?;
client.db.read().key_value().flush()?;
Ok(client)
}

Expand Down
4 changes: 0 additions & 4 deletions ethcore/src/client/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@

use std::fmt::{Display, Formatter, Error as FmtError};
use util_error::UtilError;
use kvdb;
use ethtrie::TrieError;

/// Client configuration errors.
#[derive(Debug)]
pub enum Error {
/// TrieDB-related error.
Trie(TrieError),
/// Database error
Database(kvdb::Error),
/// Util error
Util(UtilError),
}
Expand Down Expand Up @@ -53,7 +50,6 @@ impl Display for Error {
match *self {
Error::Trie(ref err) => write!(f, "{}", err),
Error::Util(ref err) => write!(f, "{}", err),
Error::Database(ref s) => write!(f, "Database error: {}", s),
}
}
}
5 changes: 1 addition & 4 deletions ethcore/src/client/evm_test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ pub enum EvmTestError {
Evm(vm::Error),
/// Initialization error.
ClientError(::error::Error),
/// Low-level database error.
Database(kvdb::Error),
/// Post-condition failure,
PostCondition(String),
}
Expand All @@ -56,7 +54,6 @@ impl fmt::Display for EvmTestError {
Trie(ref err) => write!(fmt, "Trie: {}", err),
Evm(ref err) => write!(fmt, "EVM: {}", err),
ClientError(ref err) => write!(fmt, "{}", err),
Database(ref err) => write!(fmt, "DB: {}", err),
PostCondition(ref err) => write!(fmt, "{}", err),
}
}
Expand Down Expand Up @@ -136,7 +133,7 @@ impl<'a> EvmTestClient<'a> {
{
let mut batch = kvdb::DBTransaction::new();
state_db.journal_under(&mut batch, 0, &genesis.hash())?;
db.write(batch).map_err(EvmTestError::Database)?;
db.write(batch)?;
}

state::State::from_existing(
Expand Down
14 changes: 6 additions & 8 deletions ethcore/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use std::{fmt, error};
use std::time::SystemTime;
use kvdb;
use ethereum_types::{H256, U256, Address, Bloom};
use util_error::{self, UtilError};
use snappy::InvalidInput;
Expand Down Expand Up @@ -237,11 +236,10 @@ error_chain! {
}

links {
Database(kvdb::Error, kvdb::ErrorKind) #[doc = "Database error."];
Util(UtilError, util_error::ErrorKind) #[doc = "Error concerning a utility"];
Import(ImportError, ImportErrorKind) #[doc = "Error concerning block import." ];
}

foreign_links {
Io(IoError) #[doc = "Io create error"];
StdIo(::std::io::Error) #[doc = "Error concerning the Rust standard library's IO subsystem."];
Expand Down Expand Up @@ -271,14 +269,14 @@ error_chain! {
AccountProvider(err: AccountsError) {
description("Accounts Provider error")
display("Accounts Provider error {}", err)
}
}

#[doc = "PoW hash is invalid or out of date."]
PowHashInvalid {
description("PoW hash is invalid or out of date.")
display("PoW hash is invalid or out of date.")
}

#[doc = "The value of the nonce or mishash is invalid."]
PowInvalid {
description("The value of the nonce or mishash is invalid.")
Expand Down Expand Up @@ -311,10 +309,10 @@ impl From<ClientError> for Error {
}
}

impl From<AccountsError> for Error {
fn from(err: AccountsError) -> Error {
impl From<AccountsError> for Error {
fn from(err: AccountsError) -> Error {
ErrorKind::AccountProvider(err).into()
}
}
}

impl From<::rlp::DecoderError> for Error {
Expand Down
7 changes: 3 additions & 4 deletions ethcore/src/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
//! Set of different helpers for client tests
use std::path::Path;
use std::fs;
use std::sync::Arc;
use std::{fs, io};
use account_provider::AccountProvider;
use ethereum_types::{H256, U256, Address};
use block::{OpenBlock, Drain};
use blockchain::{BlockChain, BlockChainDB, BlockChainDBHandler, Config as BlockChainConfig, ExtrasInsert};
use bytes::Bytes;
use client::{Client, ClientConfig, ChainInfo, ImportBlock, ChainNotify, ChainMessageType, PrepareOpenBlock};
use ethkey::KeyPair;
use error::Error;
use evm::Factory as EvmFactory;
use factory::Factories;
use hash::keccak;
Expand All @@ -37,7 +37,6 @@ use rlp::{self, RlpStream};
use spec::Spec;
use state_db::StateDB;
use state::*;
use std::sync::Arc;
use transaction::{Action, Transaction, SignedTransaction};
use views::BlockView;
use blooms_db;
Expand Down Expand Up @@ -327,7 +326,7 @@ pub fn restoration_db_handler(config: kvdb_rocksdb::DatabaseConfig) -> Box<Block
}

impl BlockChainDBHandler for RestorationDBHandler {
fn open(&self, db_path: &Path) -> Result<Arc<BlockChainDB>, Error> {
fn open(&self, db_path: &Path) -> io::Result<Arc<BlockChainDB>> {
let key_value = Arc::new(kvdb_rocksdb::Database::open(&self.config, &db_path.to_string_lossy())?);
let blooms_path = db_path.join("blooms");
let trace_blooms_path = db_path.join("trace_blooms");
Expand Down
2 changes: 1 addition & 1 deletion ethkey/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl DisplayMode {
}

fn main() {
panic_hook::set();
panic_hook::set_abort();
env_logger::init().expect("Logger initialized only once.");

match execute(env::args()) {
Expand Down
2 changes: 1 addition & 1 deletion ethstore/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl fmt::Display for Error {
}

fn main() {
panic_hook::set();
panic_hook::set_abort();

match execute(env::args()) {
Ok(result) => println!("{}", result),
Expand Down
2 changes: 1 addition & 1 deletion evmbin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ General options:
"#;

fn main() {
panic_hook::set();
panic_hook::set_abort();

let args: Args = Docopt::new(USAGE).and_then(|d| d.deserialize()).unwrap_or_else(|e| e.exit());

Expand Down
10 changes: 5 additions & 5 deletions local-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ const UPDATE_TIMEOUT: Duration = Duration::from_secs(15 * 60); // once every 15
/// Errors which can occur while using the local data store.
#[derive(Debug)]
pub enum Error {
/// Database errors: these manifest as `String`s.
Database(kvdb::Error),
/// Io and database errors: these manifest as `String`s.
Io(::std::io::Error),
/// JSON errors.
Json(::serde_json::Error),
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::Database(ref val) => write!(f, "{}", val),
Error::Io(ref val) => write!(f, "{}", val),
Error::Json(ref err) => write!(f, "{}", err),
}
}
Expand Down Expand Up @@ -160,7 +160,7 @@ pub struct LocalDataStore<T: NodeInfo> {
impl<T: NodeInfo> LocalDataStore<T> {
/// Attempt to read pending transactions out of the local store.
pub fn pending_transactions(&self) -> Result<Vec<PendingTransaction>, Error> {
if let Some(val) = self.db.get(self.col, LOCAL_TRANSACTIONS_KEY).map_err(Error::Database)? {
if let Some(val) = self.db.get(self.col, LOCAL_TRANSACTIONS_KEY).map_err(Error::Io)? {
let local_txs: Vec<_> = ::serde_json::from_slice::<Vec<TransactionEntry>>(&val)
.map_err(Error::Json)?
.into_iter()
Expand Down Expand Up @@ -200,7 +200,7 @@ impl<T: NodeInfo> LocalDataStore<T> {
let json_str = format!("{}", local_json);

batch.put_vec(self.col, LOCAL_TRANSACTIONS_KEY, json_str.into_bytes());
self.db.write(batch).map_err(Error::Database)
self.db.write(batch).map_err(Error::Io)
}
}

Expand Down
7 changes: 7 additions & 0 deletions parity/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@ usage! {
"--jsonrpc-server-threads=[NUM]",
"Enables multiple threads handling incoming connections for HTTP JSON-RPC server.",

ARG arg_jsonrpc_max_payload: (Option<usize>) = None, or |c: &Config| c.rpc.as_ref()?.max_payload,
"--jsonrpc-max-payload=[MB]",
"Specify maximum size for RPC requests in megabytes.",

["API and Console Options – WebSockets"]
FLAG flag_no_ws: (bool) = false, or |c: &Config| c.websockets.as_ref()?.disable.clone(),
"--no-ws",
Expand Down Expand Up @@ -1165,6 +1169,7 @@ struct Rpc {
hosts: Option<Vec<String>>,
server_threads: Option<usize>,
processing_threads: Option<usize>,
max_payload: Option<usize>,
}

#[derive(Default, Debug, PartialEq, Deserialize)]
Expand Down Expand Up @@ -1613,6 +1618,7 @@ mod tests {
arg_jsonrpc_hosts: "none".into(),
arg_jsonrpc_server_threads: None,
arg_jsonrpc_threads: 4,
arg_jsonrpc_max_payload: None,

// WS
flag_no_ws: false,
Expand Down Expand Up @@ -1880,6 +1886,7 @@ mod tests {
hosts: None,
server_threads: None,
processing_threads: None,
max_payload: None,
}),
ipc: Some(Ipc {
disable: None,
Expand Down
Loading

0 comments on commit afbf3a9

Please sign in to comment.