Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent handling triggers for failed transactions #2511

Merged
merged 1 commit into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions chain/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ethabi = { git = "https://github.com/graphprotocol/ethabi.git", branch = "master

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

graph-runtime-wasm = { path = "../../runtime/wasm" }
graph-runtime-derive = { path = "../../runtime/derive" }
Expand Down
12 changes: 7 additions & 5 deletions chain/ethereum/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use graph::{components::ethereum::EthereumNetworkIdentifier, prelude::*};
use crate::{data_source::DataSource, Chain};

pub type EventSignature = H256;
pub type FunctionSelector = [u8; 4];
tilacog marked this conversation as resolved.
Show resolved Hide resolved

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

impl EthereumCallFilter {
Expand Down Expand Up @@ -355,12 +357,12 @@ impl EthereumCallFilter {
}
}

impl FromIterator<(BlockNumber, Address, [u8; 4])> for EthereumCallFilter {
impl FromIterator<(BlockNumber, Address, FunctionSelector)> for EthereumCallFilter {
fn from_iter<I>(iter: I) -> Self
where
I: IntoIterator<Item = (BlockNumber, Address, [u8; 4])>,
I: IntoIterator<Item = (BlockNumber, Address, FunctionSelector)>,
{
let mut lookup: HashMap<Address, (BlockNumber, HashSet<[u8; 4]>)> = HashMap::new();
let mut lookup: HashMap<Address, (BlockNumber, HashSet<FunctionSelector>)> = HashMap::new();
iter.into_iter()
.for_each(|(start_block, address, function_signature)| {
if !lookup.contains_key(&address) {
Expand All @@ -387,7 +389,7 @@ impl From<EthereumBlockFilter> for EthereumCallFilter {
.contract_addresses
.into_iter()
.map(|(start_block_opt, address)| (address, (start_block_opt, HashSet::default())))
.collect::<HashMap<Address, (BlockNumber, HashSet<[u8; 4]>)>>(),
.collect::<HashMap<Address, (BlockNumber, HashSet<FunctionSelector>)>>(),
}
}
}
Expand Down
31 changes: 22 additions & 9 deletions chain/ethereum/src/chain.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::collections::HashSet;
use std::iter::FromIterator;
use std::sync::Arc;

use anyhow::{Context, Error};
use graph::data::subgraph::UnifiedMappingApiVersion;
use graph::prelude::{EthereumCallCache, LightEthereumBlock, LightEthereumBlockExt};
use graph::prelude::{
EthereumCallCache, LightEthereumBlock, LightEthereumBlockExt, StopwatchMetrics,
};
use graph::{
blockchain::{
block_stream::{
Expand All @@ -23,6 +21,9 @@ use graph::{
LoggerFactory, MetricsRegistry, NodeId, SubgraphStore,
},
};
use std::collections::HashSet;
use std::iter::FromIterator;
use std::sync::Arc;

use crate::data_source::DataSourceTemplate;
use crate::data_source::UnresolvedDataSourceTemplate;
Expand Down Expand Up @@ -142,6 +143,7 @@ impl Blockchain for Chain {
loc: &DeploymentLocator,
capabilities: &Self::NodeCapabilities,
unified_api_version: UnifiedMappingApiVersion,
stopwatch_metrics: StopwatchMetrics,
) -> Result<Arc<Self::TriggersAdapter>, Error> {
let eth_adapter = self.eth_adapters.cheapest_with(capabilities)?.clone();
let logger = self
Expand All @@ -154,8 +156,9 @@ impl Blockchain for Chain {
logger,
ethrpc_metrics,
eth_adapter,
stopwatch_metrics,
chain_store: self.chain_store.cheap_clone(),
_unified_api_version: unified_api_version,
unified_api_version,
};
Ok(Arc::new(adapter))
}
Expand All @@ -182,7 +185,12 @@ impl Blockchain for Chain {
let requirements = filter.node_capabilities();

let triggers_adapter = self
.triggers_adapter(&deployment, &requirements, unified_api_version.clone())
.triggers_adapter(
&deployment,
&requirements,
unified_api_version.clone(),
metrics.stopwatch.clone(),
)
.expect(&format!(
"no adapter for network {} with capabilities {}",
self.name, requirements
Expand Down Expand Up @@ -330,9 +338,10 @@ impl Manifest<Chain> for DummyManifest {
pub struct TriggersAdapter {
logger: Logger,
ethrpc_metrics: Arc<SubgraphEthRpcMetrics>,
stopwatch_metrics: StopwatchMetrics,
chain_store: Arc<dyn ChainStore>,
eth_adapter: Arc<EthereumAdapter>,
_unified_api_version: UnifiedMappingApiVersion,
unified_api_version: UnifiedMappingApiVersion,
}

#[async_trait]
Expand All @@ -348,9 +357,11 @@ impl TriggersAdapterTrait<Chain> for TriggersAdapter {
self.logger.clone(),
self.chain_store.clone(),
self.ethrpc_metrics.clone(),
self.stopwatch_metrics.clone(),
from,
to,
filter,
self.unified_api_version.clone(),
)
.await
}
Expand Down Expand Up @@ -378,9 +389,11 @@ impl TriggersAdapterTrait<Chain> for TriggersAdapter {
logger.clone(),
self.chain_store.clone(),
self.ethrpc_metrics.clone(),
self.stopwatch_metrics.clone(),
block_number,
block_number,
filter,
self.unified_api_version.clone(),
)
.await?;
assert!(blocks.len() == 1);
Expand All @@ -392,7 +405,7 @@ impl TriggersAdapterTrait<Chain> for TriggersAdapter {
&filter.log,
&full_block.ethereum_block,
));
triggers.append(&mut parse_call_triggers(&filter.call, &full_block));
triggers.append(&mut parse_call_triggers(&filter.call, &full_block)?);
triggers.append(&mut parse_block_triggers(filter.block.clone(), &full_block));
Ok(BlockWithTriggers::new(block, triggers))
}
Expand Down
Loading