Skip to content

Commit

Permalink
chain: Filter call triggers from unsuccessful transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
tilacog committed Jul 5, 2021
1 parent 2c3f90c commit 2eede27
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions chain/ethereum/src/ethereum_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ pub(crate) async fn blocks_with_triggers(
triggers_by_block.entry(to).or_insert(Vec::new());

let mut blocks = adapter
.load_blocks(logger1, chain_store, block_hashes)
.load_blocks(logger1, chain_store.clone(), block_hashes)
.and_then(
move |block| match triggers_by_block.remove(&(block.number() as BlockNumber)) {
Some(triggers) => Ok(BlockWithTriggers::new(
Expand All @@ -1503,11 +1503,17 @@ pub(crate) async fn blocks_with_triggers(
)),
},
)
// .map(|x| filter_call_triggers_from_unsuccessful_transactions(x))
.collect()
.compat()
.await?;

let section =
stopwatch_metrics.start_section("filter_call_triggers_from_unsuccessful_transactions");
for mut block in blocks.iter_mut() {
filter_call_triggers_from_unsuccessful_transactions(&mut block, &eth, &chain_store).await?;
}
section.end();

blocks.sort_by_key(|block| block.ptr().number);

// Sanity check that the returned blocks are in the correct range.
Expand Down Expand Up @@ -1660,10 +1666,10 @@ async fn fetch_receipt_from_ethereum_client(
}

async fn filter_call_triggers_from_unsuccessful_transactions(
mut block: BlockWithTriggers<crate::Chain>,
chain_store: Arc<dyn ChainStore>,
) -> anyhow::Result<BlockWithTriggers<crate::Chain>> {
block: &mut BlockWithTriggers<crate::Chain>,
eth: &EthereumAdapter,
chain_store: &Arc<dyn ChainStore>,
) -> anyhow::Result<()> {
// First, we separate call triggers from other trigger types
let calls: Vec<&Arc<EthereumCall>> = block
.trigger_data
Expand All @@ -1685,7 +1691,7 @@ async fn filter_call_triggers_from_unsuccessful_transactions(

// And obtain all Transaction values for the calls in this block.
let transactions: Vec<&Transaction> = {
match block.block {
match &block.block {
BlockFinality::Final(_block) => {
unreachable!("this function should not be called for dealing with final blocks")
}
Expand Down Expand Up @@ -1758,7 +1764,7 @@ async fn filter_call_triggers_from_unsuccessful_transactions(
true
}
});
Ok(block)
Ok(())
}

fn is_transaction_successful(
Expand Down

0 comments on commit 2eede27

Please sign in to comment.