From 4101396fc431854d77671c68b595e2c613ddec9f Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 29 Dec 2016 11:06:00 +0100 Subject: [PATCH] remove node journal: dead code --- util/src/trie/journal.rs | 103 --------------------------------------- util/src/trie/mod.rs | 2 - util/src/trie/node.rs | 41 ---------------- 3 files changed, 146 deletions(-) delete mode 100644 util/src/trie/journal.rs diff --git a/util/src/trie/journal.rs b/util/src/trie/journal.rs deleted file mode 100644 index c863dd8a4..000000000 --- a/util/src/trie/journal.rs +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2015, 2016 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . - -use std::default::Default; -use sha3::*; -use hash::H256; -use bytes::*; -use rlp::*; -use hashdb::*; - -/// Type of operation for the backing database - either a new node or a node deletion. -#[derive(Debug)] -enum Operation { - New(H256, DBValue), - Delete(H256), -} - -/// How many insertions and removals were done in an `apply` operation. -pub struct Score { - /// Number of insertions. - pub inserts: usize, - /// Number of removals. - pub removes: usize, -} - -/// A journal of operations on the backing database. -#[derive(Debug)] -pub struct Journal (Vec); - -impl Default for Journal { - fn default() -> Self { - Journal::new() - } -} - -impl Journal { - /// Create a new, empty, object. - pub fn new() -> Journal { Journal(vec![]) } - - /// Given the RLP that encodes a node, append a reference to that node `out` and leave `journal` - /// such that the reference is valid, once applied. - pub fn new_node(&mut self, rlp: DBValue, out: &mut RlpStream) { - if rlp.len() >= 32 { - let rlp_sha3 = rlp.sha3(); - - trace!("new_node: reference node {:?} => {:?}", rlp_sha3, &*rlp); - out.append(&rlp_sha3); - self.0.push(Operation::New(rlp_sha3, rlp)); - } - else { - trace!("new_node: inline node {:?}", &*rlp); - out.append_raw(&rlp, 1); - } - } - - /// Given the RLP that encodes a now-unused node, leave `journal` in such a state that it is noted. - pub fn delete_node_sha3(&mut self, old_sha3: H256) { - trace!("delete_node: {:?}", old_sha3); - self.0.push(Operation::Delete(old_sha3)); - } - - /// Register an RLP-encoded node for deletion (given a slice), if it needs to be deleted. - pub fn delete_node(&mut self, old: &[u8]) { - let r = Rlp::new(old); - if r.is_data() && r.size() == 32 { - self.delete_node_sha3(r.as_val()); - } - } - - /// Apply this journal to the HashDB `db` and return the number of insertions and removals done. - pub fn apply(self, db: &mut HashDB) -> Score { - trace!("applying {:?} changes", self.0.len()); - let mut ret = Score{inserts: 0, removes: 0}; - for d in self.0 { - match d { - Operation::Delete(h) => { - trace!("TrieDBMut::apply --- {:?}", &h); - db.remove(&h); - ret.removes += 1; - }, - Operation::New(h, d) => { - trace!("TrieDBMut::apply +++ {:?} -> {:?}", &h, d.pretty()); - db.emplace(h, d); - ret.inserts += 1; - } - } - } - ret - } -} diff --git a/util/src/trie/mod.rs b/util/src/trie/mod.rs index 6a0e588c3..151760c8c 100644 --- a/util/src/trie/mod.rs +++ b/util/src/trie/mod.rs @@ -22,8 +22,6 @@ use hashdb::{HashDB, DBValue}; /// Export the standardmap module. pub mod standardmap; -/// Export the journal module. -pub mod journal; /// Export the node module. pub mod node; /// Export the triedb module. diff --git a/util/src/trie/node.rs b/util/src/trie/node.rs index e21fc8b3f..44f1f3bfa 100644 --- a/util/src/trie/node.rs +++ b/util/src/trie/node.rs @@ -18,7 +18,6 @@ use elastic_array::ElasticArray36; use nibbleslice::*; use bytes::*; use rlp::*; -use super::journal::*; use hashdb::DBValue; /// Partial node key type. @@ -123,44 +122,4 @@ impl Node { } } } - - /// Encode the node, adding it to `journal` if necessary and return the RLP valid for - /// insertion into a parent node. - pub fn encoded_and_added(&self, journal: &mut Journal) -> DBValue { - let mut stream = RlpStream::new(); - match *self { - Node::Leaf(ref slice, ref value) => { - stream.begin_list(2); - stream.append(&&**slice); - stream.append(&&**value); - }, - Node::Extension(ref slice, ref raw_rlp) => { - stream.begin_list(2); - stream.append(&&**slice); - stream.append_raw(&&**raw_rlp, 1); - }, - Node::Branch(ref nodes, ref value) => { - stream.begin_list(17); - for i in 0..16 { - stream.append_raw(&*nodes[i], 1); - } - match *value { - Some(ref n) => { stream.append(&&**n); }, - None => { stream.append_empty_data(); }, - } - }, - Node::Empty => { - stream.append_empty_data(); - } - } - let node = DBValue::from_slice(stream.as_raw()); - match node.len() { - 0 ... 31 => node, - _ => { - let mut stream = RlpStream::new(); - journal.new_node(node, &mut stream); - DBValue::from_slice(stream.as_raw()) - } - } - } }