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
12 changed files with 56 additions and 112 deletions

View File

@@ -43,7 +43,7 @@ use client::{
};
use client::{
BlockId, TransactionId, UncleId, TraceId, ClientConfig, BlockChainClient,
TraceFilter, CallAnalytics, BlockImportError, Mode,
TraceFilter, CallAnalytics, Mode,
ChainNotify, ChainRoute, PruningInfo, ProvingBlockChainClient, EngineInfo, ChainMessageType,
IoClient, BadBlocks,
};
@@ -51,8 +51,8 @@ use client::bad_blocks;
use encoded;
use engines::{EthEngine, EpochTransition, ForkChoice};
use error::{
ImportErrorKind, BlockImportErrorKind, ExecutionError, CallError, BlockError, ImportResult,
QueueError, QueueErrorKind, Error as EthcoreError
ImportErrorKind, ExecutionError, CallError, BlockError,
QueueError, QueueErrorKind, Error as EthcoreError, EthcoreResult, ErrorKind as EthcoreErrorKind
};
use vm::{EnvInfo, LastHashes};
use evm::Schedule;
@@ -1392,23 +1392,23 @@ impl CallContract 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()) {
bail!(BlockImportErrorKind::Import(ImportErrorKind::AlreadyInChain));
bail!(EthcoreErrorKind::Import(ImportErrorKind::AlreadyInChain));
}
let status = self.block_status(BlockId::Hash(unverified.parent_hash()));
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();
match self.importer.block_queue.import(unverified).map_err(Into::into) {
match self.importer.block_queue.import(unverified) {
Ok(res) => Ok(res),
// 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));
bail!(BlockImportErrorKind::Block(err))
bail!(EthcoreErrorKind::Block(err))
},
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");
let hash = unverified.hash();
{
// check block order
if self.chain.read().is_known(&hash) {
bail!(BlockImportErrorKind::Import(ImportErrorKind::AlreadyInChain));
bail!(EthcoreErrorKind::Import(ImportErrorKind::AlreadyInChain));
}
let parent_hash = unverified.parent_hash();
// 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 {
let status = self.block_status(BlockId::Hash(parent_hash));
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 {
fn import_sealed_block(&self, block: SealedBlock) -> ImportResult {
fn import_sealed_block(&self, block: SealedBlock) -> EthcoreResult<H256> {
let h = block.header().hash();
let start = Instant::now();
let route = {

View File

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

View File

@@ -37,7 +37,7 @@ use blockchain::{TreeRoute, BlockReceipts};
use client::{
Nonce, Balance, ChainInfo, BlockInfo, ReopenBlock, CallContract, TransactionInfo, RegistryInfo,
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,
Call, StateClient, EngineInfo, AccountData, BlockChain, BlockProducer, SealedBlockImporter, IoClient,
BadBlocks,
@@ -47,7 +47,7 @@ use header::{Header as BlockHeader, BlockNumber};
use filter::Filter;
use log_entry::LocalizedLogEntry;
use receipt::{Receipt, LocalizedReceipt, TransactionOutcome};
use error::{Error, ImportResult};
use error::{Error, EthcoreResult};
use vm::Schedule;
use miner::{self, Miner, MinerService};
use spec::Spec;
@@ -416,7 +416,7 @@ impl ScheduleInfo 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())
}
}
@@ -523,7 +523,7 @@ impl RegistryInfo 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 h = header.hash();
let number: usize = header.number() as usize;
@@ -883,7 +883,7 @@ impl IoClient for TestBlockChainClient {
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)
}

View File

@@ -24,7 +24,7 @@ use blockchain::TreeRoute;
use client::Mode;
use encoded;
use vm::LastHashes;
use error::{Error, ImportResult, CallError, BlockImportError};
use error::{Error, CallError, EthcoreResult};
use evm::Schedule;
use executive::Executed;
use filter::Filter;
@@ -168,7 +168,7 @@ pub trait RegistryInfo {
/// Provides methods to import block into blockchain
pub trait ImportBlock {
/// 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
@@ -205,7 +205,7 @@ pub trait IoClient: Sync + Send {
fn queue_transactions(&self, transactions: Vec<Bytes>, peer_id: usize);
/// 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.
fn queue_consensus_message(&self, message: Bytes);
@@ -414,7 +414,7 @@ pub trait ScheduleInfo {
///Provides `import_sealed_block` method
pub trait ImportSealedBlock {
/// 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