Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions prdoc/unstable2507/pr_11476.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: 'revive: Skip redundant eth_block_hash RPC call in block subscription'
doc:
- audience: Runtime Dev
description: |-
Backport of #11475. Skip a redundant eth_block_hash RPC call during block subscription by
reusing the block hash already available in the subscription context. Adds extra logging for
receipt extraction.
crates:
- name: pallet-revive-eth-rpc
bump: patch
30 changes: 23 additions & 7 deletions substrate/frame/revive/rpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,30 @@ impl Client {
) -> Result<(), ClientError> {
log::info!(target: LOG_TARGET, "🔌 Subscribing to new blocks ({subscription_type:?})");
self.subscribe_new_blocks(subscription_type, |block| async {
macro_rules! time {
($label:expr, $expr:expr) => {{
let t = std::time::Instant::now();
let r = $expr;
log::trace!(
target: LOG_TARGET,
"⏱️ [{subscription_type:?}] #{} {}: {:?}",
block.number(),
$label,
t.elapsed(),
);
r
}};
}

let hash = block.hash();
let evm_block = self.runtime_api(hash).eth_block().await?;
let (_, receipts): (Vec<_>, Vec<_>) = self
.receipt_provider
.insert_block_receipts(&block, &evm_block.hash)
.await?
.into_iter()
.unzip();
let evm_block = time!("eth_block", self.runtime_api(hash).eth_block().await?);

let (_, receipts): (Vec<_>, Vec<_>) = time!(
"insert_block_receipts",
self.receipt_provider.insert_block_receipts(&block, &evm_block.hash).await?
)
.into_iter()
.unzip();

self.block_provider.update_latest(Arc::new(block), subscription_type).await;
self.fee_history_provider.update_fee_history(&evm_block, &receipts).await;
Expand Down
20 changes: 13 additions & 7 deletions substrate/frame/revive/rpc/src/receipt_extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,26 @@ impl ReceiptExtractor {
pub async fn extract_from_block(
&self,
block: &SubstrateBlock,
) -> Result<Vec<(TransactionSigned, ReceiptInfo)>, ClientError> {
let eth_block_hash = self
.get_ethereum_block_hash(&block.hash(), block.number() as u64)
.await
.unwrap_or(block.hash());
self.extract_from_block_with_eth_hash(block, eth_block_hash).await
}

/// Extract receipts from block, using a pre-fetched ethereum block hash.
pub async fn extract_from_block_with_eth_hash(
&self,
block: &SubstrateBlock,
eth_block_hash: H256,
) -> Result<Vec<(TransactionSigned, ReceiptInfo)>, ClientError> {
if self.is_before_earliest_block(block.number()) {
return Ok(vec![]);
}

let ext_iter = self.get_block_extrinsics(block).await?;

let substrate_block_number = block.number() as u64;
let substrate_block_hash = block.hash();
let eth_block_hash =
(self.fetch_eth_block_hash)(substrate_block_hash, substrate_block_number)
.await
.unwrap_or(substrate_block_hash);

// Process extrinsics in order while maintaining parallelism within buffer window
stream::iter(ext_iter)
.map(|(ext, call, receipt, ext_idx)| async move {
Expand Down
5 changes: 4 additions & 1 deletion substrate/frame/revive/rpc/src/receipt_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ impl<B: BlockInfoProvider> ReceiptProvider<B> {
block: &SubstrateBlock,
ethereum_hash: &H256,
) -> Result<Vec<(TransactionSigned, ReceiptInfo)>, ClientError> {
let receipts = self.receipts_from_block(block).await?;
let receipts = self
.receipt_extractor
.extract_from_block_with_eth_hash(block, *ethereum_hash)
.await?;
self.insert(block, &receipts, ethereum_hash).await?;
Ok(receipts)
}
Expand Down
Loading