Skip to content

Commit f1f8c31

Browse files
committed
graph: fix subgraph filter mismatch bug
1 parent 9221ff2 commit f1f8c31

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

graph/src/blockchain/block_stream.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::components::store::{BlockNumber, DeploymentLocator, SourceableStore};
2121
use crate::data::subgraph::UnifiedMappingApiVersion;
2222
use crate::firehose::{self, FirehoseEndpoint};
2323
use crate::futures03::stream::StreamExt as _;
24-
use crate::schema::InputSchema;
24+
use crate::schema::{EntityType, InputSchema};
2525
use crate::substreams_rpc::response::Message;
2626
use crate::{prelude::*, prometheus::labels};
2727

@@ -353,14 +353,14 @@ impl<C: Blockchain> TriggersAdapterWrapper<C> {
353353

354354
fn create_subgraph_trigger_from_entities(
355355
filter: &SubgraphFilter,
356-
entities: &Vec<Entity>,
356+
entities: &Vec<EntityWithType>,
357357
) -> Vec<subgraph::TriggerData> {
358358
entities
359359
.iter()
360360
.map(|e| subgraph::TriggerData {
361361
source: filter.subgraph.clone(),
362-
entity: e.clone(),
363-
entity_type: filter.entities.first().unwrap().clone(),
362+
entity: e.entity.clone(),
363+
entity_type: e.entity_type.as_str().to_string(),
364364
})
365365
.collect()
366366
}
@@ -369,7 +369,7 @@ async fn create_subgraph_triggers<C: Blockchain>(
369369
logger: Logger,
370370
blocks: Vec<C::Block>,
371371
filter: &SubgraphFilter,
372-
entities: BTreeMap<BlockNumber, Vec<Entity>>,
372+
entities: BTreeMap<BlockNumber, Vec<EntityWithType>>,
373373
) -> Result<Vec<BlockWithTriggers<C>>, Error> {
374374
let logger_clone = logger.cheap_clone();
375375

@@ -429,24 +429,39 @@ async fn scan_subgraph_triggers<C: Blockchain>(
429429
}
430430
}
431431

432+
pub struct EntityWithType {
433+
pub entity_type: EntityType,
434+
pub entity: Entity,
435+
}
436+
432437
async fn get_entities_for_range(
433438
store: &Arc<dyn SourceableStore>,
434439
filter: &SubgraphFilter,
435440
schema: &InputSchema,
436441
from: BlockNumber,
437442
to: BlockNumber,
438-
) -> Result<BTreeMap<BlockNumber, Vec<Entity>>, Error> {
443+
) -> Result<BTreeMap<BlockNumber, Vec<EntityWithType>>, Error> {
439444
let mut entities_by_block = BTreeMap::new();
440445

441446
for entity_name in &filter.entities {
442447
let entity_type = schema.entity_type(entity_name)?;
443448

444449
let entity_ranges = store.get_range(&entity_type, from..to)?;
445450

446-
for (block_number, mut entity_vec) in entity_ranges {
451+
for (block_number, entity_vec) in entity_ranges {
452+
let mut entity_vec = entity_vec
453+
.into_iter()
454+
.map(|e| EntityWithType {
455+
entity_type: entity_type.clone(),
456+
entity: e,
457+
})
458+
.collect();
459+
447460
entities_by_block
448461
.entry(block_number)
449-
.and_modify(|existing_vec: &mut Vec<Entity>| existing_vec.append(&mut entity_vec))
462+
.and_modify(|existing_vec: &mut Vec<EntityWithType>| {
463+
existing_vec.append(&mut entity_vec);
464+
})
450465
.or_insert(entity_vec);
451466
}
452467
}

0 commit comments

Comments
 (0)