simplify kvdb error types (#8924)

This commit is contained in:
Marek Kotewicz
2018-07-02 05:04:48 -04:00
committed by André Silva
parent 67721f3413
commit 5ef41ed53e
21 changed files with 125 additions and 189 deletions

View File

@@ -17,8 +17,9 @@
//! Blockchain database.
use std::collections::{HashMap, HashSet};
use std::path::Path;
use std::sync::Arc;
use std::mem;
use std::{mem, io};
use itertools::Itertools;
use blooms_db;
use heapsize::HeapSizeOf;
@@ -47,8 +48,6 @@ use engines::epoch::{Transition as EpochTransition, PendingTransition as Pending
use rayon::prelude::*;
use ansi_term::Colour;
use kvdb::{DBTransaction, KeyValueDB};
use error::Error;
use std::path::Path;
/// Database backing `BlockChain`.
pub trait BlockChainDB: Send + Sync {
@@ -66,7 +65,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.

View File

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

View File

@@ -16,7 +16,6 @@
use std::fmt::{Display, Formatter, Error as FmtError};
use util_error::UtilError;
use kvdb;
use trie::TrieError;
/// Client configuration errors.
@@ -24,8 +23,6 @@ use trie::TrieError;
pub enum Error {
/// TrieDB-related error.
Trie(TrieError),
/// Database error
Database(kvdb::Error),
/// Util error
Util(UtilError),
}
@@ -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),
}
}
}

View File

@@ -35,8 +35,6 @@ pub enum EvmTestError {
Evm(vm::Error),
/// Initialization error.
ClientError(::error::Error),
/// Low-level database error.
Database(kvdb::Error),
/// Post-condition failure,
PostCondition(String),
}
@@ -55,7 +53,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),
}
}
@@ -135,7 +132,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(

View File

@@ -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;
@@ -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."];
@@ -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.")
@@ -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 {

View File

@@ -17,7 +17,8 @@
//! 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};
@@ -25,7 +26,6 @@ use blockchain::{BlockChain, BlockChainDB, BlockChainDBHandler, Config as BlockC
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;
@@ -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;
@@ -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");