From c57c866c17b53f15e6cb0dfe13dbf9de16066f01 Mon Sep 17 00:00:00 2001 From: Noah Citron Date: Fri, 23 Sep 2022 22:52:51 -0400 Subject: [PATCH] feat: parallel tx receipt fetching (#57) --- execution/src/execution.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/execution/src/execution.rs b/execution/src/execution.rs index 3741e98..478d3dd 100644 --- a/execution/src/execution.rs +++ b/execution/src/execution.rs @@ -10,6 +10,7 @@ use eyre::Result; use common::utils::hex_str_to_bytes; use consensus::types::ExecutionPayload; +use futures::future::join_all; use revm::KECCAK_EMPTY; use triehash_ethereum::ordered_trie_root; @@ -164,16 +165,17 @@ impl ExecutionClient { .map(|tx| H256::from_slice(&keccak256(tx))) .collect::>(); - let mut receipts = vec![]; - for hash in tx_hashes { - let receipt = self.rpc.get_transaction_receipt(&hash).await?.unwrap(); + let receipts_fut = tx_hashes.iter().map(|hash| async move { + let receipt = self.rpc.get_transaction_receipt(hash).await; + receipt?.ok_or(eyre::eyre!("not reachable")) + }); - receipts.push(receipt); - } + let receipts = join_all(receipts_fut).await; + let receipts = receipts.into_iter().collect::>>()?; let receipts_encoded: Vec> = receipts .iter() - .map(|receipt| encode_receipt(receipt)) + .map(|receipt| encode_receipt(&receipt)) .collect(); let expected_receipt_root = ordered_trie_root(receipts_encoded);