Skip to content

Commit

Permalink
Fixed receipt serialization and RPC (openethereum#6555)
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar authored and Pedro Branco committed Sep 29, 2017
1 parent 9f47909 commit 71f7726
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 88 deletions.
7 changes: 3 additions & 4 deletions ethcore/light/src/on_demand/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use std::sync::Arc;

use ethcore::basic_account::BasicAccount;
use ethcore::encoded;
use ethcore::engines::Engine;
use ethcore::receipt::Receipt;
use ethcore::engines::{Engine, StateDependentProof};
use ethcore::receipt::{Receipt, TransactionOutcome};
use ethcore::state::{self, ProvedExecution};
use ethcore::transaction::SignedTransaction;
use evm::env_info::EnvInfo;
Expand Down Expand Up @@ -926,8 +926,7 @@ mod tests {
#[test]
fn check_receipts() {
let receipts = (0..5).map(|_| Receipt {
state_root: Some(H256::random()),
status_code: None,
outcome: TransactionOutcome::StateRoot(H256::random()),
gas_used: 21_000u64.into(),
log_bloom: Default::default(),
logs: Vec::new(),
Expand Down
7 changes: 5 additions & 2 deletions ethcore/light/src/types/request/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1859,13 +1859,15 @@ mod tests {

#[test]
fn receipts_roundtrip() {
use ethcore::receipt::{Receipt, TransactionOutcome};
let req = IncompleteReceiptsRequest {
hash: Field::Scalar(Default::default()),
};

let full_req = Request::Receipts(req.clone());
let receipt = Receipt::new(TransactionOutcome::Unknown, Default::default(), Vec::new());
let res = ReceiptsResponse {
receipts: vec![Default::default(), Default::default()],
receipts: vec![receipt.clone(), receipt],
};
let full_res = Response::Receipts(res.clone());

Expand Down Expand Up @@ -2020,14 +2022,15 @@ mod tests {

#[test]
fn responses_vec() {
use ethcore::receipt::{Receipt, TransactionOutcome};
let mut stream = RlpStream::new_list(2);
stream.begin_list(0).begin_list(0);

let body = ::ethcore::encoded::Body::new(stream.out());
let reqs = vec![
Response::Headers(HeadersResponse { headers: vec![] }),
Response::HeaderProof(HeaderProofResponse { proof: vec![], hash: Default::default(), td: 100.into()}),
Response::Receipts(ReceiptsResponse { receipts: vec![Default::default()] }),
Response::Receipts(ReceiptsResponse { receipts: vec![Receipt::new(TransactionOutcome::Unknown, Default::default(), Vec::new())] }),
Response::Body(BodyResponse { body: body }),
Response::Account(AccountResponse {
proof: vec![],
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use engines::Engine;
use error::{Error, BlockError, TransactionError};
use factory::Factories;
use header::Header;
use receipt::Receipt;
use receipt::{Receipt, TransactionOutcome};
use state::State;
use state_db::StateDB;
use trace::FlatTrace;
Expand Down Expand Up @@ -524,7 +524,7 @@ impl LockedBlock {
pub fn strip_receipts(self) -> LockedBlock {
let mut block = self;
for receipt in &mut block.block.receipts {
receipt.state_root = None;
receipt.outcome = TransactionOutcome::Unknown;
}
block.block.header.set_receipts_root(ordered_trie_root(block.block.receipts.iter().map(|r| r.rlp_bytes().into_vec())));
block
Expand Down
14 changes: 5 additions & 9 deletions ethcore/src/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1469,9 +1469,8 @@ mod tests {
use std::sync::Arc;
use rustc_hex::FromHex;
use util::kvdb::KeyValueDB;
use util::hash::*;
use util::sha3::Hashable;
use receipt::Receipt;
use bigint::hash::*;
use receipt::{Receipt, TransactionOutcome};
use blockchain::{BlockProvider, BlockChain, Config, ImportRoute};
use tests::helpers::*;
use blockchain::generator::{ChainGenerator, ChainIterator, BlockFinalizer};
Expand Down Expand Up @@ -2038,8 +2037,7 @@ mod tests {
let db = new_db();
let bc = new_chain(&genesis, db.clone());
insert_block(&db, &bc, &b1, vec![Receipt {
state_root: Some(H256::default()),
status_code: None,
outcome: TransactionOutcome::StateRoot(H256::default()),
gas_used: 10_000.into(),
log_bloom: Default::default(),
logs: vec![
Expand All @@ -2048,8 +2046,7 @@ mod tests {
],
},
Receipt {
state_root: Some(H256::default()),
status_code: None,
outcome: TransactionOutcome::StateRoot(H256::default()),
gas_used: 10_000.into(),
log_bloom: Default::default(),
logs: vec![
Expand All @@ -2058,8 +2055,7 @@ mod tests {
}]);
insert_block(&db, &bc, &b2, vec![
Receipt {
state_root: Some(H256::default()),
status_code: None,
outcome: TransactionOutcome::StateRoot(H256::default()),
gas_used: 10_000.into(),
log_bloom: Default::default(),
logs: vec![
Expand Down
14 changes: 6 additions & 8 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,7 @@ fn transaction_receipt(engine: &Engine, mut tx: LocalizedTransaction, mut receip
log_index: no_of_logs + i,
}).collect(),
log_bloom: receipt.log_bloom,
state_root: receipt.state_root,
outcome: receipt.outcome,
}
}

Expand Down Expand Up @@ -2023,7 +2023,7 @@ mod tests {
use super::transaction_receipt;
use ethkey::KeyPair;
use log_entry::{LogEntry, LocalizedLogEntry};
use receipt::{Receipt, LocalizedReceipt};
use receipt::{Receipt, LocalizedReceipt, TransactionOutcome};
use transaction::{Transaction, LocalizedTransaction, Action};
use util::Hashable;
use tests::helpers::TestEngine;
Expand All @@ -2035,7 +2035,7 @@ mod tests {

let block_number = 1;
let block_hash = 5.into();
let state_root = Some(99.into());
let state_root = 99.into();
let gas_used = 10.into();
let raw_tx = Transaction {
nonce: 0.into(),
Expand Down Expand Up @@ -2063,14 +2063,12 @@ mod tests {
data: vec![],
}];
let receipts = vec![Receipt {
state_root: state_root,
status_code: None,
outcome: TransactionOutcome::StateRoot(state_root),
gas_used: 5.into(),
log_bloom: Default::default(),
logs: vec![logs[0].clone()],
}, Receipt {
state_root: state_root,
status_code: None,
outcome: TransactionOutcome::StateRoot(state_root),
gas_used: gas_used,
log_bloom: Default::default(),
logs: logs.clone(),
Expand Down Expand Up @@ -2106,7 +2104,7 @@ mod tests {
log_index: 2,
}],
log_bloom: Default::default(),
state_root: state_root,
outcome: TransactionOutcome::StateRoot(state_root),
});
}
}
5 changes: 2 additions & 3 deletions ethcore/src/client/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use db::{NUM_COLUMNS, COL_STATE};
use header::{Header as BlockHeader, BlockNumber};
use filter::Filter;
use log_entry::LocalizedLogEntry;
use receipt::{Receipt, LocalizedReceipt};
use receipt::{Receipt, LocalizedReceipt, TransactionOutcome};
use blockchain::extras::BlockReceipts;
use error::{ImportResult, Error as EthcoreError};
use evm::{Factory as EvmFactory, VMType, Schedule};
Expand Down Expand Up @@ -594,8 +594,7 @@ impl BlockChainClient for TestBlockChainClient {
// starts with 'f' ?
if *hash > H256::from("f000000000000000000000000000000000000000000000000000000000000000") {
let receipt = BlockReceipts::new(vec![Receipt::new(
Some(H256::zero()),
None,
TransactionOutcome::StateRoot(H256::zero()),
U256::zero(),
vec![])]);
let mut rlp = RlpStream::new();
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/miner/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ impl MinerService for Miner {
},
logs: receipt.logs.clone(),
log_bloom: receipt.log_bloom,
state_root: receipt.state_root,
outcome: receipt.outcome.clone(),
}
})
}
Expand Down
20 changes: 9 additions & 11 deletions ethcore/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use std::cell::{RefCell, RefMut};
use std::collections::hash_map::Entry;

use receipt::Receipt;
use receipt::{Receipt, TransactionOutcome};
use engines::Engine;
use evm::env_info::EnvInfo;
use error::Error;
Expand Down Expand Up @@ -655,21 +655,19 @@ impl<B: Backend> State<B> {
eip658 ||
(env_info.number >= engine.params().eip98_transition && env_info.number >= engine.params().validate_receipts_transition);

let state_root = if no_intermediate_commits {
None
let outcome = if no_intermediate_commits {
if eip658 {
TransactionOutcome::StatusCode(if e.exception.is_some() { 0 } else { 1 })
} else {
TransactionOutcome::Unknown
}
} else {
self.commit()?;
Some(self.root().clone())
};

let status_byte = if eip658 {
Some(if e.exception.is_some() { 0 } else { 1 })
} else {
None
TransactionOutcome::StateRoot(self.root().clone())
};

let output = e.output;
let receipt = Receipt::new(state_root, status_byte, e.cumulative_gas_used, e.logs);
let receipt = Receipt::new(outcome, e.cumulative_gas_used, e.logs);
trace!(target: "state", "Transaction receipt: {:?}", receipt);

Ok(ApplyOutcome {
Expand Down
Loading

0 comments on commit 71f7726

Please sign in to comment.