reduce number of constraints for triedb types (#9043)
* NodeHandle does not require Hasher * Node does not require Hasher * change name of the template typo from I to O
This commit is contained in:
parent
434e018584
commit
802d684994
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -2485,6 +2485,7 @@ dependencies = [
|
|||||||
"ethcore-bytes 0.1.0",
|
"ethcore-bytes 0.1.0",
|
||||||
"ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hashdb 0.2.0",
|
"hashdb 0.2.0",
|
||||||
|
"heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"keccak-hash 0.1.2",
|
"keccak-hash 0.1.2",
|
||||||
"keccak-hasher 0.1.0",
|
"keccak-hasher 0.1.0",
|
||||||
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -7,10 +7,11 @@ license = "GPL-3.0"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
elastic-array = "0.10"
|
elastic-array = "0.10"
|
||||||
|
ethcore-bytes = { version = "0.1.0", path = "../bytes" }
|
||||||
|
hashdb = { version = "0.2", path = "../hashdb" }
|
||||||
|
heapsize = "0.4"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
rand = "0.4"
|
rand = "0.4"
|
||||||
hashdb = { version = "0.2", path = "../hashdb" }
|
|
||||||
ethcore-bytes = { version = "0.1.0", path = "../bytes" }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
env_logger = "0.5"
|
env_logger = "0.5"
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
extern crate elastic_array;
|
extern crate elastic_array;
|
||||||
extern crate ethcore_bytes as bytes;
|
extern crate ethcore_bytes as bytes;
|
||||||
extern crate hashdb;
|
extern crate hashdb;
|
||||||
|
extern crate heapsize;
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
|
@ -31,6 +31,8 @@ use std::collections::{HashSet, VecDeque};
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ops::Index;
|
use std::ops::Index;
|
||||||
|
use heapsize::HeapSizeOf;
|
||||||
|
use std::{fmt::Debug, hash::Hash};
|
||||||
|
|
||||||
// For lookups into the Node storage buffer.
|
// For lookups into the Node storage buffer.
|
||||||
// This is deliberately non-copyable.
|
// This is deliberately non-copyable.
|
||||||
@ -39,20 +41,20 @@ struct StorageHandle(usize);
|
|||||||
|
|
||||||
// Handles to nodes in the trie.
|
// Handles to nodes in the trie.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum NodeHandle<H: Hasher> {
|
enum NodeHandle<H> {
|
||||||
/// Loaded into memory.
|
/// Loaded into memory.
|
||||||
InMemory(StorageHandle),
|
InMemory(StorageHandle),
|
||||||
/// Either a hash or an inline node
|
/// Either a hash or an inline node
|
||||||
Hash(H::Out),
|
Hash(H),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<H: Hasher> From<StorageHandle> for NodeHandle<H> {
|
impl<H> From<StorageHandle> for NodeHandle<H> {
|
||||||
fn from(handle: StorageHandle) -> Self {
|
fn from(handle: StorageHandle) -> Self {
|
||||||
NodeHandle::InMemory(handle)
|
NodeHandle::InMemory(handle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn empty_children<H: Hasher>() -> Box<[Option<NodeHandle<H>>; 16]> {
|
fn empty_children<H>() -> Box<[Option<NodeHandle<H>>; 16]> {
|
||||||
Box::new([
|
Box::new([
|
||||||
None, None, None, None, None, None, None, None,
|
None, None, None, None, None, None, None, None,
|
||||||
None, None, None, None, None, None, None, None,
|
None, None, None, None, None, None, None, None,
|
||||||
@ -61,7 +63,7 @@ fn empty_children<H: Hasher>() -> Box<[Option<NodeHandle<H>>; 16]> {
|
|||||||
|
|
||||||
/// Node types in the Trie.
|
/// Node types in the Trie.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum Node<H: Hasher> {
|
enum Node<H> {
|
||||||
/// Empty node.
|
/// Empty node.
|
||||||
Empty,
|
Empty,
|
||||||
/// A leaf node contains the end of a key and a value.
|
/// A leaf node contains the end of a key and a value.
|
||||||
@ -77,22 +79,24 @@ enum Node<H: Hasher> {
|
|||||||
Branch(Box<[Option<NodeHandle<H>>; 16]>, Option<DBValue>)
|
Branch(Box<[Option<NodeHandle<H>>; 16]>, Option<DBValue>)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<H: Hasher> Node<H> {
|
impl<O> Node<O> where O: AsRef<[u8]> + AsMut<[u8]> + Default + HeapSizeOf + Debug + PartialEq + Eq + Hash + Send + Sync + Clone + Copy {
|
||||||
// load an inline node into memory or get the hash to do the lookup later.
|
// load an inline node into memory or get the hash to do the lookup later.
|
||||||
fn inline_or_hash<C>(node: &[u8], db: &HashDB<H>, storage: &mut NodeStorage<H>) -> NodeHandle<H>
|
fn inline_or_hash<C, H>(node: &[u8], db: &HashDB<H>, storage: &mut NodeStorage<H::Out>) -> NodeHandle<H::Out>
|
||||||
where C: NodeCodec<H>
|
where C: NodeCodec<H>,
|
||||||
|
H: Hasher<Out = O>,
|
||||||
{
|
{
|
||||||
C::try_decode_hash(&node)
|
C::try_decode_hash(&node)
|
||||||
.map(NodeHandle::Hash)
|
.map(NodeHandle::Hash)
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
let child = Node::from_encoded::<C>(node, db, storage);
|
let child = Node::from_encoded::<C, H>(node, db, storage);
|
||||||
NodeHandle::InMemory(storage.alloc(Stored::New(child)))
|
NodeHandle::InMemory(storage.alloc(Stored::New(child)))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// decode a node from encoded bytes without getting its children.
|
// decode a node from encoded bytes without getting its children.
|
||||||
fn from_encoded<C>(data: &[u8], db: &HashDB<H>, storage: &mut NodeStorage<H>) -> Self
|
fn from_encoded<C, H>(data: &[u8], db: &HashDB<H>, storage: &mut NodeStorage<H::Out>) -> Self
|
||||||
where C: NodeCodec<H>
|
where C: NodeCodec<H>,
|
||||||
|
H: Hasher<Out = O>,
|
||||||
{
|
{
|
||||||
match C::decode(data).expect("encoded bytes read from db; qed") {
|
match C::decode(data).expect("encoded bytes read from db; qed") {
|
||||||
EncodedNode::Empty => Node::Empty,
|
EncodedNode::Empty => Node::Empty,
|
||||||
@ -100,13 +104,13 @@ impl<H: Hasher> Node<H> {
|
|||||||
EncodedNode::Extension(key, cb) => {
|
EncodedNode::Extension(key, cb) => {
|
||||||
Node::Extension(
|
Node::Extension(
|
||||||
key.encoded(false),
|
key.encoded(false),
|
||||||
Self::inline_or_hash::<C>(cb, db, storage))
|
Self::inline_or_hash::<C, H>(cb, db, storage))
|
||||||
}
|
}
|
||||||
EncodedNode::Branch(ref encoded_children, val) => {
|
EncodedNode::Branch(ref encoded_children, val) => {
|
||||||
let mut child = |i:usize| {
|
let mut child = |i:usize| {
|
||||||
let raw = encoded_children[i];
|
let raw = encoded_children[i];
|
||||||
if !C::is_empty_node(raw) {
|
if !C::is_empty_node(raw) {
|
||||||
Some(Self::inline_or_hash::<C>(raw, db, storage))
|
Some(Self::inline_or_hash::<C, H>(raw, db, storage))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@ -125,10 +129,11 @@ impl<H: Hasher> Node<H> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: parallelize
|
// TODO: parallelize
|
||||||
fn into_encoded<F, C>(self, mut child_cb: F) -> ElasticArray1024<u8>
|
fn into_encoded<F, C, H>(self, mut child_cb: F) -> ElasticArray1024<u8>
|
||||||
where
|
where
|
||||||
C: NodeCodec<H>,
|
C: NodeCodec<H>,
|
||||||
F: FnMut(NodeHandle<H>) -> ChildReference<H::Out>
|
F: FnMut(NodeHandle<H::Out>) -> ChildReference<H::Out>,
|
||||||
|
H: Hasher<Out = O>,
|
||||||
{
|
{
|
||||||
match self {
|
match self {
|
||||||
Node::Empty => C::empty_node(),
|
Node::Empty => C::empty_node(),
|
||||||
@ -150,7 +155,7 @@ impl<H: Hasher> Node<H> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// post-inspect action.
|
// post-inspect action.
|
||||||
enum Action<H: Hasher> {
|
enum Action<H> {
|
||||||
// Replace a node with a new one.
|
// Replace a node with a new one.
|
||||||
Replace(Node<H>),
|
Replace(Node<H>),
|
||||||
// Restore the original node. This trusts that the node is actually the original.
|
// Restore the original node. This trusts that the node is actually the original.
|
||||||
@ -160,14 +165,14 @@ enum Action<H: Hasher> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// post-insert action. Same as action without delete
|
// post-insert action. Same as action without delete
|
||||||
enum InsertAction<H: Hasher> {
|
enum InsertAction<H> {
|
||||||
// Replace a node with a new one.
|
// Replace a node with a new one.
|
||||||
Replace(Node<H>),
|
Replace(Node<H>),
|
||||||
// Restore the original node.
|
// Restore the original node.
|
||||||
Restore(Node<H>),
|
Restore(Node<H>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<H: Hasher> InsertAction<H> {
|
impl<H> InsertAction<H> {
|
||||||
fn into_action(self) -> Action<H> {
|
fn into_action(self) -> Action<H> {
|
||||||
match self {
|
match self {
|
||||||
InsertAction::Replace(n) => Action::Replace(n),
|
InsertAction::Replace(n) => Action::Replace(n),
|
||||||
@ -184,11 +189,11 @@ impl<H: Hasher> InsertAction<H> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// What kind of node is stored here.
|
// What kind of node is stored here.
|
||||||
enum Stored<H: Hasher> {
|
enum Stored<H> {
|
||||||
// A new node.
|
// A new node.
|
||||||
New(Node<H>),
|
New(Node<H>),
|
||||||
// A cached node, loaded from the DB.
|
// A cached node, loaded from the DB.
|
||||||
Cached(Node<H>, H::Out),
|
Cached(Node<H>, H),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used to build a collection of child nodes from a collection of `NodeHandle`s
|
/// Used to build a collection of child nodes from a collection of `NodeHandle`s
|
||||||
@ -198,12 +203,12 @@ pub enum ChildReference<HO> { // `HO` is e.g. `H256`, i.e. the output of a `Hash
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Compact and cache-friendly storage for Trie nodes.
|
/// Compact and cache-friendly storage for Trie nodes.
|
||||||
struct NodeStorage<H: Hasher> {
|
struct NodeStorage<H> {
|
||||||
nodes: Vec<Stored<H>>,
|
nodes: Vec<Stored<H>>,
|
||||||
free_indices: VecDeque<usize>,
|
free_indices: VecDeque<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<H: Hasher> NodeStorage<H> {
|
impl<H> NodeStorage<H> {
|
||||||
/// Create a new storage.
|
/// Create a new storage.
|
||||||
fn empty() -> Self {
|
fn empty() -> Self {
|
||||||
NodeStorage {
|
NodeStorage {
|
||||||
@ -232,7 +237,7 @@ impl<H: Hasher> NodeStorage<H> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, H: Hasher> Index<&'a StorageHandle> for NodeStorage<H> {
|
impl<'a, H> Index<&'a StorageHandle> for NodeStorage<H> {
|
||||||
type Output = Node<H>;
|
type Output = Node<H>;
|
||||||
|
|
||||||
fn index(&self, handle: &'a StorageHandle) -> &Node<H> {
|
fn index(&self, handle: &'a StorageHandle) -> &Node<H> {
|
||||||
@ -284,10 +289,10 @@ where
|
|||||||
H: Hasher + 'a,
|
H: Hasher + 'a,
|
||||||
C: NodeCodec<H>
|
C: NodeCodec<H>
|
||||||
{
|
{
|
||||||
storage: NodeStorage<H>,
|
storage: NodeStorage<H::Out>,
|
||||||
db: &'a mut HashDB<H>,
|
db: &'a mut HashDB<H>,
|
||||||
root: &'a mut H::Out,
|
root: &'a mut H::Out,
|
||||||
root_handle: NodeHandle<H>,
|
root_handle: NodeHandle<H::Out>,
|
||||||
death_row: HashSet<H::Out>,
|
death_row: HashSet<H::Out>,
|
||||||
/// The number of hash operations this trie has performed.
|
/// The number of hash operations this trie has performed.
|
||||||
/// Note that none are performed until changes are committed.
|
/// Note that none are performed until changes are committed.
|
||||||
@ -347,7 +352,7 @@ where
|
|||||||
// cache a node by hash
|
// cache a node by hash
|
||||||
fn cache(&mut self, hash: H::Out) -> Result<StorageHandle, H::Out, C::Error> {
|
fn cache(&mut self, hash: H::Out) -> Result<StorageHandle, H::Out, C::Error> {
|
||||||
let node_encoded = self.db.get(&hash).ok_or_else(|| Box::new(TrieError::IncompleteDatabase(hash)))?;
|
let node_encoded = self.db.get(&hash).ok_or_else(|| Box::new(TrieError::IncompleteDatabase(hash)))?;
|
||||||
let node = Node::from_encoded::<C>(
|
let node = Node::from_encoded::<C, H>(
|
||||||
&node_encoded,
|
&node_encoded,
|
||||||
&*self.db,
|
&*self.db,
|
||||||
&mut self.storage
|
&mut self.storage
|
||||||
@ -357,8 +362,8 @@ where
|
|||||||
|
|
||||||
// inspect a node, choosing either to replace, restore, or delete it.
|
// inspect a node, choosing either to replace, restore, or delete it.
|
||||||
// if restored or replaced, returns the new node along with a flag of whether it was changed.
|
// if restored or replaced, returns the new node along with a flag of whether it was changed.
|
||||||
fn inspect<F>(&mut self, stored: Stored<H>, inspector: F) -> Result<Option<(Stored<H>, bool)>, H::Out, C::Error>
|
fn inspect<F>(&mut self, stored: Stored<H::Out>, inspector: F) -> Result<Option<(Stored<H::Out>, bool)>, H::Out, C::Error>
|
||||||
where F: FnOnce(&mut Self, Node<H>) -> Result<Action<H>, H::Out, C::Error> {
|
where F: FnOnce(&mut Self, Node<H::Out>) -> Result<Action<H::Out>, H::Out, C::Error> {
|
||||||
Ok(match stored {
|
Ok(match stored {
|
||||||
Stored::New(node) => match inspector(self, node)? {
|
Stored::New(node) => match inspector(self, node)? {
|
||||||
Action::Restore(node) => Some((Stored::New(node), false)),
|
Action::Restore(node) => Some((Stored::New(node), false)),
|
||||||
@ -380,7 +385,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
// walk the trie, attempting to find the key's node.
|
// walk the trie, attempting to find the key's node.
|
||||||
fn lookup<'x, 'key>(&'x self, mut partial: NibbleSlice<'key>, handle: &NodeHandle<H>) -> Result<Option<DBValue>, H::Out, C::Error>
|
fn lookup<'x, 'key>(&'x self, mut partial: NibbleSlice<'key>, handle: &NodeHandle<H::Out>) -> Result<Option<DBValue>, H::Out, C::Error>
|
||||||
where 'x: 'key
|
where 'x: 'key
|
||||||
{
|
{
|
||||||
let mut handle = handle;
|
let mut handle = handle;
|
||||||
@ -429,7 +434,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// insert a key-value pair into the trie, creating new nodes if necessary.
|
/// insert a key-value pair into the trie, creating new nodes if necessary.
|
||||||
fn insert_at(&mut self, handle: NodeHandle<H>, partial: NibbleSlice, value: DBValue, old_val: &mut Option<DBValue>) -> Result<(StorageHandle, bool), H::Out, C::Error> {
|
fn insert_at(&mut self, handle: NodeHandle<H::Out>, partial: NibbleSlice, value: DBValue, old_val: &mut Option<DBValue>) -> Result<(StorageHandle, bool), H::Out, C::Error> {
|
||||||
let h = match handle {
|
let h = match handle {
|
||||||
NodeHandle::InMemory(h) => h,
|
NodeHandle::InMemory(h) => h,
|
||||||
NodeHandle::Hash(h) => self.cache(h)?,
|
NodeHandle::Hash(h) => self.cache(h)?,
|
||||||
@ -443,7 +448,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// the insertion inspector.
|
/// the insertion inspector.
|
||||||
fn insert_inspector(&mut self, node: Node<H>, partial: NibbleSlice, value: DBValue, old_val: &mut Option<DBValue>) -> Result<InsertAction<H>, H::Out, C::Error> {
|
fn insert_inspector(&mut self, node: Node<H::Out>, partial: NibbleSlice, value: DBValue, old_val: &mut Option<DBValue>) -> Result<InsertAction<H::Out>, H::Out, C::Error> {
|
||||||
trace!(target: "trie", "augmented (partial: {:?}, value: {:?})", partial, value.pretty());
|
trace!(target: "trie", "augmented (partial: {:?}, value: {:?})", partial, value.pretty());
|
||||||
|
|
||||||
Ok(match node {
|
Ok(match node {
|
||||||
@ -604,7 +609,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Remove a node from the trie based on key.
|
/// Remove a node from the trie based on key.
|
||||||
fn remove_at(&mut self, handle: NodeHandle<H>, partial: NibbleSlice, old_val: &mut Option<DBValue>) -> Result<Option<(StorageHandle, bool)>, H::Out, C::Error> {
|
fn remove_at(&mut self, handle: NodeHandle<H::Out>, partial: NibbleSlice, old_val: &mut Option<DBValue>) -> Result<Option<(StorageHandle, bool)>, H::Out, C::Error> {
|
||||||
let stored = match handle {
|
let stored = match handle {
|
||||||
NodeHandle::InMemory(h) => self.storage.destroy(h),
|
NodeHandle::InMemory(h) => self.storage.destroy(h),
|
||||||
NodeHandle::Hash(h) => {
|
NodeHandle::Hash(h) => {
|
||||||
@ -619,7 +624,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// the removal inspector
|
/// the removal inspector
|
||||||
fn remove_inspector(&mut self, node: Node<H>, partial: NibbleSlice, old_val: &mut Option<DBValue>) -> Result<Action<H>, H::Out, C::Error> {
|
fn remove_inspector(&mut self, node: Node<H::Out>, partial: NibbleSlice, old_val: &mut Option<DBValue>) -> Result<Action<H::Out>, H::Out, C::Error> {
|
||||||
Ok(match (node, partial.is_empty()) {
|
Ok(match (node, partial.is_empty()) {
|
||||||
(Node::Empty, _) => Action::Delete,
|
(Node::Empty, _) => Action::Delete,
|
||||||
(Node::Branch(c, None), true) => Action::Restore(Node::Branch(c, None)),
|
(Node::Branch(c, None), true) => Action::Restore(Node::Branch(c, None)),
|
||||||
@ -705,7 +710,7 @@ where
|
|||||||
/// _invalid state_ means:
|
/// _invalid state_ means:
|
||||||
/// - Branch node where there is only a single entry;
|
/// - Branch node where there is only a single entry;
|
||||||
/// - Extension node followed by anything other than a Branch node.
|
/// - Extension node followed by anything other than a Branch node.
|
||||||
fn fix(&mut self, node: Node<H>) -> Result<Node<H>, H::Out, C::Error> {
|
fn fix(&mut self, node: Node<H::Out>) -> Result<Node<H::Out>, H::Out, C::Error> {
|
||||||
match node {
|
match node {
|
||||||
Node::Branch(mut children, value) => {
|
Node::Branch(mut children, value) => {
|
||||||
// if only a single value, transmute to leaf/extension and feed through fixed.
|
// if only a single value, transmute to leaf/extension and feed through fixed.
|
||||||
@ -825,7 +830,7 @@ where
|
|||||||
|
|
||||||
match self.storage.destroy(handle) {
|
match self.storage.destroy(handle) {
|
||||||
Stored::New(node) => {
|
Stored::New(node) => {
|
||||||
let encoded_root = node.into_encoded::<_, C>(|child| self.commit_child(child) );
|
let encoded_root = node.into_encoded::<_, C, H>(|child| self.commit_child(child) );
|
||||||
*self.root = self.db.insert(&encoded_root[..]);
|
*self.root = self.db.insert(&encoded_root[..]);
|
||||||
self.hash_count += 1;
|
self.hash_count += 1;
|
||||||
|
|
||||||
@ -845,14 +850,14 @@ where
|
|||||||
/// case where we can fit the actual data in the `Hasher`s output type, we
|
/// case where we can fit the actual data in the `Hasher`s output type, we
|
||||||
/// store the data inline. This function is used as the callback to the
|
/// store the data inline. This function is used as the callback to the
|
||||||
/// `into_encoded` method of `Node`.
|
/// `into_encoded` method of `Node`.
|
||||||
fn commit_child(&mut self, handle: NodeHandle<H>) -> ChildReference<H::Out> {
|
fn commit_child(&mut self, handle: NodeHandle<H::Out>) -> ChildReference<H::Out> {
|
||||||
match handle {
|
match handle {
|
||||||
NodeHandle::Hash(hash) => ChildReference::Hash(hash),
|
NodeHandle::Hash(hash) => ChildReference::Hash(hash),
|
||||||
NodeHandle::InMemory(storage_handle) => {
|
NodeHandle::InMemory(storage_handle) => {
|
||||||
match self.storage.destroy(storage_handle) {
|
match self.storage.destroy(storage_handle) {
|
||||||
Stored::Cached(_, hash) => ChildReference::Hash(hash),
|
Stored::Cached(_, hash) => ChildReference::Hash(hash),
|
||||||
Stored::New(node) => {
|
Stored::New(node) => {
|
||||||
let encoded = node.into_encoded::<_, C>(|node_handle| self.commit_child(node_handle) );
|
let encoded = node.into_encoded::<_, C, H>(|node_handle| self.commit_child(node_handle) );
|
||||||
if encoded.len() >= H::LENGTH {
|
if encoded.len() >= H::LENGTH {
|
||||||
let hash = self.db.insert(&encoded[..]);
|
let hash = self.db.insert(&encoded[..]);
|
||||||
self.hash_count +=1;
|
self.hash_count +=1;
|
||||||
@ -871,7 +876,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
// a hack to get the root node's handle
|
// a hack to get the root node's handle
|
||||||
fn root_handle(&self) -> NodeHandle<H> {
|
fn root_handle(&self) -> NodeHandle<H::Out> {
|
||||||
match self.root_handle {
|
match self.root_handle {
|
||||||
NodeHandle::Hash(h) => NodeHandle::Hash(h),
|
NodeHandle::Hash(h) => NodeHandle::Hash(h),
|
||||||
NodeHandle::InMemory(StorageHandle(x)) => NodeHandle::InMemory(StorageHandle(x)),
|
NodeHandle::InMemory(StorageHandle(x)) => NodeHandle::InMemory(StorageHandle(x)),
|
||||||
|
Loading…
Reference in New Issue
Block a user