Merge branch 'master' into sync-tests
This commit is contained in:
commit
421c70820c
@ -22,6 +22,7 @@ ethash = { path = "ethash" }
|
|||||||
num_cpus = "0.2"
|
num_cpus = "0.2"
|
||||||
clippy = "0.0.37"
|
clippy = "0.0.37"
|
||||||
crossbeam = "0.1.5"
|
crossbeam = "0.1.5"
|
||||||
|
lazy_static = "0.1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
jit = ["evmjit"]
|
jit = ["evmjit"]
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"engineName": "Ethash",
|
"engineName": "Ethash",
|
||||||
"params": {
|
"params": {
|
||||||
"accountStartNonce": "0x00",
|
"accountStartNonce": "0x00",
|
||||||
"frontierCompatibilityModeLimit": "0xDBBA0",
|
"frontierCompatibilityModeLimit": "0xdbba0",
|
||||||
"maximumExtraDataSize": "0x20",
|
"maximumExtraDataSize": "0x20",
|
||||||
"tieBreakingGas": false,
|
"tieBreakingGas": false,
|
||||||
"minGasLimit": "0x1388",
|
"minGasLimit": "0x1388",
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"engineName": "Ethash",
|
"engineName": "Ethash",
|
||||||
"params": {
|
"params": {
|
||||||
"accountStartNonce": "0x00",
|
"accountStartNonce": "0x00",
|
||||||
"frontierCompatibilityModeLimit": "0",
|
"frontierCompatibilityModeLimit": 0,
|
||||||
"maximumExtraDataSize": "0x20",
|
"maximumExtraDataSize": "0x20",
|
||||||
"minGasLimit": "0x1388",
|
"minGasLimit": "0x1388",
|
||||||
"tieBreakingGas": false,
|
"tieBreakingGas": false,
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"engineName": "Ethash",
|
"engineName": "Ethash",
|
||||||
"params": {
|
"params": {
|
||||||
"accountStartNonce": "0x0100000",
|
"accountStartNonce": "0x0100000",
|
||||||
"frontierCompatibilityModeLimit": "0xDBBA0",
|
"frontierCompatibilityModeLimit": "0xdbba0",
|
||||||
"maximumExtraDataSize": "0x20",
|
"maximumExtraDataSize": "0x20",
|
||||||
"tieBreakingGas": false,
|
"tieBreakingGas": false,
|
||||||
"minGasLimit": "0x1388",
|
"minGasLimit": "0x1388",
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit e838fd90998fc5502d0b7c9427a4c231f9a6953d
|
Subproject commit c670b1d8c9f09593a6758ab2c099360e16c7c25b
|
@ -59,9 +59,14 @@ impl Engine for Ethash {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn schedule(&self, env_info: &EnvInfo) -> Schedule {
|
fn schedule(&self, env_info: &EnvInfo) -> Schedule {
|
||||||
|
trace!(target: "client", "Creating schedule. param={:?}, fCML={}", self.spec().engine_params.get("frontierCompatibilityModeLimit"), self.u64_param("frontierCompatibilityModeLimit"));
|
||||||
match env_info.number < self.u64_param("frontierCompatibilityModeLimit") {
|
match env_info.number < self.u64_param("frontierCompatibilityModeLimit") {
|
||||||
true => Schedule::new_frontier(),
|
true => {
|
||||||
_ => Schedule::new_homestead(),
|
Schedule::new_frontier()
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
Schedule::new_homestead()
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,12 +183,13 @@ impl Ethash {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
trace!(target: "ethash", "Calculating difficulty parent.difficulty={}, header.timestamp={}, parent.timestamp={}", parent.difficulty, header.timestamp, parent.timestamp);
|
||||||
|
//block_diff = parent_diff + parent_diff // 2048 * max(1 - (block_timestamp - parent_timestamp) // 10, -99)
|
||||||
let diff_inc = (header.timestamp - parent.timestamp) / 10;
|
let diff_inc = (header.timestamp - parent.timestamp) / 10;
|
||||||
if diff_inc <= 1 {
|
if diff_inc <= 1 {
|
||||||
parent.difficulty + parent.difficulty / From::from(2048) * From::from(1 - diff_inc)
|
parent.difficulty + parent.difficulty / From::from(2048) * From::from(1 - diff_inc)
|
||||||
}
|
} else {
|
||||||
else {
|
parent.difficulty - parent.difficulty / From::from(2048) * From::from(min(diff_inc - 1, 99))
|
||||||
parent.difficulty - parent.difficulty / From::from(2048) * From::from(max(diff_inc - 1, 99))
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
target = max(min_difficulty, target);
|
target = max(min_difficulty, target);
|
||||||
|
@ -91,6 +91,8 @@ extern crate evmjit;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate ethcore_util as util;
|
extern crate ethcore_util as util;
|
||||||
extern crate crossbeam;
|
extern crate crossbeam;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate lazy_static;
|
||||||
|
|
||||||
// NOTE: Add doc parser exception for these pub declarations.
|
// NOTE: Add doc parser exception for these pub declarations.
|
||||||
|
|
||||||
|
14
src/spec.rs
14
src/spec.rs
@ -16,7 +16,7 @@ pub fn gzip64res_to_json(source: &[u8]) -> Json {
|
|||||||
Json::from_str(&s).expect("Json is invalid")
|
Json::from_str(&s).expect("Json is invalid")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert JSON value to equivlaent RLP representation.
|
/// Convert JSON value to equivalent RLP representation.
|
||||||
// TODO: handle container types.
|
// TODO: handle container types.
|
||||||
fn json_to_rlp(json: &Json) -> Bytes {
|
fn json_to_rlp(json: &Json) -> Bytes {
|
||||||
match *json {
|
match *json {
|
||||||
@ -77,6 +77,10 @@ pub struct Spec {
|
|||||||
pub gas_used: U256,
|
pub gas_used: U256,
|
||||||
/// TODO [Gav Wood] Please document me
|
/// TODO [Gav Wood] Please document me
|
||||||
pub timestamp: u64,
|
pub timestamp: u64,
|
||||||
|
/// Transactions root of the genesis block. Should be SHA3_NULL_RLP.
|
||||||
|
pub transactions_root: H256,
|
||||||
|
/// Receipts root of the genesis block. Should be SHA3_NULL_RLP.
|
||||||
|
pub receipts_root: H256,
|
||||||
/// TODO [arkpar] Please document me
|
/// TODO [arkpar] Please document me
|
||||||
pub extra_data: Bytes,
|
pub extra_data: Bytes,
|
||||||
/// TODO [Gav Wood] Please document me
|
/// TODO [Gav Wood] Please document me
|
||||||
@ -120,11 +124,11 @@ impl Spec {
|
|||||||
timestamp: self.timestamp,
|
timestamp: self.timestamp,
|
||||||
number: 0,
|
number: 0,
|
||||||
author: self.author.clone(),
|
author: self.author.clone(),
|
||||||
transactions_root: SHA3_NULL_RLP.clone(),
|
transactions_root: self.transactions_root.clone(),
|
||||||
uncles_hash: RlpStream::new_list(0).out().sha3(),
|
uncles_hash: RlpStream::new_list(0).out().sha3(),
|
||||||
extra_data: self.extra_data.clone(),
|
extra_data: self.extra_data.clone(),
|
||||||
state_root: self.state_root().clone(),
|
state_root: self.state_root().clone(),
|
||||||
receipts_root: SHA3_NULL_RLP.clone(),
|
receipts_root: self.receipts_root.clone(),
|
||||||
log_bloom: H2048::new().clone(),
|
log_bloom: H2048::new().clone(),
|
||||||
gas_used: self.gas_used.clone(),
|
gas_used: self.gas_used.clone(),
|
||||||
gas_limit: self.gas_limit.clone(),
|
gas_limit: self.gas_limit.clone(),
|
||||||
@ -172,6 +176,8 @@ impl Spec {
|
|||||||
};
|
};
|
||||||
|
|
||||||
self.parent_hash = H256::from_json(&genesis["parentHash"]);
|
self.parent_hash = H256::from_json(&genesis["parentHash"]);
|
||||||
|
self.transactions_root = genesis.find("transactionsTrie").and_then(|_| Some(H256::from_json(&genesis["transactionsTrie"]))).unwrap_or(SHA3_NULL_RLP.clone());
|
||||||
|
self.receipts_root = genesis.find("receiptTrie").and_then(|_| Some(H256::from_json(&genesis["receiptTrie"]))).unwrap_or(SHA3_NULL_RLP.clone());
|
||||||
self.author = Address::from_json(&genesis["coinbase"]);
|
self.author = Address::from_json(&genesis["coinbase"]);
|
||||||
self.difficulty = U256::from_json(&genesis["difficulty"]);
|
self.difficulty = U256::from_json(&genesis["difficulty"]);
|
||||||
self.gas_limit = U256::from_json(&genesis["gasLimit"]);
|
self.gas_limit = U256::from_json(&genesis["gasLimit"]);
|
||||||
@ -248,6 +254,8 @@ impl FromJson for Spec {
|
|||||||
gas_limit: U256::from_str(&genesis["gasLimit"].as_string().unwrap()[2..]).unwrap(),
|
gas_limit: U256::from_str(&genesis["gasLimit"].as_string().unwrap()[2..]).unwrap(),
|
||||||
gas_used: U256::from(0u8),
|
gas_used: U256::from(0u8),
|
||||||
timestamp: u64::from_str(&genesis["timestamp"].as_string().unwrap()[2..]).unwrap(),
|
timestamp: u64::from_str(&genesis["timestamp"].as_string().unwrap()[2..]).unwrap(),
|
||||||
|
transactions_root: SHA3_NULL_RLP.clone(),
|
||||||
|
receipts_root: SHA3_NULL_RLP.clone(),
|
||||||
extra_data: genesis["extraData"].as_string().unwrap()[2..].from_hex().unwrap(),
|
extra_data: genesis["extraData"].as_string().unwrap()[2..].from_hex().unwrap(),
|
||||||
genesis_state: state,
|
genesis_state: state,
|
||||||
seal_fields: seal_fields,
|
seal_fields: seal_fields,
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
use std::env;
|
||||||
|
use log::{LogLevelFilter};
|
||||||
|
use env_logger::LogBuilder;
|
||||||
use super::test_common::*;
|
use super::test_common::*;
|
||||||
use client::{BlockChainClient,Client};
|
use client::{BlockChainClient,Client};
|
||||||
use pod_state::*;
|
use pod_state::*;
|
||||||
@ -10,7 +13,24 @@ pub enum ChainEra {
|
|||||||
Homestead,
|
Homestead,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref LOG_DUMMY: bool = {
|
||||||
|
let mut builder = LogBuilder::new();
|
||||||
|
builder.filter(None, LogLevelFilter::Info);
|
||||||
|
|
||||||
|
if let Ok(log) = env::var("RUST_LOG") {
|
||||||
|
builder.parse(&log);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(_) = builder.init() {
|
||||||
|
println!("logger initialized");
|
||||||
|
}
|
||||||
|
true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
|
pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
|
||||||
|
let _ = LOG_DUMMY.deref();
|
||||||
let json = Json::from_str(::std::str::from_utf8(json_data).unwrap()).expect("Json is invalid");
|
let json = Json::from_str(::std::str::from_utf8(json_data).unwrap()).expect("Json is invalid");
|
||||||
let mut failed = Vec::new();
|
let mut failed = Vec::new();
|
||||||
|
|
||||||
@ -35,10 +55,13 @@ pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
|
|||||||
spec.set_genesis_state(s);
|
spec.set_genesis_state(s);
|
||||||
spec.overwrite_genesis(test.find("genesisBlockHeader").unwrap());
|
spec.overwrite_genesis(test.find("genesisBlockHeader").unwrap());
|
||||||
assert!(spec.is_state_root_valid());
|
assert!(spec.is_state_root_valid());
|
||||||
|
let genesis_hash = spec.genesis_header().hash();
|
||||||
|
assert_eq!(genesis_hash, H256::from_json(&test.find("genesisBlockHeader").unwrap()["hash"]));
|
||||||
|
|
||||||
let temp = RandomTempPath::new();
|
let temp = RandomTempPath::new();
|
||||||
{
|
{
|
||||||
let client = Client::new(spec, temp.as_path(), IoChannel::disconnected()).unwrap();
|
let client = Client::new(spec, temp.as_path(), IoChannel::disconnected()).unwrap();
|
||||||
|
assert_eq!(client.chain_info().best_block_hash, genesis_hash);
|
||||||
for (b, is_valid) in blocks.into_iter() {
|
for (b, is_valid) in blocks.into_iter() {
|
||||||
if Block::is_good(&b) {
|
if Block::is_good(&b) {
|
||||||
let _ = client.import_block(b.clone());
|
let _ = client.import_block(b.clone());
|
||||||
|
Loading…
Reference in New Issue
Block a user