always process trie death row on commit, add more tracing

This commit is contained in:
Robert Habermeier 2016-08-31 14:28:56 +02:00
parent 6da60afaba
commit c61da07516
2 changed files with 21 additions and 13 deletions

View File

@ -498,7 +498,7 @@ pub fn enact(
{
if ::log::max_log_level() >= ::log::LogLevel::Trace {
let s = try!(State::from_existing(db.boxed_clone(), parent.state_root().clone(), engine.account_start_nonce(), factories.clone()));
trace!("enact(): root={}, author={}, author_balance={}\n", s.root(), header.author(), s.balance(&header.author()));
trace!(target: "enact", "num={}, root={}, author={}, author_balance={}\n", header.number(), s.root(), header.author(), s.balance(&header.author()));
}
}

View File

@ -56,11 +56,11 @@ impl From<H256> for NodeHandle {
}
}
fn empty_children() -> [Option<NodeHandle>; 16] {
[
fn empty_children() -> Box<[Option<NodeHandle>; 16]> {
Box::new([
None, None, None, None, None, None, None, None,
None, None, None, None, None, None, None, None,
]
])
}
/// Node types in the Trie.
@ -78,7 +78,7 @@ enum Node {
/// The child node is always a branch.
Extension(Bytes, NodeHandle),
/// A branch has up to 16 children and an optional value.
Branch([Option<NodeHandle>; 16], Option<Bytes>)
Branch(Box<[Option<NodeHandle>; 16]>, Option<Bytes>)
}
impl Node {
@ -820,19 +820,19 @@ impl<'a> TrieDBMut<'a> {
/// Commit the in-memory changes to disk, freeing their storage and
/// updating the state root.
pub fn commit(&mut self) {
let handle = match self.root_handle() {
NodeHandle::Hash(_) => return, // no changes necessary.
NodeHandle::InMemory(h) => h,
};
trace!(target: "trie", "Committing trie changes to db.");
// kill all the nodes on death row.
// always kill all the nodes on death row.
trace!(target: "trie", "{:?} nodes to remove from db", self.death_row.len());
for hash in self.death_row.drain() {
self.db.remove(&hash);
}
let handle = match self.root_handle() {
NodeHandle::Hash(_) => return, // no changes necessary.
NodeHandle::InMemory(h) => h,
};
match self.storage.destroy(handle) {
Stored::New(node) => {
let root_rlp = node.into_rlp(|child, stream| self.commit_node(child, stream));
@ -906,21 +906,29 @@ impl<'a> TrieMut for TrieDBMut<'a> {
return self.remove(key);
}
trace!(target: "trie", "insert: key={:?}, value={:?}", key.pretty(), value.pretty());
let root_handle = self.root_handle();
let (new_handle, _) = try!(self.insert_at(root_handle, NibbleSlice::new(key), value.to_owned()));
let (new_handle, changed) = try!(self.insert_at(root_handle, NibbleSlice::new(key), value.to_owned()));
trace!(target: "trie", "insert: altered trie={}", changed);
self.root_handle = NodeHandle::InMemory(new_handle);
Ok(())
}
fn remove(&mut self, key: &[u8]) -> super::Result<()> {
trace!(target: "trie", "remove: key={:?}", key.pretty());
let root_handle = self.root_handle();
let key = NibbleSlice::new(key);
match try!(self.remove_at(root_handle, key)) {
Some((handle, _)) => {
Some((handle, changed)) => {
trace!(target: "trie", "remove: altered trie={}", changed);
self.root_handle = NodeHandle::InMemory(handle);
}
None => {
trace!(target: "trie", "remove: obliterated trie");
self.root_handle = NodeHandle::Hash(SHA3_NULL_RLP);
*self.root = SHA3_NULL_RLP;
}