From c4c5d79a0f0f7b56dec3f043459493a90ad219cb Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Sat, 6 Jul 2019 20:40:56 +0200 Subject: [PATCH] removed QueueError type (#10852) --- ethcore/src/client/client.rs | 73 ++++++++++++++++------------------ ethcore/src/error.rs | 24 +---------- ethcore/sync/src/block_sync.rs | 4 +- 3 files changed, 38 insertions(+), 63 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 1744f22ac..c924fb784 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -63,7 +63,7 @@ use engines::{MAX_UNCLE_AGE, Engine, EpochTransition, ForkChoice, EngineError, S use engines::epoch::PendingTransition; use error::{ ImportError, ExecutionError, CallError, BlockError, - QueueError, Error as EthcoreError, EthcoreResult, + Error as EthcoreError, EthcoreResult, }; use executive::{Executive, Executed, TransactOptions, contract_address}; use factory::{Factories, VmFactory}; @@ -2604,6 +2604,39 @@ fn transaction_receipt( } } +/// Queue some items to be processed by IO client. +struct IoChannelQueue { + currently_queued: Arc, + limit: usize, +} + +impl IoChannelQueue { + pub fn new(limit: usize) -> Self { + IoChannelQueue { + currently_queued: Default::default(), + limit, + } + } + + pub fn queue(&self, channel: &IoChannel, count: usize, fun: F) -> EthcoreResult<()> where + F: Fn(&Client) + Send + Sync + 'static, + { + let queue_size = self.currently_queued.load(AtomicOrdering::Relaxed); + if queue_size >= self.limit { + return Err(EthcoreError::FullQueue(self.limit)) + }; + + let currently_queued = self.currently_queued.clone(); + let _ok = channel.send(ClientIoMessage::execute(move |client| { + currently_queued.fetch_sub(count, AtomicOrdering::SeqCst); + fun(client); + }))?; + + self.currently_queued.fetch_add(count, AtomicOrdering::SeqCst); + Ok(()) + } +} + #[cfg(test)] mod tests { use ethereum_types::{H256, Address}; @@ -2761,41 +2794,3 @@ mod tests { }); } } - -/// Queue some items to be processed by IO client. -struct IoChannelQueue { - currently_queued: Arc, - limit: usize, -} - -impl IoChannelQueue { - pub fn new(limit: usize) -> Self { - IoChannelQueue { - currently_queued: Default::default(), - limit, - } - } - - pub fn queue(&self, channel: &IoChannel, count: usize, fun: F) -> Result<(), QueueError> where - F: Fn(&Client) + Send + Sync + 'static, - { - let queue_size = self.currently_queued.load(AtomicOrdering::Relaxed); - if queue_size >= self.limit { - return Err(QueueError::Full(self.limit)) - }; - - let currently_queued = self.currently_queued.clone(); - let result = channel.send(ClientIoMessage::execute(move |client| { - currently_queued.fetch_sub(count, AtomicOrdering::SeqCst); - fun(client); - })); - - match result { - Ok(_) => { - self.currently_queued.fetch_add(count, AtomicOrdering::SeqCst); - Ok(()) - }, - Err(e) => return Err(QueueError::Channel(e)), - } - } -} diff --git a/ethcore/src/error.rs b/ethcore/src/error.rs index 198d294c1..f9d288165 100644 --- a/ethcore/src/error.rs +++ b/ethcore/src/error.rs @@ -150,26 +150,6 @@ impl error::Error for BlockError { } } -/// Queue error -#[derive(Debug, Display, From)] -pub enum QueueError { - /// Queue is full - #[display(fmt = "Queue is full ({})", _0)] - Full(usize), - /// Io channel error - #[display(fmt = "Io channel error: {}", _0)] - Channel(::io::IoError) -} - -impl error::Error for QueueError { - fn source(&self) -> Option<&(dyn error::Error + 'static)> { - match self { - QueueError::Channel(e) => Some(e), - _ => None, - } - } -} - /// Block import Error #[derive(Debug, Display)] pub enum ImportError { @@ -196,8 +176,8 @@ pub enum Error { #[display(fmt = "Import error: {}", _0)] Import(ImportError), /// Io channel queue error - #[display(fmt = "Queue error: {}", _0)] - Queue(QueueError), + #[display(fmt = "Queue is full: {}", _0)] + FullQueue(usize), /// Io create error #[display(fmt = "Io error: {}", _0)] Io(::io::IoError), diff --git a/ethcore/sync/src/block_sync.rs b/ethcore/sync/src/block_sync.rs index 648d86f09..69465852f 100644 --- a/ethcore/sync/src/block_sync.rs +++ b/ethcore/sync/src/block_sync.rs @@ -25,7 +25,7 @@ use ethereum_types::H256; use rlp::{self, Rlp}; use types::BlockNumber; use ethcore::client::{BlockStatus, BlockId}; -use ethcore::error::{ImportError, QueueError, BlockError, Error as EthcoreError}; +use ethcore::error::{ImportError, BlockError, Error as EthcoreError}; use sync_io::SyncIo; use blocks::{BlockCollection, SyncBody, SyncHeader}; use chain::BlockSet; @@ -582,7 +582,7 @@ impl BlockDownloader { debug_sync!(self, "Block temporarily invalid: {:?}, restarting sync", h); break; }, - Err(EthcoreError::Queue(QueueError::Full(limit))) => { + Err(EthcoreError::FullQueue(limit)) => { debug_sync!(self, "Block import queue full ({}), restarting sync", limit); download_action = DownloadAction::Reset; break;