Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
triehash is separated from util (#6428)
Browse files Browse the repository at this point in the history
  • Loading branch information
debris authored and gavofyork committed Sep 3, 2017
1 parent 7b8af30 commit b731cce
Show file tree
Hide file tree
Showing 24 changed files with 124 additions and 139 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ bloomable = { path = "../util/bloomable" }
vm = { path = "vm" }
wasm = { path = "wasm" }
hash = { path = "../util/hash" }
triehash = { path = "../util/triehash" }
semantic_version = { path = "../util/semantic_version" }

[dev-dependencies]
Expand Down
1 change: 1 addition & 0 deletions ethcore/light/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ serde_derive = "1.0"
parking_lot = "0.4"
stats = { path = "../../util/stats" }
hash = { path = "../../util/hash" }
triehash = { path = "../../util/triehash" }

[features]
default = []
Expand Down
2 changes: 1 addition & 1 deletion ethcore/light/src/cht.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub fn compute_root<I>(cht_num: u64, iterable: I) -> Option<H256>
}

if v.len() == SIZE as usize {
Some(::util::triehash::trie_root(v))
Some(::triehash::trie_root(v))
} else {
None
}
Expand Down
1 change: 1 addition & 0 deletions ethcore/light/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ extern crate stats;
extern crate time;
extern crate vm;
extern crate hash;
extern crate triehash;

#[cfg(feature = "ipc")]
extern crate ethcore_ipc as ipc;
Expand Down
6 changes: 3 additions & 3 deletions ethcore/light/src/on_demand/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ impl Body {
pub fn check_response(&self, cache: &Mutex<::cache::Cache>, body: &encoded::Body) -> Result<encoded::Block, Error> {
// check the integrity of the the body against the header
let header = self.0.as_ref()?;
let tx_root = ::util::triehash::ordered_trie_root(body.rlp().at(0).iter().map(|r| r.as_raw().to_vec()));
let tx_root = ::triehash::ordered_trie_root(body.rlp().at(0).iter().map(|r| r.as_raw().to_vec()));
if tx_root != header.transactions_root() {
return Err(Error::WrongTrieRoot(header.transactions_root(), tx_root));
}
Expand Down Expand Up @@ -739,7 +739,7 @@ impl BlockReceipts {
/// Check a response with receipts against the stored header.
pub fn check_response(&self, cache: &Mutex<::cache::Cache>, receipts: &[Receipt]) -> Result<Vec<Receipt>, Error> {
let receipts_root = self.0.as_ref()?.receipts_root();
let found_root = ::util::triehash::ordered_trie_root(receipts.iter().map(|r| ::rlp::encode(r).into_vec()));
let found_root = ::triehash::ordered_trie_root(receipts.iter().map(|r| ::rlp::encode(r).into_vec()));

match receipts_root == found_root {
true => {
Expand Down Expand Up @@ -936,7 +936,7 @@ mod tests {
}).collect::<Vec<_>>();

let mut header = Header::new();
let receipts_root = ::util::triehash::ordered_trie_root(
let receipts_root = ::triehash::ordered_trie_root(
receipts.iter().map(|x| ::rlp::encode(x).into_vec())
);

Expand Down
3 changes: 2 additions & 1 deletion ethcore/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ use std::cmp;
use std::sync::Arc;
use std::collections::HashSet;
use hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP};
use triehash::ordered_trie_root;

use rlp::{UntrustedRlp, RlpStream, Encodable, Decodable, DecoderError};
use util::{Bytes, Address, U256, H256, ordered_trie_root};
use util::{Bytes, Address, U256, H256};
use util::error::{Mismatch, OutOfBounds};

use basic_types::{LogBloom, Seal};
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/engines/validator_set/safe_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl ValidatorSet for ValidatorSafeContract {

// ensure receipts match header.
// TODO: optimize? these were just decoded.
let found_root = ::util::triehash::ordered_trie_root(
let found_root = ::triehash::ordered_trie_root(
receipts.iter().map(::rlp::encode).map(|x| x.to_vec())
);
if found_root != *old_header.receipts_root() {
Expand Down
1 change: 1 addition & 0 deletions ethcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ extern crate rand;
extern crate rlp;
extern crate hash;
extern crate heapsize;
extern crate triehash;
extern crate ansi_term;
extern crate semantic_version;

Expand Down
1 change: 1 addition & 0 deletions ethcore/src/pod_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::fmt;
use std::collections::BTreeMap;
use itertools::Itertools;
use hash::{keccak};
use triehash::sec_trie_root;
use util::*;
use state::Account;
use ethjson;
Expand Down
1 change: 1 addition & 0 deletions ethcore/src/pod_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use std::fmt;
use std::collections::BTreeMap;
use itertools::Itertools;
use triehash::sec_trie_root;
use util::*;
use pod_account::{self, PodAccount};
use types::state_diff::StateDiff;
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/snapshot/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use hash::keccak;
use views::BlockView;
use rlp::{DecoderError, RlpStream, UntrustedRlp};
use util::{Bytes, H256};
use util::triehash::ordered_trie_root;
use triehash::ordered_trie_root;

const HEADER_FIELDS: usize = 8;
const BLOCK_FIELDS: usize = 2;
Expand Down Expand Up @@ -190,7 +190,7 @@ mod tests {
b.transactions.push(t2.into());

let receipts_root = b.header.receipts_root().clone();
b.header.set_transactions_root(::util::triehash::ordered_trie_root(
b.header.set_transactions_root(::triehash::ordered_trie_root(
b.transactions.iter().map(::rlp::encode).map(|out| out.into_vec())
));

Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/snapshot/consensus/work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl Rebuilder for PowRebuilder {
use views::BlockView;
use snapshot::verify_old_block;
use util::U256;
use util::triehash::ordered_trie_root;
use triehash::ordered_trie_root;

let rlp = UntrustedRlp::new(chunk);
let item_count = rlp.item_count()?;
Expand Down
2 changes: 2 additions & 0 deletions ethcore/src/verification/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use std::collections::HashSet;
use hash::keccak;
use triehash::ordered_trie_root;
use heapsize::HeapSizeOf;
use util::*;
use engines::Engine;
Expand Down Expand Up @@ -269,6 +270,7 @@ fn verify_block_integrity(block: &[u8], transactions_root: &H256, uncles_hash: &
mod tests {
use std::collections::{BTreeMap, HashMap};
use hash::keccak;
use triehash::ordered_trie_root;
use util::*;
use ethkey::{Random, Generator};
use header::*;
Expand Down
1 change: 1 addition & 0 deletions sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ethcore-light = { path = "../ethcore/light"}
ethcore = { path = "../ethcore" }
rlp = { path = "../util/rlp" }
hash = { path = "../util/hash" }
triehash = { path = "../util/triehash" }
clippy = { version = "0.0.103", optional = true}
log = "0.3"
env_logger = "0.4"
Expand Down
1 change: 1 addition & 0 deletions sync/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::collections::hash_map::Entry;
use smallvec::SmallVec;
use hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP};
use heapsize::HeapSizeOf;
use triehash::ordered_trie_root;
use util::*;
use rlp::*;
use network::NetworkError;
Expand Down
1 change: 1 addition & 0 deletions sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extern crate smallvec;
extern crate rlp;
extern crate ipnetwork;
extern crate hash;
extern crate triehash;

extern crate ethcore_light as light;

Expand Down
1 change: 1 addition & 0 deletions util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ ethcore-bloom-journal = { path = "bloom" }
regex = "0.2"
lru-cache = "0.1.0"
ethcore-logger = { path = "../logger" }
triehash = { path = "triehash" }

[features]
default = []
Expand Down
3 changes: 2 additions & 1 deletion util/benches/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#![feature(test)]

extern crate test;
extern crate triehash;
extern crate ethcore_util;
#[macro_use]
extern crate log;
Expand All @@ -27,7 +28,7 @@ use ethcore_util::hash::*;
use ethcore_util::bytes::*;
use ethcore_util::trie::*;
use ethcore_util::memorydb::*;
use ethcore_util::triehash::*;
use triehash::*;
use hash::keccak;

fn random_word(alphabet: &[u8], min_count: usize, diff_count: usize, seed: &mut H256) -> Vec<u8> {
Expand Down
4 changes: 0 additions & 4 deletions util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,12 @@ pub mod common;
pub mod error;
pub mod bytes;
pub mod misc;
pub mod vector;
pub mod hashdb;
pub mod memorydb;
pub mod migration;
pub mod overlaydb;
pub mod journaldb;
pub mod kvdb;
pub mod triehash;
pub mod trie;
pub mod nibbleslice;
pub mod nibblevec;
Expand All @@ -136,12 +134,10 @@ pub use hashdb::*;
pub use memorydb::MemoryDB;
pub use overlaydb::*;
pub use journaldb::JournalDB;
pub use triehash::*;
pub use trie::{Trie, TrieMut, TrieDB, TrieDBMut, TrieFactory, TrieError, SecTrieDB, SecTrieDBMut};
pub use kvdb::*;
pub use error::*;
pub use bytes::*;
pub use vector::*;
pub use bigint::prelude::*;
pub use bigint::hash;

Expand Down
3 changes: 2 additions & 1 deletion util/src/trie/triedbmut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,8 @@ impl<'a> Drop for TrieDBMut<'a> {

#[cfg(test)]
mod tests {
use triehash::trie_root;
extern crate triehash;
use self::triehash::trie_root;
use hashdb::*;
use memorydb::*;
use super::*;
Expand Down
68 changes: 0 additions & 68 deletions util/src/vector.rs

This file was deleted.

9 changes: 9 additions & 0 deletions util/triehash/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "triehash"
version = "0.1.0"
authors = ["Parity Technologies <[email protected]>"]

[dependencies]
rlp = { path = "../rlp" }
ethcore-bigint = { path = "../bigint" }
hash = { path = "../hash" }
Loading

0 comments on commit b731cce

Please sign in to comment.