Move ethcore::Error to error_chain (#8386)

* WIP

* Convert Ethcore error to use error_chain

* Use error_chain for ImportError and BlockImportError

* Fix error pattern matches for error_chain in miner

* Implement explicit From for AccountsError

* Fix pattern matches for ErrorKinds

* Handle ethcore error_chain in light client

* Explicitly define Result type to avoid shadowing

* Fix remaining Error pattern matches

* Fix tab space formatting

* Helps if the tests compile

* Fix error chain matching after merge
This commit is contained in:
Andrew Jones
2018-04-19 10:52:54 +01:00
committed by Afri Schoedon
parent 2257bc8e2f
commit 14361cc7b1
27 changed files with 249 additions and 274 deletions

View File

@@ -25,9 +25,9 @@ use ethereum_types::H256;
use rlp::Rlp;
use ethcore::views::BlockView;
use ethcore::header::{BlockNumber, Header as BlockHeader};
use ethcore::client::{BlockStatus, BlockId, BlockImportError};
use ethcore::client::{BlockStatus, BlockId, BlockImportError, BlockImportErrorKind};
use ethcore::block::Block;
use ethcore::error::{ImportError, BlockError};
use ethcore::error::{ImportErrorKind, BlockError};
use sync_io::SyncIo;
use blocks::BlockCollection;
@@ -502,11 +502,11 @@ impl BlockDownloader {
};
match result {
Err(BlockImportError::Import(ImportError::AlreadyInChain)) => {
Err(BlockImportError(BlockImportErrorKind::Import(ImportErrorKind::AlreadyInChain), _)) => {
trace!(target: "sync", "Block already in chain {:?}", h);
self.block_imported(&h, number, &parent);
},
Err(BlockImportError::Import(ImportError::AlreadyQueued)) => {
Err(BlockImportError(BlockImportErrorKind::Import(ImportErrorKind::AlreadyQueued), _)) => {
trace!(target: "sync", "Block already queued {:?}", h);
self.block_imported(&h, number, &parent);
},
@@ -515,14 +515,14 @@ impl BlockDownloader {
imported.insert(h.clone());
self.block_imported(&h, number, &parent);
},
Err(BlockImportError::Block(BlockError::UnknownParent(_))) if allow_out_of_order => {
Err(BlockImportError(BlockImportErrorKind::Block(BlockError::UnknownParent(_)), _)) if allow_out_of_order => {
break;
},
Err(BlockImportError::Block(BlockError::UnknownParent(_))) => {
Err(BlockImportError(BlockImportErrorKind::Block(BlockError::UnknownParent(_)), _)) => {
trace!(target: "sync", "Unknown new block parent, restarting sync");
break;
},
Err(BlockImportError::Block(BlockError::TemporarilyInvalid(_))) => {
Err(BlockImportError(BlockImportErrorKind::Block(BlockError::TemporarilyInvalid(_)), _)) => {
debug!(target: "sync", "Block temporarily invalid, restarting sync");
break;
},

View File

@@ -101,7 +101,7 @@ use bytes::Bytes;
use rlp::{Rlp, RlpStream, DecoderError, Encodable};
use network::{self, PeerId, PacketId};
use ethcore::header::{BlockNumber, Header as BlockHeader};
use ethcore::client::{BlockChainClient, BlockStatus, BlockId, BlockChainInfo, BlockImportError, BlockQueueInfo};
use ethcore::client::{BlockChainClient, BlockStatus, BlockId, BlockChainInfo, BlockImportError, BlockImportErrorKind, BlockQueueInfo};
use ethcore::error::*;
use ethcore::snapshot::{ManifestData, RestorationStatus};
use transaction::SignedTransaction;
@@ -943,10 +943,10 @@ impl ChainSync {
return Ok(());
}
match io.chain().import_block(block_rlp.as_raw().to_vec()) {
Err(BlockImportError::Import(ImportError::AlreadyInChain)) => {
Err(BlockImportError(BlockImportErrorKind::Import(ImportErrorKind::AlreadyInChain), _)) => {
trace!(target: "sync", "New block already in chain {:?}", h);
},
Err(BlockImportError::Import(ImportError::AlreadyQueued)) => {
Err(BlockImportError(BlockImportErrorKind::Import(ImportErrorKind::AlreadyQueued), _)) => {
trace!(target: "sync", "New block already queued {:?}", h);
},
Ok(_) => {
@@ -955,7 +955,7 @@ impl ChainSync {
self.new_blocks.mark_as_known(&header.hash(), header.number());
trace!(target: "sync", "New block queued {:?} ({})", h, header.number());
},
Err(BlockImportError::Block(BlockError::UnknownParent(p))) => {
Err(BlockImportError(BlockImportErrorKind::Block(BlockError::UnknownParent(p)), _)) => {
unknown = true;
trace!(target: "sync", "New block with unknown parent ({:?}) {:?}", p, h);
},

View File

@@ -427,7 +427,7 @@ impl<L: AsLightClient> LightSync<L> {
// handles request dispatch, block import, state machine transitions, and timeouts.
fn maintain_sync(&self, ctx: &BasicContext) {
use ethcore::error::{BlockImportError, ImportError};
use ethcore::error::{BlockImportError, BlockImportErrorKind, ImportErrorKind};
const DRAIN_AMOUNT: usize = 128;
@@ -457,10 +457,10 @@ impl<L: AsLightClient> LightSync<L> {
for header in sink.drain(..) {
match client.queue_header(header) {
Ok(_) => {}
Err(BlockImportError::Import(ImportError::AlreadyInChain)) => {
Err(BlockImportError(BlockImportErrorKind::Import(ImportErrorKind::AlreadyInChain), _)) => {
trace!(target: "sync", "Block already in chain. Continuing.");
},
Err(BlockImportError::Import(ImportError::AlreadyQueued)) => {
Err(BlockImportError(BlockImportErrorKind::Import(ImportErrorKind::AlreadyQueued), _)) => {
trace!(target: "sync", "Block already queued. Continuing.");
},
Err(e) => {