From 5dd56aa070600f0b591764b822c68c779a0770ad Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 1 Sep 2016 14:29:59 +0200 Subject: [PATCH] port ethcore --- ethcore/src/account_db.rs | 2 +- ethcore/src/block.rs | 1 + ethcore/src/blockchain/blockchain.rs | 1 + ethcore/src/blockchain/extras.rs | 1 + ethcore/src/blockchain/generator/block.rs | 2 +- ethcore/src/blooms/bloom.rs | 2 +- ethcore/src/blooms/bloom_group.rs | 2 +- ethcore/src/client/client.rs | 11 ++++++----- ethcore/src/client/test_client.rs | 11 ++++++----- ethcore/src/db.rs | 21 +++++++++++---------- ethcore/src/engines/basic_authority.rs | 8 +++++--- ethcore/src/engines/instant_seal.rs | 2 +- ethcore/src/error.rs | 4 ++-- ethcore/src/ethereum/ethash.rs | 8 +++++--- ethcore/src/executive.rs | 2 ++ ethcore/src/header.rs | 9 +++++---- ethcore/src/json_tests/transaction.rs | 1 + ethcore/src/migrations/blocks/v8.rs | 2 +- ethcore/src/migrations/state/v7.rs | 4 +++- ethcore/src/migrations/v9.rs | 2 +- ethcore/src/miner/transaction_queue.rs | 4 +++- ethcore/src/pod_account.rs | 5 +++-- ethcore/src/snapshot/account.rs | 11 ++++++----- ethcore/src/snapshot/block.rs | 6 +++--- ethcore/src/snapshot/error.rs | 2 +- ethcore/src/snapshot/io.rs | 2 +- ethcore/src/snapshot/mod.rs | 4 ++-- ethcore/src/snapshot/tests/helpers.rs | 2 +- ethcore/src/spec/genesis.rs | 2 +- ethcore/src/spec/seal.rs | 2 +- ethcore/src/spec/spec.rs | 1 + ethcore/src/state/account.rs | 2 ++ ethcore/src/tests/client.rs | 1 + ethcore/src/tests/helpers.rs | 3 ++- ethcore/src/trace/bloom.rs | 2 +- ethcore/src/types/executed.rs | 5 +++-- ethcore/src/types/log_entry.rs | 3 ++- ethcore/src/types/receipt.rs | 3 ++- ethcore/src/types/trace_types/flat.rs | 7 +++---- ethcore/src/types/trace_types/trace.rs | 3 ++- ethcore/src/types/transaction.rs | 4 ++-- ethcore/src/verification/verification.rs | 6 +++++- ethcore/src/views/block.rs | 1 + ethcore/src/views/body.rs | 1 + ethcore/src/views/header.rs | 3 ++- ethcore/src/views/transaction.rs | 3 ++- util/src/sha3.rs | 6 +++--- 47 files changed, 113 insertions(+), 77 deletions(-) diff --git a/ethcore/src/account_db.rs b/ethcore/src/account_db.rs index 32c7acbb7..a02b670d0 100644 --- a/ethcore/src/account_db.rs +++ b/ethcore/src/account_db.rs @@ -16,7 +16,7 @@ //! DB backend wrapper for Account trie use util::*; -use util::sha3::SHA3_NULL_RLP; +use rlp::NULL_RLP; static NULL_RLP_STATIC: [u8; 1] = [0x80; 1]; diff --git a/ethcore/src/block.rs b/ethcore/src/block.rs index d3b4ac168..0b42d6838 100644 --- a/ethcore/src/block.rs +++ b/ethcore/src/block.rs @@ -22,6 +22,7 @@ use state::*; use verification::PreverifiedBlock; use trace::FlatTrace; use factory::Factories; +use rlp::*; /// A block, encoded as it is on the block chain. #[derive(Default, Debug, Clone, PartialEq)] diff --git a/ethcore/src/blockchain/blockchain.rs b/ethcore/src/blockchain/blockchain.rs index 943dc04c5..ef26a6b08 100644 --- a/ethcore/src/blockchain/blockchain.rs +++ b/ethcore/src/blockchain/blockchain.rs @@ -18,6 +18,7 @@ use bloomchain as bc; use util::*; +use rlp::*; use header::*; use super::extras::*; use transaction::*; diff --git a/ethcore/src/blockchain/extras.rs b/ethcore/src/blockchain/extras.rs index e2b4e89b3..6dc7aef98 100644 --- a/ethcore/src/blockchain/extras.rs +++ b/ethcore/src/blockchain/extras.rs @@ -18,6 +18,7 @@ use bloomchain; use util::*; +use rlp::*; use header::BlockNumber; use receipt::Receipt; use db::Key; diff --git a/ethcore/src/blockchain/generator/block.rs b/ethcore/src/blockchain/generator/block.rs index 1fb9c13a1..6b8aa78f2 100644 --- a/ethcore/src/blockchain/generator/block.rs +++ b/ethcore/src/blockchain/generator/block.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use util::rlp::*; +use rlp::*; use util::{H256, H2048}; use util::bytes::Bytes; use header::Header; diff --git a/ethcore/src/blooms/bloom.rs b/ethcore/src/blooms/bloom.rs index 83d898ab5..b535bcb21 100644 --- a/ethcore/src/blooms/bloom.rs +++ b/ethcore/src/blooms/bloom.rs @@ -15,7 +15,7 @@ // along with Parity. If not, see . use bloomchain as bc; -use util::rlp::*; +use rlp::*; use util::HeapSizeOf; use basic_types::LogBloom; diff --git a/ethcore/src/blooms/bloom_group.rs b/ethcore/src/blooms/bloom_group.rs index 8e2b87189..9e3b53f18 100644 --- a/ethcore/src/blooms/bloom_group.rs +++ b/ethcore/src/blooms/bloom_group.rs @@ -15,7 +15,7 @@ // along with Parity. If not, see . use bloomchain::group as bc; -use util::rlp::*; +use rlp::*; use util::HeapSizeOf; use super::Bloom; diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index edd671b70..554afab38 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -22,11 +22,11 @@ use std::time::{Instant}; use time::precise_time_ns; // util -use util::{journaldb, rlp, Bytes, View, PerfTimer, Itertools, Mutex, RwLock}; -use util::journaldb::JournalDB; -use util::rlp::{UntrustedRlp}; +use util::{Bytes, PerfTimer, Itertools, Mutex, RwLock}; +use util::journaldb::{self, JournalDB}; use util::{U256, H256, Address, H2048, Uint}; use util::sha3::*; +use util::TrieFactory; use util::kvdb::*; // other @@ -63,9 +63,10 @@ use trace; use trace::FlatTransactionTraces; use evm::Factory as EvmFactory; use miner::{Miner, MinerService}; -use util::TrieFactory; use snapshot::{self, io as snapshot_io}; use factory::Factories; +use rlp::{View, UntrustedRlp}; + // re-export pub use types::blockchain_info::BlockChainInfo; @@ -877,7 +878,7 @@ impl BlockChainClient for Client { } fn block_receipts(&self, hash: &H256) -> Option { - self.chain.block_receipts(hash).map(|receipts| rlp::encode(&receipts).to_vec()) + self.chain.block_receipts(hash).map(|receipts| ::rlp::encode(&receipts).to_vec()) } fn import_block(&self, bytes: Bytes) -> Result { diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index fb7f9083e..aa45ed985 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -18,6 +18,7 @@ use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrder}; use util::*; +use rlp::*; use ethkey::{Generator, Random}; use devtools::*; use transaction::{Transaction, LocalizedTransaction, SignedTransaction, Action}; @@ -204,7 +205,7 @@ impl TestBlockChainClient { txs.append(&signed_tx); txs.out() }, - _ => rlp::EMPTY_LIST_RLP.to_vec() + _ => ::rlp::EMPTY_LIST_RLP.to_vec() }; let mut rlp = RlpStream::new_list(3); @@ -222,8 +223,8 @@ impl TestBlockChainClient { header.set_extra_data(b"This extra data is way too long to be considered valid".to_vec()); let mut rlp = RlpStream::new_list(3); rlp.append(&header); - rlp.append_raw(&rlp::NULL_RLP, 1); - rlp.append_raw(&rlp::NULL_RLP, 1); + rlp.append_raw(&::rlp::NULL_RLP, 1); + rlp.append_raw(&::rlp::NULL_RLP, 1); self.blocks.write().insert(hash, rlp.out()); } @@ -234,8 +235,8 @@ impl TestBlockChainClient { header.set_parent_hash(H256::from(42)); let mut rlp = RlpStream::new_list(3); rlp.append(&header); - rlp.append_raw(&rlp::NULL_RLP, 1); - rlp.append_raw(&rlp::NULL_RLP, 1); + rlp.append_raw(&::rlp::NULL_RLP, 1); + rlp.append_raw(&::rlp::NULL_RLP, 1); self.blocks.write().insert(hash, rlp.out()); } diff --git a/ethcore/src/db.rs b/ethcore/src/db.rs index 7fcf30de3..61cd41bd6 100644 --- a/ethcore/src/db.rs +++ b/ethcore/src/db.rs @@ -20,7 +20,8 @@ use std::ops::Deref; use std::hash::Hash; use std::collections::HashMap; use util::{DBTransaction, Database, RwLock}; -use util::rlp::{encode, Encodable, decode, Decodable}; + +use rlp; // database columns /// Column for State @@ -83,12 +84,12 @@ pub trait Key { /// Should be used to write value into database. pub trait Writable { /// Writes the value into the database. - fn write(&mut self, col: Option, key: &Key, value: &T) where T: Encodable, R: Deref; + fn write(&mut self, col: Option, key: &Key, value: &T) where T: rlp::Encodable, R: Deref; /// Writes the value into the database and updates the cache. fn write_with_cache(&mut self, col: Option, cache: &mut Cache, key: K, value: T, policy: CacheUpdatePolicy) where K: Key + Hash + Eq, - T: Encodable, + T: rlp::Encodable, R: Deref { self.write(col, &key, &value); match policy { @@ -104,7 +105,7 @@ pub trait Writable { /// Writes the values into the database and updates the cache. fn extend_with_cache(&mut self, col: Option, cache: &mut Cache, values: HashMap, policy: CacheUpdatePolicy) where K: Key + Hash + Eq, - T: Encodable, + T: rlp::Encodable, R: Deref { match policy { CacheUpdatePolicy::Overwrite => { @@ -127,13 +128,13 @@ pub trait Writable { pub trait Readable { /// Returns value for given key. fn read(&self, col: Option, key: &Key) -> Option where - T: Decodable, + T: rlp::Decodable, R: Deref; /// Returns value for given key either in cache or in database. fn read_with_cache(&self, col: Option, cache: &RwLock, key: &K) -> Option where K: Key + Eq + Hash + Clone, - T: Clone + Decodable, + T: Clone + rlp::Decodable, C: Cache { { let read = cache.read(); @@ -169,17 +170,17 @@ pub trait Readable { } impl Writable for DBTransaction { - fn write(&mut self, col: Option, key: &Key, value: &T) where T: Encodable, R: Deref { - self.put(col, &key.key(), &encode(value)); + fn write(&mut self, col: Option, key: &Key, value: &T) where T: rlp::Encodable, R: Deref { + self.put(col, &key.key(), &rlp::encode(value)); } } impl Readable for Database { - fn read(&self, col: Option, key: &Key) -> Option where T: Decodable, R: Deref { + fn read(&self, col: Option, key: &Key) -> Option where T: rlp::Decodable, R: Deref { let result = self.get(col, &key.key()); match result { - Ok(option) => option.map(|v| decode(&v)), + Ok(option) => option.map(|v| rlp::decode(&v)), Err(err) => { panic!("db get failed, key: {:?}, err: {:?}", &key.key() as &[u8], err); } diff --git a/ethcore/src/engines/basic_authority.rs b/ethcore/src/engines/basic_authority.rs index 332d947c3..eef3df6b1 100644 --- a/ethcore/src/engines/basic_authority.rs +++ b/ethcore/src/engines/basic_authority.rs @@ -109,7 +109,7 @@ impl Engine for BasicAuthority { let message = header.bare_hash(); // account should be pernamently unlocked, otherwise sealing will fail if let Ok(signature) = ap.sign(*block.header().author(), message) { - return Some(vec![encode(&(&*signature as &[u8])).to_vec()]); + return Some(vec![::rlp::encode(&(&*signature as &[u8])).to_vec()]); } else { trace!(target: "basicauthority", "generate_seal: FAIL: accounts secret key unavailable"); } @@ -131,6 +131,8 @@ impl Engine for BasicAuthority { } fn verify_block_unordered(&self, header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> { + use rlp::{UntrustedRlp, View}; + // check the signature is legit. let sig = try!(UntrustedRlp::new(&header.seal()[0]).as_val::()); let signer = public_to_address(&try!(recover(&sig.into(), &header.bare_hash()))); @@ -172,7 +174,7 @@ impl Engine for BasicAuthority { impl Header { /// Get the none field of the header. pub fn signature(&self) -> H520 { - decode(&self.seal()[0]) + ::rlp::decode(&self.seal()[0]) } } @@ -228,7 +230,7 @@ mod tests { fn can_do_signature_verification_fail() { let engine = new_test_authority().engine; let mut header: Header = Header::default(); - header.set_seal(vec![rlp::encode(&H520::default()).to_vec()]); + header.set_seal(vec![::rlp::encode(&H520::default()).to_vec()]); let verify_result = engine.verify_block_unordered(&header, None); assert!(verify_result.is_err()); diff --git a/ethcore/src/engines/instant_seal.rs b/ethcore/src/engines/instant_seal.rs index e98e87bf5..bdb882ee7 100644 --- a/ethcore/src/engines/instant_seal.rs +++ b/ethcore/src/engines/instant_seal.rs @@ -100,7 +100,7 @@ mod tests { assert!(engine.verify_block_basic(&header, None).is_ok()); - header.set_seal(vec![rlp::encode(&H520::default()).to_vec()]); + header.set_seal(vec![::rlp::encode(&H520::default()).to_vec()]); assert!(engine.verify_block_unordered(&header, None).is_ok()); } diff --git a/ethcore/src/error.rs b/ethcore/src/error.rs index 5c26e2f78..cb3a1cf52 100644 --- a/ethcore/src/error.rs +++ b/ethcore/src/error.rs @@ -302,8 +302,8 @@ impl From for Error { } } -impl From for Error { - fn from(err: DecoderError) -> Error { +impl From<::rlp::DecoderError> for Error { + fn from(err: ::rlp::DecoderError) -> Error { Error::Util(UtilError::Decoder(err)) } } diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 82a74d9ea..4d25f812a 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -21,6 +21,7 @@ use spec::CommonParams; use engines::Engine; use evm::Schedule; use ethjson; +use rlp::{self, UntrustedRlp, View}; /// Ethash params. #[derive(Debug, PartialEq)] @@ -328,17 +329,17 @@ impl Ethash { impl Header { /// Get the none field of the header. pub fn nonce(&self) -> H64 { - decode(&self.seal()[1]) + rlp::decode(&self.seal()[1]) } /// Get the mix hash field of the header. pub fn mix_hash(&self) -> H256 { - decode(&self.seal()[0]) + rlp::decode(&self.seal()[0]) } /// Set the nonce and mix hash fields of the header. pub fn set_nonce_and_mix_hash(&mut self, nonce: &H64, mix_hash: &H256) { - self.set_seal(vec![encode(mix_hash).to_vec(), encode(nonce).to_vec()]); + self.set_seal(vec![rlp::encode(mix_hash).to_vec(), rlp::encode(nonce).to_vec()]); } } @@ -349,6 +350,7 @@ mod tests { use tests::helpers::*; use super::super::new_morden; use super::Ethash; + use rlp; #[test] fn on_close_block() { diff --git a/ethcore/src/executive.rs b/ethcore/src/executive.rs index 53d5460ad..64771f95d 100644 --- a/ethcore/src/executive.rs +++ b/ethcore/src/executive.rs @@ -32,6 +32,8 @@ const MAX_VM_DEPTH_FOR_THREAD: usize = 64; /// Returns new address created from address and given nonce. pub fn contract_address(address: &Address, nonce: &U256) -> Address { + use rlp::{RlpStream, Stream}; + let mut stream = RlpStream::new_list(2); stream.append(address); stream.append(nonce); diff --git a/ethcore/src/header.rs b/ethcore/src/header.rs index 9b0e155f4..04581fac9 100644 --- a/ethcore/src/header.rs +++ b/ethcore/src/header.rs @@ -19,6 +19,7 @@ use util::*; use basic_types::*; use time::get_time; +use rlp::*; use std::cell::RefCell; @@ -297,7 +298,7 @@ impl Encodable for Header { #[cfg(test)] mod tests { use rustc_serialize::hex::FromHex; - use util::rlp::{decode, encode}; + use rlp; use super::Header; #[test] @@ -307,7 +308,7 @@ mod tests { let mix_hash = "a0a0349d8c3df71f1a48a9df7d03fd5f14aeee7d91332c009ecaff0a71ead405bd".from_hex().unwrap(); let nonce = "88ab4e252a7e8c2a23".from_hex().unwrap(); - let header: Header = decode(&header_rlp); + let header: Header = rlp::decode(&header_rlp); let seal_fields = header.seal; assert_eq!(seal_fields.len(), 2); assert_eq!(seal_fields[0], mix_hash); @@ -319,8 +320,8 @@ mod tests { // that's rlp of block header created with ethash engine. let header_rlp = "f901f9a0d405da4e66f1445d455195229624e133f5baafe72b5cf7b3c36c12c8146e98b7a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a05fb2b4bfdef7b314451cb138a534d225c922fc0e5fbe25e451142732c3e25c25a088d2ec6b9860aae1a2c3b299f72b6a5d70d7f7ba4722c78f2c49ba96273c2158a007c6fdfa8eea7e86b81f5b0fc0f78f90cc19f4aa60d323151e0cac660199e9a1b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302008003832fefba82524d84568e932a80a0a0349d8c3df71f1a48a9df7d03fd5f14aeee7d91332c009ecaff0a71ead405bd88ab4e252a7e8c2a23".from_hex().unwrap(); - let header: Header = decode(&header_rlp); - let encoded_header = encode(&header).to_vec(); + let header: Header = rlp::decode(&header_rlp); + let encoded_header = rlp::encode(&header).to_vec(); assert_eq!(header_rlp, encoded_header); } diff --git a/ethcore/src/json_tests/transaction.rs b/ethcore/src/json_tests/transaction.rs index 7c9a3327e..a06e3b5dc 100644 --- a/ethcore/src/json_tests/transaction.rs +++ b/ethcore/src/json_tests/transaction.rs @@ -17,6 +17,7 @@ use super::test_common::*; use evm; use ethjson; +use rlp::{UntrustedRlp, View}; fn do_json_test(json_data: &[u8]) -> Vec { let tests = ethjson::transaction::Test::load(json_data).unwrap(); diff --git a/ethcore/src/migrations/blocks/v8.rs b/ethcore/src/migrations/blocks/v8.rs index 798be0790..21024f93d 100644 --- a/ethcore/src/migrations/blocks/v8.rs +++ b/ethcore/src/migrations/blocks/v8.rs @@ -17,7 +17,7 @@ //! This migration compresses the state db. use util::migration::{SimpleMigration, Progress}; -use util::rlp::{Compressible, UntrustedRlp, View, RlpType}; +use rlp::{Compressible, UntrustedRlp, View, RlpType}; /// Compressing migration. #[derive(Default)] diff --git a/ethcore/src/migrations/state/v7.rs b/ethcore/src/migrations/state/v7.rs index 5395cec09..9327decef 100644 --- a/ethcore/src/migrations/state/v7.rs +++ b/ethcore/src/migrations/state/v7.rs @@ -23,9 +23,11 @@ use util::Bytes; use util::{Address, FixedHash, H256}; use util::kvdb::Database; use util::migration::{Batch, Config, Error, Migration, SimpleMigration, Progress}; -use util::rlp::{decode, Rlp, RlpStream, Stream, View}; use util::sha3::Hashable; +use rlp::{decode, Rlp, RlpStream, Stream, View}; + + // attempt to migrate a key, value pair. None if migration not possible. fn attempt_migrate(mut key_h: H256, val: &[u8]) -> Option { let val_hash = val.sha3(); diff --git a/ethcore/src/migrations/v9.rs b/ethcore/src/migrations/v9.rs index 0c8e77588..d4070d0c0 100644 --- a/ethcore/src/migrations/v9.rs +++ b/ethcore/src/migrations/v9.rs @@ -17,7 +17,7 @@ //! This migration consolidates all databases into single one using Column Families. -use util::{Rlp, RlpStream, View, Stream}; +use rlp::{Rlp, RlpStream, View, Stream}; use util::kvdb::Database; use util::migration::{Batch, Config, Error, Migration, Progress}; diff --git a/ethcore/src/miner/transaction_queue.rs b/ethcore/src/miner/transaction_queue.rs index 5e610da24..fb00a8aa8 100644 --- a/ethcore/src/miner/transaction_queue.rs +++ b/ethcore/src/miner/transaction_queue.rs @@ -1229,6 +1229,8 @@ mod test { #[test] fn should_reject_incorectly_signed_transaction() { + use rlp::{self, RlpStream, Stream}; + // given let mut txq = TransactionQueue::new(); let tx = new_unsigned_tx(123.into(), 1.into()); @@ -1243,7 +1245,7 @@ mod test { s.append(&0u64); // v s.append(&U256::zero()); // r s.append(&U256::zero()); // s - decode(s.as_raw()) + rlp::decode(s.as_raw()) }; // when let res = txq.add(stx, &default_account_details, TransactionOrigin::External); diff --git a/ethcore/src/pod_account.rs b/ethcore/src/pod_account.rs index 797d1a265..2596c5fca 100644 --- a/ethcore/src/pod_account.rs +++ b/ethcore/src/pod_account.rs @@ -19,6 +19,7 @@ use state::Account; use account_db::AccountDBMut; use ethjson; use types::account_diff::*; +use rlp::{self, RlpStream, Stream}; #[derive(Debug, Clone, PartialEq, Eq)] /// An account, expressed as Plain-Old-Data (hence the name). @@ -57,7 +58,7 @@ impl PodAccount { let mut stream = RlpStream::new_list(4); stream.append(&self.nonce); stream.append(&self.balance); - stream.append(&sec_trie_root(self.storage.iter().map(|(k, v)| (k.to_vec(), encode(&U256::from(v.as_slice())).to_vec())).collect())); + stream.append(&sec_trie_root(self.storage.iter().map(|(k, v)| (k.to_vec(), rlp::encode(&U256::from(v.as_slice())).to_vec())).collect())); stream.append(&self.code.as_ref().unwrap_or(&vec![]).sha3()); stream.out() } @@ -71,7 +72,7 @@ impl PodAccount { let mut r = H256::new(); let mut t = SecTrieDBMut::new(db, &mut r); for (k, v) in &self.storage { - if let Err(e) = t.insert(k, &encode(&U256::from(v.as_slice()))) { + if let Err(e) = t.insert(k, &rlp::encode(&U256::from(v.as_slice()))) { warn!("Encountered potential DB corruption: {}", e); } } diff --git a/ethcore/src/snapshot/account.rs b/ethcore/src/snapshot/account.rs index fcd7b6abc..16c59db2e 100644 --- a/ethcore/src/snapshot/account.rs +++ b/ethcore/src/snapshot/account.rs @@ -17,11 +17,12 @@ //! Account state encoding and decoding use account_db::{AccountDB, AccountDBMut}; -use util::{U256, FixedHash, H256, Bytes, HashDB, SHA3_EMPTY}; -use util::rlp::{Rlp, RlpStream, Stream, UntrustedRlp, View}; -use util::trie::{TrieDB, Trie}; use snapshot::Error; +use util::{U256, FixedHash, H256, Bytes, HashDB, SHA3_EMPTY}; +use util::trie::{TrieDB, Trie}; +use rlp::{Rlp, RlpStream, Stream, UntrustedRlp, View}; + use std::collections::{HashMap, HashSet}; // whether an encoded account has code and how it is referred to. @@ -206,9 +207,9 @@ mod tests { use tests::helpers::get_temp_journal_db; use snapshot::tests::helpers::fill_storage; - use util::{SHA3_NULL_RLP, SHA3_EMPTY}; + use util::sha3::{SHA3_EMPTY, SHA3_NULL_RLP}; use util::{Address, FixedHash, H256, HashDB}; - use util::rlp::{UntrustedRlp, View}; + use rlp::{UntrustedRlp, View}; use std::collections::{HashSet, HashMap}; diff --git a/ethcore/src/snapshot/block.rs b/ethcore/src/snapshot/block.rs index 66fc06066..05b3281c8 100644 --- a/ethcore/src/snapshot/block.rs +++ b/ethcore/src/snapshot/block.rs @@ -20,8 +20,8 @@ use block::Block; use header::Header; use views::BlockView; -use util::rlp::{DecoderError, RlpStream, Stream, UntrustedRlp, View}; -use util::rlp::{Compressible, RlpType}; +use rlp::{DecoderError, RlpStream, Stream, UntrustedRlp, View}; +use rlp::{Compressible, RlpType}; use util::{Bytes, Hashable, H256}; const HEADER_FIELDS: usize = 10; @@ -103,7 +103,7 @@ impl AbridgedBlock { header.set_gas_used(try!(rlp.val_at(7))); header.set_timestamp(try!(rlp.val_at(8))); header.set_extra_data(try!(rlp.val_at(9))); - + let transactions = try!(rlp.val_at(10)); let uncles: Vec
= try!(rlp.val_at(11)); diff --git a/ethcore/src/snapshot/error.rs b/ethcore/src/snapshot/error.rs index d4587fdba..acd9409f7 100644 --- a/ethcore/src/snapshot/error.rs +++ b/ethcore/src/snapshot/error.rs @@ -22,7 +22,7 @@ use ids::BlockID; use util::H256; use util::trie::TrieError; -use util::rlp::DecoderError; +use rlp::DecoderError; /// Snapshot-related errors. #[derive(Debug)] diff --git a/ethcore/src/snapshot/io.rs b/ethcore/src/snapshot/io.rs index 7179b97ef..ae8a83b21 100644 --- a/ethcore/src/snapshot/io.rs +++ b/ethcore/src/snapshot/io.rs @@ -27,7 +27,7 @@ use std::path::{Path, PathBuf}; use util::Bytes; use util::hash::H256; -use util::rlp::{self, Encodable, RlpStream, UntrustedRlp, Stream, View}; +use rlp::{self, Encodable, RlpStream, UntrustedRlp, Stream, View}; use super::ManifestData; diff --git a/ethcore/src/snapshot/mod.rs b/ethcore/src/snapshot/mod.rs index d1ad077fe..89e4ed8ba 100644 --- a/ethcore/src/snapshot/mod.rs +++ b/ethcore/src/snapshot/mod.rs @@ -32,9 +32,9 @@ use util::Mutex; use util::hash::{FixedHash, H256}; use util::journaldb::{self, Algorithm, JournalDB}; use util::kvdb::Database; -use util::rlp::{DecoderError, RlpStream, Stream, UntrustedRlp, View, Compressible, RlpType}; -use util::rlp::SHA3_NULL_RLP; +use util::sha3::SHA3_NULL_RLP; use util::trie::{TrieDB, TrieDBMut, Trie, TrieMut}; +use rlp::{DecoderError, RlpStream, Stream, UntrustedRlp, View, Compressible, RlpType}; use self::account::Account; use self::block::AbridgedBlock; diff --git a/ethcore/src/snapshot/tests/helpers.rs b/ethcore/src/snapshot/tests/helpers.rs index aa055e8fb..bdf6a6a6a 100644 --- a/ethcore/src/snapshot/tests/helpers.rs +++ b/ethcore/src/snapshot/tests/helpers.rs @@ -25,7 +25,7 @@ use util::hash::{FixedHash, H256}; use util::hashdb::HashDB; use util::trie::{Alphabet, StandardMap, SecTrieDBMut, TrieMut, ValueMode}; use util::trie::{TrieDB, TrieDBMut, Trie}; -use util::rlp::SHA3_NULL_RLP; +use util::sha3::SHA3_NULL_RLP; // the proportion of accounts we will alter each tick. const ACCOUNT_CHURN: f32 = 0.01; diff --git a/ethcore/src/spec/genesis.rs b/ethcore/src/spec/genesis.rs index 8f472e996..380c48aba 100644 --- a/ethcore/src/spec/genesis.rs +++ b/ethcore/src/spec/genesis.rs @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use util::rlp::*; use util::{Address, H256, Uint, U256}; +use util::sha3::SHA3_NULL_RLP; use ethjson; use super::seal::Seal; diff --git a/ethcore/src/spec/seal.rs b/ethcore/src/spec/seal.rs index 600de701a..e25f174d2 100644 --- a/ethcore/src/spec/seal.rs +++ b/ethcore/src/spec/seal.rs @@ -16,7 +16,7 @@ //! Spec seal. -use util::rlp::*; +use rlp::*; use util::hash::{H64, H256}; use ethjson; diff --git a/ethcore/src/spec/spec.rs b/ethcore/src/spec/spec.rs index 7a03a2acd..82cede922 100644 --- a/ethcore/src/spec/spec.rs +++ b/ethcore/src/spec/spec.rs @@ -24,6 +24,7 @@ use super::genesis::Genesis; use super::seal::Generic as GenericSeal; use ethereum; use ethjson; +use rlp::{Rlp, RlpStream, View, Stream}; /// Parameters common to all engines. #[derive(Debug, PartialEq, Clone)] diff --git a/ethcore/src/state/account.rs b/ethcore/src/state/account.rs index 72e2bb0ed..eb4bea833 100644 --- a/ethcore/src/state/account.rs +++ b/ethcore/src/state/account.rs @@ -19,6 +19,7 @@ use std::collections::hash_map::Entry; use util::*; use pod_account::*; +use rlp::*; use std::cell::{Ref, RefCell, Cell}; @@ -333,6 +334,7 @@ mod tests { use util::*; use super::*; use account_db::*; + use rlp::*; #[test] fn account_compress() { diff --git a/ethcore/src/tests/client.rs b/ethcore/src/tests/client.rs index 26256a760..99aae1078 100644 --- a/ethcore/src/tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -22,6 +22,7 @@ use tests::helpers::*; use common::*; use devtools::*; use miner::Miner; +use rlp::{Rlp, View}; #[test] fn imports_from_empty() { diff --git a/ethcore/src/tests/helpers.rs b/ethcore/src/tests/helpers.rs index f3975a0d0..e05c82c55 100644 --- a/ethcore/src/tests/helpers.rs +++ b/ethcore/src/tests/helpers.rs @@ -27,6 +27,7 @@ use engines::Engine; use ethereum; use devtools::*; use miner::Miner; +use rlp::{self, RlpStream, Stream}; #[cfg(feature = "json-tests")] pub enum ChainEra { @@ -116,7 +117,7 @@ pub fn create_test_block_with_data(header: &Header, transactions: &[SignedTransa rlp.append(header); rlp.begin_list(transactions.len()); for t in transactions { - rlp.append_raw(&encode::(t).to_vec(), 1); + rlp.append_raw(&rlp::encode::(t).to_vec(), 1); } rlp.append(&uncles); rlp.out() diff --git a/ethcore/src/trace/bloom.rs b/ethcore/src/trace/bloom.rs index 8640240df..9196453fd 100644 --- a/ethcore/src/trace/bloom.rs +++ b/ethcore/src/trace/bloom.rs @@ -1,6 +1,6 @@ use bloomchain::Bloom; use bloomchain::group::{BloomGroup, GroupPosition}; -use util::rlp::*; +use rlp::*; use basic_types::LogBloom; /// Helper structure representing bloom of the trace. diff --git a/ethcore/src/types/executed.rs b/ethcore/src/types/executed.rs index b81707581..b4328b75d 100644 --- a/ethcore/src/types/executed.rs +++ b/ethcore/src/types/executed.rs @@ -17,7 +17,7 @@ //! Transaction execution format module. use util::{Bytes, U256, Address, U512}; -use util::rlp::*; +use rlp::*; use trace::{VMTrace, FlatTrace}; use types::log_entry::LogEntry; use types::state_diff::StateDiff; @@ -203,7 +203,8 @@ pub type ExecutionResult = Result; #[test] fn should_encode_and_decode_call_type() { - use util::rlp; + use rlp; + let original = CallType::Call; let encoded = rlp::encode(&original); let decoded = rlp::decode(&encoded); diff --git a/ethcore/src/types/log_entry.rs b/ethcore/src/types/log_entry.rs index 5267686bc..0e5f7d531 100644 --- a/ethcore/src/types/log_entry.rs +++ b/ethcore/src/types/log_entry.rs @@ -18,8 +18,9 @@ use std::ops::Deref; use util::{H256, Address, Bytes, HeapSizeOf, Hashable}; -use util::rlp::*; use util::bloom::Bloomable; +use rlp::*; + use basic_types::LogBloom; use header::BlockNumber; use ethjson; diff --git a/ethcore/src/types/receipt.rs b/ethcore/src/types/receipt.rs index c6d413381..52e6747e8 100644 --- a/ethcore/src/types/receipt.rs +++ b/ethcore/src/types/receipt.rs @@ -17,8 +17,9 @@ //! Receipt use util::{H256, U256, Address}; -use util::rlp::*; use util::HeapSizeOf; +use rlp::*; + use basic_types::LogBloom; use header::BlockNumber; use log_entry::{LogEntry, LocalizedLogEntry}; diff --git a/ethcore/src/types/trace_types/flat.rs b/ethcore/src/types/trace_types/flat.rs index e5dd9dd8b..58983558d 100644 --- a/ethcore/src/types/trace_types/flat.rs +++ b/ethcore/src/types/trace_types/flat.rs @@ -17,7 +17,7 @@ //! Flat trace module use std::collections::VecDeque; -use util::rlp::*; +use rlp::*; use util::HeapSizeOf; use basic_types::LogBloom; use super::trace::{Action, Res}; @@ -167,7 +167,6 @@ mod tests { #[test] fn test_trace_serialization() { - use util::rlp; // block #51921 let flat_trace = FlatTrace { @@ -220,8 +219,8 @@ mod tests { FlatTransactionTraces(vec![flat_trace1, flat_trace2]) ]); - let encoded = rlp::encode(&block_traces); - let decoded = rlp::decode(&encoded); + let encoded = ::rlp::encode(&block_traces); + let decoded = ::rlp::decode(&encoded); assert_eq!(block_traces, decoded); } } diff --git a/ethcore/src/types/trace_types/trace.rs b/ethcore/src/types/trace_types/trace.rs index f594dd4bb..7261107e6 100644 --- a/ethcore/src/types/trace_types/trace.rs +++ b/ethcore/src/types/trace_types/trace.rs @@ -17,9 +17,10 @@ //! Tracing datatypes. use util::{U256, Bytes, Address}; -use util::rlp::*; use util::sha3::Hashable; use util::bloom::Bloomable; +use rlp::*; + use action_params::ActionParams; use basic_types::LogBloom; use types::executed::CallType; diff --git a/ethcore/src/types/transaction.rs b/ethcore/src/types/transaction.rs index 02d3da30a..f7e582f11 100644 --- a/ethcore/src/types/transaction.rs +++ b/ethcore/src/types/transaction.rs @@ -18,7 +18,7 @@ use std::ops::Deref; use std::cell::*; -use util::rlp::*; +use rlp::*; use util::sha3::Hashable; use util::{H256, Address, U256, Bytes}; use ethkey::{Signature, sign, Secret, recover, public_to_address, Error as EthkeyError}; @@ -275,7 +275,7 @@ impl SignedTransaction { match hash { Some(h) => h, None => { - let h = self.rlp_sha3(); + let h = (&*self.rlp_bytes()).sha3(); self.hash.set(Some(h)); h } diff --git a/ethcore/src/verification/verification.rs b/ethcore/src/verification/verification.rs index aa719cf23..db3a9314c 100644 --- a/ethcore/src/verification/verification.rs +++ b/ethcore/src/verification/verification.rs @@ -24,6 +24,7 @@ use common::*; use engines::Engine; use blockchain::*; +use rlp::{UntrustedRlp, View}; /// Preprocessed block data gathered in `verify_block_unordered` call pub struct PreverifiedBlock { @@ -240,6 +241,7 @@ mod tests { use spec::*; use transaction::*; use tests::helpers::*; + use rlp::View; fn check_ok(result: Result<(), Error>) { result.unwrap_or_else(|e| panic!("Block verification failed: {:?}", e)); @@ -346,6 +348,8 @@ mod tests { #[test] #[cfg_attr(feature="dev", allow(similar_names))] fn test_verify_block() { + use rlp::{RlpStream, Stream}; + // Test against morden let mut good = Header::new(); let spec = Spec::new_test(); @@ -411,7 +415,7 @@ mod tests { let mut uncles_rlp = RlpStream::new(); uncles_rlp.append(&good_uncles); let good_uncles_hash = uncles_rlp.as_raw().sha3(); - let good_transactions_root = ordered_trie_root(good_transactions.iter().map(|t| encode::(t).to_vec()).collect()); + let good_transactions_root = ordered_trie_root(good_transactions.iter().map(|t| ::rlp::encode::(t).to_vec()).collect()); let mut parent = good.clone(); parent.set_number(9); diff --git a/ethcore/src/views/block.rs b/ethcore/src/views/block.rs index fdcae383b..97cf26441 100644 --- a/ethcore/src/views/block.rs +++ b/ethcore/src/views/block.rs @@ -20,6 +20,7 @@ use util::*; use header::*; use transaction::*; use super::{TransactionView, HeaderView}; +use rlp::{Rlp, View}; /// View onto block rlp. pub struct BlockView<'a> { diff --git a/ethcore/src/views/body.rs b/ethcore/src/views/body.rs index 8f1295f31..989acd465 100644 --- a/ethcore/src/views/body.rs +++ b/ethcore/src/views/body.rs @@ -20,6 +20,7 @@ use util::*; use header::*; use transaction::*; use super::{TransactionView, HeaderView}; +use rlp::{Rlp, View}; /// View onto block rlp. pub struct BodyView<'a> { diff --git a/ethcore/src/views/header.rs b/ethcore/src/views/header.rs index 70b59fbfa..6c3b14b15 100644 --- a/ethcore/src/views/header.rs +++ b/ethcore/src/views/header.rs @@ -16,7 +16,8 @@ //! View onto block header rlp -use util::{Rlp, U256, Bytes, Hashable, H256, Address, H2048, View}; +use util::{U256, Bytes, Hashable, H256, Address, H2048}; +use rlp::{Rlp, View}; use header::BlockNumber; /// View onto block header rlp. diff --git a/ethcore/src/views/transaction.rs b/ethcore/src/views/transaction.rs index d83290909..df861d9fd 100644 --- a/ethcore/src/views/transaction.rs +++ b/ethcore/src/views/transaction.rs @@ -15,7 +15,8 @@ // along with Parity. If not, see . //! View onto transaction rlp -use util::{Rlp, U256, Bytes, Hashable, H256, View}; +use util::{U256, Bytes, Hashable, H256}; +use rlp::{Rlp, View}; /// View onto transaction rlp. pub struct TransactionView<'a> { diff --git a/util/src/sha3.rs b/util/src/sha3.rs index 5ab55257d..29c66f8dc 100644 --- a/util/src/sha3.rs +++ b/util/src/sha3.rs @@ -20,7 +20,7 @@ extern crate sha3 as sha3_ext; use std::io; use std::mem::uninitialized; use tiny_keccak::Keccak; -use bytes::{BytesConvertable, Populatable}; +use bytes::{Populatable}; use hash::{H256, FixedHash}; use self::sha3_ext::*; @@ -55,7 +55,7 @@ pub trait Hashable { } } -impl Hashable for T where T: BytesConvertable { +impl Hashable for T where T: AsRef<[u8]> { fn sha3(&self) -> H256 { unsafe { let mut ret: H256 = uninitialized(); @@ -65,7 +65,7 @@ impl Hashable for T where T: BytesConvertable { } fn sha3_into(&self, dest: &mut [u8]) { unsafe { - let input: &[u8] = self.as_slice(); + let input: &[u8] = self.as_ref(); sha3_256(dest.as_mut_ptr(), dest.len(), input.as_ptr(), input.len()); } }