Skip to content

Commit 649f0c2

Browse files
committed
chain: optimize transaction status cache for a single block
1 parent 22f621e commit 649f0c2

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

chain/ethereum/src/ethereum_adapter.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ impl EthereumAdapter {
710710

711711
// Hit the database and fetch all failed transactions in the block range.
712712
// TODO: handle this Result/expect
713-
let transaction_statuses_in_block_range = chain_store
713+
let mut transaction_statuses_in_block_range = chain_store
714714
.transaction_statuses_in_block_range(&(from..to))
715715
.expect("failed to fetch failed transactions in the database");
716716

@@ -720,8 +720,12 @@ impl EthereumAdapter {
720720
eth.trace_stream(&logger, subgraph_metrics, from, to, addresses)
721721
.filter(move |trace| {
722722
// TODO: handle this Result/expect
723-
trace_transaction_succeeded(&trace, &eth2, &transaction_statuses_in_block_range)
724-
.expect("failed to determine if trace's transaction has failed")
723+
trace_transaction_succeeded(
724+
&trace,
725+
&eth2,
726+
&mut transaction_statuses_in_block_range,
727+
)
728+
.expect("failed to determine if trace's transaction has failed")
725729
})
726730
.filter_map(|trace| EthereumCall::try_from_trace(&trace))
727731
.filter(move |call| {
@@ -1668,7 +1672,7 @@ pub(crate) fn parse_block_triggers(
16681672
fn trace_transaction_succeeded(
16691673
trace: &Trace,
16701674
eth: &EthereumAdapter,
1671-
failed_transactions: &HashMap<H256, bool>,
1675+
failed_transactions: &mut HashMap<H256, bool>,
16721676
) -> anyhow::Result<bool> {
16731677
let transaction_hash = trace
16741678
.transaction_hash
@@ -1693,10 +1697,15 @@ fn trace_transaction_succeeded(
16931697
.ok_or(anyhow::anyhow!("Running in light client mode"))?
16941698
>= transaction.gas
16951699
{
1700+
// update our source of truth to prevent future api calls for the same transaction
1701+
failed_transactions.insert(transaction_hash, false);
16961702
return Ok(false);
16971703
}
16981704

1699-
Ok(matches!(receipt.status, Some(x) if x == web3::types::U64::from(1)))
1705+
let status = matches!(receipt.status, Some(x) if x == web3::types::U64::from(1));
1706+
// update our source of truth to prevent future api calls for the same transaction
1707+
failed_transactions.insert(transaction_hash, status);
1708+
Ok(status)
17001709
}
17011710

17021711
async fn fetch_transaction_and_receipt_from_ethereum_client(

0 commit comments

Comments
 (0)