Skip to content

Commit e37fec8

Browse files
committed
chain, core, graph, store: Filter call handlers from failed txns
1 parent 9e2e5e6 commit e37fec8

File tree

18 files changed

+594
-57
lines changed

18 files changed

+594
-57
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chain/ethereum/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ethabi = { git = "https://github.com/graphprotocol/ethabi.git", branch = "master
2828

2929
# We have a couple custom patches to web3.
3030
web3 = { git = "https://github.com/graphprotocol/rust-web3", branch = "master" }
31+
itertools = "0.10.0"
3132

3233
graph-runtime-wasm = { path = "../../runtime/wasm" }
3334
graph-runtime-derive = { path = "../../runtime/derive" }

chain/ethereum/src/adapter.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::capabilities::NodeCapabilities;
2222
use crate::{data_source::DataSource, Chain};
2323

2424
pub type EventSignature = H256;
25+
pub type FunctionSelector = [u8; 4];
2526

2627
#[derive(Clone, Debug)]
2728
pub struct EthereumContractCall {
@@ -268,7 +269,8 @@ impl EthereumLogFilter {
268269
pub(crate) struct EthereumCallFilter {
269270
// Each call filter has a map of filters keyed by address, each containing a tuple with
270271
// start_block and the set of function signatures
271-
pub contract_addresses_function_signatures: HashMap<Address, (BlockNumber, HashSet<[u8; 4]>)>,
272+
pub contract_addresses_function_signatures:
273+
HashMap<Address, (BlockNumber, HashSet<FunctionSelector>)>,
272274
}
273275

274276
impl EthereumCallFilter {
@@ -353,12 +355,12 @@ impl EthereumCallFilter {
353355
}
354356
}
355357

356-
impl FromIterator<(BlockNumber, Address, [u8; 4])> for EthereumCallFilter {
358+
impl FromIterator<(BlockNumber, Address, FunctionSelector)> for EthereumCallFilter {
357359
fn from_iter<I>(iter: I) -> Self
358360
where
359-
I: IntoIterator<Item = (BlockNumber, Address, [u8; 4])>,
361+
I: IntoIterator<Item = (BlockNumber, Address, FunctionSelector)>,
360362
{
361-
let mut lookup: HashMap<Address, (BlockNumber, HashSet<[u8; 4]>)> = HashMap::new();
363+
let mut lookup: HashMap<Address, (BlockNumber, HashSet<FunctionSelector>)> = HashMap::new();
362364
iter.into_iter()
363365
.for_each(|(start_block, address, function_signature)| {
364366
if !lookup.contains_key(&address) {
@@ -385,7 +387,7 @@ impl From<EthereumBlockFilter> for EthereumCallFilter {
385387
.contract_addresses
386388
.into_iter()
387389
.map(|(start_block_opt, address)| (address, (start_block_opt, HashSet::default())))
388-
.collect::<HashMap<Address, (BlockNumber, HashSet<[u8; 4]>)>>(),
390+
.collect::<HashMap<Address, (BlockNumber, HashSet<FunctionSelector>)>>(),
389391
}
390392
}
391393
}

chain/ethereum/src/chain.rs

+22-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
use std::collections::HashSet;
2-
use std::iter::FromIterator;
3-
use std::sync::Arc;
4-
51
use anyhow::{Context, Error};
62
use graph::data::subgraph::UnifiedMappingApiVersion;
7-
use graph::prelude::{EthereumCallCache, LightEthereumBlock, LightEthereumBlockExt};
3+
use graph::prelude::{
4+
EthereumCallCache, LightEthereumBlock, LightEthereumBlockExt, StopwatchMetrics,
5+
};
86
use graph::{
97
blockchain::{
108
block_stream::{
@@ -23,6 +21,9 @@ use graph::{
2321
SubgraphStore,
2422
},
2523
};
24+
use std::collections::HashSet;
25+
use std::iter::FromIterator;
26+
use std::sync::Arc;
2627

2728
use crate::data_source::DataSourceTemplate;
2829
use crate::data_source::UnresolvedDataSourceTemplate;
@@ -140,6 +141,7 @@ impl Blockchain for Chain {
140141
loc: &DeploymentLocator,
141142
capabilities: &Self::NodeCapabilities,
142143
unified_api_version: UnifiedMappingApiVersion,
144+
stopwatch_metrics: StopwatchMetrics,
143145
) -> Result<Arc<Self::TriggersAdapter>, Error> {
144146
let eth_adapter = self.eth_adapters.cheapest_with(capabilities)?.clone();
145147
let logger = self
@@ -152,8 +154,9 @@ impl Blockchain for Chain {
152154
logger,
153155
ethrpc_metrics,
154156
eth_adapter,
157+
stopwatch_metrics,
155158
chain_store: self.chain_store.cheap_clone(),
156-
_unified_api_version: unified_api_version,
159+
unified_api_version,
157160
};
158161
Ok(Arc::new(adapter))
159162
}
@@ -180,7 +183,12 @@ impl Blockchain for Chain {
180183
let requirements = filter.node_capabilities();
181184

182185
let triggers_adapter = self
183-
.triggers_adapter(&deployment, &requirements, unified_api_version.clone())
186+
.triggers_adapter(
187+
&deployment,
188+
&requirements,
189+
unified_api_version.clone(),
190+
metrics.stopwatch.clone(),
191+
)
184192
.expect(&format!(
185193
"no adapter for network {} with capabilities {}",
186194
self.name, requirements
@@ -306,9 +314,10 @@ pub struct DummyDataSourceTemplate;
306314
pub struct TriggersAdapter {
307315
logger: Logger,
308316
ethrpc_metrics: Arc<SubgraphEthRpcMetrics>,
317+
stopwatch_metrics: StopwatchMetrics,
309318
chain_store: Arc<dyn ChainStore>,
310319
eth_adapter: Arc<EthereumAdapter>,
311-
_unified_api_version: UnifiedMappingApiVersion,
320+
unified_api_version: UnifiedMappingApiVersion,
312321
}
313322

314323
#[async_trait]
@@ -324,9 +333,11 @@ impl TriggersAdapterTrait<Chain> for TriggersAdapter {
324333
self.logger.clone(),
325334
self.chain_store.clone(),
326335
self.ethrpc_metrics.clone(),
336+
self.stopwatch_metrics.clone(),
327337
from,
328338
to,
329339
filter,
340+
self.unified_api_version.clone(),
330341
)
331342
.await
332343
}
@@ -354,9 +365,11 @@ impl TriggersAdapterTrait<Chain> for TriggersAdapter {
354365
logger.clone(),
355366
self.chain_store.clone(),
356367
self.ethrpc_metrics.clone(),
368+
self.stopwatch_metrics.clone(),
357369
block_number,
358370
block_number,
359371
filter,
372+
self.unified_api_version.clone(),
360373
)
361374
.await?;
362375
assert!(blocks.len() == 1);
@@ -368,7 +381,7 @@ impl TriggersAdapterTrait<Chain> for TriggersAdapter {
368381
&filter.log,
369382
&full_block.ethereum_block,
370383
));
371-
triggers.append(&mut parse_call_triggers(&filter.call, &full_block));
384+
triggers.append(&mut parse_call_triggers(&filter.call, &full_block)?);
372385
triggers.append(&mut parse_block_triggers(filter.block.clone(), &full_block));
373386
Ok(BlockWithTriggers::new(block, triggers))
374387
}

0 commit comments

Comments
 (0)