Skip to content

Commit

Permalink
renames
Browse files Browse the repository at this point in the history
  • Loading branch information
zorancv committed Dec 10, 2024
1 parent 56f041a commit 632ef9f
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 53 deletions.
12 changes: 6 additions & 6 deletions graph/src/blockchain/block_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ impl<C: Blockchain> TriggersAdapterWrapper<C> {

fn create_subgraph_trigger_from_entities(
filter: &SubgraphFilter,
entities: Vec<EntityWithType>,
entities: Vec<EntitySourceOperation>,
) -> Vec<subgraph::TriggerData> {
entities
.into_iter()
Expand All @@ -372,7 +372,7 @@ async fn create_subgraph_triggers<C: Blockchain>(
logger: Logger,
blocks: Vec<C::Block>,
filter: &SubgraphFilter,
mut entities: BTreeMap<BlockNumber, Vec<EntityWithType>>,
mut entities: BTreeMap<BlockNumber, Vec<EntitySourceOperation>>,
) -> Result<Vec<BlockWithTriggers<C>>, Error> {
let logger_clone = logger.cheap_clone();

Expand Down Expand Up @@ -428,15 +428,15 @@ async fn scan_subgraph_triggers<C: Blockchain>(
}

#[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,
Expand All @@ -448,7 +448,7 @@ async fn get_entities_for_range(
schema: &InputSchema,
from: BlockNumber,
to: BlockNumber,
) -> Result<BTreeMap<BlockNumber, Vec<EntityWithType>>, Error> {
) -> Result<BTreeMap<BlockNumber, Vec<EntitySourceOperation>>, Error> {
let entity_types: Result<Vec<EntityType>> = filter
.entities
.iter()
Expand Down
6 changes: 3 additions & 3 deletions graph/src/components/store/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -302,7 +302,7 @@ pub trait SourceableStore: Sync + Send + 'static {
entity_types: Vec<EntityType>,
causality_region: CausalityRegion,
block_range: Range<BlockNumber>,
) -> Result<BTreeMap<BlockNumber, Vec<EntityWithType>>, StoreError>;
) -> Result<BTreeMap<BlockNumber, Vec<EntitySourceOperation>>, StoreError>;

fn input_schema(&self) -> InputSchema;

Expand All @@ -318,7 +318,7 @@ impl<T: ?Sized + SourceableStore> SourceableStore for Arc<T> {
entity_types: Vec<EntityType>,
causality_region: CausalityRegion,
block_range: Range<BlockNumber>,
) -> Result<BTreeMap<BlockNumber, Vec<EntityWithType>>, StoreError> {
) -> Result<BTreeMap<BlockNumber, Vec<EntitySourceOperation>>, StoreError> {
(**self).get_range(entity_types, causality_region, block_range)
}

Expand Down
15 changes: 9 additions & 6 deletions graph/src/data_source/common.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -193,7 +193,10 @@ impl CallDecl {
})
}

pub fn address_for_entity_handler(&self, entity: &EntityWithType) -> Result<H160, Error> {
pub fn address_for_entity_handler(
&self,
entity: &EntitySourceOperation,
) -> Result<H160, Error> {
match &self.expr.address {
// Static hex address - just return it directly
CallArg::HexAddress(address) => Ok(*address),
Expand Down Expand Up @@ -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<ParamType>,
) -> Result<Vec<Token>, Error> {
self.validate_entity_handler_args(&param_types)?;
Expand Down Expand Up @@ -260,7 +263,7 @@ impl CallDecl {
&self,
arg: &CallArg,
expected_type: &ParamType,
entity: &EntityWithType,
entity: &EntitySourceOperation,
) -> Result<Token, Error> {
match arg {
CallArg::HexAddress(address) => self.process_hex_address(*address, expected_type),
Expand Down Expand Up @@ -292,7 +295,7 @@ impl CallDecl {
&self,
name: &str,
expected_type: &ParamType,
entity: &EntityWithType,
entity: &EntitySourceOperation,
) -> Result<Token, Error> {
let value = entity
.entity
Expand Down Expand Up @@ -549,7 +552,7 @@ impl DeclaredCall {
pub fn from_entity_trigger(
mapping: &dyn FindMappingABI,
call_decls: &CallDecls,
entity: &EntityWithType,
entity: &EntitySourceOperation,
) -> Result<Vec<DeclaredCall>, anyhow::Error> {
Self::create_calls(mapping, call_decls, |decl, function| {
let param_types = function
Expand Down
6 changes: 3 additions & 3 deletions graph/src/data_source/subgraph.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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 }
}

Expand Down
10 changes: 5 additions & 5 deletions runtime/wasm/src/to_from/external.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -482,16 +482,16 @@ pub struct AscEntityTrigger {
pub vid: i64,
}

impl ToAscObj<AscEntityTrigger> for EntityWithType {
impl ToAscObj<AscEntityTrigger> for EntitySourceOperation {
fn to_asc_obj<H: AscHeap + ?Sized>(
&self,
heap: &mut H,
gas: &GasCounter,
) -> Result<AscEntityTrigger, HostExportError> {
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 {
Expand Down
4 changes: 2 additions & 2 deletions store/postgres/src/deployment_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -1062,7 +1062,7 @@ impl DeploymentStore {
entity_types: Vec<EntityType>,
causality_region: CausalityRegion,
block_range: Range<BlockNumber>,
) -> Result<BTreeMap<BlockNumber, Vec<EntityWithType>>, StoreError> {
) -> Result<BTreeMap<BlockNumber, Vec<EntitySourceOperation>>, 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)
Expand Down
22 changes: 11 additions & 11 deletions store/postgres/src/relational.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -522,14 +522,14 @@ impl Layout {
entity_types: Vec<EntityType>,
causality_region: CausalityRegion,
block_range: Range<BlockNumber>,
) -> Result<BTreeMap<BlockNumber, Vec<EntityWithType>>, StoreError> {
) -> Result<BTreeMap<BlockNumber, Vec<EntitySourceOperation>>, StoreError> {
let mut tables = vec![];
let mut et_map: HashMap<String, Arc<EntityType>> = HashMap::new();
for et in entity_types {
tables.push(self.table_for_entity(&et)?.as_ref());
et_map.insert(et.to_string(), Arc::new(et));
}
let mut entities: BTreeMap<BlockNumber, Vec<EntityWithType>> = BTreeMap::new();
let mut entities: BTreeMap<BlockNumber, Vec<EntitySourceOperation>> = 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
Expand Down Expand Up @@ -558,14 +558,14 @@ impl Layout {
let mut lower = lower_now.unwrap_or(&EntityDataExt::default()).clone();
let mut upper = upper_now.unwrap_or(&EntityDataExt::default()).clone();
let transform = |ede: EntityDataExt,
entity_op: EntitySubgraphOperation|
-> Result<(EntityWithType, BlockNumber), StoreError> {
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::<Entity>(self, None)?;
let vid = ede.vid;
let ewt = EntityWithType {
let ewt = EntitySourceOperation {
entity_op,
entity_type,
entity,
Expand All @@ -588,22 +588,22 @@ 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();
upper = upper_now.unwrap_or(&EntityDataExt::default()).clone();
(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();
lower = lower_now.unwrap_or(&EntityDataExt::default()).clone();
(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();
lower = lower_now.unwrap_or(&EntityDataExt::default()).clone();
Expand All @@ -615,7 +615,7 @@ impl Layout {
}
(true, false) => {
// 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();
lower = lower_now.unwrap_or(&EntityDataExt::default()).clone();
Expand All @@ -624,7 +624,7 @@ impl Layout {
(false, have_upper) => {
// we have upper bound at this block, but no lower bounds at all so it's deletion
assert!(have_upper);
let (ewt, block) = transform(upper, EntitySubgraphOperation::Delete)?;
let (ewt, block) = transform(upper, EntityOperationKind::Delete)?;
// advance upper_vec pointer
upper_now = upper_iter.next();
upper = upper_now.unwrap_or(&EntityDataExt::default()).clone();
Expand Down
4 changes: 2 additions & 2 deletions store/postgres/src/writable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1593,7 +1593,7 @@ impl store::SourceableStore for SourceableStore {
entity_types: Vec<EntityType>,
causality_region: CausalityRegion,
block_range: Range<BlockNumber>,
) -> Result<BTreeMap<BlockNumber, Vec<EntityWithType>>, StoreError> {
) -> Result<BTreeMap<BlockNumber, Vec<EntitySourceOperation>>, StoreError> {
self.store.get_range(
self.site.clone(),
entity_types,
Expand Down
20 changes: 10 additions & 10 deletions store/test-store/tests/postgres/writable.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -337,13 +337,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();
Expand All @@ -356,7 +356,7 @@ fn read_range_test() {

let br: Range<BlockNumber> = 0..18;
let entity_types = vec![COUNTER_TYPE.clone(), COUNTER2_TYPE.clone()];
let e: BTreeMap<i32, Vec<EntityWithType>> = sourceable
let e: BTreeMap<i32, Vec<EntitySourceOperation>> = sourceable
.get_range(entity_types.clone(), CausalityRegion::ONCHAIN, br.clone())
.unwrap();
assert_eq!(e.len(), 5);
Expand All @@ -370,7 +370,7 @@ fn read_range_test() {
}
writable.flush().await.unwrap();
writable.deployment_synced().unwrap();
let e: BTreeMap<i32, Vec<EntityWithType>> = sourceable
let e: BTreeMap<i32, Vec<EntitySourceOperation>> = sourceable
.get_range(entity_types, CausalityRegion::ONCHAIN, br)
.unwrap();
assert_eq!(e.len(), 7);
Expand Down
6 changes: 3 additions & 3 deletions tests/src/fixture/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 632ef9f

Please sign in to comment.