don't return a state in state_at if the db prunes and the block is before guaranteed history

This commit is contained in:
Robert Habermeier 2016-06-02 20:34:38 +02:00
parent 81d8dafd9e
commit d7b79c1274
3 changed files with 13 additions and 0 deletions

View File

@ -371,6 +371,14 @@ impl<V> Client<V> where V: Verifier {
return Some(self.state())
}
let block_number = self.block_number(id.clone());
// check that the block is not too old -- blocks within `HISTORY` blocks of the best will
// always be available.
if self.state_db.does_pruning() && self.best_block_number() >= block_number + HISTORY {
return None;
}
self.block_header(id).map(|header| {
let db = self.state_db.lock().unwrap().boxed_clone();
State::from_existing(db, HeaderView::new(&header).state_root(), self.engine.account_start_nonce())

View File

@ -175,6 +175,8 @@ impl JournalDB for ArchiveDB {
fn state(&self, id: &H256) -> Option<Bytes> {
self.backing.get_by_prefix(&id.bytes()[0..12]).and_then(|b| Some(b.to_vec()))
}
fn does_pruning(&self) -> bool { false }
}
#[cfg(test)]

View File

@ -42,4 +42,7 @@ pub trait JournalDB : HashDB + Send + Sync {
fn state(&self, _id: &H256) -> Option<Bytes> {
None
}
/// Whether this database does pruning.
fn does_pruning(&self) -> bool { true }
}