Skip to content

Commit fb6b8fd

Browse files
committed
chain, core, graph, store: Filter call handlers from failed txns
1 parent c887324 commit fb6b8fd

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
@@ -24,6 +24,7 @@ use graph::{components::ethereum::EthereumNetworkIdentifier, prelude::*};
2424
use crate::{data_source::DataSource, Chain};
2525

2626
pub type EventSignature = H256;
27+
pub type FunctionSelector = [u8; 4];
2728

2829
#[derive(Clone, Debug)]
2930
pub struct EthereumContractCall {
@@ -270,7 +271,8 @@ impl EthereumLogFilter {
270271
pub(crate) struct EthereumCallFilter {
271272
// Each call filter has a map of filters keyed by address, each containing a tuple with
272273
// start_block and the set of function signatures
273-
pub contract_addresses_function_signatures: HashMap<Address, (BlockNumber, HashSet<[u8; 4]>)>,
274+
pub contract_addresses_function_signatures:
275+
HashMap<Address, (BlockNumber, HashSet<FunctionSelector>)>,
274276
}
275277

276278
impl EthereumCallFilter {
@@ -355,12 +357,12 @@ impl EthereumCallFilter {
355357
}
356358
}
357359

358-
impl FromIterator<(BlockNumber, Address, [u8; 4])> for EthereumCallFilter {
360+
impl FromIterator<(BlockNumber, Address, FunctionSelector)> for EthereumCallFilter {
359361
fn from_iter<I>(iter: I) -> Self
360362
where
361-
I: IntoIterator<Item = (BlockNumber, Address, [u8; 4])>,
363+
I: IntoIterator<Item = (BlockNumber, Address, FunctionSelector)>,
362364
{
363-
let mut lookup: HashMap<Address, (BlockNumber, HashSet<[u8; 4]>)> = HashMap::new();
365+
let mut lookup: HashMap<Address, (BlockNumber, HashSet<FunctionSelector>)> = HashMap::new();
364366
iter.into_iter()
365367
.for_each(|(start_block, address, function_signature)| {
366368
if !lookup.contains_key(&address) {
@@ -387,7 +389,7 @@ impl From<EthereumBlockFilter> for EthereumCallFilter {
387389
.contract_addresses
388390
.into_iter()
389391
.map(|(start_block_opt, address)| (address, (start_block_opt, HashSet::default())))
390-
.collect::<HashMap<Address, (BlockNumber, HashSet<[u8; 4]>)>>(),
392+
.collect::<HashMap<Address, (BlockNumber, HashSet<FunctionSelector>)>>(),
391393
}
392394
}
393395
}

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
LoggerFactory, MetricsRegistry, NodeId, 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;
@@ -142,6 +143,7 @@ impl Blockchain for Chain {
142143
loc: &DeploymentLocator,
143144
capabilities: &Self::NodeCapabilities,
144145
unified_api_version: UnifiedMappingApiVersion,
146+
stopwatch_metrics: StopwatchMetrics,
145147
) -> Result<Arc<Self::TriggersAdapter>, Error> {
146148
let eth_adapter = self.eth_adapters.cheapest_with(capabilities)?.clone();
147149
let logger = self
@@ -154,8 +156,9 @@ impl Blockchain for Chain {
154156
logger,
155157
ethrpc_metrics,
156158
eth_adapter,
159+
stopwatch_metrics,
157160
chain_store: self.chain_store.cheap_clone(),
158-
_unified_api_version: unified_api_version,
161+
unified_api_version,
159162
};
160163
Ok(Arc::new(adapter))
161164
}
@@ -182,7 +185,12 @@ impl Blockchain for Chain {
182185
let requirements = filter.node_capabilities();
183186

184187
let triggers_adapter = self
185-
.triggers_adapter(&deployment, &requirements, unified_api_version.clone())
188+
.triggers_adapter(
189+
&deployment,
190+
&requirements,
191+
unified_api_version.clone(),
192+
metrics.stopwatch.clone(),
193+
)
186194
.expect(&format!(
187195
"no adapter for network {} with capabilities {}",
188196
self.name, requirements
@@ -330,9 +338,10 @@ impl Manifest<Chain> for DummyManifest {
330338
pub struct TriggersAdapter {
331339
logger: Logger,
332340
ethrpc_metrics: Arc<SubgraphEthRpcMetrics>,
341+
stopwatch_metrics: StopwatchMetrics,
333342
chain_store: Arc<dyn ChainStore>,
334343
eth_adapter: Arc<EthereumAdapter>,
335-
_unified_api_version: UnifiedMappingApiVersion,
344+
unified_api_version: UnifiedMappingApiVersion,
336345
}
337346

338347
#[async_trait]
@@ -348,9 +357,11 @@ impl TriggersAdapterTrait<Chain> for TriggersAdapter {
348357
self.logger.clone(),
349358
self.chain_store.clone(),
350359
self.ethrpc_metrics.clone(),
360+
self.stopwatch_metrics.clone(),
351361
from,
352362
to,
353363
filter,
364+
self.unified_api_version.clone(),
354365
)
355366
.await
356367
}
@@ -378,9 +389,11 @@ impl TriggersAdapterTrait<Chain> for TriggersAdapter {
378389
logger.clone(),
379390
self.chain_store.clone(),
380391
self.ethrpc_metrics.clone(),
392+
self.stopwatch_metrics.clone(),
381393
block_number,
382394
block_number,
383395
filter,
396+
self.unified_api_version.clone(),
384397
)
385398
.await?;
386399
assert!(blocks.len() == 1);
@@ -392,7 +405,7 @@ impl TriggersAdapterTrait<Chain> for TriggersAdapter {
392405
&filter.log,
393406
&full_block.ethereum_block,
394407
));
395-
triggers.append(&mut parse_call_triggers(&filter.call, &full_block));
408+
triggers.append(&mut parse_call_triggers(&filter.call, &full_block)?);
396409
triggers.append(&mut parse_block_triggers(filter.block.clone(), &full_block));
397410
Ok(BlockWithTriggers::new(block, triggers))
398411
}

0 commit comments

Comments
 (0)