File tree Expand file tree Collapse file tree 3 files changed +40
-15
lines changed
substrate/frame/revive/rpc/src Expand file tree Collapse file tree 3 files changed +40
-15
lines changed Original file line number Diff line number Diff line change @@ -361,14 +361,30 @@ impl Client {
361361 ) -> Result < ( ) , ClientError > {
362362 log:: info!( target: LOG_TARGET , "🔌 Subscribing to new blocks ({subscription_type:?})" ) ;
363363 self . subscribe_new_blocks ( subscription_type, |block| async {
364+ macro_rules! time {
365+ ( $label: expr, $expr: expr) => { {
366+ let t = std:: time:: Instant :: now( ) ;
367+ let r = $expr;
368+ log:: trace!(
369+ target: LOG_TARGET ,
370+ "⏱️ [{subscription_type:?}] #{} {}: {:?}" ,
371+ block. number( ) ,
372+ $label,
373+ t. elapsed( ) ,
374+ ) ;
375+ r
376+ } } ;
377+ }
378+
364379 let hash = block. hash ( ) ;
365- let evm_block = self . runtime_api ( hash) . eth_block ( ) . await ?;
366- let ( _, receipts) : ( Vec < _ > , Vec < _ > ) = self
367- . receipt_provider
368- . insert_block_receipts ( & block, & evm_block. hash )
369- . await ?
370- . into_iter ( )
371- . unzip ( ) ;
380+ let evm_block = time ! ( "eth_block" , self . runtime_api( hash) . eth_block( ) . await ?) ;
381+
382+ let ( _, receipts) : ( Vec < _ > , Vec < _ > ) = time ! (
383+ "insert_block_receipts" ,
384+ self . receipt_provider. insert_block_receipts( & block, & evm_block. hash) . await ?
385+ )
386+ . into_iter ( )
387+ . unzip ( ) ;
372388
373389 self . block_provider . update_latest ( Arc :: new ( block) , subscription_type) . await ;
374390 self . fee_history_provider . update_fee_history ( & evm_block, & receipts) . await ;
Original file line number Diff line number Diff line change @@ -232,20 +232,26 @@ impl ReceiptExtractor {
232232 pub async fn extract_from_block (
233233 & self ,
234234 block : & SubstrateBlock ,
235+ ) -> Result < Vec < ( TransactionSigned , ReceiptInfo ) > , ClientError > {
236+ let eth_block_hash = self
237+ . get_ethereum_block_hash ( & block. hash ( ) , block. number ( ) as u64 )
238+ . await
239+ . unwrap_or ( block. hash ( ) ) ;
240+ self . extract_from_block_with_eth_hash ( block, eth_block_hash) . await
241+ }
242+
243+ /// Extract receipts from block, using a pre-fetched ethereum block hash.
244+ pub async fn extract_from_block_with_eth_hash (
245+ & self ,
246+ block : & SubstrateBlock ,
247+ eth_block_hash : H256 ,
235248 ) -> Result < Vec < ( TransactionSigned , ReceiptInfo ) > , ClientError > {
236249 if self . is_before_earliest_block ( block. number ( ) ) {
237250 return Ok ( vec ! [ ] ) ;
238251 }
239252
240253 let ext_iter = self . get_block_extrinsics ( block) . await ?;
241254
242- let substrate_block_number = block. number ( ) as u64 ;
243- let substrate_block_hash = block. hash ( ) ;
244- let eth_block_hash =
245- ( self . fetch_eth_block_hash ) ( substrate_block_hash, substrate_block_number)
246- . await
247- . unwrap_or ( substrate_block_hash) ;
248-
249255 // Process extrinsics in order while maintaining parallelism within buffer window
250256 stream:: iter ( ext_iter)
251257 . map ( |( ext, call, receipt, ext_idx) | async move {
Original file line number Diff line number Diff line change @@ -245,7 +245,10 @@ impl<B: BlockInfoProvider> ReceiptProvider<B> {
245245 block : & SubstrateBlock ,
246246 ethereum_hash : & H256 ,
247247 ) -> Result < Vec < ( TransactionSigned , ReceiptInfo ) > , ClientError > {
248- let receipts = self . receipts_from_block ( block) . await ?;
248+ let receipts = self
249+ . receipt_extractor
250+ . extract_from_block_with_eth_hash ( block, * ethereum_hash)
251+ . await ?;
249252 self . insert ( block, & receipts, ethereum_hash) . await ?;
250253 Ok ( receipts)
251254 }
You can’t perform that action at this time.
0 commit comments