From df151ab92c652c354d7b498a98943c08092e02db Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 15 Jan 2016 14:40:51 +0100 Subject: [PATCH 1/2] Make clear when the panic occurs to a missing trie root. --- src/common.rs | 5 ----- src/standard.rs | 5 +++++ src/trie/triedb.rs | 10 +++++----- src/trie/triedbmut.rs | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/common.rs b/src/common.rs index 7750d9ea5..78f9fbf64 100644 --- a/src/common.rs +++ b/src/common.rs @@ -34,8 +34,3 @@ macro_rules! xx { From::from(From::from($x)) } } - -pub fn flush(s: String) { - ::std::io::stdout().write(s.as_bytes()).unwrap(); - ::std::io::stdout().flush().unwrap(); -} diff --git a/src/standard.rs b/src/standard.rs index 19a084a2c..59b6c4c38 100644 --- a/src/standard.rs +++ b/src/standard.rs @@ -27,3 +27,8 @@ pub use rustc_serialize::hex::{FromHex, FromHexError}; pub use heapsize::HeapSizeOf; pub use itertools::Itertools; + +pub fn flush(s: String) { + ::std::io::stdout().write(s.as_bytes()).unwrap(); + ::std::io::stdout().flush().unwrap(); +} diff --git a/src/trie/triedb.rs b/src/trie/triedb.rs index 862bbb96c..bd34e710d 100644 --- a/src/trie/triedb.rs +++ b/src/trie/triedb.rs @@ -1,10 +1,7 @@ -use std::fmt; +use common::*; use hashdb::*; -use hash::*; use nibbleslice::*; -use bytes::*; use rlp::*; -use std::collections::HashMap; use super::trietraits::*; use super::node::*; @@ -44,7 +41,10 @@ impl<'db> TrieDB<'db> { /// Create a new trie with the backing database `db` and `root` /// Panics, if `root` does not exist pub fn new(db: &'db HashDB, root: &'db H256) -> Self { - assert!(db.exists(root)); + if !db.exists(root) { + flush(format!("Trie root not found {}", root)); + panic!("Trie root not found!"); + } TrieDB { db: db, root: root, diff --git a/src/trie/triedbmut.rs b/src/trie/triedbmut.rs index c6f47fa5e..832b532f8 100644 --- a/src/trie/triedbmut.rs +++ b/src/trie/triedbmut.rs @@ -1,10 +1,7 @@ -use std::fmt; +use common::*; use hashdb::*; -use hash::*; use nibbleslice::*; -use bytes::*; use rlp::*; -use std::collections::HashMap; use super::node::*; use super::journal::*; use super::trietraits::*; @@ -71,7 +68,10 @@ impl<'db> TrieDBMut<'db> { /// Create a new trie with the backing database `db` and `root` /// Panics, if `root` does not exist pub fn from_existing(db: &'db mut HashDB, root: &'db mut H256) -> Self { - assert!(db.exists(root)); + if !db.exists(root) { + flush(format!("Trie root not found {}", root)); + panic!("Trie root not found!"); + } TrieDBMut { db: db, root: root, From 34b516b8b0d3c99d79f0d67b0d152663bbac7a5a Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 15 Jan 2016 14:42:16 +0100 Subject: [PATCH 2/2] Move flush back to common. --- src/common.rs | 5 +++++ src/standard.rs | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common.rs b/src/common.rs index 78f9fbf64..7750d9ea5 100644 --- a/src/common.rs +++ b/src/common.rs @@ -34,3 +34,8 @@ macro_rules! xx { From::from(From::from($x)) } } + +pub fn flush(s: String) { + ::std::io::stdout().write(s.as_bytes()).unwrap(); + ::std::io::stdout().flush().unwrap(); +} diff --git a/src/standard.rs b/src/standard.rs index 59b6c4c38..19a084a2c 100644 --- a/src/standard.rs +++ b/src/standard.rs @@ -27,8 +27,3 @@ pub use rustc_serialize::hex::{FromHex, FromHexError}; pub use heapsize::HeapSizeOf; pub use itertools::Itertools; - -pub fn flush(s: String) { - ::std::io::stdout().write(s.as_bytes()).unwrap(); - ::std::io::stdout().flush().unwrap(); -}