RPC: parity_getBlockReceipts#9527
Conversation
debris
left a comment
There was a problem hiding this comment.
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>>; |
| 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`. |
| receipts.into_iter() | ||
| .flat_map(|r| { | ||
| let hash = r.transaction_hash; | ||
| r.logs.into_iter().map(move |l| (hash.clone(), l)) |
There was a problem hiding this comment.
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>(); |
There was a problem hiding this comment.
I don't understand these 3 lines. why do we pop a receipt and then take a gas_used from the one before it?
There was a problem hiding this comment.
So to actually generate a LocalizedReceipt we need 3 things:
- Actual receipt
- Gas used by that transaction
- Number of logs generate prior to this transaction (to calculate log_index_in_block).
So the logic is as follows:
- Fetch all receipts from 0 to
index(inclusive) - Take the last one (
receipts.pop(); point 1.) - Take the previous to last one to calculate (point 2.) (receipts only store cumulative gas, so we calculate
current.gas_used - previous.gas_usedto figure out whatcurrentgas usage of transaction was) - Use all previous receipts to calculate total number of logs. (point 3.)
| Some(receipt) | ||
| } | ||
|
|
||
| fn block_receipts(&self, id: BlockId) -> Option<Vec<LocalizedReceipt>> { |
There was a problem hiding this comment.
This method could probably use a test.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Since there is no Pending state, I'd say either return an empty vector or keep the deprecation log from num_to_id.
| 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`"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Moved it to a trait, so it explicitly says it's for light client only.
|
please rebase on master |
…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)
|
I'm having a weird behavior, calling |
* 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.
* 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.
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_getTransactionReceiptperformance 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_getBlockReceiptsas the second one, cause the first call fills up the cache. Updated the results, but even ifgetBlockReceiptsfetches data from disk it's faster, so it's not really a contributing factor here.