Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into dp/chore/extract-engine-trait
Browse files Browse the repository at this point in the history
* master:
  Extract Machine from ethcore (#10949)
  removed redundant state_root function from spec, improve spec error types (#10955)
  Add support for Energy Web Foundation's new chains (#10957)
  [evmbin] add more tests to main.rs (#10956)
  • Loading branch information
dvdplm committed Aug 13, 2019
2 parents b244bfb + 73f4564 commit 37be7b2
Show file tree
Hide file tree
Showing 11 changed files with 550 additions and 174 deletions.
208 changes: 208 additions & 0 deletions ethcore/res/ethereum/ewc.json

Large diffs are not rendered by default.

80 changes: 0 additions & 80 deletions ethcore/res/ethereum/tobalaba.json

This file was deleted.

202 changes: 202 additions & 0 deletions ethcore/res/ethereum/volta.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions ethcore/src/spec/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ bundle_release_spec! {
"ethereum/poasokol" => new_sokol,
"ethereum/rinkeby" => new_rinkeby,
"ethereum/ropsten" => new_ropsten,
"ethereum/tobalaba" => new_tobalaba
"ethereum/volta" => new_volta,
"ethereum/ewc" => new_ewc
}

bundle_test_spec! {
Expand Down Expand Up @@ -146,7 +147,7 @@ mod tests {
let tempdir = TempDir::new("").unwrap();
let morden = new_morden(&tempdir.path());

assert_eq!(morden.state_root(), "f3f4696bbf3b3b07775128eb7a3763279a394e382130f27c21e70233e04946a9".parse().unwrap());
assert_eq!(morden.state_root, "f3f4696bbf3b3b07775128eb7a3763279a394e382130f27c21e70233e04946a9".parse().unwrap());
let genesis = morden.genesis_block();
assert_eq!(view!(BlockView, &genesis).header_view().hash(), "0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303".parse().unwrap());
}
Expand All @@ -156,7 +157,7 @@ mod tests {
let tempdir = TempDir::new("").unwrap();
let frontier = new_foundation(&tempdir.path());

assert_eq!(frontier.state_root(), "d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544".parse().unwrap());
assert_eq!(frontier.state_root, "d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544".parse().unwrap());
let genesis = frontier.genesis_block();
assert_eq!(view!(BlockView, &genesis).header_view().hash(), "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3".parse().unwrap());
}
Expand Down
38 changes: 14 additions & 24 deletions ethcore/src/spec/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ use trace::{NoopTracer, NoopVMTracer};

pub use ethash::OptimizeFor;

// helper for formatting errors.
fn fmt_err<F: ::std::fmt::Display>(f: F) -> String {
format!("Spec json is invalid: {}", f)
}

/// Runtime parameters for the spec that are related to how the software should run the chain,
/// rather than integral properties of the chain itself.
pub struct SpecParams<'a> {
Expand Down Expand Up @@ -222,7 +217,7 @@ pub struct Spec {
/// Contract constructors to be executed on genesis.
pub constructors: Vec<(Address, Bytes)>,
/// May be prepopulated if we know this in advance.
pub state_root_memo: H256,
pub state_root: H256,
/// Genesis state as plain old data.
pub genesis_state: PodState,
}
Expand Down Expand Up @@ -282,7 +277,7 @@ fn load_from(spec_params: SpecParams, s: ethjson::spec::Spec) -> Result<Spec, Er
.collect();
let genesis_state: PodState = s.accounts.into();

let (state_root_memo, _) = run_constructors(
let (state_root, _) = run_constructors(
&genesis_state,
&constructors,
&*engine,
Expand Down Expand Up @@ -311,7 +306,7 @@ fn load_from(spec_params: SpecParams, s: ethjson::spec::Spec) -> Result<Spec, Er
hardcoded_sync,
constructors,
genesis_state,
state_root_memo,
state_root,
};

Ok(s)
Expand Down Expand Up @@ -354,11 +349,6 @@ impl Spec {
}
}

/// Return the state root for the genesis state, memoising accordingly.
pub fn state_root(&self) -> H256 {
self.state_root_memo
}

/// Get common blockchain parameters.
pub fn params(&self) -> &CommonParams {
&self.engine.params()
Expand Down Expand Up @@ -394,7 +384,7 @@ impl Spec {
header.set_transactions_root(self.transactions_root.clone());
header.set_uncles_hash(keccak(RlpStream::new_list(0).out()));
header.set_extra_data(self.extra_data.clone());
header.set_state_root(self.state_root());
header.set_state_root(self.state_root);
header.set_receipts_root(self.receipts_root.clone());
header.set_log_bloom(Bloom::default());
header.set_gas_used(self.gas_used.clone());
Expand Down Expand Up @@ -448,13 +438,13 @@ impl Spec {
BasicBackend(journaldb::new_memory_db()),
)?;

self.state_root_memo = root;
self.state_root = root;
Ok(())
}

/// Ensure that the given state DB has the trie nodes in for the genesis state.
pub fn ensure_db_good<T: Backend>(&self, db: T, factories: &Factories) -> Result<T, Error> {
if db.as_hash_db().contains(&self.state_root(), hash_db::EMPTY_PREFIX) {
if db.as_hash_db().contains(&self.state_root, hash_db::EMPTY_PREFIX) {
return Ok(db);
}

Expand All @@ -471,14 +461,14 @@ impl Spec {
db
)?;

assert_eq!(root, self.state_root(), "Spec's state root has not been precomputed correctly.");
assert_eq!(root, self.state_root, "Spec's state root has not been precomputed correctly.");
Ok(db)
}

/// Loads just the state machine from a json file.
pub fn load_machine<R: Read>(reader: R) -> Result<Machine, String> {
pub fn load_machine<R: Read>(reader: R) -> Result<Machine, Error> {
ethjson::spec::Spec::load(reader)
.map_err(fmt_err)
.map_err(|e| Error::Msg(e.to_string()))
.map(|s| {
let builtins = s.accounts.builtins().into_iter().map(|p| (p.0.into(), From::from(p.1))).collect();
let params = CommonParams::from(s.params);
Expand All @@ -488,10 +478,10 @@ impl Spec {

/// Loads spec from json file. Provide factories for executing contracts and ensuring
/// storage goes to the right place.
pub fn load<'a, T: Into<SpecParams<'a>>, R: Read>(params: T, reader: R) -> Result<Self, String> {
pub fn load<'a, T: Into<SpecParams<'a>>, R: Read>(params: T, reader: R) -> Result<Self, Error> {
ethjson::spec::Spec::load(reader)
.map_err(fmt_err)
.and_then(|x| load_from(params.into(), x).map_err(fmt_err))
.map_err(|e| Error::Msg(e.to_string()))
.and_then(|x| load_from(params.into(), x))
}

/// initialize genesis epoch data, using in-memory database for
Expand Down Expand Up @@ -573,7 +563,7 @@ mod tests {
let test_spec = spec::new_test();

assert_eq!(
test_spec.state_root(),
test_spec.state_root,
H256::from_str("f3f4696bbf3b3b07775128eb7a3763279a394e382130f27c21e70233e04946a9").unwrap()
);
let genesis = test_spec.genesis_block();
Expand All @@ -591,7 +581,7 @@ mod tests {
.unwrap();
let state = State::from_existing(
db.boxed_clone(),
spec.state_root(),
spec.state_root,
spec.engine.account_start_nonce(0),
Default::default(),
).unwrap();
Expand Down
19 changes: 10 additions & 9 deletions evmbin/src/display/std_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,20 +332,21 @@ pub mod tests {
}
}

pub fn informant() -> (Informant<TestWriter, TestWriter>, Arc<Mutex<Vec<u8>>>) {
pub fn informant() -> (Informant<TestWriter, TestWriter>, TestWriter, TestWriter) {
let trace_writer: TestWriter = Default::default();
let out_writer: TestWriter = Default::default();
let res = trace_writer.0.clone();
(Informant::new(trace_writer, out_writer), res)
let trace_copy = Clone::clone(&trace_writer);
let out_copy = Clone::clone(&out_writer);
(Informant::new(trace_writer, out_writer), trace_copy, out_copy)
}

#[test]
fn should_trace_failure() {
let (inf, res) = informant();
let (inf, res, _) = informant();
run_test(
inf,
move |_, expected| {
let bytes = res.lock().unwrap();
let bytes = res.0.lock().unwrap();
assert_eq!(expected, &String::from_utf8_lossy(&**bytes))
},
"60F8d6",
Expand All @@ -355,11 +356,11 @@ pub mod tests {
"#,
);

let (inf, res) = informant();
let (inf, res, _) = informant();
run_test(
inf,
move |_, expected| {
let bytes = res.lock().unwrap();
let bytes = res.0.lock().unwrap();
assert_eq!(expected, &String::from_utf8_lossy(&**bytes))
},
"F8d6",
Expand All @@ -371,11 +372,11 @@ pub mod tests {

#[test]
fn should_trace_create_correctly() {
let (informant, res) = informant();
let (informant, res, _) = informant();
run_test(
informant,
move |_, expected| {
let bytes = res.lock().unwrap();
let bytes = res.0.lock().unwrap();
assert_eq!(expected, &String::from_utf8_lossy(&**bytes))
},
"32343434345830f138343438323439f0",
Expand Down
4 changes: 2 additions & 2 deletions evmbin/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ pub mod tests {
fn should_call_account_from_spec() {
use display::std_json::tests::informant;

let (inf, res) = informant();
let (inf, res, _) = informant();
let mut params = ActionParams::default();
params.code_address = Address::from_low_u64_be(0x20);
params.gas = 0xffff.into();
Expand All @@ -284,7 +284,7 @@ pub mod tests {
let _result = run_action(&spec, params, inf, TrieSpec::Secure);

assert_eq!(
&String::from_utf8_lossy(&**res.lock().unwrap()),
&String::from_utf8_lossy(&**res.0.lock().unwrap()),
r#"{"pc":0,"op":98,"opName":"PUSH3","gas":"0xffff","stack":[],"storage":{},"depth":1}
{"pc":4,"op":96,"opName":"PUSH1","gas":"0xfffc","stack":["0xaaaaaa"],"storage":{},"depth":1}
{"pc":6,"op":96,"opName":"PUSH1","gas":"0xfff9","stack":["0xaaaaaa","0xaa"],"storage":{},"depth":1}
Expand Down
Loading

0 comments on commit 37be7b2

Please sign in to comment.