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

Subgraph composition: TriggersAdapterWrapper refactor #5602

Open
wants to merge 10 commits into
base: subgraph-composition-interfacing
Choose a base branch
from
4 changes: 2 additions & 2 deletions chain/arweave/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use graph::{
prelude::{async_trait, o, BlockNumber, ChainStore, Error, Logger, LoggerFactory},
};
use prost::Message;
use std::collections::HashSet;
use std::collections::{HashMap, HashSet};
use std::sync::Arc;

use crate::adapter::TriggerFilter;
Expand Down Expand Up @@ -121,7 +121,7 @@ impl Blockchain for Chain {
deployment: DeploymentLocator,
store: impl DeploymentCursorTracker,
start_blocks: Vec<BlockNumber>,
_source_subgraph_stores: Vec<(DeploymentHash, Arc<dyn WritableStore>)>,
_source_subgraph_stores: HashMap<DeploymentHash, Arc<dyn WritableStore>>,
filter: Arc<TriggerFilterWrapper<Self>>,
unified_api_version: UnifiedMappingApiVersion,
) -> Result<Box<dyn BlockStream<Self>>, Error> {
Expand Down
4 changes: 2 additions & 2 deletions chain/cosmos/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use graph::components::adapter::ChainId;
use graph::env::EnvVars;
use graph::prelude::{DeploymentHash, MetricsRegistry};
use graph::substreams::Clock;
use std::collections::HashSet;
use std::collections::{HashMap, HashSet};
use std::convert::TryFrom;
use std::sync::Arc;

Expand Down Expand Up @@ -114,7 +114,7 @@ impl Blockchain for Chain {
deployment: DeploymentLocator,
store: impl DeploymentCursorTracker,
start_blocks: Vec<BlockNumber>,
_source_subgraph_stores: Vec<(DeploymentHash, Arc<dyn WritableStore>)>,
_source_subgraph_stores: HashMap<DeploymentHash, Arc<dyn WritableStore>>,
filter: Arc<TriggerFilterWrapper<Self>>,
unified_api_version: UnifiedMappingApiVersion,
) -> Result<Box<dyn BlockStream<Self>>, Error> {
Expand Down
8 changes: 4 additions & 4 deletions chain/ethereum/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use graph::{
},
};
use prost::Message;
use std::collections::HashSet;
use std::collections::{HashMap, HashSet};
use std::iter::FromIterator;
use std::sync::Arc;
use std::time::Duration;
Expand Down Expand Up @@ -128,7 +128,7 @@ impl BlockStreamBuilder<Chain> for EthereumStreamBuilder {
chain: &Chain,
deployment: DeploymentLocator,
start_blocks: Vec<BlockNumber>,
source_subgraph_stores: Vec<(DeploymentHash, Arc<dyn WritableStore>)>,
source_subgraph_stores: HashMap<DeploymentHash, Arc<dyn WritableStore>>,
subgraph_current_block: Option<BlockPtr>,
filter: Arc<TriggerFilterWrapper<Chain>>,
unified_api_version: UnifiedMappingApiVersion,
Expand All @@ -150,7 +150,7 @@ impl BlockStreamBuilder<Chain> for EthereumStreamBuilder {
chain: &Chain,
deployment: DeploymentLocator,
start_blocks: Vec<BlockNumber>,
source_subgraph_stores: Vec<(DeploymentHash, Arc<dyn WritableStore>)>,
source_subgraph_stores: HashMap<DeploymentHash, Arc<dyn WritableStore>>,
subgraph_current_block: Option<BlockPtr>,
filter: Arc<TriggerFilterWrapper<Chain>>,
unified_api_version: UnifiedMappingApiVersion,
Expand Down Expand Up @@ -437,7 +437,7 @@ impl Blockchain for Chain {
deployment: DeploymentLocator,
store: impl DeploymentCursorTracker,
start_blocks: Vec<BlockNumber>,
source_subgraph_stores: Vec<(DeploymentHash, Arc<dyn WritableStore>)>,
source_subgraph_stores: HashMap<DeploymentHash, Arc<dyn WritableStore>>,
filter: Arc<TriggerFilterWrapper<Self>>,
unified_api_version: UnifiedMappingApiVersion,
) -> Result<Box<dyn BlockStream<Self>>, Error> {
Expand Down
6 changes: 3 additions & 3 deletions chain/near/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use graph::{
prelude::{async_trait, o, BlockNumber, ChainStore, Error, Logger, LoggerFactory},
};
use prost::Message;
use std::collections::HashSet;
use std::collections::{HashMap, HashSet};
use std::sync::Arc;

use crate::adapter::TriggerFilter;
Expand Down Expand Up @@ -152,7 +152,7 @@ impl BlockStreamBuilder<Chain> for NearStreamBuilder {
_chain: &Chain,
_deployment: DeploymentLocator,
_start_blocks: Vec<BlockNumber>,
_source_subgraph_stores: Vec<(DeploymentHash, Arc<dyn WritableStore>)>,
_source_subgraph_stores: HashMap<DeploymentHash, Arc<dyn WritableStore>>,
_subgraph_current_block: Option<BlockPtr>,
_filter: Arc<TriggerFilterWrapper<Chain>>,
_unified_api_version: UnifiedMappingApiVersion,
Expand Down Expand Up @@ -232,7 +232,7 @@ impl Blockchain for Chain {
deployment: DeploymentLocator,
store: impl DeploymentCursorTracker,
start_blocks: Vec<BlockNumber>,
_source_subgraph_stores: Vec<(DeploymentHash, Arc<dyn WritableStore>)>,
_source_subgraph_stores: HashMap<DeploymentHash, Arc<dyn WritableStore>>,
filter: Arc<TriggerFilterWrapper<Self>>,
unified_api_version: UnifiedMappingApiVersion,
) -> Result<Box<dyn BlockStream<Self>>, Error> {
Expand Down
9 changes: 6 additions & 3 deletions chain/starknet/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ use graph::{
slog::o,
};
use prost::Message;
use std::{collections::HashSet, sync::Arc};
use std::{
collections::{HashMap, HashSet},
sync::Arc,
};

use crate::{
adapter::TriggerFilter,
Expand Down Expand Up @@ -116,7 +119,7 @@ impl Blockchain for Chain {
deployment: DeploymentLocator,
store: impl DeploymentCursorTracker,
start_blocks: Vec<BlockNumber>,
_source_subgraph_stores: Vec<(DeploymentHash, Arc<dyn WritableStore>)>,
_source_subgraph_stores: HashMap<DeploymentHash, Arc<dyn WritableStore>>,
filter: Arc<TriggerFilterWrapper<Self>>,
unified_api_version: UnifiedMappingApiVersion,
) -> Result<Box<dyn BlockStream<Self>>, Error> {
Expand Down Expand Up @@ -240,7 +243,7 @@ impl BlockStreamBuilder<Chain> for StarknetStreamBuilder {
_chain: &Chain,
_deployment: DeploymentLocator,
_start_blocks: Vec<BlockNumber>,
_source_subgraph_stores: Vec<(DeploymentHash, Arc<dyn WritableStore>)>,
_source_subgraph_stores: HashMap<DeploymentHash, Arc<dyn WritableStore>>,
_subgraph_current_block: Option<BlockPtr>,
_filter: Arc<TriggerFilterWrapper<Chain>>,
_unified_api_version: UnifiedMappingApiVersion,
Expand Down
4 changes: 2 additions & 2 deletions chain/substreams/src/block_stream.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use std::sync::Arc;
use std::{collections::HashMap, sync::Arc};

use graph::{
blockchain::{
Expand Down Expand Up @@ -104,7 +104,7 @@ impl BlockStreamBuilderTrait<Chain> for BlockStreamBuilder {
_chain: &Chain,
_deployment: DeploymentLocator,
_start_blocks: Vec<BlockNumber>,
_source_subgraph_stores: Vec<(DeploymentHash, Arc<dyn WritableStore>)>,
_source_subgraph_stores: HashMap<DeploymentHash, Arc<dyn WritableStore>>,
_subgraph_current_block: Option<BlockPtr>,
_filter: Arc<TriggerFilterWrapper<Chain>>,
_unified_api_version: UnifiedMappingApiVersion,
Expand Down
3 changes: 2 additions & 1 deletion chain/substreams/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use graph::{
slog::Logger,
};

use std::collections::HashMap;
use std::sync::Arc;

// ParsedChanges are an internal representation of the equivalent operations defined on the
Expand Down Expand Up @@ -142,7 +143,7 @@ impl Blockchain for Chain {
deployment: DeploymentLocator,
store: impl DeploymentCursorTracker,
_start_blocks: Vec<BlockNumber>,
_source_subgraph_stores: Vec<(DeploymentHash, Arc<dyn WritableStore>)>,
_source_subgraph_stores: HashMap<DeploymentHash, Arc<dyn WritableStore>>,
filter: Arc<TriggerFilterWrapper<Self>>,
_unified_api_version: UnifiedMappingApiVersion,
) -> Result<Box<dyn BlockStream<Self>>, Error> {
Expand Down
4 changes: 2 additions & 2 deletions core/src/subgraph/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ use graph::{
data_source::DataSourceTemplate,
prelude::{BlockNumber, DeploymentHash},
};
use std::collections::BTreeSet;
use std::collections::{BTreeSet, HashMap};
use std::sync::Arc;

pub struct IndexingInputs<C: Blockchain> {
pub deployment: DeploymentLocator,
pub features: BTreeSet<SubgraphFeature>,
pub start_blocks: Vec<BlockNumber>,
pub end_blocks: BTreeSet<BlockNumber>,
pub source_subgraph_stores: Vec<(DeploymentHash, Arc<dyn WritableStore>)>,
pub source_subgraph_stores: HashMap<DeploymentHash, Arc<dyn WritableStore>>,
pub stop_block: Option<BlockNumber>,
pub store: Arc<dyn WritableStore>,
pub debug_fork: Option<Arc<dyn SubgraphFork>>,
Expand Down
8 changes: 4 additions & 4 deletions core/src/subgraph/instance_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::subgraph::context::{IndexingContext, SubgraphKeepAlive};
use crate::subgraph::inputs::IndexingInputs;
use crate::subgraph::loader::load_dynamic_data_sources;
use crate::subgraph::Decoder;
use std::collections::BTreeSet;
use std::collections::{BTreeSet, HashMap};

use crate::subgraph::runner::SubgraphRunner;
use graph::blockchain::block_stream::{BlockStreamMetrics, TriggersAdapterWrapper};
Expand Down Expand Up @@ -211,8 +211,8 @@ impl<S: SubgraphStore> SubgraphInstanceManager<S> {
hashes: Vec<DeploymentHash>,
max_spec_version: Version,
is_runner_test: bool,
) -> anyhow::Result<Vec<(DeploymentHash, Arc<dyn WritableStore>)>> {
let mut writable_stores = Vec::new();
) -> anyhow::Result<HashMap<DeploymentHash, Arc<dyn WritableStore>>> {
let mut writable_stores = HashMap::new();
let subgraph_store = self.subgraph_store.clone();

if is_runner_test {
Expand Down Expand Up @@ -244,7 +244,7 @@ impl<S: SubgraphStore> SubgraphInstanceManager<S> {
)
.await?;

writable_stores.push((loc.hash, writable_store));
writable_stores.insert(hash, writable_store);
}

Ok(writable_stores)
Expand Down
12 changes: 8 additions & 4 deletions core/src/subgraph/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use graph::schema::EntityKey;
use graph::util::{backoff::ExponentialBackoff, lfu_cache::LfuCache};
use std::sync::Arc;
use std::time::{Duration, Instant};
use std::vec;

const MINUTE: Duration = Duration::from_secs(60);

Expand Down Expand Up @@ -447,9 +448,12 @@ where
let (data_sources, runtime_hosts) =
self.create_dynamic_data_sources(block_state.drain_created_data_sources())?;

let filter = C::TriggerFilter::from_data_sources(
data_sources.iter().filter_map(DataSource::as_onchain),
);
let filter = &Arc::new(TriggerFilterWrapper::new(
C::TriggerFilter::from_data_sources(
data_sources.iter().filter_map(DataSource::as_onchain),
),
vec![],
));

let block: Arc<C::Block> = if self.inputs.chain.is_refetch_block_required() {
let cur = firehose_cursor.clone();
Expand Down Expand Up @@ -478,7 +482,7 @@ where
let block_with_triggers = self
.inputs
.triggers_adapter
.triggers_in_block(&logger, block.as_ref().clone(), &filter)
.triggers_in_block(&logger, block.as_ref().clone(), filter)
.await?;

let triggers = block_with_triggers.trigger_data;
Expand Down
Loading
Loading