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

RPC: parity_getBlockReceipts #9527

Merged
merged 11 commits into from
Sep 25, 2018
Merged

RPC: parity_getBlockReceipts #9527

merged 11 commits into from
Sep 25, 2018

Conversation

tomusdrw
Copy link
Collaborator

@tomusdrw tomusdrw commented Sep 11, 2018

Closes: #9430

Some performance benchmarks:
After: http://gist.github.com/tomusdrw/05242fb0a7d42ed13474218e6a83f517
Before: https://gist.github.com/tomusdrw/f664ff78ce2714fadc2128fa5539cd86

(Not realy meant to compare eth_getTransactionReceipt performance before and after, cause obviously here is obviously a huge variance here, but I think it's clearly visible that getBlockReceipts is way faster and single receipt performance has not degraded)

Script used to check the performance:
https://gist.github.com/tomusdrw/ffd102326522d415ddea1b2aa1938cc9

EDIT: realised it's a bit unfair if we test parity_getBlockReceipts as the second one, cause the first call fills up the cache. Updated the results, but even if getBlockReceipts fetches data from disk it's faster, so it's not really a contributing factor here.

@tomusdrw tomusdrw added A0-pleasereview 🤓 Pull request needs code review. M6-rpcapi 📣 RPC API. labels Sep 11, 2018
@5chdn 5chdn added this to the 2.1 milestone Sep 11, 2018
Copy link
Collaborator

@debris debris left a comment

Choose a reason for hiding this comment

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

lgtm, just a few questions

/// Get block receipts.
/// Allows you to fetch receipts from the entire block at once.
#[rpc(name = "parity_getBlockReceipts")]
fn block_receipts(&self, Trailing<BlockNumber>) -> BoxFuture<Vec<Receipt>>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Trailing == latest?

fn block_receipts(&self, number: Trailing<BlockNumber>) -> BoxFuture<Vec<Receipt>> {
// Note: Here we treat `Pending` as `Latest`.
// Since light clients don't produce pending blocks
// (they don't have state) we can safely fallback to `Latest`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

redundant extra spaces

receipts.into_iter()
.flat_map(|r| {
let hash = r.transaction_hash;
r.logs.into_iter().map(move |l| (hash.clone(), l))
Copy link
Collaborator

Choose a reason for hiding this comment

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

move and clone() are probably redundant, cause hash implements Copy

let transaction = body.view().localized_transaction_at(&hash, number, address.index)?;
let receipt = receipts.pop()?;
let gas_used = receipts.last().map_or_else(|| 0.into(), |r| r.gas_used);
let no_of_logs = receipts.into_iter().map(|receipt| receipt.logs.len()).sum::<usize>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand these 3 lines. why do we pop a receipt and then take a gas_used from the one before it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So to actually generate a LocalizedReceipt we need 3 things:

  1. Actual receipt
  2. Gas used by that transaction
  3. Number of logs generate prior to this transaction (to calculate log_index_in_block).

So the logic is as follows:

  1. Fetch all receipts from 0 to index (inclusive)
  2. Take the last one (receipts.pop(); point 1.)
  3. Take the previous to last one to calculate (point 2.) (receipts only store cumulative gas, so we calculate current.gas_used - previous.gas_used to figure out what current gas usage of transaction was)
  4. Use all previous receipts to calculate total number of logs. (point 3.)

@debris debris 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 12, 2018
Copy link
Contributor

@jimpo jimpo left a comment

Choose a reason for hiding this comment

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

👍

Some(receipt)
}

fn block_receipts(&self, id: BlockId) -> Option<Vec<LocalizedReceipt>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

This method could probably use a test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added for both block_receipt and transaction_receipt

let id = match number.unwrap_or_default() {
BlockNumber::Num(n) => BlockId::Number(n),
BlockNumber::Earliest => BlockId::Earliest,
BlockNumber::Latest | BlockNumber::Pending => BlockId::Latest,
Copy link
Contributor

Choose a reason for hiding this comment

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

Since there is no Pending state, I'd say either return an empty vector or keep the deprecation log from num_to_id.

@tomusdrw tomusdrw added A0-pleasereview 🤓 Pull request needs code review. and removed A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. labels Sep 13, 2018
@5chdn 5chdn modified the milestones: 2.1, 2.2 Sep 13, 2018
BlockNumber::Earliest => BlockId::Earliest,
BlockNumber::Latest => BlockId::Latest,
BlockNumber::Pending => {
warn!("`Pending` is deprecated and may be removed in future versions. Falling back to `Latest`");
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, this should only get logged when accessed from the light client impl. So maybe move back to num_to_id on the light client or add a light_client: bool method param?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved it to a trait, so it explicitly says it's for light client only.

@debris debris added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Sep 17, 2018
@5chdn
Copy link
Contributor

5chdn commented Sep 17, 2018

please rebase on master

@5chdn 5chdn added A7-looksgoodtestsfail 🤖 Pull request is reviewed well, but cannot be merged due to tests failing. and removed A8-looksgood 🦄 Pull request is reviewed well. labels Sep 19, 2018
@debris debris added A8-looksgood 🦄 Pull request is reviewed well. and removed A7-looksgoodtestsfail 🤖 Pull request is reviewed well, but cannot be merged due to tests failing. labels Sep 24, 2018
@debris debris requested a review from andresilva September 25, 2018 11:38
@debris debris merged commit cc963d4 into master Sep 25, 2018
@debris debris deleted the td-blockreceipts branch September 25, 2018 17:06
dvdplm added a commit that referenced this pull request Sep 27, 2018
…mon-deps

* origin/master:
  ethereum libfuzzer integration small change (#9547)
  cli: remove reference to --no-ui in --unlock flag help (#9616)
  remove master from releasable branches (#9655)
  ethcore/VerificationQueue don't spawn up extra `worker-threads` when explictly specified not to (#9620)
  RPC: parity_getBlockReceipts (#9527)
  Remove unused dependencies (#9589)
  ignore key_server_cluster randomly failing tests (#9639)
  ethcore: handle vm exception when estimating gas (#9615)
  fix bad-block reporting no reason (#9638)
  Use static call and apparent value transfer for block reward contract code (#9603)
  HF in POA Sokol (2018-09-19) (#9607)
  bump smallvec to 0.6 in ethcore-light, ethstore and whisper (#9588)
  Add constantinople conf to EvmTestClient. (#9570)
@roccomuso
Copy link

I'm having a weird behavior, calling parity_getBlockReceipts on one of the latest block number I get RPC error (code: -32602): Unknown block number. For that same block number the rpc eth_getBlockByNumber returns it instead.
What am I missing?

niklasad1 pushed a commit that referenced this pull request Dec 12, 2018
* Block receipts RPC.

* Use lazy evaluation of block receipts (ecrecover).

* Optimize transaction_receipt to prevent performance regression.

* Fix RPC grumbles.

* Add block & transaction receipt tests.

* Fix conversion to block id.
@Tbaut Tbaut mentioned this pull request Dec 12, 2018
7 tasks
Tbaut added a commit that referenced this pull request Dec 13, 2018
* bump stable to 2.1.10

* RPC: parity_getBlockReceipts (#9527)

* Block receipts RPC.

* Use lazy evaluation of block receipts (ecrecover).

* Optimize transaction_receipt to prevent performance regression.

* Fix RPC grumbles.

* Add block & transaction receipt tests.

* Fix conversion to block id.

* Update a few parity-common dependencies (#9663)

* Update a few parity-common dependencies

* cleanup

* cleanup

* revert update of ethereum/tests

* better reporting of network rlp errors

* Use rlp 0.3.0-beta.1

* fix util function get_dummy_blocks

* Already a Vec

* encode_list returns vec already

* Address grumble

* No need for betas

* Fix double spaces

* Fix empty steps (#9939)

* Don't send empty step twice or empty step then block.

* Perform basic validation of locally sealed blocks.

* Don't include empty step twice.

* Strict empty steps validation (#10041)

* Add two failings tests for strict empty steps.

* Implement strict validation of empty steps.

* ethcore: enable constantinople on ethereum (#10031)

* ethcore: change blockreward to 2e18 for foundation after constantinople

* ethcore: delay diff bomb by 2e6 blocks for foundation after constantinople

* ethcore: enable eip-{145,1014,1052,1283} for foundation after constantinople

* Change test miner max memory to malloc reports. (#10024)

* Bump crossbeam. (#10048)

* Revert "Bump crossbeam. (#10048)"

This reverts commit ed1db0c.
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