-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Transactions hashes missing in trace_replayBlockTransactions method result #8725 #8883
Conversation
It looks like @shamardy hasn't signed our Contributor License Agreement, yet.
You can read and sign our full Contributor License Agreement at the following URL: https://cla.parity.io Once you've signed, please reply to this thread with Many thanks, Parity Technologies CLA Bot |
[clabot:check] |
It looks like @shamardy signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution. I believe that if add transaction_hash
, it should belong to struct Executed
, not StateDiff
.
Regarding jsonrpc and output json, it should be placed next to stateDiff
, not inside it
@sorpaas what do you think?
rpc/src/v1/types/trace.rs
Outdated
@@ -195,20 +195,19 @@ impl From<account_diff::AccountDiff> for AccountDiff { | |||
} | |||
} | |||
|
|||
#[derive(Debug)] | |||
#[derive(Debug, Serialize)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a breaking change
ethcore/types/src/state_diff.rs
Outdated
use account_diff::*; | ||
|
||
/// Expression for the delta between two system states. Encoded the | ||
/// delta of every altered account. | ||
#[derive(Debug, PartialEq, Eq, Clone)] | ||
pub struct StateDiff { | ||
/// Raw diff key-value | ||
pub raw: BTreeMap<Address, AccountDiff> | ||
pub raw: BTreeMap<Address, AccountDiff>, | ||
pub transaction_hash: H256 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
transaction_hash
is not a part of a StateDiff
and should not be a property of a struct StateDiff
@debris Yes. I think we should only change RPC types. @shamardy Maybe we can consider to add an additional Or another idea might be to change replay_block_transactions in client (https://github.com/paritytech/parity/blob/master/ethcore/src/client/client.rs#L1552) to return an iterator of tuple of transaction hash and |
This comment has been minimized.
This comment has been minimized.
@debris I implemented |
ethcore/src/client/client.rs
Outdated
@@ -1240,6 +1241,8 @@ impl Client { | |||
|
|||
let mut ret = Executive::new(state, env_info, machine).transact_virtual(transaction, options)?; | |||
|
|||
ret.transaction_hash = if hash_trace { Some(transaction.hash()) } else { None }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh, I don't know what to do with this. I generally don't like mutating structures like this. Making one field optional and then overwriting it in a different function is not idiomatic.
Unfortunately, it's not a new pattern and the same thing is done with ret.state_diff
few lines below :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what can be done with this since it depends on if the user wants to trace transaction hashes or not.
Another way can be implementing it the same way but inside replay_block_transactions
but I thought implementing this inside the same function that state_diff
is implemented would look better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I can create a function that returns transaction hash inside the implementation of the Executed
Struct like this:
impl Executed { pub fn transaction_hash(transaction: &SignedTransaction) -> Option<H256> { ........................... } }
then inside the do_virtual_call function I would set transaction_hash with this:
if hash_trace { Some(ret.transaction_hash(transaction) };
what do you think @debris
My opinion on this is still that we should only change RPC types. The issue with adding @shamardy Would you mind to take a look at #8883 (comment)? We can directly fetch transaction hashes in the RPC call function, or if you want, return |
@sorpaas please check updates. Thanks. |
ethcore/src/client/client.rs
Outdated
@@ -1541,15 +1541,15 @@ impl EngineInfo for Client { | |||
} | |||
|
|||
impl BlockChainClient for Client { | |||
fn replay(&self, id: TransactionId, analytics: CallAnalytics) -> Result<Executed, CallError> { | |||
fn replay(&self, id: TransactionId, analytics: CallAnalytics) -> Result<(Option<H256>, Executed), CallError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this Option? Isn't replay_block_transactions always return Some(tx_hash)
?
ethcore/src/client/client.rs
Outdated
let address = self.transaction_address(id).ok_or(CallError::TransactionNotFound)?; | ||
let block = BlockId::Hash(address.block_hash); | ||
|
||
const PROOF: &'static str = "The transaction address contains a valid index within block; qed"; | ||
Ok(self.replay_block_transactions(block, analytics)?.nth(address.index).expect(PROOF)) | ||
} | ||
|
||
fn replay_block_transactions(&self, block: BlockId, analytics: CallAnalytics) -> Result<Box<Iterator<Item = Executed>>, CallError> { | ||
fn replay_block_transactions(&self, block: BlockId, analytics: CallAnalytics) -> Result<Box<Iterator<Item = (Option<H256>,Executed)>>, CallError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing whitespace before Executed
.
ethcore/src/client/client.rs
Outdated
let t = SignedTransaction::new(t).expect(PROOF); | ||
let machine = engine.machine(); | ||
let x = Self::do_virtual_call(machine, &env_info, &mut state, &t, analytics).expect(EXECUTE_PROOF); | ||
env_info.gas_used = env_info.gas_used + x.gas_used; | ||
x | ||
(Some(tx_hash),x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing whitespace before x.
ethcore/src/client/test_client.rs
Outdated
@@ -607,12 +607,12 @@ impl EngineInfo for TestBlockChainClient { | |||
} | |||
|
|||
impl BlockChainClient for TestBlockChainClient { | |||
fn replay(&self, _id: TransactionId, _analytics: CallAnalytics) -> Result<Executed, CallError> { | |||
self.execution_result.read().clone().unwrap() | |||
fn replay(&self, _id: TransactionId, _analytics: CallAnalytics) -> Result<(Option<H256>,Executed), CallError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing whitespace for this and several cases below.
ethcore/src/client/test_client.rs
Outdated
fn replay(&self, _id: TransactionId, _analytics: CallAnalytics) -> Result<Executed, CallError> { | ||
self.execution_result.read().clone().unwrap() | ||
fn replay(&self, _id: TransactionId, _analytics: CallAnalytics) -> Result<(Option<H256>,Executed), CallError> { | ||
Ok((None,self.execution_result.read().clone().unwrap()?)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we fetch the transaction hash from TransactionId
?
ethcore/src/client/test_client.rs
Outdated
fn replay_block_transactions(&self, _block: BlockId, _analytics: CallAnalytics) -> Result<Box<Iterator<Item = Executed>>, CallError> { | ||
Ok(Box::new(self.execution_result.read().clone().unwrap().into_iter())) | ||
fn replay_block_transactions(&self, _block: BlockId, _analytics: CallAnalytics) -> Result<Box<Iterator<Item = (Option<H256>,Executed)>>, CallError> { | ||
Ok(Box::new(None.into_iter().zip(self.execution_result.read().clone().unwrap().into_iter()))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. Block info are available in TestBlockChainClient, so I think it may be better to fetch that available info.
rpc/src/v1/types/trace.rs
Outdated
@@ -631,6 +632,36 @@ impl From<Executed> for TraceResults { | |||
} | |||
} | |||
|
|||
#[derive(Debug, Serialize)] | |||
/// A diff of some chunk of memory. | |||
pub struct TraceResultsWithTransHash { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use full name: TraceResultsWithTransactionHash
.
rpc/src/v1/types/trace.rs
Outdated
#[serde(rename="stateDiff")] | ||
pub state_diff: Option<StateDiff>, | ||
/// The transaction Hash. | ||
#[serde(rename="TransactionHash")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usual json conversion is transactionHash
.
rpc/src/v1/types/trace.rs
Outdated
pub state_diff: Option<StateDiff>, | ||
/// The transaction Hash. | ||
#[serde(rename="TransactionHash")] | ||
pub trans_hash: Option<H256>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be changed to full name. And why is it Option? I think if we're using this type then the transaction hash should always be available, otherwise we'd rather use TraceResults
?
rpc/src/v1/types/trace.rs
Outdated
@@ -22,6 +22,7 @@ use ethcore::trace as et; | |||
use ethcore::state_diff; | |||
use ethcore::account_diff; | |||
use ethcore::client::Executed; | |||
use ethereum_types::H256 as ethH256; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually have Rust type with first letter to be capped.
@sorpaas please check last update. Thanks. |
Please rebase on latest master if possible, this will fix the CI issue. |
commit 1f85076 Author: shamardy <shamardy@yahoo.com> Date: Sat Jun 30 03:40:12 2018 +0200 update commit 63363cc Author: shamardy <shamardy@yahoo.com> Date: Sat Jun 30 03:36:25 2018 +0200 Update commit e05cadd Author: shamardy <shamardy@yahoo.com> Date: Fri Jun 29 10:04:34 2018 +0200 Test commit b0be065 Author: shamardy <shamardy@yahoo.com> Date: Fri Jun 29 09:19:57 2018 +0200 test_client edit commit 949205c Author: shamardy <shamardy@yahoo.com> Date: Fri Jun 29 05:14:53 2018 +0200 Edit Test commit 7cd44ee Author: shamardy <shamardy@yahoo.com> Date: Fri Jun 29 04:25:22 2018 +0200 Updates commit e90de71 Author: shamardy <shamardy@yahoo.com> Date: Wed Jun 27 13:53:15 2018 +0200 Test commit 12a7638 Author: shamardy <shamardy@yahoo.com> Date: Wed Jun 27 11:43:39 2018 +0200 Edited Tests commit 6c21e6d Merge: 87c4c74 9550cf7 Author: shamardy <shamardy@yahoo.com> Date: Wed Jun 27 10:31:21 2018 +0200 Merge branch 'Issue#8725' of https://github.com/shamardy/parity into Issue#8725 commit 87c4c74 Author: shamardy <shamardy@yahoo.com> Date: Wed Jun 27 10:31:13 2018 +0200 Avoided Changing non-RPC Types commit 9550cf7 Author: shamardy <39480341+shamardy@users.noreply.github.com> Date: Wed Jun 27 10:29:03 2018 +0200 Update traces.rs commit 3e0b0ef Author: shamardy <39480341+shamardy@users.noreply.github.com> Date: Wed Jun 27 10:27:44 2018 +0200 Update trace.rs commit 5078d67 Author: shamardy <39480341+shamardy@users.noreply.github.com> Date: Wed Jun 27 10:26:08 2018 +0200 Update traces.rs commit 28f5ba1 Author: shamardy <39480341+shamardy@users.noreply.github.com> Date: Wed Jun 27 10:24:04 2018 +0200 Update parity.rs commit 3b86b98 Author: shamardy <39480341+shamardy@users.noreply.github.com> Date: Wed Jun 27 10:23:33 2018 +0200 Update eth.rs commit bcad5a4 Author: shamardy <39480341+shamardy@users.noreply.github.com> Date: Wed Jun 27 10:21:43 2018 +0200 Update call_analytics.rs commit e9029e0 Author: shamardy <39480341+shamardy@users.noreply.github.com> Date: Wed Jun 27 10:20:56 2018 +0200 Update transaction.rs commit 0dacc81 Author: shamardy <39480341+shamardy@users.noreply.github.com> Date: Wed Jun 27 10:20:01 2018 +0200 Update executive.rs commit 3921d4e Author: shamardy <39480341+shamardy@users.noreply.github.com> Date: Wed Jun 27 10:18:39 2018 +0200 Update executed.rs commit 8416df6 Author: shamardy <39480341+shamardy@users.noreply.github.com> Date: Wed Jun 27 10:17:34 2018 +0200 Update client.rs commit cf0b4dd Merge: 23bfa78 36e05e5 Author: shamardy <shamardy@yahoo.com> Date: Sun Jun 24 04:54:04 2018 +0200 Merge branch 'Issue#8725' of https://github.com/shamardy/parity into Issue#8725 commit 23bfa78 Author: shamardy <shamardy@yahoo.com> Date: Sun Jun 24 04:53:50 2018 +0200 Undo commit 36e05e5 Merge: 2f6e1ef 0afc748 Author: shamardy <shamardy@yahoo.com> Date: Sun Jun 24 04:44:33 2018 +0200 Merge branch 'Issue#8725' of https://github.com/shamardy/parity into Issue#8725 commit 2f6e1ef Author: shamardy <shamardy@yahoo.com> Date: Sun Jun 24 04:44:22 2018 +0200 Another rpc test output with ("transactionHash":null) commit 0afc748 Author: shamardy <shamardy@yahoo.com> Date: Thu Jun 14 07:18:45 2018 +0200 Another rpc test output with ("transactionHash":null) commit 138fbac Author: shamardy <shamardy@yahoo.com> Date: Thu Jun 14 06:30:41 2018 +0200 Edited some rpc tests output with ("transactionHash":null) commit 8c129a6 Author: shamardy <39480341+shamardy@users.noreply.github.com> Date: Thu Jun 14 05:48:39 2018 +0200 Update traces.rs commit 52c17f6 Author: shamardy <39480341+shamardy@users.noreply.github.com> Date: Thu Jun 14 05:47:29 2018 +0200 Update parity.rs commit d39303a Author: shamardy <39480341+shamardy@users.noreply.github.com> Date: Thu Jun 14 05:46:25 2018 +0200 Update eth.rs commit 49be84b Author: shamardy <39480341+shamardy@users.noreply.github.com> Date: Thu Jun 14 05:40:56 2018 +0200 Update trace.rs commit 4fc8013 Merge: d34ba23 5442104 Author: shamardy <shamardy@yahoo.com> Date: Thu Jun 14 05:12:21 2018 +0200 Merge branch 'Issue#8725' of https://github.com/shamardy/parity into Issue#8725 commit 5442104 Author: shamardy <39480341+shamardy@users.noreply.github.com> Date: Thu Jun 14 05:04:51 2018 +0200 Update trace.rs commit 2b2524a Author: shamardy <39480341+shamardy@users.noreply.github.com> Date: Thu Jun 14 05:01:47 2018 +0200 Update state_diff.rs commit 2bf9982 Author: shamardy <39480341+shamardy@users.noreply.github.com> Date: Thu Jun 14 05:00:50 2018 +0200 Update transaction.rs commit da696ea Author: shamardy <39480341+shamardy@users.noreply.github.com> Date: Thu Jun 14 05:00:13 2018 +0200 Update mod.rs commit cfc194c Author: shamardy <39480341+shamardy@users.noreply.github.com> Date: Thu Jun 14 04:59:18 2018 +0200 Update pod_state.rs commit 3b31568 Author: shamardy <39480341+shamardy@users.noreply.github.com> Date: Thu Jun 14 04:57:37 2018 +0200 Update client.rs commit d34ba23 Author: shamardy <shamardy@yahoo.com> Date: Thu Jun 14 04:53:50 2018 +0200 RPC Only commit 8b5c4f1 Merge: 7444916 291b4a0 Author: shamardy <shamardy@yahoo.com> Date: Thu Jun 14 02:55:14 2018 +0200 Merge branch 'Issue#8725' of https://github.com/shamardy/parity into Issue#8725 commit 7444916 Author: shamardy <shamardy@yahoo.com> Date: Thu Jun 14 02:27:13 2018 +0200 Issue#8725 Transactions hashes missing in trace_replayBlockTransactions method result openethereum#8725 commit 291b4a0 Author: shamardy <shamardy@yahoo.com> Date: Thu Jun 14 01:18:18 2018 +0200 Edited to make changes to RPC types only To make a transactions hash trace with "trace_replayBlockTransactions" add "transactionHash" to parameters commit 9d082be Author: shamardy <shamardy@yahoo.com> Date: Wed Jun 13 09:15:56 2018 +0200 Issue#8725 Transactions hashes missing in trace_replayBlockTransactions method result openethereum#8725
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Only minor grumbles.
fn replay_block_transactions(&self, _block: BlockId, _analytics: CallAnalytics) -> Result<Box<Iterator<Item = Executed>>, CallError> { | ||
Ok(Box::new(self.execution_result.read().clone().unwrap().into_iter())) | ||
fn replay_block_transactions(&self, _block: BlockId, _analytics: CallAnalytics) -> Result<Box<Iterator<Item = (H256, Executed)>>, CallError> { | ||
Ok(Box::new(self.traces.read().clone().unwrap().into_iter().map(|t| t.transaction_hash.unwrap_or(H256::new())).zip(self.execution_result.read().clone().unwrap().into_iter()))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The self.execution_result
param is always set by self.set_execution_result
function. We've never set the actual transaction hashes or modify self.traces
when calling that function. So it always returns H256::new
regardless. The unwrap_or
can be removed.
ethcore/src/client/test_client.rs
Outdated
fn replay_block_transactions(&self, _block: BlockId, _analytics: CallAnalytics) -> Result<Box<Iterator<Item = Executed>>, CallError> { | ||
Ok(Box::new(self.execution_result.read().clone().unwrap().into_iter())) | ||
fn replay_block_transactions(&self, _block: BlockId, _analytics: CallAnalytics) -> Result<Box<Iterator<Item = (H256, Executed)>>, CallError> { | ||
Ok(Box::new(self.traces.read().clone().unwrap().into_iter().map(|t| t.transaction_hash.unwrap()).zip(self.execution_result.read().clone().unwrap().into_iter()))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shamardy Sorry if I wasn't clear -- I think this should be changed not to use self.traces
(but just return H256::new
), because when we query self.execution_result
in test, self.traces
is never available -- self.execution_result
is only set by self.set_execution_result
and we only have a few appearance our code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above code will cause testing run of replayBlockTransactions to always return empty vector -- definitely not something we want. (It looks like we're missing a few tests there, though.)
@sorpaas in
in line 236 there is a test for replay_block_transactions:
in the response the |
also if thats the case should I revert to the one which uses |
@shamardy Ah you're right. Sorry it's my mistake. Then I think your original one is correct -- we should revert to use |
@debris can you check the last update please. Thanks. |
Needs a second review, anyone? |
any update here? |
or anyone? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
closes #8725