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

Add pagination for trace_filter rpc method #6312

Merged
merged 12 commits into from
Oct 3, 2017
Merged

Add pagination for trace_filter rpc method #6312

merged 12 commits into from
Oct 3, 2017

Conversation

grbIzl
Copy link
Collaborator

@grbIzl grbIzl commented Aug 16, 2017

  • This work is done in terms of Trace & Fat DB module improvement suggestions #4858 issue.

  • trace_filter method was extended with two optional parameters offset and count in order to paginate through output traces.

  • For offset the new type was created TraceIndex in order to identify the trace. Inside the client it's converted into TraceId

  • New tests were not created as we have only trivial implementation for these methods in test_client.

@grbIzl grbIzl added A0-pleasereview 🤓 Pull request needs code review. B7-releasenotes 📜 Changes should be mentioned in the release notes of the next minor version release. labels Aug 16, 2017
@@ -1641,7 +1641,7 @@ impl BlockChainClient for Client {
self.chain.read().logs(blocks, |entry| filter.matches(entry), filter.limit)
}

fn filter_traces(&self, filter: TraceFilter) -> Option<Vec<LocalizedTrace>> {
fn filter_traces(&self, filter: TraceFilter, after: Option<&TraceId>, count: Option<u64>) -> Option<Vec<LocalizedTrace>> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not making it part of TraceFilter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually there were 3 options how to add this here:

  • Modify TraceFIlter
  • Add optional parameters to filter_traces
  • Instead add new method like filter_traces_with_pagination
    I've discussed it with @arkpar and we chosen the second one. But frankly all of them pretty similar. There is no decisive advantage for any of them.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Using separate parameters breaks backward compatibility, we already support limit parameter for eth_getLogs filter object and that would be inline with that.

Would be good if those parameters could be omitted (using Trailing), but we don't suport two optional parameters.

IMHO would be better to make it part of TraceFilter object.

@@ -195,7 +195,7 @@ pub trait BlockChainClient : Sync + Send {
fn replay(&self, t: TransactionId, analytics: CallAnalytics) -> Result<Executed, CallError>;

/// Returns traces matching given filter.
fn filter_traces(&self, filter: TraceFilter) -> Option<Vec<LocalizedTrace>>;
fn filter_traces(&self, filter: TraceFilter, after: Option<&TraceId>, count: Option<u64>) -> Option<Vec<LocalizedTrace>>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

usize will be enough for count

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree

@grbIzl grbIzl added the M6-rpcapi 📣 RPC API. label Aug 17, 2017

let mut traces_iter = traces.into_iter();
if let Some(after) = after {
if let TransactionId::Location(BlockId::Hash(block_hash), transaction_number) = after.transaction {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does it quietly ignores after argument if it is Some(TransactionId::Hash(_))? I can see that in RPC only TransactionId::Location is used, but it is not good to have public method in separate (not RPC crate) which accepts two options and quietly works for single option only.

let mut traces_iter = traces.into_iter();
if let Some(after) = after {
if let TransactionId::Location(BlockId::Hash(block_hash), transaction_number) = after.transaction {
match traces_iter.find(|ref trace| trace.block_hash == block_hash
Copy link
Collaborator

Choose a reason for hiding this comment

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

ref is not needed in ref trace here

}
}
if let Some(count) = count {
traces_iter = traces_iter.take(count as usize).collect::<Vec<_>>().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.

count is already usize, so count as usize is not needed here

}
}
}
if let Some(count) = count {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could avoid extra allocation here like that:

				Some(match count {
					Some(count) => traces_iter.take(count as usize).collect(),
					None => traces_iter.collect(),
				})

@NikVolf NikVolf added the M7-ui label Aug 30, 2017
TransactionId::Hash(transaction_hash) => {
match traces_iter.find(|trace| trace.transaction_hash == transaction_hash) {
Some(_) => {},
None => return None,
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 more idiomatic to write:

if traces_iter.find(|trace| trace.transaction_hash == transaction_hash).is_none() {
  return None;
}

@@ -31,7 +31,7 @@ pub struct TracesClient;
impl Traces for TracesClient {
type Metadata = Metadata;

fn filter(&self, _filter: TraceFilter) -> Result<Option<Vec<LocalizedTrace>>, Error> {
fn filter(&self, _filter: TraceFilter, _offset: Option<TraceIndex>, _count: Option<usize>) -> Result<Option<Vec<LocalizedTrace>>, Error> {
Copy link
Collaborator

@debris debris Aug 31, 2017

Choose a reason for hiding this comment

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

wouldn't offset being usize be faster and easier to use (and to implement)?

With offset being TraceIndex you can't fetch traces in parallel and/or from multiple clients. I imagine this might be a common practice for exchanges.

// thread 0,
ethereum_client_0.filter(filter_options, 0, 1000);

// thread 1,
ethereum_client_1.filter(filter_options, 1000, 2000);

// thread 2,
ethereum_client_2.filter(filter_options, 2000, 3000);

@grbIzl grbIzl added A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. and removed A0-pleasereview 🤓 Pull request needs code review. labels Sep 5, 2017
@grbIzl grbIzl added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels Sep 12, 2017
Some(traces)
let traces = self.tracedb.read().filter(&db_filter);
if traces.is_empty() {
return None;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not Some(vec![]) - I think None was used to indicate invalid block range.

@tomusdrw tomusdrw added A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. and removed A0-pleasereview 🤓 Pull request needs code review. labels Sep 18, 2017
@gavofyork gavofyork added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. and removed A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. labels Sep 19, 2017
@gavofyork
Copy link
Contributor

@grbIzl still waiting for this (fairly minor) change...

@grbIzl grbIzl added A0-pleasereview 🤓 Pull request needs code review. and removed A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. labels Sep 28, 2017
@tomusdrw tomusdrw added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Oct 2, 2017
@gavofyork gavofyork merged commit 0a5c9b0 into master Oct 3, 2017
@gavofyork gavofyork deleted the Fix-4858-p2 branch October 3, 2017 08:03
@SinErgy84
Copy link

Please keep your wiki up2date ...
mentioned changes are missing on https://github.com/paritytech/parity/wiki/JSONRPC-trace-module#trace_filter

@5chdn
Copy link
Contributor

5chdn commented Feb 23, 2018

FYI https://github.com/paritytech/wiki/blob/master/JSONRPC-trace-module.md#trace_filter

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. B7-releasenotes 📜 Changes should be mentioned in the release notes of the next minor version release. M6-rpcapi 📣 RPC API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants