Make clear when the panic occurs to a missing trie root.

This commit is contained in:
Gav Wood 2016-01-15 14:40:51 +01:00
parent 73f849d7c9
commit df151ab92c
4 changed files with 15 additions and 15 deletions

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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,

View File

@ -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,