Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Box TrieErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdplm committed Jun 22, 2018
1 parent 9c84453 commit 0142e70
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 28 deletions.
11 changes: 3 additions & 8 deletions ethcore/light/src/on_demand/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,16 +652,11 @@ impl From<::rlp::DecoderError> for Error {
}
}

impl From<TrieError> for Error {
fn from(err: TrieError) -> Self {
Error::Trie(err)
impl From<Box<TrieError>> for Error {
fn from(err: Box<TrieError>) -> Self {
Error::Trie(*err)
}
}
// impl From<Box<TrieError>> for Error {
// fn from(err: Box<TrieError>) -> Self {
// Error::Trie(*err)
// }
// }

/// Request for header proof by number
#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/client/evm_test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use ethtrie;
#[derive(Debug)]
pub enum EvmTestError {
/// Trie integrity error.
Trie(ethtrie::TrieError),
Trie(Box<ethtrie::TrieError>),
/// EVM error.
Evm(vm::Error),
/// Initialization error.
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl<B: Backend> State<B> {
/// Creates new state with existing state root
pub fn from_existing(db: B, root: H256, account_start_nonce: U256, factories: Factories) -> TrieResult<State<B>> {
if !db.as_hashdb().contains(&root) {
return Err(TrieError::InvalidStateRoot(root));
return Err(Box::new(TrieError::InvalidStateRoot(root)));
}

let state = State {
Expand Down
4 changes: 2 additions & 2 deletions util/patricia_trie/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ impl<T, E> error::Error for TrieError<T, E> where T: std::fmt::Debug, E: std::er
}
}

/// Trie result type. Boxed to avoid copying around extra space for the `Hasher`s `Out`s on successful queries.
pub type Result<T, H, E> = ::std::result::Result<T, TrieError<H, E>>;
/// Trie result type. Boxed to avoid copying around extra space for the `Hasher`s `Out` on successful queries.
pub type Result<T, H, E> = ::std::result::Result<T, Box<TrieError<H, E>>>;


/// Trie-Item type used for iterators over trie data.
Expand Down
11 changes: 3 additions & 8 deletions util/patricia_trie/src/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,10 @@ where
for depth in 0.. {
let node_data = match self.db.get(&hash) {
Some(value) => value,
None => return Err(match depth {
None => return Err(Box::new(match depth {
0 => TrieError::InvalidStateRoot(hash),
_ => TrieError::IncompleteDatabase(hash),
}),
// None => return Err(Box::new(match depth {
// 0 => TrieError::<_, C::E>::InvalidStateRoot(hash),
// _ => TrieError::<_, C::E>::IncompleteDatabase(hash),
// })),
})),
};

self.query.record(&hash, &node_data, depth);
Expand All @@ -68,8 +64,7 @@ where
let decoded = match C::decode(node_data) {
Ok(node) => node,
Err(e) => {
return Err(TrieError::DecoderError(hash, e))
// return Err(Box::new(TrieError::DecoderError(hash, Box::new(e))))
return Err(Box::new(TrieError::DecoderError(hash, e)))
}
};
match decoded {
Expand Down
9 changes: 3 additions & 6 deletions util/patricia_trie/src/triedb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ where
/// Returns an error if `root` does not exist
pub fn new(db: &'db HashDB<H>, root: &'db H::Out) -> Result<Self, H::Out, C::E> {
if !db.contains(root) {
Err(TrieError::InvalidStateRoot(*root))
// Err(Box::new(TrieError::InvalidStateRoot(*root)))
Err(Box::new(TrieError::InvalidStateRoot(*root)))
} else {
Ok(TrieDB {db, root, hash_count: 0, codec_marker: PhantomData})
}
Expand All @@ -93,8 +92,7 @@ where
fn root_data(&self) -> Result<DBValue, H::Out, C::E> {
self.db
.get(self.root)
.ok_or_else(|| TrieError::InvalidStateRoot(*self.root))
// .ok_or_else(|| Box::new(TrieError::InvalidStateRoot(*self.root)))
.ok_or_else(|| Box::new(TrieError::InvalidStateRoot(*self.root)))
}

/// Given some node-describing data `node`, return the actual node RLP.
Expand All @@ -103,8 +101,7 @@ where
fn get_raw_or_lookup(&'db self, node: &'db [u8]) -> Result<DBValue, H::Out, C::E> {
match C::try_decode_hash(node) {
Some(key) => {
self.db.get(&key).ok_or_else(|| TrieError::IncompleteDatabase(key))
// self.db.get(&key).ok_or_else(|| Box::new(TrieError::IncompleteDatabase(key)))
self.db.get(&key).ok_or_else(|| Box::new(TrieError::IncompleteDatabase(key)))
}
None => Ok(DBValue::from_slice(node))
}
Expand Down
3 changes: 1 addition & 2 deletions util/patricia_trie/src/triedbmut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,7 @@ where
/// Returns an error if `root` does not exist.
pub fn from_existing(db: &'a mut HashDB<H>, root: &'a mut H::Out) -> Result<Self, H::Out, C::E> {
if !db.contains(root) {
return Err(TrieError::InvalidStateRoot(*root));
// return Err(Box::new(TrieError::InvalidStateRoot(*root)));
return Err(Box::new(TrieError::InvalidStateRoot(*root)));
}

let root_handle = NodeHandle::Hash(*root);
Expand Down

0 comments on commit 0142e70

Please sign in to comment.