exists -> contains

This commit is contained in:
Robert Habermeier 2016-06-02 21:01:47 +02:00
parent 6c6229c963
commit 1e10445f82
2 changed files with 10 additions and 6 deletions

View File

@ -371,19 +371,23 @@ impl<V> Client<V> where V: Verifier {
return Some(self.state())
}
let block_number = self.block_number(id.clone());
let block_number = match self.block_number(id.clone()) {
Some(num) => num,
None => return None,
};
self.block_header(id).and_then(|header| {
let db = self.state_db.lock().unwrap().boxed_clone();
let root = HeaderView::new(&header).state_root();
// check that the block is not too old -- blocks within `HISTORY` blocks of the best will
// always be available. If the block could be too old, check if its state root is valid.
if self.state_db.does_pruning()
&& self.best_block_number() >= block_number + HISTORY
&& self.state_db.exists(root) {
if db.does_pruning()
&& self.chain.best_block_number() >= block_number + HISTORY
&& !db.contains(&root) {
return None;
}
let db = self.state_db.lock().unwrap().boxed_clone();
Some(State::from_existing(db, HeaderView::new(&header).state_root(), self.engine.account_start_nonce()))
})
}

View File

@ -59,7 +59,7 @@ 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 {
if !db.exists(root) {
if !db.contains(root) {
flushln!("TrieDB::new({}): Trie root not found!", root);
panic!("Trie root not found!");
}