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

Commit

Permalink
Fixed receipt serialization and RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar committed Sep 20, 2017
1 parent 8a21cde commit 4368229
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 85 deletions.
5 changes: 2 additions & 3 deletions ethcore/light/src/on_demand/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::sync::Arc;
use ethcore::basic_account::BasicAccount;
use ethcore::encoded;
use ethcore::engines::{Engine, StateDependentProof};
use ethcore::receipt::Receipt;
use ethcore::receipt::{Receipt, TransactionOutcome};
use ethcore::state::{self, ProvedExecution};
use ethcore::transaction::SignedTransaction;
use vm::EnvInfo;
Expand Down Expand Up @@ -973,8 +973,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 @@ -1739,13 +1739,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 @@ -1900,14 +1902,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 @@ -35,7 +35,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 @@ -533,7 +533,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
11 changes: 4 additions & 7 deletions ethcore/src/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,7 @@ mod tests {
use hash::keccak;
use util::kvdb::KeyValueDB;
use bigint::hash::*;
use receipt::Receipt;
use receipt::{Receipt, TransactionOutcome};
use blockchain::{BlockProvider, BlockChain, Config, ImportRoute};
use tests::helpers::*;
use blockchain::generator::{ChainGenerator, ChainIterator, BlockFinalizer};
Expand Down Expand Up @@ -2048,8 +2048,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 @@ -2058,8 +2057,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 @@ -2068,8 +2066,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 @@ -2054,7 +2054,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 @@ -2100,7 +2100,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 tests::helpers::TestEngine;

Expand All @@ -2111,7 +2111,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 @@ -2139,14 +2139,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 @@ -2182,7 +2180,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 @@ -42,7 +42,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};
Expand Down Expand Up @@ -618,8 +618,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 @@ -1022,7 +1022,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 @@ -26,7 +26,7 @@ use std::fmt;
use std::sync::Arc;
use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY};

use receipt::Receipt;
use receipt::{Receipt, TransactionOutcome};
use engines::Engine;
use vm::EnvInfo;
use error::Error;
Expand Down Expand Up @@ -699,21 +699,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 4368229

Please sign in to comment.