From 137998657dd7cc3f7d31877644c3718aa3376acb Mon Sep 17 00:00:00 2001 From: Zoran Cvetkov Date: Tue, 10 Dec 2024 17:25:01 +0200 Subject: [PATCH 1/2] renames --- graph/src/blockchain/block_stream.rs | 12 ++++----- graph/src/components/store/traits.rs | 6 ++--- graph/src/data_source/common.rs | 15 +++++++----- graph/src/data_source/subgraph.rs | 6 ++--- runtime/wasm/src/to_from/external.rs | 10 ++++---- store/postgres/src/deployment_store.rs | 4 +-- store/postgres/src/relational.rs | 27 +++++++++++---------- store/postgres/src/writable.rs | 4 +-- store/test-store/tests/postgres/writable.rs | 20 +++++++-------- tests/src/fixture/ethereum.rs | 6 ++--- tests/tests/runner_tests.rs | 4 +-- 11 files changed, 59 insertions(+), 55 deletions(-) diff --git a/graph/src/blockchain/block_stream.rs b/graph/src/blockchain/block_stream.rs index 3fd035bc387..cfe36169810 100644 --- a/graph/src/blockchain/block_stream.rs +++ b/graph/src/blockchain/block_stream.rs @@ -357,7 +357,7 @@ impl TriggersAdapterWrapper { fn create_subgraph_trigger_from_entities( filter: &SubgraphFilter, - entities: Vec, + entities: Vec, ) -> Vec { entities .into_iter() @@ -372,7 +372,7 @@ async fn create_subgraph_triggers( logger: Logger, blocks: Vec, filter: &SubgraphFilter, - mut entities: BTreeMap>, + mut entities: BTreeMap>, ) -> Result>, Error> { let logger_clone = logger.cheap_clone(); @@ -428,15 +428,15 @@ async fn scan_subgraph_triggers( } #[derive(Debug, Clone, Eq, PartialEq)] -pub enum EntitySubgraphOperation { +pub enum EntityOperationKind { Create, Modify, Delete, } #[derive(Debug, Clone, Eq, PartialEq)] -pub struct EntityWithType { - pub entity_op: EntitySubgraphOperation, +pub struct EntitySourceOperation { + pub entity_op: EntityOperationKind, pub entity_type: EntityType, pub entity: Entity, pub vid: i64, @@ -448,7 +448,7 @@ async fn get_entities_for_range( schema: &InputSchema, from: BlockNumber, to: BlockNumber, -) -> Result>, Error> { +) -> Result>, Error> { let entity_types: Result> = filter .entities .iter() diff --git a/graph/src/components/store/traits.rs b/graph/src/components/store/traits.rs index 69ca216e007..f157eeb78c0 100644 --- a/graph/src/components/store/traits.rs +++ b/graph/src/components/store/traits.rs @@ -6,7 +6,7 @@ use async_trait::async_trait; use web3::types::{Address, H256}; use super::*; -use crate::blockchain::block_stream::{EntityWithType, FirehoseCursor}; +use crate::blockchain::block_stream::{EntitySourceOperation, FirehoseCursor}; use crate::blockchain::{BlockTime, ChainIdentifier, ExtendedBlockPtr}; use crate::components::metrics::stopwatch::StopwatchMetrics; use crate::components::server::index_node::VersionInfo; @@ -302,7 +302,7 @@ pub trait SourceableStore: Sync + Send + 'static { entity_types: Vec, causality_region: CausalityRegion, block_range: Range, - ) -> Result>, StoreError>; + ) -> Result>, StoreError>; fn input_schema(&self) -> InputSchema; @@ -318,7 +318,7 @@ impl SourceableStore for Arc { entity_types: Vec, causality_region: CausalityRegion, block_range: Range, - ) -> Result>, StoreError> { + ) -> Result>, StoreError> { (**self).get_range(entity_types, causality_region, block_range) } diff --git a/graph/src/data_source/common.rs b/graph/src/data_source/common.rs index 80612340526..a70f0ab8e17 100644 --- a/graph/src/data_source/common.rs +++ b/graph/src/data_source/common.rs @@ -1,4 +1,4 @@ -use crate::blockchain::block_stream::EntityWithType; +use crate::blockchain::block_stream::EntitySourceOperation; use crate::prelude::{BlockPtr, Value}; use crate::{components::link_resolver::LinkResolver, data::value::Word, prelude::Link}; use anyhow::{anyhow, Context, Error}; @@ -193,7 +193,10 @@ impl CallDecl { }) } - pub fn address_for_entity_handler(&self, entity: &EntityWithType) -> Result { + pub fn address_for_entity_handler( + &self, + entity: &EntitySourceOperation, + ) -> Result { match &self.expr.address { // Static hex address - just return it directly CallArg::HexAddress(address) => Ok(*address), @@ -227,7 +230,7 @@ impl CallDecl { /// Returns an error if argument count mismatches or if conversion fails. pub fn args_for_entity_handler( &self, - entity: &EntityWithType, + entity: &EntitySourceOperation, param_types: Vec, ) -> Result, Error> { self.validate_entity_handler_args(¶m_types)?; @@ -260,7 +263,7 @@ impl CallDecl { &self, arg: &CallArg, expected_type: &ParamType, - entity: &EntityWithType, + entity: &EntitySourceOperation, ) -> Result { match arg { CallArg::HexAddress(address) => self.process_hex_address(*address, expected_type), @@ -292,7 +295,7 @@ impl CallDecl { &self, name: &str, expected_type: &ParamType, - entity: &EntityWithType, + entity: &EntitySourceOperation, ) -> Result { let value = entity .entity @@ -549,7 +552,7 @@ impl DeclaredCall { pub fn from_entity_trigger( mapping: &dyn FindMappingABI, call_decls: &CallDecls, - entity: &EntityWithType, + entity: &EntitySourceOperation, ) -> Result, anyhow::Error> { Self::create_calls(mapping, call_decls, |decl, function| { let param_types = function diff --git a/graph/src/data_source/subgraph.rs b/graph/src/data_source/subgraph.rs index bed226ea6af..93f5d920825 100644 --- a/graph/src/data_source/subgraph.rs +++ b/graph/src/data_source/subgraph.rs @@ -1,5 +1,5 @@ use crate::{ - blockchain::{block_stream::EntityWithType, Block, Blockchain}, + blockchain::{block_stream::EntitySourceOperation, Block, Blockchain}, components::{link_resolver::LinkResolver, store::BlockNumber}, data::{ subgraph::{calls_host_fn, SPEC_VERSION_1_3_0}, @@ -353,11 +353,11 @@ pub struct MappingEntityTrigger { #[derive(Clone, PartialEq, Eq)] pub struct TriggerData { pub source: DeploymentHash, - pub entity: EntityWithType, + pub entity: EntitySourceOperation, } impl TriggerData { - pub fn new(source: DeploymentHash, entity: EntityWithType) -> Self { + pub fn new(source: DeploymentHash, entity: EntitySourceOperation) -> Self { Self { source, entity } } diff --git a/runtime/wasm/src/to_from/external.rs b/runtime/wasm/src/to_from/external.rs index 9167b87b029..30740e77696 100644 --- a/runtime/wasm/src/to_from/external.rs +++ b/runtime/wasm/src/to_from/external.rs @@ -1,6 +1,6 @@ use ethabi; -use graph::blockchain::block_stream::{EntitySubgraphOperation, EntityWithType}; +use graph::blockchain::block_stream::{EntityOperationKind, EntitySourceOperation}; use graph::data::store::scalar::Timestamp; use graph::data::value::Word; use graph::prelude::{BigDecimal, BigInt}; @@ -482,16 +482,16 @@ pub struct AscEntityTrigger { pub vid: i64, } -impl ToAscObj for EntityWithType { +impl ToAscObj for EntitySourceOperation { fn to_asc_obj( &self, heap: &mut H, gas: &GasCounter, ) -> Result { let entity_op = match self.entity_op { - EntitySubgraphOperation::Create => AscSubgraphEntityOp::Create, - EntitySubgraphOperation::Modify => AscSubgraphEntityOp::Modify, - EntitySubgraphOperation::Delete => AscSubgraphEntityOp::Delete, + EntityOperationKind::Create => AscSubgraphEntityOp::Create, + EntityOperationKind::Modify => AscSubgraphEntityOp::Modify, + EntityOperationKind::Delete => AscSubgraphEntityOp::Delete, }; Ok(AscEntityTrigger { diff --git a/store/postgres/src/deployment_store.rs b/store/postgres/src/deployment_store.rs index 9870179a620..ed34b2a4e42 100644 --- a/store/postgres/src/deployment_store.rs +++ b/store/postgres/src/deployment_store.rs @@ -4,7 +4,7 @@ use diesel::pg::PgConnection; use diesel::r2d2::{ConnectionManager, PooledConnection}; use diesel::{prelude::*, sql_query}; use graph::anyhow::Context; -use graph::blockchain::block_stream::{EntityWithType, FirehoseCursor}; +use graph::blockchain::block_stream::{EntitySourceOperation, FirehoseCursor}; use graph::blockchain::BlockTime; use graph::components::store::write::RowGroup; use graph::components::store::{ @@ -1062,7 +1062,7 @@ impl DeploymentStore { entity_types: Vec, causality_region: CausalityRegion, block_range: Range, - ) -> Result>, StoreError> { + ) -> Result>, StoreError> { let mut conn = self.get_conn()?; let layout = self.layout(&mut conn, site)?; layout.find_range(&mut conn, entity_types, causality_region, block_range) diff --git a/store/postgres/src/relational.rs b/store/postgres/src/relational.rs index 87d9d46bdd5..c6762535cd8 100644 --- a/store/postgres/src/relational.rs +++ b/store/postgres/src/relational.rs @@ -24,7 +24,7 @@ use diesel::serialize::{Output, ToSql}; use diesel::sql_types::Text; use diesel::{connection::SimpleConnection, Connection}; use diesel::{debug_query, sql_query, OptionalExtension, PgConnection, QueryResult, RunQueryDsl}; -use graph::blockchain::block_stream::{EntitySubgraphOperation, EntityWithType}; +use graph::blockchain::block_stream::{EntityOperationKind, EntitySourceOperation}; use graph::blockchain::BlockTime; use graph::cheap_clone::CheapClone; use graph::components::store::write::{RowGroup, WriteChunk}; @@ -522,12 +522,12 @@ impl Layout { entity_types: Vec, causality_region: CausalityRegion, block_range: Range, - ) -> Result>, StoreError> { + ) -> Result>, StoreError> { let mut tables = vec![]; for et in entity_types { tables.push(self.table_for_entity(&et)?.as_ref()); } - let mut entities: BTreeMap> = BTreeMap::new(); + let mut entities: BTreeMap> = BTreeMap::new(); // Collect all entities that have their 'lower(block_range)' attribute in the // interval of blocks defined by the variable block_range. For the immutable @@ -559,15 +559,15 @@ impl Layout { let mut lower_now = lower_iter.next(); let mut upper_now = upper_iter.next(); // A closure to convert the entity data from the database into entity operation. - let transform = |ede: &EntityDataExt, - entity_op: EntitySubgraphOperation| - -> Result<(EntityWithType, BlockNumber), StoreError> { - let e = EntityData::new(ede.entity.clone(), ede.data.clone()); + let transform = |ede: EntityDataExt, + entity_op: EntityOperationKind| + -> Result<(EntitySourceOperation, BlockNumber), StoreError> { + let e = EntityData::new(ede.entity, ede.data); let block = ede.block_number; let entity_type = e.entity_type(&self.input_schema); let entity = e.deserialize_with_layout::(self, None)?; let vid = ede.vid; - let ewt = EntityWithType { + let ewt = EntitySourceOperation { entity_op, entity_type, entity, @@ -592,20 +592,20 @@ impl Layout { match lower.cmp(&upper) { std::cmp::Ordering::Greater => { // we have upper bound at this block, but no lower bounds at the same block so it's deletion - let (ewt, block) = transform(upper, EntitySubgraphOperation::Delete)?; + let (ewt, block) = transform(upper, EntityOperationKind::Delete)?; // advance upper_vec pointer upper_now = upper_iter.next(); (ewt, block) } std::cmp::Ordering::Less => { // we have lower bound at this block but no upper bound at the same block so its creation - let (ewt, block) = transform(lower, EntitySubgraphOperation::Create)?; + let (ewt, block) = transform(lower, EntityOperationKind::Create)?; // advance lower_vec pointer lower_now = lower_iter.next(); (ewt, block) } std::cmp::Ordering::Equal => { - let (ewt, block) = transform(lower, EntitySubgraphOperation::Modify)?; + let (ewt, block) = transform(lower, EntityOperationKind::Modify)?; // advance both lower_vec and upper_vec pointers lower_now = lower_iter.next(); upper_now = upper_iter.next(); @@ -615,13 +615,14 @@ impl Layout { } (Some(lower), None) => { // we have lower bound at this block but no upper bound at the same block so its creation - let (ewt, block) = transform(lower, EntitySubgraphOperation::Create)?; + let (ewt, block) = transform(lower, EntityOperationKind::Create)?; // advance lower_vec pointer lower_now = lower_iter.next(); (ewt, block) } (None, Some(upper)) => { - let (ewt, block) = transform(upper, EntitySubgraphOperation::Delete)?; + // we have upper bound at this block, but no lower bounds at all so it's deletion + let (ewt, block) = transform(upper, EntityOperationKind::Delete)?; // advance upper_vec pointer upper_now = upper_iter.next(); (ewt, block) diff --git a/store/postgres/src/writable.rs b/store/postgres/src/writable.rs index e670efdba2f..2efdcce399a 100644 --- a/store/postgres/src/writable.rs +++ b/store/postgres/src/writable.rs @@ -6,7 +6,7 @@ use std::time::Instant; use std::{collections::BTreeMap, sync::Arc}; use async_trait::async_trait; -use graph::blockchain::block_stream::{EntityWithType, FirehoseCursor}; +use graph::blockchain::block_stream::{EntitySourceOperation, FirehoseCursor}; use graph::blockchain::BlockTime; use graph::components::store::{Batch, DeploymentCursorTracker, DerivedEntityQuery, ReadStore}; use graph::constraint_violation; @@ -1593,7 +1593,7 @@ impl store::SourceableStore for SourceableStore { entity_types: Vec, causality_region: CausalityRegion, block_range: Range, - ) -> Result>, StoreError> { + ) -> Result>, StoreError> { self.store.get_range( self.site.clone(), entity_types, diff --git a/store/test-store/tests/postgres/writable.rs b/store/test-store/tests/postgres/writable.rs index b528a762a42..c331f1cb0e1 100644 --- a/store/test-store/tests/postgres/writable.rs +++ b/store/test-store/tests/postgres/writable.rs @@ -1,4 +1,4 @@ -use graph::blockchain::block_stream::{EntityWithType, FirehoseCursor}; +use graph::blockchain::block_stream::{EntitySourceOperation, FirehoseCursor}; use graph::data::subgraph::schema::DeploymentCreate; use graph::data::value::Word; use graph::data_source::CausalityRegion; @@ -341,13 +341,13 @@ fn restart() { fn read_range_test() { run_test(|store, writable, sourceable, deployment| async move { let result_entities = vec![ - r#"(1, [EntityWithType { entity_op: Create, entity_type: EntityType(Counter), entity: Entity { count: Int(2), id: String("1") }, vid: 1 }, EntityWithType { entity_op: Create, entity_type: EntityType(Counter2), entity: Entity { count: Int(2), id: String("1") }, vid: 1 }])"#, - r#"(2, [EntityWithType { entity_op: Modify, entity_type: EntityType(Counter), entity: Entity { count: Int(4), id: String("1") }, vid: 2 }, EntityWithType { entity_op: Create, entity_type: EntityType(Counter2), entity: Entity { count: Int(4), id: String("2") }, vid: 2 }])"#, - r#"(3, [EntityWithType { entity_op: Delete, entity_type: EntityType(Counter), entity: Entity { count: Int(4), id: String("1") }, vid: 2 }, EntityWithType { entity_op: Create, entity_type: EntityType(Counter2), entity: Entity { count: Int(6), id: String("3") }, vid: 3 }])"#, - r#"(4, [EntityWithType { entity_op: Create, entity_type: EntityType(Counter), entity: Entity { count: Int(8), id: String("1") }, vid: 3 }, EntityWithType { entity_op: Create, entity_type: EntityType(Counter2), entity: Entity { count: Int(8), id: String("4") }, vid: 4 }])"#, - r#"(5, [EntityWithType { entity_op: Delete, entity_type: EntityType(Counter), entity: Entity { count: Int(8), id: String("1") }, vid: 3 }, EntityWithType { entity_op: Create, entity_type: EntityType(Counter2), entity: Entity { count: Int(10), id: String("5") }, vid: 5 }])"#, - r#"(6, [EntityWithType { entity_op: Create, entity_type: EntityType(Counter), entity: Entity { count: Int(12), id: String("1") }, vid: 4 }])"#, - r#"(7, [EntityWithType { entity_op: Delete, entity_type: EntityType(Counter), entity: Entity { count: Int(12), id: String("1") }, vid: 4 }])"#, + r#"(1, [EntitySourceOperation { entity_op: Create, entity_type: EntityType(Counter), entity: Entity { count: Int(2), id: String("1") }, vid: 1 }, EntitySourceOperation { entity_op: Create, entity_type: EntityType(Counter2), entity: Entity { count: Int(2), id: String("1") }, vid: 1 }])"#, + r#"(2, [EntitySourceOperation { entity_op: Modify, entity_type: EntityType(Counter), entity: Entity { count: Int(4), id: String("1") }, vid: 2 }, EntitySourceOperation { entity_op: Create, entity_type: EntityType(Counter2), entity: Entity { count: Int(4), id: String("2") }, vid: 2 }])"#, + r#"(3, [EntitySourceOperation { entity_op: Delete, entity_type: EntityType(Counter), entity: Entity { count: Int(4), id: String("1") }, vid: 2 }, EntitySourceOperation { entity_op: Create, entity_type: EntityType(Counter2), entity: Entity { count: Int(6), id: String("3") }, vid: 3 }])"#, + r#"(4, [EntitySourceOperation { entity_op: Create, entity_type: EntityType(Counter), entity: Entity { count: Int(8), id: String("1") }, vid: 3 }, EntitySourceOperation { entity_op: Create, entity_type: EntityType(Counter2), entity: Entity { count: Int(8), id: String("4") }, vid: 4 }])"#, + r#"(5, [EntitySourceOperation { entity_op: Delete, entity_type: EntityType(Counter), entity: Entity { count: Int(8), id: String("1") }, vid: 3 }, EntitySourceOperation { entity_op: Create, entity_type: EntityType(Counter2), entity: Entity { count: Int(10), id: String("5") }, vid: 5 }])"#, + r#"(6, [EntitySourceOperation { entity_op: Create, entity_type: EntityType(Counter), entity: Entity { count: Int(12), id: String("1") }, vid: 4 }])"#, + r#"(7, [EntitySourceOperation { entity_op: Delete, entity_type: EntityType(Counter), entity: Entity { count: Int(12), id: String("1") }, vid: 4 }])"#, ]; let subgraph_store = store.subgraph_store(); writable.deployment_synced().unwrap(); @@ -360,7 +360,7 @@ fn read_range_test() { let br: Range = 0..18; let entity_types = vec![COUNTER_TYPE.clone(), COUNTER2_TYPE.clone()]; - let e: BTreeMap> = sourceable + let e: BTreeMap> = sourceable .get_range(entity_types.clone(), CausalityRegion::ONCHAIN, br.clone()) .unwrap(); assert_eq!(e.len(), 5); @@ -374,7 +374,7 @@ fn read_range_test() { } writable.flush().await.unwrap(); writable.deployment_synced().unwrap(); - let e: BTreeMap> = sourceable + let e: BTreeMap> = sourceable .get_range(entity_types, CausalityRegion::ONCHAIN, br) .unwrap(); assert_eq!(e.len(), 7); diff --git a/tests/src/fixture/ethereum.rs b/tests/src/fixture/ethereum.rs index 50328f89a11..2ff94744f8e 100644 --- a/tests/src/fixture/ethereum.rs +++ b/tests/src/fixture/ethereum.rs @@ -6,7 +6,7 @@ use super::{ test_ptr, CommonChainConfig, MutexBlockStreamBuilder, NoopAdapterSelector, NoopRuntimeAdapterBuilder, StaticBlockRefetcher, StaticStreamBuilder, Stores, TestChain, }; -use graph::blockchain::block_stream::{EntitySubgraphOperation, EntityWithType}; +use graph::blockchain::block_stream::{EntityOperationKind, EntitySourceOperation}; use graph::blockchain::client::ChainClient; use graph::blockchain::{BlockPtr, Trigger, TriggersAdapterSelector}; use graph::cheap_clone::CheapClone; @@ -167,10 +167,10 @@ pub fn push_test_subgraph_trigger( source: DeploymentHash, entity: Entity, entity_type: EntityType, - entity_op: EntitySubgraphOperation, + entity_op: EntityOperationKind, vid: i64, ) { - let entity = EntityWithType { + let entity = EntitySourceOperation { entity: entity, entity_type: entity_type, entity_op: entity_op, diff --git a/tests/tests/runner_tests.rs b/tests/tests/runner_tests.rs index 1692d8cc959..a6eb3200829 100644 --- a/tests/tests/runner_tests.rs +++ b/tests/tests/runner_tests.rs @@ -6,7 +6,7 @@ use std::sync::Arc; use std::time::Duration; use assert_json_diff::assert_json_eq; -use graph::blockchain::block_stream::{BlockWithTriggers, EntitySubgraphOperation}; +use graph::blockchain::block_stream::{BlockWithTriggers, EntityOperationKind}; use graph::blockchain::{Block, BlockPtr, Blockchain}; use graph::data::store::scalar::Bytes; use graph::data::subgraph::schema::{SubgraphError, SubgraphHealth}; @@ -1120,7 +1120,7 @@ async fn subgraph_data_sources() { DeploymentHash::new("QmRFXhvyvbm4z5Lo7z2mN9Ckmo623uuB2jJYbRmAXgYKXJ").unwrap(), entity, entity_type, - EntitySubgraphOperation::Create, + EntityOperationKind::Create, 1, ); From 9658d8ca96502d2ca58701b180f89c2fc9b60fe3 Mon Sep 17 00:00:00 2001 From: Zoran Cvetkov Date: Wed, 18 Dec 2024 20:02:30 +0200 Subject: [PATCH 2/2] fix rebase --- store/postgres/src/relational.rs | 4 ++-- store/test-store/tests/postgres/writable.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/store/postgres/src/relational.rs b/store/postgres/src/relational.rs index c6762535cd8..f6a14c3a5fa 100644 --- a/store/postgres/src/relational.rs +++ b/store/postgres/src/relational.rs @@ -559,10 +559,10 @@ impl Layout { let mut lower_now = lower_iter.next(); let mut upper_now = upper_iter.next(); // A closure to convert the entity data from the database into entity operation. - let transform = |ede: EntityDataExt, + let transform = |ede: &EntityDataExt, entity_op: EntityOperationKind| -> Result<(EntitySourceOperation, BlockNumber), StoreError> { - let e = EntityData::new(ede.entity, ede.data); + let e = EntityData::new(ede.entity.clone(), ede.data.clone()); let block = ede.block_number; let entity_type = e.entity_type(&self.input_schema); let entity = e.deserialize_with_layout::(self, None)?; diff --git a/store/test-store/tests/postgres/writable.rs b/store/test-store/tests/postgres/writable.rs index c331f1cb0e1..96ce2d58b39 100644 --- a/store/test-store/tests/postgres/writable.rs +++ b/store/test-store/tests/postgres/writable.rs @@ -399,7 +399,7 @@ fn read_immutable_only_range_test() { writable.deployment_synced().unwrap(); let br: Range = 0..18; let entity_types = vec![COUNTER2_TYPE.clone()]; - let e: BTreeMap> = sourceable + let e: BTreeMap> = sourceable .get_range(entity_types.clone(), CausalityRegion::ONCHAIN, br.clone()) .unwrap(); assert_eq!(e.len(), 4);