Remove (almost all) panickers from trie module (#1776)
* memorydb ub patch and other cleanup * fix denote invocations * move trie traits into trie module * replace "denote" with shim * triedb returns results and no longer panics * fix warnings * get ethcore compiling * warn on trie errors in ethcore * remove unsafety from node decoder * restore broken denote behavior for this branch * fix overlayrecent fallout * fix triedb tests * remove unwrap in state * alter Trie::get to return Result<Option<_>> * fix refcell error in require * fix test warnings * fix json tests * whitespace [ci:skip] * Avoid unneeded match/indentation * whitespace * prettify map_or_else * remove test warning
This commit is contained in:
committed by
Gav Wood
parent
40a304b177
commit
11b65ce53d
@@ -17,7 +17,7 @@
|
||||
use hash::H256;
|
||||
use sha3::Hashable;
|
||||
use hashdb::HashDB;
|
||||
use super::{TrieDBMut, TrieMut, TrieError};
|
||||
use super::{TrieDBMut, TrieMut};
|
||||
|
||||
/// A mutable `Trie` implementation which hashes keys and uses a generic `HashDB` backing database.
|
||||
/// Additionaly it stores inserted hash-key mappings for later retrieval.
|
||||
@@ -38,7 +38,7 @@ impl<'db> FatDBMut<'db> {
|
||||
/// Create a new trie with the backing database `db` and `root`.
|
||||
///
|
||||
/// Returns an error if root does not exist.
|
||||
pub fn from_existing(db: &'db mut HashDB, root: &'db mut H256) -> Result<Self, TrieError> {
|
||||
pub fn from_existing(db: &'db mut HashDB, root: &'db mut H256) -> super::Result<Self> {
|
||||
Ok(FatDBMut { raw: try!(TrieDBMut::from_existing(db, root)) })
|
||||
}
|
||||
|
||||
@@ -62,23 +62,26 @@ impl<'db> TrieMut for FatDBMut<'db> {
|
||||
self.raw.is_empty()
|
||||
}
|
||||
|
||||
fn contains(&self, key: &[u8]) -> bool {
|
||||
fn contains(&self, key: &[u8]) -> super::Result<bool> {
|
||||
self.raw.contains(&key.sha3())
|
||||
}
|
||||
|
||||
fn get<'a, 'key>(&'a self, key: &'key [u8]) -> Option<&'a [u8]> where 'a: 'key {
|
||||
fn get<'a, 'key>(&'a self, key: &'key [u8]) -> super::Result<Option<&'a [u8]>>
|
||||
where 'a: 'key
|
||||
{
|
||||
self.raw.get(&key.sha3())
|
||||
}
|
||||
|
||||
fn insert(&mut self, key: &[u8], value: &[u8]) {
|
||||
fn insert(&mut self, key: &[u8], value: &[u8]) -> super::Result<()> {
|
||||
let hash = key.sha3();
|
||||
self.raw.insert(&hash, value);
|
||||
try!(self.raw.insert(&hash, value));
|
||||
let db = self.raw.db_mut();
|
||||
db.insert_aux(hash.to_vec(), key.to_vec());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn remove(&mut self, key: &[u8]) {
|
||||
self.raw.remove(&key.sha3());
|
||||
fn remove(&mut self, key: &[u8]) -> super::Result<()> {
|
||||
self.raw.remove(&key.sha3())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,8 +95,8 @@ fn fatdb_to_trie() {
|
||||
let mut root = H256::default();
|
||||
{
|
||||
let mut t = FatDBMut::new(&mut memdb, &mut root);
|
||||
t.insert(&[0x01u8, 0x23], &[0x01u8, 0x23]);
|
||||
t.insert(&[0x01u8, 0x23], &[0x01u8, 0x23]).unwrap();
|
||||
}
|
||||
let t = TrieDB::new(&memdb, &root).unwrap();
|
||||
assert_eq!(t.get(&(&[0x01u8, 0x23]).sha3()).unwrap(), &[0x01u8, 0x23]);
|
||||
assert_eq!(t.get(&(&[0x01u8, 0x23]).sha3()).unwrap().unwrap(), &[0x01u8, 0x23]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user