Merge branch 'master' into light-poa

This commit is contained in:
Robert Habermeier
2017-09-04 12:30:37 +02:00
217 changed files with 1613 additions and 1459 deletions

View File

@@ -479,7 +479,7 @@ impl BlockDownloader {
let receipts = block_and_receipts.receipts;
let (h, number, parent) = {
let header = BlockView::new(&block).header_view();
(header.sha3(), header.number(), header.parent_hash())
(header.hash(), header.number(), header.parent_hash())
};
// Perform basic block verification

View File

@@ -17,7 +17,9 @@
use std::collections::{HashSet, HashMap};
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;
@@ -343,7 +345,7 @@ impl BlockCollection {
let body = UntrustedRlp::new(&b);
let tx = body.at(0)?;
let tx_root = ordered_trie_root(tx.iter().map(|r| r.as_raw().to_vec())); //TODO: get rid of vectors here
let uncles = body.at(1)?.as_raw().sha3();
let uncles = keccak(body.at(1)?.as_raw());
HeaderId {
transactions_root: tx_root,
uncles: uncles
@@ -426,7 +428,7 @@ impl BlockCollection {
transactions_root: info.transactions_root().clone(),
uncles: info.uncles_hash().clone(),
};
if header_id.transactions_root == sha3::SHA3_NULL_RLP && header_id.uncles == sha3::SHA3_EMPTY_LIST_RLP {
if header_id.transactions_root == KECCAK_NULL_RLP && header_id.uncles == KECCAK_EMPTY_LIST_RLP {
// empty body, just mark as downloaded
let mut body_stream = RlpStream::new_list(2);
body_stream.append_raw(&::rlp::EMPTY_LIST_RLP, 1);
@@ -439,7 +441,7 @@ impl BlockCollection {
}
if self.need_receipts {
let receipt_root = info.receipts_root().clone();
if receipt_root == sha3::SHA3_NULL_RLP {
if receipt_root == KECCAK_NULL_RLP {
let receipts_stream = RlpStream::new_list(0);
block.receipts = Some(receipts_stream.out());
} else {
@@ -490,7 +492,6 @@ mod test {
use ethcore::client::{TestBlockChainClient, EachBlockWith, BlockId, BlockChainClient};
use ethcore::views::HeaderView;
use ethcore::header::BlockNumber;
use util::*;
use rlp::*;
fn is_empty(bc: &BlockCollection) -> bool {
@@ -527,7 +528,7 @@ mod test {
.map(|i| (&client as &BlockChainClient).block(BlockId::Number(i as BlockNumber)).unwrap().into_inner())
.collect();
let headers: Vec<_> = blocks.iter().map(|b| Rlp::new(b).at(0).as_raw().to_vec()).collect();
let hashes: Vec<_> = headers.iter().map(|h| HeaderView::new(h).sha3()).collect();
let hashes: Vec<_> = headers.iter().map(|h| HeaderView::new(h).hash()).collect();
let heads: Vec<_> = hashes.iter().enumerate().filter_map(|(i, h)| if i % 20 == 0 { Some(h.clone()) } else { None }).collect();
bc.reset_to(heads);
assert!(!bc.is_empty());
@@ -582,7 +583,7 @@ mod test {
.map(|i| (&client as &BlockChainClient).block(BlockId::Number(i as BlockNumber)).unwrap().into_inner())
.collect();
let headers: Vec<_> = blocks.iter().map(|b| Rlp::new(b).at(0).as_raw().to_vec()).collect();
let hashes: Vec<_> = headers.iter().map(|h| HeaderView::new(h).sha3()).collect();
let hashes: Vec<_> = headers.iter().map(|h| HeaderView::new(h).hash()).collect();
let heads: Vec<_> = hashes.iter().enumerate().filter_map(|(i, h)| if i % 20 == 0 { Some(h.clone()) } else { None }).collect();
bc.reset_to(heads);
@@ -606,7 +607,7 @@ mod test {
.map(|i| (&client as &BlockChainClient).block(BlockId::Number(i as BlockNumber)).unwrap().into_inner())
.collect();
let headers: Vec<_> = blocks.iter().map(|b| Rlp::new(b).at(0).as_raw().to_vec()).collect();
let hashes: Vec<_> = headers.iter().map(|h| HeaderView::new(h).sha3()).collect();
let hashes: Vec<_> = headers.iter().map(|h| HeaderView::new(h).hash()).collect();
let heads: Vec<_> = hashes.iter().enumerate().filter_map(|(i, h)| if i % 20 == 0 { Some(h.clone()) } else { None }).collect();
bc.reset_to(heads);

View File

@@ -91,7 +91,9 @@
use std::collections::{HashSet, HashMap};
use std::cmp;
use hash::keccak;
use heapsize::HeapSizeOf;
use parking_lot::RwLock;
use util::*;
use rlp::*;
use network::*;
@@ -683,7 +685,7 @@ impl ChainSync {
peer.confirmation = ForkConfirmation::TooShort;
} else {
let header = r.at(0)?.as_raw();
if header.sha3() == fork_hash {
if keccak(&header) == fork_hash {
trace!(target: "sync", "{}: Confirmed peer", peer_id);
peer.confirmation = ForkConfirmation::Confirmed;
if !io.chain_overlay().read().contains_key(&fork_number) {
@@ -895,7 +897,7 @@ impl ChainSync {
}
let block_rlp = r.at(0)?;
let header_rlp = block_rlp.at(0)?;
let h = header_rlp.as_raw().sha3();
let h = keccak(&header_rlp.as_raw());
trace!(target: "sync", "{} -> NewBlock ({})", peer_id, h);
let header: BlockHeader = header_rlp.as_val()?;
if header.number() > self.highest_block.unwrap_or(0) {
@@ -1056,7 +1058,7 @@ impl ChainSync {
self.continue_sync(io);
return Ok(());
}
self.snapshot.reset_to(&manifest, &manifest_rlp.as_raw().sha3());
self.snapshot.reset_to(&manifest, &keccak(manifest_rlp.as_raw()));
io.snapshot_service().begin_restore(manifest);
self.state = SyncState::SnapshotData;
@@ -1510,7 +1512,7 @@ impl ChainSync {
false => io.snapshot_service().manifest(),
};
let block_number = manifest.as_ref().map_or(0, |m| m.block_number);
let manifest_hash = manifest.map_or(H256::new(), |m| m.into_rlp().sha3());
let manifest_hash = manifest.map_or(H256::new(), |m| keccak(m.into_rlp()));
packet.append(&manifest_hash);
packet.append(&block_number);
}
@@ -1532,7 +1534,7 @@ impl ChainSync {
match io.chain().block_header(BlockId::Hash(hash)) {
Some(hdr) => {
let number = hdr.number().into();
debug_assert_eq!(hdr.sha3(), hash);
debug_assert_eq!(hdr.hash(), hash);
if max_headers == 1 || io.chain().block_hash(BlockId::Number(number)) != Some(hash) {
// Non canonical header or single header requested
@@ -2229,8 +2231,8 @@ mod tests {
use network::PeerId;
use tests::helpers::*;
use tests::snapshot::TestSnapshotService;
use util::{U256, Address, RwLock};
use util::sha3::Hashable;
use parking_lot::RwLock;
use util::{U256, Address};
use util::hash::H256;
use util::bytes::Bytes;
use rlp::{Rlp, RlpStream, UntrustedRlp};
@@ -2395,7 +2397,7 @@ mod tests {
let blocks: Vec<_> = (0 .. 100)
.map(|i| (&client as &BlockChainClient).block(BlockId::Number(i as BlockNumber)).map(|b| b.into_inner()).unwrap()).collect();
let headers: Vec<_> = blocks.iter().map(|b| Rlp::new(b).at(0).as_raw().to_vec()).collect();
let hashes: Vec<_> = headers.iter().map(|h| HeaderView::new(h).sha3()).collect();
let hashes: Vec<_> = headers.iter().map(|h| HeaderView::new(h).hash()).collect();
let queue = RwLock::new(VecDeque::new());
let ss = TestSnapshotService::new();

View File

@@ -38,6 +38,8 @@ extern crate parking_lot;
extern crate smallvec;
extern crate rlp;
extern crate ipnetwork;
extern crate hash;
extern crate triehash;
extern crate ethcore_light as light;

View File

@@ -45,7 +45,8 @@ use light::net::{
};
use light::request::{self, CompleteHeadersRequest as HeadersRequest};
use network::PeerId;
use util::{U256, H256, Mutex, RwLock};
use util::{U256, H256};
use parking_lot::{Mutex, RwLock};
use rand::{Rng, OsRng};
use self::sync_round::{AbortReason, SyncRound, ResponseContext};

View File

@@ -29,7 +29,7 @@ use light::client::fetch::{self, Unavailable};
use light::net::{LightProtocol, IoContext, Capabilities, Params as LightParams};
use light::provider::LightProvider;
use network::{NodeId, PeerId};
use util::RwLock;
use parking_lot::RwLock;
use time::Duration;
use light::cache::Cache;

View File

@@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use util::{H256, Hashable};
use hash::keccak;
use util::H256;
use std::collections::HashSet;
use ethcore::snapshot::ManifestData;
@@ -71,7 +71,7 @@ impl Snapshot {
/// Validate chunk and mark it as downloaded
pub fn validate_chunk(&mut self, chunk: &[u8]) -> Result<ChunkType, ()> {
let hash = chunk.sha3();
let hash = keccak(chunk);
if self.completed_chunks.contains(&hash) {
trace!(target: "sync", "Ignored proccessed chunk: {}", hash.hex());
return Err(());
@@ -136,6 +136,7 @@ impl Snapshot {
#[cfg(test)]
mod test {
use hash::keccak;
use util::*;
use super::*;
use ethcore::snapshot::ManifestData;
@@ -153,13 +154,13 @@ mod test {
let block_chunks: Vec<Bytes> = (0..20).map(|_| H256::random().to_vec()).collect();
let manifest = ManifestData {
version: 2,
state_hashes: state_chunks.iter().map(|data| data.sha3()).collect(),
block_hashes: block_chunks.iter().map(|data| data.sha3()).collect(),
state_hashes: state_chunks.iter().map(|data| keccak(data)).collect(),
block_hashes: block_chunks.iter().map(|data| keccak(data)).collect(),
state_root: H256::new(),
block_number: 42,
block_hash: H256::new(),
};
let mhash = manifest.clone().into_rlp().sha3();
let mhash = keccak(manifest.clone().into_rlp());
(manifest, mhash, state_chunks, block_chunks)
}
@@ -211,7 +212,7 @@ mod test {
assert!(snapshot.is_complete());
assert_eq!(snapshot.done_chunks(), 40);
assert_eq!(snapshot.done_chunks(), snapshot.total_chunks());
assert_eq!(snapshot.snapshot_hash(), Some(manifest.into_rlp().sha3()));
assert_eq!(snapshot.snapshot_hash(), Some(keccak(manifest.into_rlp())));
}
#[test]

View File

@@ -15,6 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::sync::Arc;
use hash::keccak;
use util::*;
use io::{IoHandler, IoContext, IoChannel};
use ethcore::client::{BlockChainClient, Client};
@@ -56,8 +57,8 @@ fn new_tx(secret: &Secret, nonce: U256, chain_id: u64) -> PendingTransaction {
#[test]
fn authority_round() {
let s0 = KeyPair::from_secret_slice(&"1".sha3()).unwrap();
let s1 = KeyPair::from_secret_slice(&"0".sha3()).unwrap();
let s0 = KeyPair::from_secret_slice(&keccak("1")).unwrap();
let s1 = KeyPair::from_secret_slice(&keccak("0")).unwrap();
let ap = Arc::new(AccountProvider::transient_provider());
ap.insert_account(s0.secret().clone(), "").unwrap();
ap.insert_account(s1.secret().clone(), "").unwrap();
@@ -143,8 +144,8 @@ fn authority_round() {
#[test]
fn tendermint() {
let s0 = KeyPair::from_secret_slice(&"1".sha3()).unwrap();
let s1 = KeyPair::from_secret_slice(&"0".sha3()).unwrap();
let s0 = KeyPair::from_secret_slice(&keccak("1")).unwrap();
let s1 = KeyPair::from_secret_slice(&keccak("0")).unwrap();
let ap = Arc::new(AccountProvider::transient_provider());
ap.insert_account(s0.secret().clone(), "").unwrap();
ap.insert_account(s1.secret().clone(), "").unwrap();

View File

@@ -16,6 +16,7 @@
use std::collections::{VecDeque, HashSet, HashMap};
use std::sync::Arc;
use parking_lot::RwLock;
use util::*;
use network::*;
use tests::snapshot::*;

View File

@@ -16,6 +16,8 @@
use std::collections::HashMap;
use std::sync::Arc;
use hash::keccak;
use parking_lot::Mutex;
use util::*;
use ethcore::snapshot::{SnapshotService, ManifestData, RestorationStatus};
use ethcore::header::BlockNumber;
@@ -50,14 +52,14 @@ impl TestSnapshotService {
let block_chunks: Vec<Bytes> = (0..num_block_chunks).map(|_| H256::random().to_vec()).collect();
let manifest = ManifestData {
version: 2,
state_hashes: state_chunks.iter().map(|data| data.sha3()).collect(),
block_hashes: block_chunks.iter().map(|data| data.sha3()).collect(),
state_hashes: state_chunks.iter().map(|data| keccak(data)).collect(),
block_hashes: block_chunks.iter().map(|data| keccak(data)).collect(),
state_root: H256::new(),
block_number: block_number,
block_hash: block_hash,
};
let mut chunks: HashMap<H256, Bytes> = state_chunks.into_iter().map(|data| (data.sha3(), data)).collect();
chunks.extend(block_chunks.into_iter().map(|data| (data.sha3(), data)));
let mut chunks: HashMap<H256, Bytes> = state_chunks.into_iter().map(|data| (keccak(&data), data)).collect();
chunks.extend(block_chunks.into_iter().map(|data| (keccak(&data), data)));
TestSnapshotService {
manifest: Some(manifest),
chunks: chunks,