Make stuff work.

This commit is contained in:
Gav Wood 2016-01-16 01:44:07 +01:00
parent 4fde74c5e8
commit 2f14b755f1
5 changed files with 12 additions and 9 deletions

View File

@ -205,7 +205,6 @@ impl Account {
match (self.code_hash.is_none(), self.code_cache.is_empty()) { match (self.code_hash.is_none(), self.code_cache.is_empty()) {
(true, true) => self.code_hash = Some(SHA3_EMPTY), (true, true) => self.code_hash = Some(SHA3_EMPTY),
(true, false) => { (true, false) => {
println!("Writing into DB {:?}", self.code_cache);
self.code_hash = Some(db.insert(&self.code_cache)); self.code_hash = Some(db.insert(&self.code_cache));
}, },
(false, _) => {}, (false, _) => {},

View File

@ -171,6 +171,7 @@ impl<'a> Executive<'a> {
// at first, transfer value to destination // at first, transfer value to destination
self.state.transfer_balance(&params.sender, &params.address, &params.value); self.state.transfer_balance(&params.sender, &params.address, &params.value);
debug!("Executive::call(params={:?}) self.env_info={:?}", params, self.info);
if self.engine.is_builtin(&params.code_address) { if self.engine.is_builtin(&params.code_address) {
// if destination is builtin, try to execute it // if destination is builtin, try to execute it

View File

@ -133,6 +133,7 @@ impl<'a> Ext for Externalities<'a> {
data: &[u8], data: &[u8],
code_address: &Address, code_address: &Address,
output: &mut [u8]) -> Result<(U256, bool), evm::Error> { output: &mut [u8]) -> Result<(U256, bool), evm::Error> {
let mut gas_cost = *call_gas; let mut gas_cost = *call_gas;
let mut call_gas = *call_gas; let mut call_gas = *call_gas;
@ -147,9 +148,10 @@ impl<'a> Ext for Externalities<'a> {
call_gas = call_gas + U256::from(self.schedule.call_stipend); call_gas = call_gas + U256::from(self.schedule.call_stipend);
} }
// flush(format!("Externalities::call(gas={}, call_gas={}, recv={}, value={}, data={}, code={})\n", gas, call_gas, receive_address, value, data.pretty(), code_address)); debug!("Externalities::call(gas={}, call_gas={}, recv={}, value={}, data={}, code={})\n", gas, call_gas, receive_address, value, data.pretty(), code_address);
if gas_cost > *gas { if gas_cost > *gas {
debug!("Externalities::call: OutOfGas gas_cost={}, gas={}", gas_cost, gas);
return Err(evm::Error::OutOfGas); return Err(evm::Error::OutOfGas);
} }
@ -157,7 +159,8 @@ impl<'a> Ext for Externalities<'a> {
// if balance is insufficient or we are too 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 { if self.state.balance(&self.params.address) < *value || self.depth >= self.schedule.max_depth {
return Ok((gas + call_gas, true)); debug!("Externalities::call: OutOfCash bal({})={}, value={}", self.params.address, self.state.balance(&self.params.address), value);
return Ok((gas + call_gas, false));
} }
let params = ActionParams { let params = ActionParams {

View File

@ -150,7 +150,7 @@ impl State {
let e = try!(Executive::new(self, env_info, engine).transact(t)); let e = try!(Executive::new(self, env_info, engine).transact(t));
//println!("Executed: {:?}", e); //println!("Executed: {:?}", e);
// flush(format!("Applied transaction. Diff:\n{}\n", StateDiff::diff_pod(&old, &self.to_pod()))); debug!("Applied transaction. Diff:\n{}\n", StateDiff::diff_pod(&old, &self.to_pod()));
self.commit(); self.commit();
let receipt = Receipt::new(self.root().clone(), e.cumulative_gas_used, e.logs); let receipt = Receipt::new(self.root().clone(), e.cumulative_gas_used, e.logs);
debug!("Transaction receipt: {:?}", receipt); debug!("Transaction receipt: {:?}", receipt);

View File

@ -115,18 +115,18 @@ pub fn verify_block_family<BC>(header: &Header, bytes: &[u8], engine: &Engine, b
/// Phase 4 verification. Check block information against transaction enactment results, /// Phase 4 verification. Check block information against transaction enactment results,
pub fn verify_block_final(expected: &Header, got: &Header) -> Result<(), Error> { pub fn verify_block_final(expected: &Header, got: &Header) -> Result<(), Error> {
if expected.state_root != got.state_root { if expected.gas_used != got.gas_used {
return Err(From::from(BlockError::InvalidStateRoot(Mismatch { expected: expected.state_root.clone(), found: got.state_root.clone() }))) return Err(From::from(BlockError::InvalidGasUsed(Mismatch { expected: expected.gas_used, found: got.gas_used })))
} }
if expected.receipts_root != got.receipts_root { if expected.receipts_root != got.receipts_root {
return Err(From::from(BlockError::InvalidReceiptsStateRoot(Mismatch { expected: expected.receipts_root.clone(), found: got.receipts_root.clone() }))) return Err(From::from(BlockError::InvalidReceiptsStateRoot(Mismatch { expected: expected.receipts_root.clone(), found: got.receipts_root.clone() })))
} }
if expected.state_root != got.state_root {
return Err(From::from(BlockError::InvalidStateRoot(Mismatch { expected: expected.state_root.clone(), found: got.state_root.clone() })))
}
if expected.log_bloom != got.log_bloom { if expected.log_bloom != got.log_bloom {
return Err(From::from(BlockError::InvalidLogBloom(Mismatch { expected: expected.log_bloom.clone(), found: got.log_bloom.clone() }))) return Err(From::from(BlockError::InvalidLogBloom(Mismatch { expected: expected.log_bloom.clone(), found: got.log_bloom.clone() })))
} }
if expected.gas_used != got.gas_used {
return Err(From::from(BlockError::InvalidGasUsed(Mismatch { expected: expected.gas_used, found: got.gas_used })))
}
Ok(()) Ok(())
} }