Merge branch 'master' into coverage-effort

Conflicts:
	ethcore/res/ethereum/tests
This commit is contained in:
Nikolay Volf 2016-01-31 18:40:59 +04:00
commit 5837b6e131
71 changed files with 180 additions and 76 deletions

4
.gitmodules vendored
View File

@ -1,4 +0,0 @@
[submodule "res/ethereum/tests"]
path = res/ethereum/tests
url = git@github.com:ethereum/tests
branch = develop

View File

@ -1,16 +1,47 @@
sudo: required
dist: trusty
language: rust language: rust
matrix:
rust: fast_finish: true
- nightly include:
- rust: nightly
os:
- osx
before_script:
- brew update
- brew install rocksdb
cache: cache:
apt: true
directories: directories:
- $TRAVIS_BUILD_DIR/target - target/release/deps
- $HOME/.cargo - target/release/build
addons:
apt:
packages:
- libcurl4-openssl-dev
- libelf-dev
- libdw-dev
before_script: |
sudo add-apt-repository "deb http://ppa.launchpad.net/giskou/librocksdb/ubuntu trusty main" &&
sudo apt-get update &&
sudo apt-get install -y --force-yes librocksdb
script:
- cargo build --release --verbose
- cargo test --release -p ethash --verbose
- cargo test --release -p ethcore-util --verbose
- cargo test --release -p ethcore --verbose
- cargo test --release --verbose
- cargo bench --no-run
after_success: |
wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz &&
tar xzf master.tar.gz && mkdir kcov-master/build && cd kcov-master/build && cmake .. && make && make install DESTDIR=../tmp && cd ../.. &&
ls target/release &&
./kcov-master/tmp/usr/local/bin/kcov --coveralls-id=${COVERALLS_TOKEN} --exclude-pattern=/.cargo --include-pattern=ethcore/src target/kcov target/release/deps/ethcore-* &&
[ $TRAVIS_BRANCH = master ] &&
[ $TRAVIS_PULL_REQUEST = false ] &&
[ $TRAVIS_RUST_VERSION = nightly ] &&
cargo doc --no-deps &&
echo '<meta http-equiv=refresh content=0;url=ethcore/index.html>' > target/doc/index.html &&
pip install --user ghp-import &&
/home/travis/.local/bin/ghp-import -n target/doc
#&&
#git push -fq https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages
env:
global:
secure: 3sUjNi9mhdL5h1GTm8L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1YJA7HPySMYzCjYqkJ2r62xYk0gXmNXphfU+F/X/rHzHsTMJPONJ54HQwu12m7zVlKIYBGHgEXg/HAM/g4ljUzl6WWR/nHH/tQM8ND/8FpHluJSZJWacq/1QNhVdTq2x6cqws2fs5A7nVpccR9+6RRgYgv6+YS2LxvFzByuZveGGoKif+uMECXN876j40araUqU528Yz9i8bHJlnM3coRBndaLNWByLcUyXCB9r9IUosUu41rr+L2mVzkSDm0GicuNCzqvzYQ9Q6QY4uQ=

View File

@ -1,30 +1,26 @@
[package] [package]
description = "Ethcore library" description = "Ethcore client."
homepage = "http://ethcore.io" name = "parity"
version = "0.9.0"
license = "GPL-3.0" license = "GPL-3.0"
name = "ethcore"
version = "0.1.0"
authors = ["Ethcore <admin@ethcore.io>"] authors = ["Ethcore <admin@ethcore.io>"]
[dependencies] [dependencies]
log = "0.3" log = "0.3"
env_logger = "0.3" env_logger = "0.3"
ethcore-util = { path = "util" }
rustc-serialize = "0.3" rustc-serialize = "0.3"
flate2 = "0.2" docopt = "0.6"
rocksdb = "0.3" docopt_macros = "0.6"
heapsize = "0.2.0" ctrlc = "1.0"
rust-crypto = "0.2.34"
time = "0.1"
#interpolate_idents = { git = "https://github.com/SkylerLipthay/interpolate_idents" }
evmjit = { path = "evmjit", optional = true }
ethash = { path = "ethash" }
num_cpus = "0.2"
clippy = "0.0.37" clippy = "0.0.37"
crossbeam = "0.1.5" ethcore-util = { path = "util" }
lazy_static = "0.1" ethcore = { path = "ethcore" }
ethsync = { path = "sync" }
ethcore-rpc = { path = "rpc", optional = true }
[features] [features]
jit = ["evmjit"] rpc = ["ethcore-rpc"]
evm_debug = []
test-heavy = [] [[bin]]
path = "parity/main.rs"
name = "parity"

View File

@ -1,22 +0,0 @@
[package]
description = "Ethcore client."
name = "parity"
version = "0.9.0"
license = "GPL-3.0"
authors = ["Ethcore <admin@ethcore.io>"]
[dependencies]
log = "0.3"
env_logger = "0.3"
rustc-serialize = "0.3"
docopt = "0.6"
docopt_macros = "0.6"
ctrlc = "1.0"
ethcore-util = { path = "../util" }
ethcore-rpc = { path = "../rpc", optional = true }
ethcore = { path = ".." }
ethsync = { path = "../sync" }
clippy = "0.0.37"
[features]
rpc = ["ethcore-rpc"]

View File

@ -6,4 +6,6 @@ authors = ["arkpar <arkadiy@ethcore.io"]
[lib] [lib]
[dependencies] [dependencies]
log = "0.3"
lru-cache = "0.0"
sha3 = { path = "../util/sha3" } sha3 = { path = "../util/sha3" }

View File

@ -6,7 +6,11 @@
use std::mem; use std::mem;
use std::ptr; use std::ptr;
use sizes::{CACHE_SIZES, DAG_SIZES}; use sizes::{CACHE_SIZES, DAG_SIZES};
use sha3::{self}; use sha3;
use std::slice;
use std::path::PathBuf;
use std::io::{Read, Write, self};
use std::fs::{self, File};
pub const ETHASH_EPOCH_LENGTH: u64 = 30000; pub const ETHASH_EPOCH_LENGTH: u64 = 30000;
pub const ETHASH_CACHE_ROUNDS: usize = 3; pub const ETHASH_CACHE_ROUNDS: usize = 3;
@ -76,6 +80,45 @@ impl Light {
pub fn compute(&self, header_hash: &H256, nonce: u64) -> ProofOfWork { pub fn compute(&self, header_hash: &H256, nonce: u64) -> ProofOfWork {
light_compute(self, header_hash, nonce) light_compute(self, header_hash, nonce)
} }
pub fn file_path(block_number: u64) -> PathBuf {
let mut home = ::std::env::home_dir().unwrap();
home.push(".ethash");
home.push("light");
let seed_hash = get_seedhash(block_number);
home.push(to_hex(&seed_hash));
home
}
pub fn from_file(block_number: u64) -> io::Result<Light> {
let path = Light::file_path(block_number);
let mut file = try!(File::open(path));
let cache_size = get_cache_size(block_number);
if try!(file.metadata()).len() != cache_size as u64 {
return Err(io::Error::new(io::ErrorKind::Other, "Cache file size mismatch"));
}
let num_nodes = cache_size / NODE_BYTES;
let mut nodes: Vec<Node> = Vec::new();
nodes.resize(num_nodes, unsafe { mem::uninitialized() });
let buf = unsafe { slice::from_raw_parts_mut(nodes.as_mut_ptr() as *mut u8, cache_size) };
try!(file.read_exact(buf));
Ok(Light {
cache: nodes,
block_number: block_number,
})
}
pub fn to_file(&self) -> io::Result<()> {
let path = Light::file_path(self.block_number);
try!(fs::create_dir_all(path.parent().unwrap()));
let mut file = try!(File::create(path));
let cache_size = self.cache.len() * NODE_BYTES;
let buf = unsafe { slice::from_raw_parts(self.cache.as_ptr() as *const u8, cache_size) };
try!(file.write(buf));
Ok(())
}
} }
#[inline] #[inline]
@ -249,6 +292,19 @@ fn light_new(block_number: u64) -> Light {
} }
} }
static CHARS: &'static[u8] = b"0123456789abcdef";
fn to_hex(bytes: &[u8]) -> String {
let mut v = Vec::with_capacity(bytes.len() * 2);
for &byte in bytes.iter() {
v.push(CHARS[(byte >> 4) as usize]);
v.push(CHARS[(byte & 0xf) as usize]);
}
unsafe {
String::from_utf8_unchecked(v)
}
}
#[test] #[test]
fn test_difficulty_test() { fn test_difficulty_test() {
let hash = [0xf5, 0x7e, 0x6f, 0x3a, 0xcf, 0xc0, 0xdd, 0x4b, 0x5b, 0xf2, 0xbe, 0xe4, 0x0a, 0xb3, 0x35, 0x8a, 0xa6, 0x87, 0x73, 0xa8, 0xd0, 0x9f, 0x5e, 0x59, 0x5e, 0xab, 0x55, 0x94, 0x05, 0x52, 0x7d, 0x72]; let hash = [0xf5, 0x7e, 0x6f, 0x3a, 0xcf, 0xc0, 0xdd, 0x4b, 0x5b, 0xf2, 0xbe, 0xe4, 0x0a, 0xb3, 0x35, 0x8a, 0xa6, 0x87, 0x73, 0xa8, 0xd0, 0x9f, 0x5e, 0x59, 0x5e, 0xab, 0x55, 0x94, 0x05, 0x52, 0x7d, 0x72];

View File

@ -1,25 +1,28 @@
//! Ethash implementation //! Ethash implementation
//! See https://github.com/ethereum/wiki/wiki/Ethash //! See https://github.com/ethereum/wiki/wiki/Ethash
extern crate sha3; extern crate sha3;
extern crate lru_cache;
#[macro_use]
extern crate log;
mod sizes; mod sizes;
mod compute; mod compute;
use lru_cache::LruCache;
use compute::Light; use compute::Light;
pub use compute::{quick_get_difficulty, H256, ProofOfWork, ETHASH_EPOCH_LENGTH}; pub use compute::{quick_get_difficulty, H256, ProofOfWork, ETHASH_EPOCH_LENGTH};
use std::collections::HashMap; use std::sync::{Arc, Mutex};
use std::sync::RwLock;
/// Lighy/Full cache manager /// Lighy/Full cache manager
pub struct EthashManager { pub struct EthashManager {
lights: RwLock<HashMap<u64, Light>>, lights: Mutex<LruCache<u64, Arc<Light>>>
} }
impl EthashManager { impl EthashManager {
/// Create a new new instance of ethash manager /// Create a new new instance of ethash manager
pub fn new() -> EthashManager { pub fn new() -> EthashManager {
EthashManager { EthashManager {
lights: RwLock::new(HashMap::new()) lights: Mutex::new(LruCache::new(2))
} }
} }
@ -30,15 +33,27 @@ impl EthashManager {
/// `nonce` - The nonce to pack into the mix /// `nonce` - The nonce to pack into the mix
pub fn compute_light(&self, block_number: u64, header_hash: &H256, nonce: u64) -> ProofOfWork { pub fn compute_light(&self, block_number: u64, header_hash: &H256, nonce: u64) -> ProofOfWork {
let epoch = block_number / ETHASH_EPOCH_LENGTH; let epoch = block_number / ETHASH_EPOCH_LENGTH;
while !self.lights.read().unwrap().contains_key(&epoch) { let light = {
if let Ok(mut lights) = self.lights.try_write() let mut lights = self.lights.lock().unwrap();
{ match lights.get_mut(&epoch).map(|l| l.clone()) {
if !lights.contains_key(&epoch) { None => {
let light = Light::new(block_number); let light = match Light::from_file(block_number) {
lights.insert(epoch, light); Ok(light) => Arc::new(light),
Err(e) => {
debug!("Light cache file not found for {}:{}", block_number, e);
let light = Light::new(block_number);
if let Err(e) = light.to_file() {
warn!("Light cache file write error: {}", e);
}
Arc::new(light)
}
};
lights.insert(epoch, light.clone());
light
} }
Some(light) => light
} }
} };
self.lights.read().unwrap().get(&epoch).unwrap().compute(header_hash, nonce) light.compute(header_hash, nonce)
} }
} }

30
ethcore/Cargo.toml Normal file
View File

@ -0,0 +1,30 @@
[package]
description = "Ethcore library"
homepage = "http://ethcore.io"
license = "GPL-3.0"
name = "ethcore"
version = "0.1.0"
authors = ["Ethcore <admin@ethcore.io>"]
[dependencies]
log = "0.3"
env_logger = "0.3"
rustc-serialize = "0.3"
flate2 = "0.2"
rocksdb = "0.3"
heapsize = "0.2.0"
rust-crypto = "0.2.34"
time = "0.1"
#interpolate_idents = { git = "https://github.com/SkylerLipthay/interpolate_idents" }
ethcore-util = { path = "../util" }
evmjit = { path = "../evmjit", optional = true }
ethash = { path = "../ethash" }
num_cpus = "0.2"
clippy = "0.0.37"
crossbeam = "0.1.5"
lazy_static = "0.1"
[features]
jit = ["evmjit"]
evm_debug = []
test-heavy = []

View File

@ -84,7 +84,7 @@ pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
declare_test!{StateTests_stBlockHashTest, "StateTests/stBlockHashTest"} declare_test!{StateTests_stBlockHashTest, "StateTests/stBlockHashTest"}
declare_test!{StateTests_stCallCodes, "StateTests/stCallCodes"} declare_test!{StateTests_stCallCodes, "StateTests/stCallCodes"}
declare_test!{StateTests_stCallCreateCallCodeTest, "StateTests/stCallCreateCallCodeTest"} //declare_test!{StateTests_stCallCreateCallCodeTest, "StateTests/stCallCreateCallCodeTest"}
declare_test!{StateTests_stDelegatecallTest, "StateTests/stDelegatecallTest"} declare_test!{StateTests_stDelegatecallTest, "StateTests/stDelegatecallTest"}
declare_test!{StateTests_stExample, "StateTests/stExample"} declare_test!{StateTests_stExample, "StateTests/stExample"}
declare_test!{StateTests_stInitCodeTest, "StateTests/stInitCodeTest"} declare_test!{StateTests_stInitCodeTest, "StateTests/stInitCodeTest"}
@ -297,7 +297,7 @@ declare_test!{StateTests_RandomTests_st201503181357CPPJIT, "StateTests/RandomTes
declare_test!{StateTests_RandomTests_st201503181358CPPJIT, "StateTests/RandomTests/st201503181358CPPJIT"} declare_test!{StateTests_RandomTests_st201503181358CPPJIT, "StateTests/RandomTests/st201503181358CPPJIT"}
declare_test!{StateTests_RandomTests_st201503181358GO, "StateTests/RandomTests/st201503181358GO"} declare_test!{StateTests_RandomTests_st201503181358GO, "StateTests/RandomTests/st201503181358GO"}
declare_test!{StateTests_RandomTests_st201503181359GO, "StateTests/RandomTests/st201503181359GO"} declare_test!{StateTests_RandomTests_st201503181359GO, "StateTests/RandomTests/st201503181359GO"}
declare_test!{StateTests_RandomTests_st201503181402CPPJIT, "StateTests/RandomTests/st201503181402CPPJIT"} //declare_test!{StateTests_RandomTests_st201503181402CPPJIT, "StateTests/RandomTests/st201503181402CPPJIT"}
declare_test!{StateTests_RandomTests_st201503181403GO, "StateTests/RandomTests/st201503181403GO"} declare_test!{StateTests_RandomTests_st201503181403GO, "StateTests/RandomTests/st201503181403GO"}
declare_test!{StateTests_RandomTests_st201503181406CPPJIT, "StateTests/RandomTests/st201503181406CPPJIT"} declare_test!{StateTests_RandomTests_st201503181406CPPJIT, "StateTests/RandomTests/st201503181406CPPJIT"}
declare_test!{StateTests_RandomTests_st201503181406GO, "StateTests/RandomTests/st201503181406GO"} declare_test!{StateTests_RandomTests_st201503181406GO, "StateTests/RandomTests/st201503181406GO"}
@ -569,7 +569,7 @@ declare_test!{StateTests_RandomTests_st201503181929GO, "StateTests/RandomTests/s
declare_test!{StateTests_RandomTests_st201503181931CPPJIT, "StateTests/RandomTests/st201503181931CPPJIT"} declare_test!{StateTests_RandomTests_st201503181931CPPJIT, "StateTests/RandomTests/st201503181931CPPJIT"}
declare_test!{StateTests_RandomTests_st201503181931GO, "StateTests/RandomTests/st201503181931GO"} declare_test!{StateTests_RandomTests_st201503181931GO, "StateTests/RandomTests/st201503181931GO"}
declare_test!{StateTests_RandomTests_st201503181931PYTHON, "StateTests/RandomTests/st201503181931PYTHON"} declare_test!{StateTests_RandomTests_st201503181931PYTHON, "StateTests/RandomTests/st201503181931PYTHON"}
declare_test!{StateTests_RandomTests_st201503191646GO, "StateTests/RandomTests/st201503191646GO"} //declare_test!{StateTests_RandomTests_st201503191646GO, "StateTests/RandomTests/st201503191646GO"}
declare_test!{StateTests_RandomTests_st201503200837JS, "StateTests/RandomTests/st201503200837JS"} declare_test!{StateTests_RandomTests_st201503200837JS, "StateTests/RandomTests/st201503200837JS"}
declare_test!{StateTests_RandomTests_st201503200838JS, "StateTests/RandomTests/st201503200838JS"} declare_test!{StateTests_RandomTests_st201503200838JS, "StateTests/RandomTests/st201503200838JS"}
declare_test!{StateTests_RandomTests_st201503200841JS, "StateTests/RandomTests/st201503200841JS"} declare_test!{StateTests_RandomTests_st201503200841JS, "StateTests/RandomTests/st201503200841JS"}

View File

@ -27,6 +27,4 @@ slab = { git = "https://github.com/arkpar/slab.git" }
sha3 = { path = "sha3" } sha3 = { path = "sha3" }
serde = "0.6.7" serde = "0.6.7"
clippy = "0.0.37" clippy = "0.0.37"
[dev-dependencies]
json-tests = { path = "json-tests" } json-tests = { path = "json-tests" }

View File

@ -1217,6 +1217,8 @@ mod tests {
#[test] #[test]
#[should_panic] #[should_panic]
// overflows panic only in debug builds. Running this test with `--release` flag, always fails
#[ignore]
pub fn uint128_add_overflow_panic() { pub fn uint128_add_overflow_panic() {
U128::from_str("ffffffffffffffffffffffffffffffff").unwrap() U128::from_str("ffffffffffffffffffffffffffffffff").unwrap()
+ +