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

added a new RPC call trace_replayBlockTransactions #7366

Merged
merged 11 commits into from
Jan 10, 2018

Conversation

tzapu
Copy link
Contributor

@tzapu tzapu commented Dec 22, 2017

in relation to #7365

as i mentioned this is my first go at rust so I could do with some pointers about error checking or tests, or whatever else is needed to make this mergeable

thank you guys for everything

@parity-cla-bot
Copy link

It looks like @tzapu hasn'signed our Contributor License Agreement, yet.

The purpose of a CLA is to ensure that the guardian of a project's outputs has the necessary ownership or grants of rights over all contributions to allow them to distribute under the chosen licence.
Wikipedia

You can read and sign our full Contributor License Agreement at the following URL: https://cla.parity.io

Once you've signed, plesae reply to this thread with [clabot:check] to prove it.

Many thanks,

Parity Technologies CLA Bot

@tzapu
Copy link
Contributor Author

tzapu commented Dec 22, 2017

[clabot:check]

@parity-cla-bot
Copy link

It looks like @tzapu signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

Copy link
Collaborator

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

The RPC tests should go to rpc/src/v1/tests/mocked/traces.rs, this will at least check the public API.

As for client tests it will be more tricky, have a look at ethcore/src/tests/helpers.rs and generate_dummy_client_with_spec_accounts_and_data to create a client, and later pick the last block and replay it.

const EXECUTE_PROOF: &'static str = "Transaction replayed; qed";
for t in txs {
let t = SignedTransaction::new(t).expect(PROOF);
let x = self.do_virtual_call(&env_info, &mut state, &t, analytics).expect(EXECUTE_PROOF);
Copy link
Collaborator

@tomusdrw tomusdrw Dec 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just do self.do_virtual_call(..)? here. But you are right that the call should never error, so I'm fine with expect as well.

@@ -429,6 +429,12 @@ impl BlockChainClient for TestBlockChainClient {
self.execution_result.read().clone().unwrap()
}

// TODO add test
fn replay_block_transactions(&self, _block: BlockId, _analytics: CallAnalytics) -> Result<Vec<Executed>, CallError> {
let res = Vec::with_capacity(0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave this as unimplemented!()

@@ -1318,6 +1318,25 @@ impl BlockChainClient for Client {
self.do_virtual_call(&env_info, &mut state, &t, analytics)
}

fn replay_block_transactions(&self, block: BlockId, analytics: CallAnalytics) -> Result<Vec<Executed>, CallError> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To share the code with replay() you could return a Result<Box<Iterator<Item = Executed>>, CallError> here and then replay() just becomes:

let index = <get-tx-index>;
Ok(self.replay_block(...)?.nth(index))

@tomusdrw tomusdrw added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. M6-rpcapi 📣 RPC API. labels Dec 22, 2017
@tzapu
Copy link
Contributor Author

tzapu commented Dec 22, 2017

@tomusdrw thank you for taking at look at this

i tried implementing the suggested changes, but my non existent rust knowledge got the best of me
i have no idea how i would ofrmulate this to work

	fn replay_block_transactions(&self, block_number: BlockNumber, flags: TraceOptions) -> Result<Box<Iterator<Item = TraceResults>>> {
		self.client.replay_block_transactions(block_number.into(), to_call_analytics(flags))
			.map(|results| results.into_iter().map(TraceResults::from).collect())
			.map_err(errors::call)
	}

with the new result, or if the rest of the changes are ok
thank you again, maybe you can give me some tips

@tzapu
Copy link
Contributor Author

tzapu commented Dec 23, 2017

i think i may have sorted it
while testing, if i make the request for a not synced yet block i get This request is not supported because your node is running with state pruning. Run with --pruning=archive. which is not quite accurate.
How would i go changing that to something more appropriate?
Aaaannnndddd what else do you think I need to sort to get this merged? :D
Thank you very much

Copy link
Collaborator

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if i make the request for a not synced yet block i get This request is not supported because your node is running with state pruning. Run with --pruning=archive.

I think we should deal with it in a separate issue, it's currently common behaviour in all RPC methods.

@@ -1293,7 +1293,7 @@ impl BlockChainClient for Client {
trace!(target: "estimate_gas", "estimate_gas chopping {} .. {}", lower, upper);
binary_chop(lower, upper, cond)
}

/*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove commented out code.

let address = self.transaction_address(id).ok_or(CallError::TransactionNotFound)?;
let block = BlockId::Hash(address.block_hash);

Ok(self.replay_block_transactions(block, analytics)?.nth(address.index).unwrap())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of unwrap use expect(<proof>). Here the proof will be something like: "The transaction address contains a valid index within block; qed".

replays.push(x);
}

Ok(Box::new(replays.into_iter()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's almost fine - right now you are executing all transactions and putting the results into a vector, but Iterator allows you to do it lazily (which will make replay work faster).
It should look like this (instead of a loop you should use map):

let txs = block.transactions();
Ok(Box::new(txs.into_iter()
  .map(|tx| {
     ...
     self.do_virtual_call(...).expect(EXECUTE_PROOF)
   })))

@@ -429,6 +429,11 @@ impl BlockChainClient for TestBlockChainClient {
self.execution_result.read().clone().unwrap()
}

// TODO add test
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove.

@tomusdrw
Copy link
Collaborator

Could you also prepare a mocked RPC test?

@tomusdrw tomusdrw closed this Dec 27, 2017
@tomusdrw tomusdrw reopened this Dec 27, 2017
tzapu and others added 3 commits December 28, 2017 00:25
@5chdn 5chdn added this to the 1.10 milestone Dec 30, 2017
@5chdn 5chdn added the A1-onice 🌨 Pull request is reviewed well, but should not yet be merged. label Dec 30, 2017
@tzapu
Copy link
Contributor Author

tzapu commented Dec 30, 2017

again, i would like to thank you for all the hand holding
i have added a naive rpc test, it looks like the tests pass

@5chdn 5chdn added A0-pleasereview 🤓 Pull request needs code review. and removed A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. labels Jan 1, 2018
@tomusdrw tomusdrw added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jan 3, 2018
Copy link
Contributor

@andresilva andresilva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍
Just some minor comments regarding docs.

@@ -56,5 +56,9 @@ build_rpc_trait! {
/// Executes the transaction with the given hash and returns a number of possible traces for it.
#[rpc(name = "trace_replayTransaction")]
fn replay_transaction(&self, H256, TraceOptions) -> Result<TraceResults>;

/// Executes the transaction with the given hash and returns a number of possible traces for it.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executes all the transactions at the given block and returns a number of possible traces for each transaction.

@@ -196,6 +196,9 @@ pub trait BlockChainClient : Sync + Send {
/// Replays a given transaction for inspection.
fn replay(&self, t: TransactionId, analytics: CallAnalytics) -> Result<Executed, CallError>;

/// Replays a given transaction for inspection.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replays all the transactions in a given block for inspection.

@tzapu
Copy link
Contributor Author

tzapu commented Jan 5, 2018

thanks guys, much appreciated, happy new year
updated

@5chdn 5chdn removed the A1-onice 🌨 Pull request is reviewed well, but should not yet be merged. label Jan 9, 2018
@5chdn 5chdn merged commit df5d27d into openethereum:master Jan 10, 2018
@tzapu
Copy link
Contributor Author

tzapu commented Jan 10, 2018

thanks guys, for everything

@ankitchiplunkar
Copy link

Would it be possible to also add uncle rewards and miner rewards with this JSON RPC?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M6-rpcapi 📣 RPC API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants