Merge pull request #125 from gavofyork/gav

Gav
This commit is contained in:
Arkadiy Paronyan 2016-01-15 13:18:01 +01:00
commit 93292f8d09
3 changed files with 24 additions and 43 deletions

View File

@ -21,8 +21,6 @@ pub struct Substate {
logs: Vec<LogEntry>,
/// Refund counter of SSTORE nonzero->zero.
refunds_count: U256,
/// True if transaction, or one of its subcalls runs out of gas.
excepted: bool,
/// Created contracts.
contracts_created: Vec<Address>
}
@ -34,7 +32,6 @@ impl Substate {
suicides: HashSet::new(),
logs: vec![],
refunds_count: U256::zero(),
excepted: false,
contracts_created: vec![]
}
}
@ -43,11 +40,8 @@ impl Substate {
self.suicides.extend(s.suicides.into_iter());
self.logs.extend(s.logs.into_iter());
self.refunds_count = self.refunds_count + s.refunds_count;
self.excepted |= s.excepted;
self.contracts_created.extend(s.contracts_created.into_iter());
}
pub fn excepted(&self) -> bool { self.excepted }
}
/// Transaction execution receipt.
@ -68,8 +62,6 @@ pub struct Executed {
pub cumulative_gas_used: U256,
/// Vector of logs generated by transaction.
pub logs: Vec<LogEntry>,
/// Execution ended running out of gas.
pub excepted: bool,
/// Addresses of contracts created during execution of transaction.
/// Ordered from earliest creation.
///
@ -208,8 +200,8 @@ impl<'a> Executive<'a> {
},
// just drain the whole gas
false => {
substate.excepted = true;
Ok(U256::zero())
self.state.revert(backup);
Err(evm::Error::OutOfGas)
}
}
} else if params.code.len() > 0 {
@ -296,7 +288,6 @@ impl<'a> Executive<'a> {
refunded: refund,
cumulative_gas_used: self.info.gas_used + gas_used,
logs: substate.logs,
excepted: substate.excepted,
contracts_created: substate.contracts_created
})
},
@ -307,7 +298,6 @@ impl<'a> Executive<'a> {
refunded: U256::zero(),
cumulative_gas_used: self.info.gas_used + t.gas,
logs: vec![],
excepted: true,
contracts_created: vec![]
})
}
@ -318,7 +308,6 @@ impl<'a> Executive<'a> {
// TODO: handle other evm::Errors same as OutOfGas once they are implemented
match result {
&Err(evm::Error::OutOfGas) => {
substate.excepted = true;
self.state.revert(backup);
},
&Ok(_) | &Err(evm::Error::Internal) => substate.accrue(un_substate)
@ -464,7 +453,7 @@ impl<'a> Ext for Externalities<'a> {
let gas = *gas - gas_cost;
// if balance is insufficient or we are to deep, return
// if balance is insufficient or we are too deep, return
if self.state.balance(&self.params.address) < *value || self.depth >= self.schedule.max_depth {
return Ok((gas + call_gas, true));
}
@ -902,7 +891,6 @@ mod tests {
assert_eq!(executed.refunded, U256::from(58_699));
assert_eq!(executed.cumulative_gas_used, U256::from(41_301));
assert_eq!(executed.logs.len(), 0);
assert_eq!(executed.excepted, false);
assert_eq!(executed.contracts_created.len(), 0);
assert_eq!(state.balance(&sender), U256::from(1));
assert_eq!(state.balance(&contract), U256::from(17));

View File

@ -31,8 +31,7 @@ impl PodAccount {
let mut stream = RlpStream::new_list(4);
stream.append(&self.nonce);
stream.append(&self.balance);
// TODO.
stream.append(&SHA3_NULL_RLP);
stream.append(&sec_trie_root(self.storage.iter().map(|(k, v)| (k.to_vec(), encode(&U256::from(v.as_slice())))).collect()));
stream.append(&self.code.sha3());
stream.out()
}

View File

@ -4,11 +4,6 @@ use pod_state::*;
use state_diff::*;
use ethereum;
fn flush(s: String) {
::std::io::stdout().write(s.as_bytes()).unwrap();
::std::io::stdout().flush().unwrap();
}
fn do_json_test(json_data: &[u8]) -> Vec<String> {
let json = Json::from_str(::std::str::from_utf8(json_data).unwrap()).expect("Json is invalid");
let mut failed = Vec::new();
@ -39,32 +34,31 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
//println!("Transaction: {:?}", t);
//println!("Env: {:?}", env);
let calc_post = sec_trie_root(post.get().iter().map(|(k, v)| (k.to_vec(), v.rlp())).collect());
{
if fail_unless(post_state_root == calc_post) {
println!("!!! {}: Trie root mismatch (got: {}, expect: {}):", name, calc_post, post_state_root);
println!("!!! Post:\n{}", post);
} else {
let mut s = State::new_temp();
s.populate_from(post.clone());
s.populate_from(pre);
s.commit();
assert_eq!(&post_state_root, s.root());
}
let res = s.apply(&env, engine.deref(), &t);
let mut s = State::new_temp();
s.populate_from(pre);
s.commit();
let res = s.apply(&env, engine.deref(), &t);
if fail_unless(s.root() == &post_state_root) {
println!("!!! {}: State mismatch (got: {}, expect: {}):", name, s.root(), post_state_root);
let our_post = s.to_pod();
println!("Got:\n{}", our_post);
println!("Expect:\n{}", post);
println!("Diff ---expect -> +++got:\n{}", StateDiff::diff_pod(&post, &our_post));
}
if fail_unless(s.root() == &post_state_root) {
println!("!!! {}: State mismatch (got: {}, expect: {}):", name, s.root(), post_state_root);
let our_post = s.to_pod();
println!("Got:\n{}", our_post);
println!("Expect:\n{}", post);
println!("Diff ---expect -> +++got:\n{}", StateDiff::diff_pod(&post, &our_post));
}
if let Ok(r) = res {
if fail_unless(logs == r.logs) {
println!("!!! {}: Logs mismatch:", name);
println!("Got:\n{:?}", r.logs);
println!("Expect:\n{:?}", logs);
if let Ok(r) = res {
if fail_unless(logs == r.logs) {
println!("!!! {}: Logs mismatch:", name);
println!("Got:\n{:?}", r.logs);
println!("Expect:\n{:?}", logs);
}
}
}
}