Remove panickers from trie iterators (#2209)

* port trie iterators to use error handling

* use new trie iterators in snapshot

allows proper recovery from a premature periodic snapshot
This commit is contained in:
Robert Habermeier
2016-09-21 12:56:13 +02:00
committed by Gav Wood
parent 8c111da70b
commit a100b9d09e
9 changed files with 62 additions and 37 deletions

View File

@@ -72,12 +72,12 @@ impl fmt::Display for TrieError {
}
}
/// Trie-Item type.
pub type TrieItem<'a> = (Vec<u8>, &'a [u8]);
/// Trie result type. Boxed to avoid copying around extra space for `H256`s on successful queries.
pub type Result<T> = ::std::result::Result<T, Box<TrieError>>;
/// Trie-Item type.
pub type TrieItem<'a> = Result<(Vec<u8>, &'a [u8])>;
/// A key-value datastore implemented as a database-backed modified Merkle tree.
pub trait Trie {
/// Return the root of the trie.
@@ -102,7 +102,7 @@ pub trait Trie {
where 'a: 'b, R: Recorder;
/// Returns an iterator over elements of trie.
fn iter<'a>(&'a self) -> Box<Iterator<Item = TrieItem> + 'a>;
fn iter<'a>(&'a self) -> Result<Box<Iterator<Item = TrieItem> + 'a>>;
}
/// A key-value datastore implemented as a database-backed modified Merkle tree.
@@ -193,7 +193,7 @@ impl<'db> Trie for TrieKinds<'db> {
wrapper!(self, get_recorded, key, r)
}
fn iter<'a>(&'a self) -> Box<Iterator<Item = TrieItem> + 'a> {
fn iter<'a>(&'a self) -> Result<Box<Iterator<Item = TrieItem> + 'a>> {
wrapper!(self, iter,)
}
}