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

@@ -21,7 +21,8 @@ use std::time::{Instant, Duration};
use std::thread::sleep;
use std::sync::Arc;
use rustc_hex::FromHex;
use util::{ToPretty, U256, H256, Address, Hashable};
use hash::{keccak, KECCAK_NULL_RLP};
use util::{ToPretty, U256, H256, Address};
use rlp::PayloadInfo;
use ethcore::service::ClientService;
use ethcore::client::{Mode, DatabaseCompactionProfile, VMType, BlockImportError, BlockChainClient, BlockId};
@@ -154,6 +155,7 @@ pub fn execute(cmd: BlockchainCmd) -> Result<(), String> {
fn execute_import_light(cmd: ImportBlockchain) -> Result<(), String> {
use light::client::{Service as LightClientService, Config as LightClientConfig};
use light::cache::Cache as LightDataCache;
use parking_lot::Mutex;
let timer = Instant::now();
@@ -187,7 +189,7 @@ fn execute_import_light(cmd: ImportBlockchain) -> Result<(), String> {
// create dirs used by parity
cmd.dirs.create_dirs(false, false, false)?;
let cache = Arc::new(::util::Mutex::new(
let cache = Arc::new(Mutex::new(
LightDataCache::new(Default::default(), ::time::Duration::seconds(0))
));
@@ -641,13 +643,13 @@ fn execute_export_state(cmd: ExportState) -> Result<(), String> {
out.write_fmt(format_args!("\n\"0x{}\": {{\"balance\": \"{:x}\", \"nonce\": \"{:x}\"", account.hex(), balance, client.nonce(&account, at).unwrap_or_else(U256::zero))).expect("Write error");
let code = client.code(&account, at).unwrap_or(None).unwrap_or_else(Vec::new);
if !code.is_empty() {
out.write_fmt(format_args!(", \"code_hash\": \"0x{}\"", code.sha3().hex())).expect("Write error");
out.write_fmt(format_args!(", \"code_hash\": \"0x{}\"", keccak(&code).hex())).expect("Write error");
if cmd.code {
out.write_fmt(format_args!(", \"code\": \"{}\"", code.to_hex())).expect("Write error");
}
}
let storage_root = client.storage_root(&account, at).unwrap_or(::util::SHA3_NULL_RLP);
if storage_root != ::util::SHA3_NULL_RLP {
let storage_root = client.storage_root(&account, at).unwrap_or(KECCAK_NULL_RLP);
if storage_root != KECCAK_NULL_RLP {
out.write_fmt(format_args!(", \"storage_root\": \"0x{}\"", storage_root.hex())).expect("Write error");
if cmd.storage {
out.write_fmt(format_args!(", \"storage\": {{")).expect("Write error");

View File

@@ -22,9 +22,10 @@ use std::collections::BTreeMap;
use std::cmp::max;
use std::str::FromStr;
use cli::{Args, ArgsError};
use util::{Hashable, H256, U256, Bytes, version_data, Address};
use hash::keccak;
use util::{H256, U256, Bytes, version_data, Address};
use util::journaldb::Algorithm;
use util::Colour;
use ansi_term::Colour;
use ethsync::{NetworkConfiguration, is_valid_node_url};
use ethcore::ethstore::ethkey::{Secret, Public};
use ethcore::client::{VMType};
@@ -506,7 +507,7 @@ impl Configuration {
io_path: self.directories().db,
listen_addr: self.stratum_interface(),
port: self.args.flag_ports_shift + self.args.flag_stratum_port,
secret: self.args.flag_stratum_secret.as_ref().map(|s| s.parse::<H256>().unwrap_or_else(|_| s.sha3())),
secret: self.args.flag_stratum_secret.as_ref().map(|s| s.parse::<H256>().unwrap_or_else(|_| keccak(s))),
}))
} else { Ok(None) }
}
@@ -729,7 +730,7 @@ impl Configuration {
ret.listen_address = Some(format!("{}", listen));
ret.public_address = public.map(|p| format!("{}", p));
ret.use_secret = match self.args.flag_node_key.as_ref()
.map(|s| s.parse::<Secret>().or_else(|_| Secret::from_unsafe_slice(&s.sha3())).map_err(|e| format!("Invalid key: {:?}", e))
.map(|s| s.parse::<Secret>().or_else(|_| Secret::from_unsafe_slice(&keccak(s))).map_err(|e| format!("Invalid key: {:?}", e))
) {
None => None,
Some(Ok(key)) => Some(key),

View File

@@ -16,7 +16,7 @@
extern crate ansi_term;
use self::ansi_term::Colour::{White, Yellow, Green, Cyan, Blue};
use self::ansi_term::Style;
use self::ansi_term::{Colour, Style};
use std::sync::{Arc};
use std::sync::atomic::{AtomicUsize, AtomicBool, Ordering as AtomicOrdering};
@@ -35,7 +35,8 @@ use light::client::LightChainClient;
use number_prefix::{binary_prefix, Standalone, Prefixed};
use parity_rpc::{is_major_importing};
use parity_rpc::informant::RpcStats;
use util::{RwLock, Mutex, H256, Colour, Bytes};
use parking_lot::{RwLock, Mutex};
use util::{H256, Bytes};
/// Format byte counts to standard denominations.
pub fn format_bytes(b: usize) -> String {

View File

@@ -31,7 +31,7 @@ use futures::{future, Future};
use parity_reactor::Remote;
use util::RwLock;
use parking_lot::RwLock;
// Attepmt to cull once every 10 minutes.
const TOKEN: TimerToken = 1;

View File

@@ -34,6 +34,7 @@ extern crate isatty;
extern crate jsonrpc_core;
extern crate num_cpus;
extern crate number_prefix;
extern crate parking_lot;
extern crate regex;
extern crate rlp;
extern crate rpassword;
@@ -70,6 +71,7 @@ extern crate parity_whisper;
extern crate path;
extern crate rpc_cli;
extern crate node_filter;
extern crate hash;
#[macro_use]
extern crate log as rlog;
@@ -130,7 +132,7 @@ use std::collections::HashMap;
use std::io::{self as stdio, BufReader, Read, Write};
use std::fs::{remove_file, metadata, File, create_dir_all};
use std::path::PathBuf;
use util::sha3::sha3;
use hash::keccak_buffer;
use cli::Args;
use configuration::{Cmd, Execute, Configuration};
use deprecated::find_deprecated;
@@ -140,7 +142,7 @@ use dir::default_hypervisor_path;
fn print_hash_of(maybe_file: Option<String>) -> Result<String, String> {
if let Some(file) = maybe_file {
let mut f = BufReader::new(File::open(&file).map_err(|_| "Unable to open file".to_owned())?);
let hash = sha3(&mut f).map_err(|_| "Unable to read from file".to_owned())?;
let hash = keccak_buffer(&mut f).map_err(|_| "Unable to read from file".to_owned())?;
Ok(hash.hex())
} else {
Err("Streaming from standard input not yet supported. Specify a file.".to_owned())

View File

@@ -39,7 +39,7 @@ use parity_rpc::dispatch::{FullDispatcher, LightDispatcher};
use parity_rpc::informant::{ActivityNotifier, ClientNotifier};
use parity_rpc::{Metadata, NetworkSettings};
use updater::Updater;
use util::{Mutex, RwLock};
use parking_lot::{Mutex, RwLock};
#[derive(Debug, PartialEq, Clone, Eq, Hash)]
pub enum Api {

View File

@@ -37,7 +37,9 @@ use node_health;
use parity_reactor::EventLoop;
use parity_rpc::{NetworkSettings, informant, is_major_importing};
use updater::{UpdatePolicy, Updater};
use util::{Colour, version, Mutex, Condvar};
use ansi_term::Colour;
use util::version;
use parking_lot::{Condvar, Mutex};
use node_filter::NodeFilter;
use params::{
@@ -170,7 +172,7 @@ impl ::local_store::NodeInfo for FullNodeInfo {
fn execute_light(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> Result<(bool, Option<String>), String> {
use light::client as light_client;
use ethsync::{LightSyncParams, LightSync, ManageNetwork};
use util::RwLock;
use parking_lot::{Mutex, RwLock};
// load spec
let spec = cmd.spec.spec(&cmd.dirs.cache)?;
@@ -205,7 +207,7 @@ fn execute_light(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) ->
// TODO: configurable cache size.
let cache = LightDataCache::new(Default::default(), ::time::Duration::minutes(GAS_CORPUS_EXPIRATION_MINUTES));
let cache = Arc::new(::util::Mutex::new(cache));
let cache = Arc::new(Mutex::new(cache));
// start client and create transaction queue.
let mut config = light_client::Config {

View File

@@ -20,6 +20,7 @@ use std::time::Duration;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use hash::keccak;
use ethcore::snapshot::{Progress, RestorationStatus, SnapshotService as SS};
use ethcore::snapshot::io::{SnapshotReader, PackedReader, PackedWriter};
use ethcore::snapshot::service::Service as SnapshotService;
@@ -65,8 +66,6 @@ pub struct SnapshotCommand {
// helper for reading chunks from arbitrary reader and feeding them into the
// service.
fn restore_using<R: SnapshotReader>(snapshot: Arc<SnapshotService>, reader: &R, recover: bool) -> Result<(), String> {
use util::sha3::Hashable;
let manifest = reader.manifest();
info!("Restoring to block #{} (0x{:?})", manifest.block_number, manifest.block_hash);
@@ -95,7 +94,7 @@ fn restore_using<R: SnapshotReader>(snapshot: Arc<SnapshotService>, reader: &R,
let chunk = reader.chunk(state_hash)
.map_err(|e| format!("Encountered error while reading chunk {:?}: {}", state_hash, e))?;
let hash = chunk.sha3();
let hash = keccak(&chunk);
if hash != state_hash {
return Err(format!("Mismatched chunk hash. Expected {:?}, got {:?}", state_hash, hash));
}
@@ -112,7 +111,7 @@ fn restore_using<R: SnapshotReader>(snapshot: Arc<SnapshotService>, reader: &R,
let chunk = reader.chunk(block_hash)
.map_err(|e| format!("Encountered error while reading chunk {:?}: {}", block_hash, e))?;
let hash = chunk.sha3();
let hash = keccak(&chunk);
if hash != block_hash {
return Err(format!("Mismatched chunk hash. Expected {:?}, got {:?}", block_hash, hash));
}