simplify ethcore errors by removing BlockImportError (#9593)

This commit is contained in:
Marek Kotewicz 2018-09-24 11:28:54 +01:00 committed by GitHub
parent 2f159d4f45
commit b57607e7d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 56 additions and 112 deletions

View File

@ -33,7 +33,7 @@ use cht;
use ethcore::block_status::BlockStatus; use ethcore::block_status::BlockStatus;
use ethcore::encoded; use ethcore::encoded;
use ethcore::engines::epoch::{Transition as EpochTransition, PendingTransition as PendingEpochTransition}; use ethcore::engines::epoch::{Transition as EpochTransition, PendingTransition as PendingEpochTransition};
use ethcore::error::{Error, BlockImportError, BlockImportErrorKind, BlockError}; use ethcore::error::{Error, EthcoreResult, ErrorKind as EthcoreErrorKind, BlockError};
use ethcore::header::Header; use ethcore::header::Header;
use ethcore::ids::BlockId; use ethcore::ids::BlockId;
use ethcore::spec::{Spec, SpecHardcodedSync}; use ethcore::spec::{Spec, SpecHardcodedSync};
@ -351,7 +351,7 @@ impl HeaderChain {
transaction: &mut DBTransaction, transaction: &mut DBTransaction,
header: &Header, header: &Header,
transition_proof: Option<Vec<u8>>, transition_proof: Option<Vec<u8>>,
) -> Result<PendingChanges, BlockImportError> { ) -> EthcoreResult<PendingChanges> {
self.insert_inner(transaction, header, None, transition_proof) self.insert_inner(transaction, header, None, transition_proof)
} }
@ -364,7 +364,7 @@ impl HeaderChain {
header: &Header, header: &Header,
total_difficulty: U256, total_difficulty: U256,
transition_proof: Option<Vec<u8>>, transition_proof: Option<Vec<u8>>,
) -> Result<PendingChanges, BlockImportError> { ) -> EthcoreResult<PendingChanges> {
self.insert_inner(transaction, header, Some(total_difficulty), transition_proof) self.insert_inner(transaction, header, Some(total_difficulty), transition_proof)
} }
@ -374,7 +374,7 @@ impl HeaderChain {
header: &Header, header: &Header,
total_difficulty: Option<U256>, total_difficulty: Option<U256>,
transition_proof: Option<Vec<u8>>, transition_proof: Option<Vec<u8>>,
) -> Result<PendingChanges, BlockImportError> { ) -> EthcoreResult<PendingChanges> {
let hash = header.hash(); let hash = header.hash();
let number = header.number(); let number = header.number();
let parent_hash = *header.parent_hash(); let parent_hash = *header.parent_hash();
@ -403,7 +403,7 @@ impl HeaderChain {
.and_then(|entry| entry.candidates.iter().find(|c| c.hash == parent_hash)) .and_then(|entry| entry.candidates.iter().find(|c| c.hash == parent_hash))
.map(|c| c.total_difficulty) .map(|c| c.total_difficulty)
.ok_or_else(|| BlockError::UnknownParent(parent_hash)) .ok_or_else(|| BlockError::UnknownParent(parent_hash))
.map_err(BlockImportErrorKind::Block)? .map_err(EthcoreErrorKind::Block)?
}; };
parent_td + *header.difficulty() parent_td + *header.difficulty()

View File

@ -22,7 +22,7 @@ use ethcore::block_status::BlockStatus;
use ethcore::client::{ClientReport, EnvInfo, ClientIoMessage}; use ethcore::client::{ClientReport, EnvInfo, ClientIoMessage};
use ethcore::engines::{epoch, EthEngine, EpochChange, EpochTransition, Proof}; use ethcore::engines::{epoch, EthEngine, EpochChange, EpochTransition, Proof};
use ethcore::machine::EthereumMachine; use ethcore::machine::EthereumMachine;
use ethcore::error::{Error, BlockImportError}; use ethcore::error::{Error, EthcoreResult};
use ethcore::ids::BlockId; use ethcore::ids::BlockId;
use ethcore::header::{BlockNumber, Header}; use ethcore::header::{BlockNumber, Header};
use ethcore::verification::queue::{self, HeaderQueue}; use ethcore::verification::queue::{self, HeaderQueue};
@ -85,7 +85,7 @@ pub trait LightChainClient: Send + Sync {
/// Queue header to be verified. Required that all headers queued have their /// Queue header to be verified. Required that all headers queued have their
/// parent queued prior. /// parent queued prior.
fn queue_header(&self, header: Header) -> Result<H256, BlockImportError>; fn queue_header(&self, header: Header) -> EthcoreResult<H256>;
/// Attempt to get a block hash by block id. /// Attempt to get a block hash by block id.
fn block_hash(&self, id: BlockId) -> Option<H256>; fn block_hash(&self, id: BlockId) -> Option<H256>;
@ -206,7 +206,7 @@ impl<T: ChainDataFetcher> Client<T> {
} }
/// Import a header to the queue for additional verification. /// Import a header to the queue for additional verification.
pub fn import_header(&self, header: Header) -> Result<H256, BlockImportError> { pub fn import_header(&self, header: Header) -> EthcoreResult<H256> {
self.queue.import(header).map_err(Into::into) self.queue.import(header).map_err(Into::into)
} }
@ -526,7 +526,7 @@ impl<T: ChainDataFetcher> LightChainClient for Client<T> {
fn chain_info(&self) -> BlockChainInfo { Client::chain_info(self) } fn chain_info(&self) -> BlockChainInfo { Client::chain_info(self) }
fn queue_header(&self, header: Header) -> Result<H256, BlockImportError> { fn queue_header(&self, header: Header) -> EthcoreResult<H256> {
self.import_header(header) self.import_header(header)
} }

View File

@ -43,7 +43,7 @@ use client::{
}; };
use client::{ use client::{
BlockId, TransactionId, UncleId, TraceId, ClientConfig, BlockChainClient, BlockId, TransactionId, UncleId, TraceId, ClientConfig, BlockChainClient,
TraceFilter, CallAnalytics, BlockImportError, Mode, TraceFilter, CallAnalytics, Mode,
ChainNotify, ChainRoute, PruningInfo, ProvingBlockChainClient, EngineInfo, ChainMessageType, ChainNotify, ChainRoute, PruningInfo, ProvingBlockChainClient, EngineInfo, ChainMessageType,
IoClient, BadBlocks, IoClient, BadBlocks,
}; };
@ -51,8 +51,8 @@ use client::bad_blocks;
use encoded; use encoded;
use engines::{EthEngine, EpochTransition, ForkChoice}; use engines::{EthEngine, EpochTransition, ForkChoice};
use error::{ use error::{
ImportErrorKind, BlockImportErrorKind, ExecutionError, CallError, BlockError, ImportResult, ImportErrorKind, ExecutionError, CallError, BlockError,
QueueError, QueueErrorKind, Error as EthcoreError QueueError, QueueErrorKind, Error as EthcoreError, EthcoreResult, ErrorKind as EthcoreErrorKind
}; };
use vm::{EnvInfo, LastHashes}; use vm::{EnvInfo, LastHashes};
use evm::Schedule; use evm::Schedule;
@ -1392,23 +1392,23 @@ impl CallContract for Client {
} }
impl ImportBlock for Client { impl ImportBlock for Client {
fn import_block(&self, unverified: Unverified) -> Result<H256, BlockImportError> { fn import_block(&self, unverified: Unverified) -> EthcoreResult<H256> {
if self.chain.read().is_known(&unverified.hash()) { if self.chain.read().is_known(&unverified.hash()) {
bail!(BlockImportErrorKind::Import(ImportErrorKind::AlreadyInChain)); bail!(EthcoreErrorKind::Import(ImportErrorKind::AlreadyInChain));
} }
let status = self.block_status(BlockId::Hash(unverified.parent_hash())); let status = self.block_status(BlockId::Hash(unverified.parent_hash()));
if status == BlockStatus::Unknown { if status == BlockStatus::Unknown {
bail!(BlockImportErrorKind::Block(BlockError::UnknownParent(unverified.parent_hash()))); bail!(EthcoreErrorKind::Block(BlockError::UnknownParent(unverified.parent_hash())));
} }
let raw = unverified.bytes.clone(); let raw = unverified.bytes.clone();
match self.importer.block_queue.import(unverified).map_err(Into::into) { match self.importer.block_queue.import(unverified) {
Ok(res) => Ok(res), Ok(res) => Ok(res),
// we only care about block errors (not import errors) // we only care about block errors (not import errors)
Err(BlockImportError(BlockImportErrorKind::Block(err), _))=> { Err(EthcoreError(EthcoreErrorKind::Block(err), _))=> {
self.importer.bad_blocks.report(raw, format!("{:?}", err)); self.importer.bad_blocks.report(raw, format!("{:?}", err));
bail!(BlockImportErrorKind::Block(err)) bail!(EthcoreErrorKind::Block(err))
}, },
Err(e) => Err(e), Err(e) => Err(e),
} }
@ -2085,14 +2085,14 @@ impl IoClient for Client {
}); });
} }
fn queue_ancient_block(&self, unverified: Unverified, receipts_bytes: Bytes) -> Result<H256, BlockImportError> { fn queue_ancient_block(&self, unverified: Unverified, receipts_bytes: Bytes) -> EthcoreResult<H256> {
trace_time!("queue_ancient_block"); trace_time!("queue_ancient_block");
let hash = unverified.hash(); let hash = unverified.hash();
{ {
// check block order // check block order
if self.chain.read().is_known(&hash) { if self.chain.read().is_known(&hash) {
bail!(BlockImportErrorKind::Import(ImportErrorKind::AlreadyInChain)); bail!(EthcoreErrorKind::Import(ImportErrorKind::AlreadyInChain));
} }
let parent_hash = unverified.parent_hash(); let parent_hash = unverified.parent_hash();
// NOTE To prevent race condition with import, make sure to check queued blocks first // NOTE To prevent race condition with import, make sure to check queued blocks first
@ -2101,7 +2101,7 @@ impl IoClient for Client {
if !is_parent_pending { if !is_parent_pending {
let status = self.block_status(BlockId::Hash(parent_hash)); let status = self.block_status(BlockId::Hash(parent_hash));
if status == BlockStatus::Unknown { if status == BlockStatus::Unknown {
bail!(BlockImportErrorKind::Block(BlockError::UnknownParent(parent_hash))); bail!(EthcoreErrorKind::Block(BlockError::UnknownParent(parent_hash)));
} }
} }
} }
@ -2237,7 +2237,7 @@ impl ScheduleInfo for Client {
} }
impl ImportSealedBlock for Client { impl ImportSealedBlock for Client {
fn import_sealed_block(&self, block: SealedBlock) -> ImportResult { fn import_sealed_block(&self, block: SealedBlock) -> EthcoreResult<H256> {
let h = block.header().hash(); let h = block.header().hash();
let start = Instant::now(); let start = Instant::now();
let route = { let route = {

View File

@ -50,7 +50,7 @@ pub use types::call_analytics::CallAnalytics;
pub use executive::{Executed, Executive, TransactOptions}; pub use executive::{Executed, Executive, TransactOptions};
pub use vm::{LastHashes, EnvInfo}; pub use vm::{LastHashes, EnvInfo};
pub use error::{BlockImportError, BlockImportErrorKind, TransactionImportError}; pub use error::TransactionImportError;
pub use verification::VerifierType; pub use verification::VerifierType;
mod traits; mod traits;

View File

@ -37,7 +37,7 @@ use blockchain::{TreeRoute, BlockReceipts};
use client::{ use client::{
Nonce, Balance, ChainInfo, BlockInfo, ReopenBlock, CallContract, TransactionInfo, RegistryInfo, Nonce, Balance, ChainInfo, BlockInfo, ReopenBlock, CallContract, TransactionInfo, RegistryInfo,
PrepareOpenBlock, BlockChainClient, BlockChainInfo, BlockStatus, BlockId, Mode, PrepareOpenBlock, BlockChainClient, BlockChainInfo, BlockStatus, BlockId, Mode,
TransactionId, UncleId, TraceId, TraceFilter, LastHashes, CallAnalytics, BlockImportError, TransactionId, UncleId, TraceId, TraceFilter, LastHashes, CallAnalytics,
ProvingBlockChainClient, ScheduleInfo, ImportSealedBlock, BroadcastProposalBlock, ImportBlock, StateOrBlock, ProvingBlockChainClient, ScheduleInfo, ImportSealedBlock, BroadcastProposalBlock, ImportBlock, StateOrBlock,
Call, StateClient, EngineInfo, AccountData, BlockChain, BlockProducer, SealedBlockImporter, IoClient, Call, StateClient, EngineInfo, AccountData, BlockChain, BlockProducer, SealedBlockImporter, IoClient,
BadBlocks, BadBlocks,
@ -47,7 +47,7 @@ use header::{Header as BlockHeader, BlockNumber};
use filter::Filter; use filter::Filter;
use log_entry::LocalizedLogEntry; use log_entry::LocalizedLogEntry;
use receipt::{Receipt, LocalizedReceipt, TransactionOutcome}; use receipt::{Receipt, LocalizedReceipt, TransactionOutcome};
use error::{Error, ImportResult}; use error::{Error, EthcoreResult};
use vm::Schedule; use vm::Schedule;
use miner::{self, Miner, MinerService}; use miner::{self, Miner, MinerService};
use spec::Spec; use spec::Spec;
@ -416,7 +416,7 @@ impl ScheduleInfo for TestBlockChainClient {
} }
impl ImportSealedBlock for TestBlockChainClient { impl ImportSealedBlock for TestBlockChainClient {
fn import_sealed_block(&self, _block: SealedBlock) -> ImportResult { fn import_sealed_block(&self, _block: SealedBlock) -> EthcoreResult<H256> {
Ok(H256::default()) Ok(H256::default())
} }
} }
@ -523,7 +523,7 @@ impl RegistryInfo for TestBlockChainClient {
} }
impl ImportBlock for TestBlockChainClient { impl ImportBlock for TestBlockChainClient {
fn import_block(&self, unverified: Unverified) -> Result<H256, BlockImportError> { fn import_block(&self, unverified: Unverified) -> EthcoreResult<H256> {
let header = unverified.header; let header = unverified.header;
let h = header.hash(); let h = header.hash();
let number: usize = header.number() as usize; let number: usize = header.number() as usize;
@ -883,7 +883,7 @@ impl IoClient for TestBlockChainClient {
self.miner.import_external_transactions(self, txs); self.miner.import_external_transactions(self, txs);
} }
fn queue_ancient_block(&self, unverified: Unverified, _r: Bytes) -> Result<H256, BlockImportError> { fn queue_ancient_block(&self, unverified: Unverified, _r: Bytes) -> EthcoreResult<H256> {
self.import_block(unverified) self.import_block(unverified)
} }

View File

@ -24,7 +24,7 @@ use blockchain::TreeRoute;
use client::Mode; use client::Mode;
use encoded; use encoded;
use vm::LastHashes; use vm::LastHashes;
use error::{Error, ImportResult, CallError, BlockImportError}; use error::{Error, CallError, EthcoreResult};
use evm::Schedule; use evm::Schedule;
use executive::Executed; use executive::Executed;
use filter::Filter; use filter::Filter;
@ -168,7 +168,7 @@ pub trait RegistryInfo {
/// Provides methods to import block into blockchain /// Provides methods to import block into blockchain
pub trait ImportBlock { pub trait ImportBlock {
/// Import a block into the blockchain. /// Import a block into the blockchain.
fn import_block(&self, block: Unverified) -> Result<H256, BlockImportError>; fn import_block(&self, block: Unverified) -> EthcoreResult<H256>;
} }
/// Provides `call_contract` method /// Provides `call_contract` method
@ -205,7 +205,7 @@ pub trait IoClient: Sync + Send {
fn queue_transactions(&self, transactions: Vec<Bytes>, peer_id: usize); fn queue_transactions(&self, transactions: Vec<Bytes>, peer_id: usize);
/// Queue block import with transaction receipts. Does no sealing and transaction validation. /// Queue block import with transaction receipts. Does no sealing and transaction validation.
fn queue_ancient_block(&self, block_bytes: Unverified, receipts_bytes: Bytes) -> Result<H256, BlockImportError>; fn queue_ancient_block(&self, block_bytes: Unverified, receipts_bytes: Bytes) -> EthcoreResult<H256>;
/// Queue conensus engine message. /// Queue conensus engine message.
fn queue_consensus_message(&self, message: Bytes); fn queue_consensus_message(&self, message: Bytes);
@ -414,7 +414,7 @@ pub trait ScheduleInfo {
///Provides `import_sealed_block` method ///Provides `import_sealed_block` method
pub trait ImportSealedBlock { pub trait ImportSealedBlock {
/// Import sealed block. Skips all verifications. /// Import sealed block. Skips all verifications.
fn import_sealed_block(&self, block: SealedBlock) -> ImportResult; fn import_sealed_block(&self, block: SealedBlock) -> EthcoreResult<H256>;
} }
/// Provides `broadcast_proposal_block` method /// Provides `broadcast_proposal_block` method

View File

@ -29,6 +29,7 @@ use engines::EngineError;
use ethkey::Error as EthkeyError; use ethkey::Error as EthkeyError;
use account_provider::SignError as AccountsError; use account_provider::SignError as AccountsError;
use transaction::Error as TransactionError; use transaction::Error as TransactionError;
use rlp;
pub use executed::{ExecutionError, CallError}; pub use executed::{ExecutionError, CallError};
@ -194,40 +195,6 @@ error_chain! {
} }
} }
error_chain! {
types {
BlockImportError, BlockImportErrorKind, BlockImportErrorResultExt;
}
links {
Import(ImportError, ImportErrorKind) #[doc = "Import error"];
Queue(QueueError, QueueErrorKind) #[doc = "Io channel queue error"];
}
foreign_links {
Block(BlockError) #[doc = "Block error"];
Decoder(::rlp::DecoderError) #[doc = "Rlp decoding error"];
}
errors {
#[doc = "Other error"]
Other(err: String) {
description("Other error")
display("Other error {}", err)
}
}
}
impl From<Error> for BlockImportError {
fn from(e: Error) -> Self {
match e {
Error(ErrorKind::Block(block_error), _) => BlockImportErrorKind::Block(block_error).into(),
Error(ErrorKind::Import(import_error), _) => BlockImportErrorKind::Import(import_error.into()).into(),
_ => BlockImportErrorKind::Other(format!("other block import error: {:?}", e)).into(),
}
}
}
/// Api-level error for transaction import /// Api-level error for transaction import
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum TransactionImportError { pub enum TransactionImportError {
@ -253,6 +220,7 @@ error_chain! {
links { links {
Import(ImportError, ImportErrorKind) #[doc = "Error concerning block import." ]; Import(ImportError, ImportErrorKind) #[doc = "Error concerning block import." ];
Queue(QueueError, QueueErrorKind) #[doc = "Io channel queue error"];
} }
foreign_links { foreign_links {
@ -265,6 +233,7 @@ error_chain! {
Snappy(InvalidInput) #[doc = "Snappy error."]; Snappy(InvalidInput) #[doc = "Snappy error."];
Engine(EngineError) #[doc = "Consensus vote error."]; Engine(EngineError) #[doc = "Consensus vote error."];
Ethkey(EthkeyError) #[doc = "Ethkey error."]; Ethkey(EthkeyError) #[doc = "Ethkey error."];
Decoder(rlp::DecoderError) #[doc = "RLP decoding errors"];
} }
errors { errors {
@ -297,40 +266,15 @@ error_chain! {
description("Unknown engine name") description("Unknown engine name")
display("Unknown engine name ({})", name) display("Unknown engine name ({})", name)
} }
#[doc = "RLP decoding errors"]
Decoder(err: ::rlp::DecoderError) {
description("decoding value failed")
display("decoding value failed with error: {}", err)
}
} }
} }
/// Result of import block operation.
pub type ImportResult = EthcoreResult<H256>;
impl From<AccountsError> for Error { impl From<AccountsError> for Error {
fn from(err: AccountsError) -> Error { fn from(err: AccountsError) -> Error {
ErrorKind::AccountProvider(err).into() ErrorKind::AccountProvider(err).into()
} }
} }
impl From<::rlp::DecoderError> for Error {
fn from(err: ::rlp::DecoderError) -> Error {
ErrorKind::Decoder(err).into()
}
}
impl From<BlockImportError> for Error {
fn from(err: BlockImportError) -> Error {
match err {
BlockImportError(BlockImportErrorKind::Block(e), _) => ErrorKind::Block(e).into(),
BlockImportError(BlockImportErrorKind::Import(e), _) => ErrorKind::Import(e).into(),
_ => ErrorKind::Msg(format!("other block import error: {:?}", err)).into(),
}
}
}
impl From<SnapshotError> for Error { impl From<SnapshotError> for Error {
fn from(err: SnapshotError) -> Error { fn from(err: SnapshotError) -> Error {
match err { match err {

View File

@ -464,7 +464,7 @@ impl<K: Kind> VerificationQueue<K> {
} }
/// Add a block to the queue. /// Add a block to the queue.
pub fn import(&self, input: K::Input) -> ImportResult { pub fn import(&self, input: K::Input) -> EthcoreResult<H256> {
let h = input.hash(); let h = input.hash();
{ {
if self.processing.read().contains_key(&h) { if self.processing.read().contains_key(&h) {

View File

@ -24,8 +24,8 @@ use heapsize::HeapSizeOf;
use ethereum_types::H256; use ethereum_types::H256;
use rlp::{self, Rlp}; use rlp::{self, Rlp};
use ethcore::header::BlockNumber; use ethcore::header::BlockNumber;
use ethcore::client::{BlockStatus, BlockId, BlockImportError, BlockImportErrorKind}; use ethcore::client::{BlockStatus, BlockId};
use ethcore::error::{ImportErrorKind, QueueErrorKind, BlockError}; use ethcore::error::{ImportErrorKind, QueueErrorKind, BlockError, Error as EthcoreError, ErrorKind as EthcoreErrorKind};
use sync_io::SyncIo; use sync_io::SyncIo;
use blocks::{BlockCollection, SyncBody, SyncHeader}; use blocks::{BlockCollection, SyncBody, SyncHeader};
@ -489,11 +489,11 @@ impl BlockDownloader {
}; };
match result { match result {
Err(BlockImportError(BlockImportErrorKind::Import(ImportErrorKind::AlreadyInChain), _)) => { Err(EthcoreError(EthcoreErrorKind::Import(ImportErrorKind::AlreadyInChain), _)) => {
trace!(target: "sync", "Block already in chain {:?}", h); trace!(target: "sync", "Block already in chain {:?}", h);
self.block_imported(&h, number, &parent); self.block_imported(&h, number, &parent);
}, },
Err(BlockImportError(BlockImportErrorKind::Import(ImportErrorKind::AlreadyQueued), _)) => { Err(EthcoreError(EthcoreErrorKind::Import(ImportErrorKind::AlreadyQueued), _)) => {
trace!(target: "sync", "Block already queued {:?}", h); trace!(target: "sync", "Block already queued {:?}", h);
self.block_imported(&h, number, &parent); self.block_imported(&h, number, &parent);
}, },
@ -502,18 +502,18 @@ impl BlockDownloader {
imported.insert(h.clone()); imported.insert(h.clone());
self.block_imported(&h, number, &parent); self.block_imported(&h, number, &parent);
}, },
Err(BlockImportError(BlockImportErrorKind::Block(BlockError::UnknownParent(_)), _)) if allow_out_of_order => { Err(EthcoreError(EthcoreErrorKind::Block(BlockError::UnknownParent(_)), _)) if allow_out_of_order => {
break; break;
}, },
Err(BlockImportError(BlockImportErrorKind::Block(BlockError::UnknownParent(_)), _)) => { Err(EthcoreError(EthcoreErrorKind::Block(BlockError::UnknownParent(_)), _)) => {
trace!(target: "sync", "Unknown new block parent, restarting sync"); trace!(target: "sync", "Unknown new block parent, restarting sync");
break; break;
}, },
Err(BlockImportError(BlockImportErrorKind::Block(BlockError::TemporarilyInvalid(_)), _)) => { Err(EthcoreError(EthcoreErrorKind::Block(BlockError::TemporarilyInvalid(_)), _)) => {
debug!(target: "sync", "Block temporarily invalid, restarting sync"); debug!(target: "sync", "Block temporarily invalid, restarting sync");
break; break;
}, },
Err(BlockImportError(BlockImportErrorKind::Queue(QueueErrorKind::Full(limit)), _)) => { Err(EthcoreError(EthcoreErrorKind::Queue(QueueErrorKind::Full(limit)), _)) => {
debug!(target: "sync", "Block import queue full ({}), restarting sync", limit); debug!(target: "sync", "Block import queue full ({}), restarting sync", limit);
break; break;
}, },

View File

@ -17,8 +17,8 @@
use api::WARP_SYNC_PROTOCOL_ID; use api::WARP_SYNC_PROTOCOL_ID;
use block_sync::{BlockDownloaderImportError as DownloaderImportError, DownloadAction}; use block_sync::{BlockDownloaderImportError as DownloaderImportError, DownloadAction};
use bytes::Bytes; use bytes::Bytes;
use ethcore::client::{BlockStatus, BlockId, BlockImportError, BlockImportErrorKind}; use ethcore::client::{BlockId, BlockStatus};
use ethcore::error::*; use ethcore::error::{Error as EthcoreError, ErrorKind as EthcoreErrorKind, ImportErrorKind, BlockError};
use ethcore::header::BlockNumber; use ethcore::header::BlockNumber;
use ethcore::snapshot::{ManifestData, RestorationStatus}; use ethcore::snapshot::{ManifestData, RestorationStatus};
use ethcore::verification::queue::kind::blocks::Unverified; use ethcore::verification::queue::kind::blocks::Unverified;
@ -182,10 +182,10 @@ impl SyncHandler {
return Err(DownloaderImportError::Invalid); return Err(DownloaderImportError::Invalid);
} }
match io.chain().import_block(block) { match io.chain().import_block(block) {
Err(BlockImportError(BlockImportErrorKind::Import(ImportErrorKind::AlreadyInChain), _)) => { Err(EthcoreError(EthcoreErrorKind::Import(ImportErrorKind::AlreadyInChain), _)) => {
trace!(target: "sync", "New block already in chain {:?}", hash); trace!(target: "sync", "New block already in chain {:?}", hash);
}, },
Err(BlockImportError(BlockImportErrorKind::Import(ImportErrorKind::AlreadyQueued), _)) => { Err(EthcoreError(EthcoreErrorKind::Import(ImportErrorKind::AlreadyQueued), _)) => {
trace!(target: "sync", "New block already queued {:?}", hash); trace!(target: "sync", "New block already queued {:?}", hash);
}, },
Ok(_) => { Ok(_) => {
@ -194,7 +194,7 @@ impl SyncHandler {
sync.new_blocks.mark_as_known(&hash, number); sync.new_blocks.mark_as_known(&hash, number);
trace!(target: "sync", "New block queued {:?} ({})", hash, number); trace!(target: "sync", "New block queued {:?} ({})", hash, number);
}, },
Err(BlockImportError(BlockImportErrorKind::Block(BlockError::UnknownParent(p)), _)) => { Err(EthcoreError(EthcoreErrorKind::Block(BlockError::UnknownParent(p)), _)) => {
unknown = true; unknown = true;
trace!(target: "sync", "New block with unknown parent ({:?}) {:?}", p, hash); trace!(target: "sync", "New block with unknown parent ({:?}) {:?}", p, hash);
}, },

View File

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

View File

@ -26,8 +26,8 @@ use ethereum_types::{U256, H256, Address};
use bytes::ToPretty; use bytes::ToPretty;
use rlp::PayloadInfo; use rlp::PayloadInfo;
use ethcore::account_provider::AccountProvider; use ethcore::account_provider::AccountProvider;
use ethcore::client::{Mode, DatabaseCompactionProfile, VMType, BlockImportError, Nonce, Balance, BlockChainClient, BlockId, BlockInfo, ImportBlock}; use ethcore::client::{Mode, DatabaseCompactionProfile, VMType, Nonce, Balance, BlockChainClient, BlockId, BlockInfo, ImportBlock};
use ethcore::error::{ImportErrorKind, BlockImportErrorKind}; use ethcore::error::{ImportErrorKind, ErrorKind as EthcoreErrorKind, Error as EthcoreError};
use ethcore::miner::Miner; use ethcore::miner::Miner;
use ethcore::verification::queue::VerifierSettings; use ethcore::verification::queue::VerifierSettings;
use ethcore::verification::queue::kind::blocks::Unverified; use ethcore::verification::queue::kind::blocks::Unverified;
@ -251,7 +251,7 @@ fn execute_import_light(cmd: ImportBlockchain) -> Result<(), String> {
} }
match client.import_header(header) { match client.import_header(header) {
Err(BlockImportError(BlockImportErrorKind::Import(ImportErrorKind::AlreadyInChain), _)) => { Err(EthcoreError(EthcoreErrorKind::Import(ImportErrorKind::AlreadyInChain), _)) => {
trace!("Skipping block already in chain."); trace!("Skipping block already in chain.");
} }
Err(e) => { Err(e) => {
@ -421,7 +421,7 @@ fn execute_import(cmd: ImportBlockchain) -> Result<(), String> {
let block = Unverified::from_rlp(bytes).map_err(|_| "Invalid block rlp")?; let block = Unverified::from_rlp(bytes).map_err(|_| "Invalid block rlp")?;
while client.queue_info().is_full() { sleep(Duration::from_secs(1)); } while client.queue_info().is_full() { sleep(Duration::from_secs(1)); }
match client.import_block(block) { match client.import_block(block) {
Err(BlockImportError(BlockImportErrorKind::Import(ImportErrorKind::AlreadyInChain), _)) => { Err(EthcoreError(EthcoreErrorKind::Import(ImportErrorKind::AlreadyInChain), _)) => {
trace!("Skipping block already in chain."); trace!("Skipping block already in chain.");
} }
Err(e) => { Err(e) => {