diff --git a/Cargo.lock b/Cargo.lock index 1c515550c1f..f95cfc31b7e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1944,21 +1944,6 @@ dependencies = [ "trigger-filters", ] -[[package]] -name = "graph-chain-starknet" -version = "0.35.0" -dependencies = [ - "graph", - "graph-runtime-derive", - "graph-runtime-wasm", - "hex", - "prost 0.12.6", - "prost-types 0.12.6", - "serde", - "sha3", - "tonic-build", -] - [[package]] name = "graph-chain-substreams" version = "0.35.0" @@ -1991,7 +1976,6 @@ dependencies = [ "graph-chain-cosmos", "graph-chain-ethereum", "graph-chain-near", - "graph-chain-starknet", "graph-chain-substreams", "graph-runtime-wasm", "serde_yaml", @@ -2030,7 +2014,6 @@ dependencies = [ "graph-chain-cosmos", "graph-chain-ethereum", "graph-chain-near", - "graph-chain-starknet", "graph-chain-substreams", "graph-core", "graph-graphql", @@ -2116,7 +2099,6 @@ dependencies = [ "graph-chain-cosmos", "graph-chain-ethereum", "graph-chain-near", - "graph-chain-starknet", "graph-chain-substreams", "graph-graphql", ] @@ -2425,9 +2407,6 @@ name = "hex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -dependencies = [ - "serde", -] [[package]] name = "hex-literal" diff --git a/chain/starknet/Cargo.toml b/chain/starknet/Cargo.toml deleted file mode 100644 index 9366d3cf697..00000000000 --- a/chain/starknet/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "graph-chain-starknet" -version.workspace = true -edition.workspace = true - -[build-dependencies] -tonic-build = { workspace = true } - -[dependencies] -graph = { path = "../../graph" } -hex = { version = "0.4.3", features = ["serde"] } -prost = { workspace = true } -prost-types = { workspace = true } -serde = { workspace = true } -sha3 = "0.10.8" - -graph-runtime-wasm = { path = "../../runtime/wasm" } -graph-runtime-derive = { path = "../../runtime/derive" } diff --git a/chain/starknet/build.rs b/chain/starknet/build.rs deleted file mode 100644 index 8a67809dfca..00000000000 --- a/chain/starknet/build.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - println!("cargo:rerun-if-changed=proto"); - tonic_build::configure() - .out_dir("src/protobuf") - .compile(&["proto/starknet.proto"], &["proto"]) - .expect("Failed to compile Firehose StarkNet proto(s)"); -} diff --git a/chain/starknet/proto/starknet.proto b/chain/starknet/proto/starknet.proto deleted file mode 100644 index 073b8c2c569..00000000000 --- a/chain/starknet/proto/starknet.proto +++ /dev/null @@ -1,37 +0,0 @@ -syntax = "proto3"; - -package zklend.starknet.type.v1; - -option go_package = "github.com/starknet-graph/firehose-starknet/types/pb/zklend/starknet/type/v1;pbacme"; - -// This file only contains the bare minimum types for the POC. It's far from a complete -// representation of a StarkNet network's history as required by the Firehose protocol. As a result, -// any future changes to this schema would require a full re-sync of the StarkNet node. - -message Block { - uint64 height = 1; - bytes hash = 2; - bytes prevHash = 3; - uint64 timestamp = 4; - repeated Transaction transactions = 5; -} - -message Transaction { - TransactionType type = 1; - bytes hash = 2; - repeated Event events = 3; -} - -enum TransactionType { - DEPLOY = 0; - INVOKE_FUNCTION = 1; - DECLARE = 2; - L1_HANDLER = 3; - DEPLOY_ACCOUNT = 4; -} - -message Event { - bytes fromAddr = 1; - repeated bytes keys = 2; - repeated bytes data = 3; -} diff --git a/chain/starknet/src/adapter.rs b/chain/starknet/src/adapter.rs deleted file mode 100644 index e04df8e979c..00000000000 --- a/chain/starknet/src/adapter.rs +++ /dev/null @@ -1,27 +0,0 @@ -use graph::blockchain::{EmptyNodeCapabilities, TriggerFilter as TriggerFilterTrait}; - -use crate::{ - data_source::{DataSource, DataSourceTemplate}, - Chain, -}; - -#[derive(Default, Clone)] -pub struct TriggerFilter; - -impl TriggerFilterTrait for TriggerFilter { - #[allow(unused)] - fn extend_with_template(&mut self, data_source: impl Iterator) { - todo!() - } - - #[allow(unused)] - fn extend<'a>(&mut self, data_sources: impl Iterator + Clone) {} - - fn node_capabilities(&self) -> EmptyNodeCapabilities { - todo!() - } - - fn to_firehose_filter(self) -> Vec { - todo!() - } -} diff --git a/chain/starknet/src/chain.rs b/chain/starknet/src/chain.rs deleted file mode 100644 index 69406b7b1f6..00000000000 --- a/chain/starknet/src/chain.rs +++ /dev/null @@ -1,507 +0,0 @@ -use graph::components::network_provider::ChainName; -use graph::{ - anyhow::Result, - blockchain::{ - block_stream::{ - BlockStream, BlockStreamBuilder, BlockStreamEvent, BlockWithTriggers, FirehoseCursor, - FirehoseError, FirehoseMapper as FirehoseMapperTrait, - TriggersAdapter as TriggersAdapterTrait, - }, - client::ChainClient, - firehose_block_ingestor::FirehoseBlockIngestor, - firehose_block_stream::FirehoseBlockStream, - BasicBlockchainBuilder, Block, BlockIngestor, BlockPtr, Blockchain, BlockchainBuilder, - BlockchainKind, EmptyNodeCapabilities, IngestorError, NoopDecoderHook, NoopRuntimeAdapter, - RuntimeAdapter as RuntimeAdapterTrait, - }, - cheap_clone::CheapClone, - components::store::{DeploymentCursorTracker, DeploymentLocator}, - data::subgraph::UnifiedMappingApiVersion, - env::EnvVars, - firehose::{self, FirehoseEndpoint, ForkStep}, - futures03::future::TryFutureExt, - prelude::{ - async_trait, BlockHash, BlockNumber, ChainStore, Error, Logger, LoggerFactory, - MetricsRegistry, - }, - schema::InputSchema, - slog::o, -}; -use prost::Message; -use std::sync::Arc; - -use crate::{ - adapter::TriggerFilter, - codec, - data_source::{ - DataSource, DataSourceTemplate, UnresolvedDataSource, UnresolvedDataSourceTemplate, - }, - trigger::{StarknetBlockTrigger, StarknetEventTrigger, StarknetTrigger}, -}; - -pub struct Chain { - logger_factory: LoggerFactory, - name: ChainName, - client: Arc>, - chain_store: Arc, - metrics_registry: Arc, - block_stream_builder: Arc>, -} - -pub struct StarknetStreamBuilder; - -pub struct FirehoseMapper { - adapter: Arc>, - filter: Arc, -} - -pub struct TriggersAdapter; - -#[async_trait] -impl BlockchainBuilder for BasicBlockchainBuilder { - async fn build(self, _config: &Arc) -> Chain { - Chain { - logger_factory: self.logger_factory, - name: self.name, - chain_store: self.chain_store, - client: Arc::new(ChainClient::new_firehose(self.firehose_endpoints)), - metrics_registry: self.metrics_registry, - block_stream_builder: Arc::new(StarknetStreamBuilder {}), - } - } -} - -impl std::fmt::Debug for Chain { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "chain: starknet") - } -} - -#[async_trait] -impl Blockchain for Chain { - const KIND: BlockchainKind = BlockchainKind::Starknet; - - type Client = (); - type Block = codec::Block; - type DataSource = DataSource; - type UnresolvedDataSource = UnresolvedDataSource; - - type DataSourceTemplate = DataSourceTemplate; - type UnresolvedDataSourceTemplate = UnresolvedDataSourceTemplate; - - type TriggerData = crate::trigger::StarknetTrigger; - - type MappingTrigger = crate::trigger::StarknetTrigger; - - type TriggerFilter = crate::adapter::TriggerFilter; - - type NodeCapabilities = EmptyNodeCapabilities; - - type DecoderHook = NoopDecoderHook; - - fn triggers_adapter( - &self, - _log: &DeploymentLocator, - _capabilities: &Self::NodeCapabilities, - _unified_api_version: UnifiedMappingApiVersion, - ) -> Result>, Error> { - Ok(Arc::new(TriggersAdapter)) - } - - async fn new_block_stream( - &self, - deployment: DeploymentLocator, - store: impl DeploymentCursorTracker, - start_blocks: Vec, - filter: Arc, - unified_api_version: UnifiedMappingApiVersion, - ) -> Result>, Error> { - self.block_stream_builder - .build_firehose( - self, - deployment, - store.firehose_cursor(), - start_blocks, - store.block_ptr(), - filter, - unified_api_version, - ) - .await - } - - fn is_refetch_block_required(&self) -> bool { - false - } - - async fn refetch_firehose_block( - &self, - _logger: &Logger, - _cursor: FirehoseCursor, - ) -> Result { - unimplemented!("This chain does not support Dynamic Data Sources. is_refetch_block_required always returns false, this shouldn't be called.") - } - - fn chain_store(&self) -> Arc { - self.chain_store.clone() - } - - async fn block_pointer_from_number( - &self, - logger: &Logger, - number: BlockNumber, - ) -> Result { - let firehose_endpoint = self.client.firehose_endpoint().await?; - - firehose_endpoint - .block_ptr_for_number::(logger, number) - .map_err(Into::into) - .await - } - - fn runtime( - &self, - ) -> graph::anyhow::Result<(Arc>, Self::DecoderHook)> { - Ok((Arc::new(NoopRuntimeAdapter::default()), NoopDecoderHook)) - } - - fn chain_client(&self) -> Arc> { - self.client.clone() - } - - async fn block_ingestor(&self) -> Result> { - let ingestor = FirehoseBlockIngestor::::new( - self.chain_store.cheap_clone(), - self.chain_client(), - self.logger_factory - .component_logger("StarknetFirehoseBlockIngestor", None), - self.name.clone(), - ); - Ok(Box::new(ingestor)) - } -} - -#[async_trait] -impl BlockStreamBuilder for StarknetStreamBuilder { - async fn build_substreams( - &self, - _chain: &Chain, - _schema: InputSchema, - _deployment: DeploymentLocator, - _block_cursor: FirehoseCursor, - _subgraph_current_block: Option, - _filter: Arc<::TriggerFilter>, - ) -> Result>> { - unimplemented!() - } - - async fn build_firehose( - &self, - chain: &Chain, - deployment: DeploymentLocator, - block_cursor: FirehoseCursor, - start_blocks: Vec, - subgraph_current_block: Option, - filter: Arc, - unified_api_version: UnifiedMappingApiVersion, - ) -> Result>> { - let adapter = chain - .triggers_adapter( - &deployment, - &EmptyNodeCapabilities::default(), - unified_api_version, - ) - .unwrap_or_else(|_| panic!("no adapter for network {}", chain.name)); - - let logger = chain - .logger_factory - .subgraph_logger(&deployment) - .new(o!("component" => "FirehoseBlockStream")); - - let firehose_mapper = Arc::new(FirehoseMapper { adapter, filter }); - - Ok(Box::new(FirehoseBlockStream::new( - deployment.hash, - chain.chain_client(), - subgraph_current_block, - block_cursor, - firehose_mapper, - start_blocks, - logger, - chain.metrics_registry.clone(), - ))) - } - - async fn build_polling( - &self, - _chain: &Chain, - _deployment: DeploymentLocator, - _start_blocks: Vec, - _subgraph_current_block: Option, - _filter: Arc, - _unified_api_version: UnifiedMappingApiVersion, - ) -> Result>> { - panic!("StarkNet does not support polling block stream") - } -} - -#[async_trait] -impl FirehoseMapperTrait for FirehoseMapper { - fn trigger_filter(&self) -> &TriggerFilter { - self.filter.as_ref() - } - - async fn to_block_stream_event( - &self, - logger: &Logger, - response: &firehose::Response, - ) -> Result, FirehoseError> { - let step = ForkStep::try_from(response.step).unwrap_or_else(|_| { - panic!( - "unknown step i32 value {}, maybe you forgot update & re-regenerate the protobuf definitions?", - response.step - ) - }); - - let any_block = response - .block - .as_ref() - .expect("block payload information should always be present"); - - // Right now, this is done in all cases but in reality, with how the BlockStreamEvent::Revert - // is defined right now, only block hash and block number is necessary. However, this information - // is not part of the actual bstream::BlockResponseV2 payload. As such, we need to decode the full - // block which is useless. - // - // Check about adding basic information about the block in the bstream::BlockResponseV2 or maybe - // define a slimmed down stuct that would decode only a few fields and ignore all the rest. - let block = codec::Block::decode(any_block.value.as_ref())?; - - use ForkStep::*; - match step { - StepNew => Ok(BlockStreamEvent::ProcessBlock( - self.adapter - .triggers_in_block(logger, block, &self.filter) - .await?, - FirehoseCursor::from(response.cursor.clone()), - )), - - StepUndo => { - let parent_ptr = block - .parent_ptr() - .expect("Genesis block should never be reverted"); - - Ok(BlockStreamEvent::Revert( - parent_ptr, - FirehoseCursor::from(response.cursor.clone()), - )) - } - - StepFinal => { - panic!("irreversible step is not handled and should not be requested in the Firehose request") - } - - StepUnset => { - panic!("unknown step should not happen in the Firehose response") - } - } - } - - /// Returns the [BlockPtr] value for this given block number. This is the block pointer - /// of the longuest according to Firehose view of the blockchain state. - /// - /// This is a thin wrapper around [FirehoseEndpoint#block_ptr_for_number] to make - /// it chain agnostic and callable from chain agnostic [FirehoseBlockStream]. - async fn block_ptr_for_number( - &self, - logger: &Logger, - endpoint: &Arc, - number: BlockNumber, - ) -> Result { - endpoint - .block_ptr_for_number::(logger, number) - .await - } - - /// Returns the closest final block ptr to the block ptr received. - /// On probablitics chain like Ethereum, final is determined by - /// the confirmations threshold configured for the Firehose stack (currently - /// hard-coded to 200). - /// - /// On some other chain like NEAR, the actual final block number is determined - /// from the block itself since it contains information about which block number - /// is final against the current block. - /// - /// To take an example, assuming we are on Ethereum, the final block pointer - /// for block #10212 would be the determined final block #10012 (10212 - 200 = 10012). - async fn final_block_ptr_for( - &self, - logger: &Logger, - endpoint: &Arc, - block: &codec::Block, - ) -> Result { - // Firehose for Starknet has an hard-coded confirmations for finality sets to 100 block - // behind the current block. The magic value 100 here comes from this hard-coded Firehose - // value. - let final_block_number = match block.number() { - x if x >= 100 => x - 100, - _ => 0, - }; - - self.block_ptr_for_number(logger, endpoint, final_block_number) - .await - } -} - -#[async_trait] -impl TriggersAdapterTrait for TriggersAdapter { - // Return the block that is `offset` blocks before the block pointed to - // by `ptr` from the local cache. An offset of 0 means the block itself, - // an offset of 1 means the block's parent etc. If the block is not in - // the local cache, return `None` - async fn ancestor_block( - &self, - _ptr: BlockPtr, - _offset: BlockNumber, - _root: Option, - ) -> Result, Error> { - panic!("Should never be called since FirehoseBlockStream cannot resolve it") - } - - // Returns a sequence of blocks in increasing order of block number. - // Each block will include all of its triggers that match the given `filter`. - // The sequence may omit blocks that contain no triggers, - // but all returned blocks must part of a same chain starting at `chain_base`. - // At least one block will be returned, even if it contains no triggers. - // `step_size` is the suggested number blocks to be scanned. - async fn scan_triggers( - &self, - _from: BlockNumber, - _to: BlockNumber, - _filter: &crate::adapter::TriggerFilter, - ) -> Result<(Vec>, BlockNumber), Error> { - panic!("Should never be called since not used by FirehoseBlockStream") - } - - #[allow(unused)] - async fn triggers_in_block( - &self, - logger: &Logger, - block: codec::Block, - filter: &crate::adapter::TriggerFilter, - ) -> Result, Error> { - let shared_block = Arc::new(block.clone()); - - let mut triggers: Vec<_> = shared_block - .transactions - .iter() - .flat_map(|transaction| -> Vec { - let transaction = Arc::new(transaction.clone()); - transaction - .events - .iter() - .map(|event| { - StarknetTrigger::Event(StarknetEventTrigger { - event: Arc::new(event.clone()), - block: shared_block.clone(), - transaction: transaction.clone(), - }) - }) - .collect() - }) - .collect(); - - triggers.push(StarknetTrigger::Block(StarknetBlockTrigger { - block: shared_block, - })); - - Ok(BlockWithTriggers::new(block, triggers, logger)) - } - - /// Return `true` if the block with the given hash and number is on the - /// main chain, i.e., the chain going back from the current chain head. - async fn is_on_main_chain(&self, _ptr: BlockPtr) -> Result { - panic!("Should never be called since not used by FirehoseBlockStream") - } - - /// Get pointer to parent of `block`. This is called when reverting `block`. - async fn parent_ptr(&self, block: &BlockPtr) -> Result, Error> { - // Panics if `block` is genesis. - // But that's ok since this is only called when reverting `block`. - Ok(Some(BlockPtr { - hash: BlockHash::from(vec![0xff; 32]), - number: block.number.saturating_sub(1), - })) - } -} - -#[cfg(test)] -mod tests { - use std::sync::Arc; - - use graph::{blockchain::DataSource as _, data::subgraph::LATEST_VERSION}; - - use crate::{ - data_source::{ - DataSource, Mapping, MappingBlockHandler, MappingEventHandler, STARKNET_KIND, - }, - felt::Felt, - }; - - #[test] - fn validate_no_handler() { - let ds = new_data_source(None); - - let errs = ds.validate(LATEST_VERSION); - assert_eq!(errs.len(), 1, "{:?}", ds); - assert_eq!( - errs[0].to_string(), - "data source does not define any handler" - ); - } - - #[test] - fn validate_address_without_event_handler() { - let mut ds = new_data_source(Some([1u8; 32].into())); - ds.mapping.block_handler = Some(MappingBlockHandler { - handler: "asdf".into(), - }); - - let errs = ds.validate(LATEST_VERSION); - assert_eq!(errs.len(), 1, "{:?}", ds); - assert_eq!( - errs[0].to_string(), - "data source cannot have source address without event handlers" - ); - } - - #[test] - fn validate_no_address_with_event_handler() { - let mut ds = new_data_source(None); - ds.mapping.event_handlers.push(MappingEventHandler { - handler: "asdf".into(), - event_selector: [2u8; 32].into(), - }); - - let errs = ds.validate(LATEST_VERSION); - assert_eq!(errs.len(), 1, "{:?}", ds); - assert_eq!(errs[0].to_string(), "subgraph source address is required"); - } - - fn new_data_source(address: Option) -> DataSource { - DataSource { - kind: STARKNET_KIND.to_string(), - network: "starknet-mainnet".into(), - name: "asd".to_string(), - source: crate::data_source::Source { - start_block: 10, - end_block: None, - address, - }, - mapping: Mapping { - block_handler: None, - event_handlers: vec![], - runtime: Arc::new(vec![]), - }, - } - } -} diff --git a/chain/starknet/src/codec.rs b/chain/starknet/src/codec.rs deleted file mode 100644 index 4d029c8c01d..00000000000 --- a/chain/starknet/src/codec.rs +++ /dev/null @@ -1,35 +0,0 @@ -#[rustfmt::skip] -#[path = "protobuf/zklend.starknet.r#type.v1.rs"] -mod pbcodec; - -use graph::blockchain::{Block as BlockchainBlock, BlockHash, BlockPtr}; - -pub use pbcodec::*; - -impl BlockchainBlock for Block { - fn number(&self) -> i32 { - self.height as i32 - } - - fn ptr(&self) -> BlockPtr { - BlockPtr { - hash: BlockHash(self.hash.clone().into_boxed_slice()), - number: self.height as i32, - } - } - - fn parent_ptr(&self) -> Option { - if self.height == 0 { - None - } else { - Some(BlockPtr { - hash: BlockHash(self.prev_hash.clone().into_boxed_slice()), - number: (self.height - 1) as i32, - }) - } - } - - fn timestamp(&self) -> graph::blockchain::BlockTime { - graph::blockchain::BlockTime::since_epoch(self.timestamp as i64, 0) - } -} diff --git a/chain/starknet/src/data_source.rs b/chain/starknet/src/data_source.rs deleted file mode 100644 index 8f168dc47c5..00000000000 --- a/chain/starknet/src/data_source.rs +++ /dev/null @@ -1,407 +0,0 @@ -use graph::{ - anyhow::{anyhow, Error}, - blockchain::{self, Block as BlockchainBlock, TriggerWithHandler}, - components::{ - link_resolver::LinkResolver, store::StoredDynamicDataSource, - subgraph::InstanceDSTemplateInfo, - }, - data::subgraph::{DataSourceContext, SubgraphManifestValidationError}, - prelude::{async_trait, BlockNumber, Deserialize, Link, Logger}, - semver, -}; -use sha3::{Digest, Keccak256}; -use std::{collections::HashSet, sync::Arc}; - -use crate::{ - chain::Chain, - codec, - felt::Felt, - trigger::{StarknetEventTrigger, StarknetTrigger}, -}; - -pub const STARKNET_KIND: &str = "starknet"; -const BLOCK_HANDLER_KIND: &str = "block"; -const EVENT_HANDLER_KIND: &str = "event"; - -#[derive(Debug, Clone)] -pub struct DataSource { - pub kind: String, - pub network: String, - pub name: String, - pub source: Source, - pub mapping: Mapping, -} - -#[derive(Debug, Clone)] -pub struct Mapping { - pub block_handler: Option, - pub event_handlers: Vec, - pub runtime: Arc>, -} - -#[derive(Deserialize)] -pub struct UnresolvedDataSource { - pub kind: String, - pub network: String, - pub name: String, - pub source: Source, - pub mapping: UnresolvedMapping, -} - -#[derive(Debug, Clone, PartialEq, Eq, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct Source { - pub start_block: BlockNumber, - pub end_block: Option, - #[serde(default)] - pub address: Option, -} - -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct UnresolvedMapping { - #[serde(default)] - pub block_handler: Option, - #[serde(default)] - pub event_handlers: Vec, - pub file: Link, -} - -#[derive(Debug, Clone, PartialEq, Eq, Deserialize)] -pub struct MappingBlockHandler { - pub handler: String, -} - -#[derive(Debug, Clone, PartialEq, Eq, Deserialize)] -pub struct MappingEventHandler { - pub handler: String, - pub event_selector: Felt, -} - -#[derive(Clone, Deserialize)] -pub struct UnresolvedMappingEventHandler { - pub handler: String, - pub event: String, -} - -#[derive(Debug, Clone)] -pub struct DataSourceTemplate; - -#[derive(Clone, Default, Deserialize)] -pub struct UnresolvedDataSourceTemplate; - -impl blockchain::DataSource for DataSource { - fn from_template_info( - _info: InstanceDSTemplateInfo, - _template: &graph::data_source::DataSourceTemplate, - ) -> Result { - Err(anyhow!("StarkNet subgraphs do not support templates")) - } - - fn address(&self) -> Option<&[u8]> { - self.source.address.as_ref().map(|addr| addr.as_ref()) - } - - fn start_block(&self) -> BlockNumber { - self.source.start_block - } - - fn end_block(&self) -> Option { - self.source.end_block - } - - fn handler_kinds(&self) -> HashSet<&str> { - let mut kinds = HashSet::new(); - - let Mapping { - block_handler, - event_handlers, - .. - } = &self.mapping; - - if block_handler.is_some() { - kinds.insert(BLOCK_HANDLER_KIND); - } - if !event_handlers.is_empty() { - kinds.insert(EVENT_HANDLER_KIND); - } - - kinds - } - - fn match_and_decode( - &self, - trigger: &StarknetTrigger, - block: &Arc, - _logger: &Logger, - ) -> Result>, Error> { - if self.start_block() > block.number() { - return Ok(None); - } - - let handler = match trigger { - StarknetTrigger::Block(_) => match &self.mapping.block_handler { - Some(handler) => handler.handler.clone(), - None => return Ok(None), - }, - StarknetTrigger::Event(event) => match self.handler_for_event(event) { - Some(handler) => handler.handler, - None => return Ok(None), - }, - }; - - Ok(Some(TriggerWithHandler::::new( - trigger.clone(), - handler, - block.ptr(), - block.timestamp(), - ))) - } - - fn name(&self) -> &str { - &self.name - } - - fn kind(&self) -> &str { - &self.kind - } - - fn network(&self) -> Option<&str> { - Some(&self.network) - } - - fn context(&self) -> Arc> { - Arc::new(None) - } - - fn creation_block(&self) -> Option { - None - } - - fn is_duplicate_of(&self, other: &Self) -> bool { - let DataSource { - kind, - network, - name, - source, - mapping, - } = self; - - kind == &other.kind - && network == &other.network - && name == &other.name - && source == &other.source - && mapping.event_handlers == other.mapping.event_handlers - && mapping.block_handler == other.mapping.block_handler - } - - fn as_stored_dynamic_data_source(&self) -> StoredDynamicDataSource { - // FIXME (Starknet): Implement me! - todo!() - } - - fn from_stored_dynamic_data_source( - _template: &DataSourceTemplate, - _stored: StoredDynamicDataSource, - ) -> Result { - // FIXME (Starknet): Implement me correctly - todo!() - } - - fn validate(&self, _: &semver::Version) -> Vec { - let mut errors = Vec::new(); - - if self.kind != STARKNET_KIND { - errors.push(anyhow!( - "data source has invalid `kind`, expected {} but found {}", - STARKNET_KIND, - self.kind - )) - } - - // Validate that there's at least one handler of any kind - if self.mapping.block_handler.is_none() && self.mapping.event_handlers.is_empty() { - errors.push(anyhow!("data source does not define any handler")); - } - - // Validate that `source` address must not be present if there's no event handler - if self.mapping.event_handlers.is_empty() && self.address().is_some() { - errors.push(anyhow!( - "data source cannot have source address without event handlers" - )); - } - - // Validate that `source` address must be present when there's at least 1 event handler - if !self.mapping.event_handlers.is_empty() && self.address().is_none() { - errors.push(SubgraphManifestValidationError::SourceAddressRequired.into()); - } - - errors - } - - fn api_version(&self) -> semver::Version { - semver::Version::new(0, 0, 5) - } - - fn runtime(&self) -> Option>> { - Some(self.mapping.runtime.clone()) - } -} - -impl DataSource { - /// Returns event trigger if an event.key matches the handler.key and optionally - /// if event.fromAddr matches the source address. Note this only supports the default - /// Starknet behavior of one key per event. - fn handler_for_event(&self, event: &StarknetEventTrigger) -> Option { - let event_key: Felt = Self::pad_to_32_bytes(event.event.keys.first()?)?.into(); - - // Always padding first here seems fine as we expect most sources to define an address - // filter anyways. Alternatively we can use lazy init here, which seems unnecessary. - let event_from_addr: Felt = Self::pad_to_32_bytes(&event.event.from_addr)?.into(); - - return self - .mapping - .event_handlers - .iter() - .find(|handler| { - // No need to compare address if selector doesn't match - if handler.event_selector != event_key { - return false; - } - - match &self.source.address { - Some(addr_filter) => addr_filter == &event_from_addr, - None => true, - } - }) - .cloned(); - } - - /// We need to pad incoming event selectors and addresses to 32 bytes as our data source uses - /// padded 32 bytes. - fn pad_to_32_bytes(slice: &[u8]) -> Option<[u8; 32]> { - if slice.len() > 32 { - None - } else { - let mut buffer = [0u8; 32]; - buffer[(32 - slice.len())..].copy_from_slice(slice); - Some(buffer) - } - } -} - -#[async_trait] -impl blockchain::UnresolvedDataSource for UnresolvedDataSource { - async fn resolve( - self, - resolver: &Arc, - logger: &Logger, - _manifest_idx: u32, - ) -> Result { - let module_bytes = resolver.cat(logger, &self.mapping.file).await?; - - Ok(DataSource { - kind: self.kind, - network: self.network, - name: self.name, - source: self.source, - mapping: Mapping { - block_handler: self.mapping.block_handler, - event_handlers: self - .mapping - .event_handlers - .into_iter() - .map(|handler| { - Ok(MappingEventHandler { - handler: handler.handler, - event_selector: get_selector_from_name(&handler.event)?, - }) - }) - .collect::, Error>>()?, - runtime: Arc::new(module_bytes), - }, - }) - } -} - -impl blockchain::DataSourceTemplate for DataSourceTemplate { - fn api_version(&self) -> semver::Version { - todo!() - } - - fn runtime(&self) -> Option>> { - todo!() - } - - fn name(&self) -> &str { - todo!() - } - - fn manifest_idx(&self) -> u32 { - todo!() - } - - fn kind(&self) -> &str { - todo!() - } -} - -#[async_trait] -impl blockchain::UnresolvedDataSourceTemplate for UnresolvedDataSourceTemplate { - #[allow(unused)] - async fn resolve( - self, - resolver: &Arc, - logger: &Logger, - manifest_idx: u32, - ) -> Result { - todo!() - } -} - -// Adapted from: -// https://github.com/xJonathanLEI/starknet-rs/blob/f16271877c9dbf08bc7bf61e4fc72decc13ff73d/starknet-core/src/utils.rs#L110-L121 -fn get_selector_from_name(func_name: &str) -> graph::anyhow::Result { - const DEFAULT_ENTRY_POINT_NAME: &str = "__default__"; - const DEFAULT_L1_ENTRY_POINT_NAME: &str = "__l1_default__"; - - if func_name == DEFAULT_ENTRY_POINT_NAME || func_name == DEFAULT_L1_ENTRY_POINT_NAME { - Ok([0u8; 32].into()) - } else { - let name_bytes = func_name.as_bytes(); - if name_bytes.is_ascii() { - Ok(starknet_keccak(name_bytes).into()) - } else { - Err(anyhow!("the provided name contains non-ASCII characters")) - } - } -} - -// Adapted from: -// https://github.com/xJonathanLEI/starknet-rs/blob/f16271877c9dbf08bc7bf61e4fc72decc13ff73d/starknet-core/src/utils.rs#L98-L108 -fn starknet_keccak(data: &[u8]) -> [u8; 32] { - let mut hasher = Keccak256::new(); - hasher.update(data); - let mut hash = hasher.finalize(); - - // Remove the first 6 bits - hash[0] &= 0b00000011; - - hash.into() -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_starknet_keccak() { - let expected_hash: [u8; 32] = - hex::decode("016c11b0b5b808960df26f5bfc471d04c1995b0ffd2055925ad1be28d6baadfd") - .unwrap() - .try_into() - .unwrap(); - - assert_eq!(starknet_keccak("Hello world".as_bytes()), expected_hash); - } -} diff --git a/chain/starknet/src/felt.rs b/chain/starknet/src/felt.rs deleted file mode 100644 index 7c0e6b6496d..00000000000 --- a/chain/starknet/src/felt.rs +++ /dev/null @@ -1,88 +0,0 @@ -use std::{ - fmt::{Debug, Formatter}, - str::FromStr, -}; - -use graph::anyhow; -use serde::{de::Visitor, Deserialize}; - -/// Represents the primitive `FieldElement` type used in Starknet. Each `FieldElement` is 252-bit -/// in size. -#[derive(Clone, PartialEq, Eq)] -pub struct Felt([u8; 32]); - -struct FeltVisitor; - -impl Debug for Felt { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "0x{}", hex::encode(self.0)) - } -} - -impl From<[u8; 32]> for Felt { - fn from(value: [u8; 32]) -> Self { - Self(value) - } -} - -impl AsRef<[u8]> for Felt { - fn as_ref(&self) -> &[u8] { - &self.0 - } -} - -impl FromStr for Felt { - type Err = anyhow::Error; - - fn from_str(s: &str) -> Result { - let hex_str = s.trim_start_matches("0x"); - if hex_str.len() % 2 == 0 { - Ok(Felt(decode_even_hex_str(hex_str)?)) - } else { - // We need to manually pad it as the `hex` crate does not allow odd hex length - let mut padded_string = String::from("0"); - padded_string.push_str(hex_str); - - Ok(Felt(decode_even_hex_str(&padded_string)?)) - } - } -} - -impl<'de> Deserialize<'de> for Felt { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - deserializer.deserialize_any(FeltVisitor) - } -} - -impl<'de> Visitor<'de> for FeltVisitor { - type Value = Felt; - - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(formatter, "string") - } - - fn visit_str(self, v: &str) -> Result - where - E: serde::de::Error, - { - Felt::from_str(v).map_err(|_| { - serde::de::Error::invalid_value(serde::de::Unexpected::Str(v), &"valid Felt value") - }) - } -} - -/// Attempts to decode a even-length hex string into a padded 32-byte array. -pub fn decode_even_hex_str(hex_str: &str) -> anyhow::Result<[u8; 32]> { - let byte_len = hex_str.len() / 2; - if byte_len > 32 { - anyhow::bail!("length exceeds 32 bytes"); - } - - let mut buffer = [0u8; 32]; - hex::decode_to_slice(hex_str, &mut buffer[(32 - byte_len)..])?; - - Ok(buffer) -} diff --git a/chain/starknet/src/lib.rs b/chain/starknet/src/lib.rs deleted file mode 100644 index a2d71dbb626..00000000000 --- a/chain/starknet/src/lib.rs +++ /dev/null @@ -1,10 +0,0 @@ -mod adapter; -mod chain; -pub mod codec; -mod data_source; -mod felt; -mod runtime; -mod trigger; - -pub use crate::chain::{Chain, StarknetStreamBuilder}; -pub use codec::Block; diff --git a/chain/starknet/src/protobuf/zklend.starknet.r#type.v1.rs b/chain/starknet/src/protobuf/zklend.starknet.r#type.v1.rs deleted file mode 100644 index 35e4dc1adc3..00000000000 --- a/chain/starknet/src/protobuf/zklend.starknet.r#type.v1.rs +++ /dev/null @@ -1,70 +0,0 @@ -// This file is @generated by prost-build. -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Block { - #[prost(uint64, tag = "1")] - pub height: u64, - #[prost(bytes = "vec", tag = "2")] - pub hash: ::prost::alloc::vec::Vec, - #[prost(bytes = "vec", tag = "3")] - pub prev_hash: ::prost::alloc::vec::Vec, - #[prost(uint64, tag = "4")] - pub timestamp: u64, - #[prost(message, repeated, tag = "5")] - pub transactions: ::prost::alloc::vec::Vec, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Transaction { - #[prost(enumeration = "TransactionType", tag = "1")] - pub r#type: i32, - #[prost(bytes = "vec", tag = "2")] - pub hash: ::prost::alloc::vec::Vec, - #[prost(message, repeated, tag = "3")] - pub events: ::prost::alloc::vec::Vec, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Event { - #[prost(bytes = "vec", tag = "1")] - pub from_addr: ::prost::alloc::vec::Vec, - #[prost(bytes = "vec", repeated, tag = "2")] - pub keys: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec>, - #[prost(bytes = "vec", repeated, tag = "3")] - pub data: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec>, -} -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] -#[repr(i32)] -pub enum TransactionType { - Deploy = 0, - InvokeFunction = 1, - Declare = 2, - L1Handler = 3, - DeployAccount = 4, -} -impl TransactionType { - /// String value of the enum field names used in the ProtoBuf definition. - /// - /// The values are not transformed in any way and thus are considered stable - /// (if the ProtoBuf definition does not change) and safe for programmatic use. - pub fn as_str_name(&self) -> &'static str { - match self { - TransactionType::Deploy => "DEPLOY", - TransactionType::InvokeFunction => "INVOKE_FUNCTION", - TransactionType::Declare => "DECLARE", - TransactionType::L1Handler => "L1_HANDLER", - TransactionType::DeployAccount => "DEPLOY_ACCOUNT", - } - } - /// Creates an enum from field names used in the ProtoBuf definition. - pub fn from_str_name(value: &str) -> ::core::option::Option { - match value { - "DEPLOY" => Some(Self::Deploy), - "INVOKE_FUNCTION" => Some(Self::InvokeFunction), - "DECLARE" => Some(Self::Declare), - "L1_HANDLER" => Some(Self::L1Handler), - "DEPLOY_ACCOUNT" => Some(Self::DeployAccount), - _ => None, - } - } -} diff --git a/chain/starknet/src/runtime/abi.rs b/chain/starknet/src/runtime/abi.rs deleted file mode 100644 index a03019ebb01..00000000000 --- a/chain/starknet/src/runtime/abi.rs +++ /dev/null @@ -1,106 +0,0 @@ -use graph::{ - prelude::BigInt, - runtime::{asc_new, gas::GasCounter, AscHeap, HostExportError, ToAscObj}, -}; -use graph_runtime_wasm::asc_abi::class::{Array, AscEnum, EnumPayload}; - -use crate::{ - codec, - trigger::{StarknetBlockTrigger, StarknetEventTrigger}, -}; - -pub(crate) use super::generated::*; - -impl ToAscObj for codec::Block { - fn to_asc_obj( - &self, - heap: &mut H, - gas: &GasCounter, - ) -> Result { - Ok(AscBlock { - number: asc_new(heap, &BigInt::from(self.height), gas)?, - hash: asc_new(heap, self.hash.as_slice(), gas)?, - prev_hash: asc_new(heap, self.prev_hash.as_slice(), gas)?, - timestamp: asc_new(heap, &BigInt::from(self.timestamp), gas)?, - }) - } -} - -impl ToAscObj for codec::Transaction { - fn to_asc_obj( - &self, - heap: &mut H, - gas: &GasCounter, - ) -> Result { - Ok(AscTransaction { - r#type: asc_new( - heap, - &codec::TransactionType::try_from(self.r#type) - .expect("invalid TransactionType value"), - gas, - )?, - hash: asc_new(heap, self.hash.as_slice(), gas)?, - }) - } -} - -impl ToAscObj for codec::TransactionType { - fn to_asc_obj( - &self, - _heap: &mut H, - _gas: &GasCounter, - ) -> Result { - Ok(AscTransactionTypeEnum(AscEnum { - kind: match self { - codec::TransactionType::Deploy => AscTransactionType::Deploy, - codec::TransactionType::InvokeFunction => AscTransactionType::InvokeFunction, - codec::TransactionType::Declare => AscTransactionType::Declare, - codec::TransactionType::L1Handler => AscTransactionType::L1Handler, - codec::TransactionType::DeployAccount => AscTransactionType::DeployAccount, - }, - _padding: 0, - payload: EnumPayload(0), - })) - } -} - -impl ToAscObj for Vec> { - fn to_asc_obj( - &self, - heap: &mut H, - gas: &GasCounter, - ) -> Result { - let content: Result, _> = self - .iter() - .map(|x| asc_new(heap, x.as_slice(), gas)) - .collect(); - - Ok(AscBytesArray(Array::new(&content?, heap, gas)?)) - } -} - -impl ToAscObj for StarknetBlockTrigger { - fn to_asc_obj( - &self, - heap: &mut H, - gas: &GasCounter, - ) -> Result { - self.block.to_asc_obj(heap, gas) - } -} - -impl ToAscObj for StarknetEventTrigger { - fn to_asc_obj( - &self, - heap: &mut H, - gas: &GasCounter, - ) -> Result { - Ok(AscEvent { - from_addr: asc_new(heap, self.event.from_addr.as_slice(), gas)?, - keys: asc_new(heap, &self.event.keys, gas)?, - data: asc_new(heap, &self.event.data, gas)?, - block: asc_new(heap, self.block.as_ref(), gas)?, - transaction: asc_new(heap, self.transaction.as_ref(), gas)?, - }) - } -} diff --git a/chain/starknet/src/runtime/generated.rs b/chain/starknet/src/runtime/generated.rs deleted file mode 100644 index 59932ae576e..00000000000 --- a/chain/starknet/src/runtime/generated.rs +++ /dev/null @@ -1,100 +0,0 @@ -use graph::runtime::{ - AscIndexId, AscPtr, AscType, AscValue, DeterministicHostError, IndexForAscTypeId, -}; -use graph::semver::Version; -use graph_runtime_derive::AscType; -use graph_runtime_wasm::asc_abi::class::{Array, AscBigInt, AscEnum, Uint8Array}; - -pub struct AscBytesArray(pub(crate) Array>); - -impl AscType for AscBytesArray { - fn to_asc_bytes(&self) -> Result, DeterministicHostError> { - self.0.to_asc_bytes() - } - - fn from_asc_bytes( - asc_obj: &[u8], - api_version: &Version, - ) -> Result { - Ok(Self(Array::from_asc_bytes(asc_obj, api_version)?)) - } -} - -impl AscIndexId for AscBytesArray { - const INDEX_ASC_TYPE_ID: IndexForAscTypeId = IndexForAscTypeId::StarknetArrayBytes; -} - -pub struct AscTransactionTypeEnum(pub(crate) AscEnum); - -impl AscType for AscTransactionTypeEnum { - fn to_asc_bytes(&self) -> Result, DeterministicHostError> { - self.0.to_asc_bytes() - } - - fn from_asc_bytes( - asc_obj: &[u8], - api_version: &Version, - ) -> Result { - Ok(Self(AscEnum::from_asc_bytes(asc_obj, api_version)?)) - } -} - -impl AscIndexId for AscTransactionTypeEnum { - const INDEX_ASC_TYPE_ID: IndexForAscTypeId = IndexForAscTypeId::StarknetTransactionTypeEnum; -} - -#[repr(C)] -#[derive(AscType)] -pub(crate) struct AscBlock { - pub number: AscPtr, - pub hash: AscPtr, - pub prev_hash: AscPtr, - pub timestamp: AscPtr, -} - -impl AscIndexId for AscBlock { - const INDEX_ASC_TYPE_ID: IndexForAscTypeId = IndexForAscTypeId::StarknetBlock; -} - -#[repr(C)] -#[derive(AscType)] -pub(crate) struct AscTransaction { - pub r#type: AscPtr, - pub hash: AscPtr, -} - -impl AscIndexId for AscTransaction { - const INDEX_ASC_TYPE_ID: IndexForAscTypeId = IndexForAscTypeId::StarknetTransaction; -} - -#[repr(u32)] -#[derive(AscType, Copy, Clone)] -pub(crate) enum AscTransactionType { - Deploy, - InvokeFunction, - Declare, - L1Handler, - DeployAccount, -} - -impl AscValue for AscTransactionType {} - -impl Default for AscTransactionType { - fn default() -> Self { - Self::Deploy - } -} - -#[repr(C)] -#[derive(AscType)] -pub(crate) struct AscEvent { - pub from_addr: AscPtr, - pub keys: AscPtr, - pub data: AscPtr, - pub block: AscPtr, - pub transaction: AscPtr, -} - -impl AscIndexId for AscEvent { - const INDEX_ASC_TYPE_ID: IndexForAscTypeId = IndexForAscTypeId::StarknetEvent; -} diff --git a/chain/starknet/src/runtime/mod.rs b/chain/starknet/src/runtime/mod.rs deleted file mode 100644 index 31e18de7dd8..00000000000 --- a/chain/starknet/src/runtime/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod abi; - -mod generated; diff --git a/chain/starknet/src/trigger.rs b/chain/starknet/src/trigger.rs deleted file mode 100644 index 690c4c5c719..00000000000 --- a/chain/starknet/src/trigger.rs +++ /dev/null @@ -1,105 +0,0 @@ -use graph::{ - blockchain::{MappingTriggerTrait, TriggerData}, - runtime::{asc_new, gas::GasCounter, AscPtr, HostExportError}, -}; -use graph_runtime_wasm::module::ToAscPtr; -use std::{cmp::Ordering, sync::Arc}; - -use crate::codec; - -#[derive(Debug, Clone)] -pub enum StarknetTrigger { - Block(StarknetBlockTrigger), - Event(StarknetEventTrigger), -} - -#[derive(Debug, Clone)] -pub struct StarknetBlockTrigger { - pub(crate) block: Arc, -} - -#[derive(Debug, Clone)] -pub struct StarknetEventTrigger { - pub(crate) event: Arc, - pub(crate) block: Arc, - pub(crate) transaction: Arc, -} - -impl PartialEq for StarknetTrigger { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (Self::Block(l), Self::Block(r)) => l.block == r.block, - (Self::Event(l), Self::Event(r)) => { - // Without event index we can't really tell if they're the same - // TODO: implement add event index to trigger data - l.block.hash == r.block.hash - && l.transaction.hash == r.transaction.hash - && l.event == r.event - } - _ => false, - } - } -} - -impl Eq for StarknetTrigger {} - -impl PartialOrd for StarknetTrigger { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -impl Ord for StarknetTrigger { - fn cmp(&self, other: &Self) -> Ordering { - match (self, other) { - (Self::Block(l), Self::Block(r)) => l.block.height.cmp(&r.block.height), - - // Block triggers always come last - (Self::Block(..), _) => Ordering::Greater, - (_, Self::Block(..)) => Ordering::Less, - - // Keep the order when comparing two event triggers - // TODO: compare block hash, tx index, and event index - (Self::Event(..), Self::Event(..)) => Ordering::Equal, - } - } -} - -impl TriggerData for StarknetTrigger { - fn error_context(&self) -> String { - match self { - Self::Block(block) => format!("block #{}", block.block.height), - Self::Event(event) => { - format!("event from 0x{}", hex::encode(&event.event.from_addr),) - } - } - } - - fn address_match(&self) -> Option<&[u8]> { - None - } -} - -impl ToAscPtr for StarknetTrigger { - fn to_asc_ptr( - self, - heap: &mut H, - gas: &GasCounter, - ) -> Result, HostExportError> { - Ok(match self { - StarknetTrigger::Block(block) => asc_new(heap, &block, gas)?.erase(), - StarknetTrigger::Event(event) => asc_new(heap, &event, gas)?.erase(), - }) - } -} - -impl MappingTriggerTrait for StarknetTrigger { - fn error_context(&self) -> String { - match self { - Self::Block(block) => format!("block #{}", block.block.height), - Self::Event(event) => { - format!("event from 0x{}", hex::encode(&event.event.from_addr)) - } - } - } -} diff --git a/core/Cargo.toml b/core/Cargo.toml index 7c232f60807..4533b5d8880 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -15,7 +15,6 @@ graph-chain-ethereum = { path = "../chain/ethereum" } graph-chain-near = { path = "../chain/near" } graph-chain-cosmos = { path = "../chain/cosmos" } graph-chain-substreams = { path = "../chain/substreams" } -graph-chain-starknet = { path = "../chain/starknet" } graph-runtime-wasm = { path = "../runtime/wasm" } serde_yaml = { workspace = true } # Switch to crates.io once tower 0.5 is released diff --git a/core/src/subgraph/instance_manager.rs b/core/src/subgraph/instance_manager.rs index 996268da460..aba94ec2d3a 100644 --- a/core/src/subgraph/instance_manager.rs +++ b/core/src/subgraph/instance_manager.rs @@ -121,20 +121,6 @@ impl SubgraphInstanceManagerTrait for SubgraphInstanceManager< self.start_subgraph_inner(logger, loc, runner).await } - BlockchainKind::Starknet => { - let runner = instance_manager - .build_subgraph_runner::( - logger.clone(), - self.env_vars.cheap_clone(), - loc.clone(), - manifest, - stop_block, - Box::new(SubgraphTriggerProcessor {}), - ) - .await?; - - self.start_subgraph_inner(logger, loc, runner).await - } } }; diff --git a/core/src/subgraph/registrar.rs b/core/src/subgraph/registrar.rs index fe80d118457..b7d45613b74 100644 --- a/core/src/subgraph/registrar.rs +++ b/core/src/subgraph/registrar.rs @@ -417,24 +417,6 @@ where ) .await? } - BlockchainKind::Starknet => { - create_subgraph_version::( - &logger, - self.store.clone(), - self.chains.cheap_clone(), - name.clone(), - hash.cheap_clone(), - start_block_override, - graft_block_override, - raw, - node_id, - debug_fork, - self.version_switching_mode, - &self.resolver, - history_blocks, - ) - .await? - } }; debug!( diff --git a/graph/src/blockchain/mod.rs b/graph/src/blockchain/mod.rs index d100decb9f0..9f3df60fe5f 100644 --- a/graph/src/blockchain/mod.rs +++ b/graph/src/blockchain/mod.rs @@ -460,8 +460,6 @@ pub enum BlockchainKind { Cosmos, Substreams, - - Starknet, } impl fmt::Display for BlockchainKind { @@ -472,7 +470,6 @@ impl fmt::Display for BlockchainKind { BlockchainKind::Near => "near", BlockchainKind::Cosmos => "cosmos", BlockchainKind::Substreams => "substreams", - BlockchainKind::Starknet => "starknet", }; write!(f, "{}", value) } @@ -488,7 +485,6 @@ impl FromStr for BlockchainKind { "near" => Ok(BlockchainKind::Near), "cosmos" => Ok(BlockchainKind::Cosmos), "substreams" => Ok(BlockchainKind::Substreams), - "starknet" => Ok(BlockchainKind::Starknet), _ => Err(anyhow!("unknown blockchain kind {}", s)), } } diff --git a/node/Cargo.toml b/node/Cargo.toml index 8a98396d6fd..820ed8405a8 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -27,7 +27,6 @@ graph-chain-ethereum = { path = "../chain/ethereum" } graph-chain-near = { path = "../chain/near" } graph-chain-cosmos = { path = "../chain/cosmos" } graph-chain-substreams = { path = "../chain/substreams" } -graph-chain-starknet = { path = "../chain/starknet" } graph-graphql = { path = "../graphql" } graph-server-http = { path = "../server/http" } graph-server-index-node = { path = "../server/index-node" } diff --git a/node/src/chain.rs b/node/src/chain.rs index 6de493631cd..1c62bf2248e 100644 --- a/node/src/chain.rs +++ b/node/src/chain.rs @@ -530,33 +530,6 @@ pub async fn networks_as_chains( ) .await; } - BlockchainKind::Starknet => { - let firehose_endpoints = networks.firehose_endpoints(chain_id.clone()); - blockchain_map.insert::( - chain_id.clone(), - Arc::new( - BasicBlockchainBuilder { - logger_factory: logger_factory.clone(), - name: chain_id.clone(), - chain_store: chain_store.cheap_clone(), - firehose_endpoints, - metrics_registry: metrics_registry.clone(), - } - .build(config) - .await, - ), - ); - add_substreams::( - networks, - config, - chain_id.clone(), - blockchain_map, - logger_factory.clone(), - chain_store, - metrics_registry.clone(), - ) - .await; - } BlockchainKind::Substreams => { let substreams_endpoints = networks.substreams_endpoints(chain_id.clone()); blockchain_map.insert::( diff --git a/node/src/network_setup.rs b/node/src/network_setup.rs index 6114b6eefd3..4a8b4cedca1 100644 --- a/node/src/network_setup.rs +++ b/node/src/network_setup.rs @@ -342,10 +342,6 @@ impl Networks { block_ingestor::(logger, id, chain, &mut res).await? } BlockchainKind::Substreams => {} - BlockchainKind::Starknet => { - block_ingestor::(logger, id, chain, &mut res) - .await? - } } } diff --git a/server/index-node/Cargo.toml b/server/index-node/Cargo.toml index d623c998d80..edc438d1279 100644 --- a/server/index-node/Cargo.toml +++ b/server/index-node/Cargo.toml @@ -11,6 +11,5 @@ graph-chain-arweave = { path = "../../chain/arweave" } graph-chain-ethereum = { path = "../../chain/ethereum" } graph-chain-near = { path = "../../chain/near" } graph-chain-cosmos = { path = "../../chain/cosmos" } -graph-chain-starknet = { path = "../../chain/starknet" } graph-chain-substreams = { path = "../../chain/substreams" } git-testament = "0.2.5" diff --git a/server/index-node/src/resolver.rs b/server/index-node/src/resolver.rs index fb3937afdc2..6603d296509 100644 --- a/server/index-node/src/resolver.rs +++ b/server/index-node/src/resolver.rs @@ -591,23 +591,6 @@ impl IndexNodeResolver { ) .await? } - BlockchainKind::Starknet => { - let unvalidated_subgraph_manifest = - UnvalidatedSubgraphManifest::::resolve( - deployment_hash.clone(), - raw_yaml, - &self.link_resolver, - &self.logger, - max_spec_version, - ) - .await?; - - Self::validate_and_extract_features( - &self.store.subgraph_store(), - unvalidated_subgraph_manifest, - ) - .await? - } }; Ok(result) @@ -717,7 +700,6 @@ impl IndexNodeResolver { try_resolve_for_chain!(graph_chain_arweave::Chain); try_resolve_for_chain!(graph_chain_cosmos::Chain); try_resolve_for_chain!(graph_chain_near::Chain); - try_resolve_for_chain!(graph_chain_starknet::Chain); // If you're adding support for a new chain and this `match` clause just // gave you a compiler error, then this message is for you! You need to @@ -729,8 +711,7 @@ impl IndexNodeResolver { | BlockchainKind::Arweave | BlockchainKind::Ethereum | BlockchainKind::Cosmos - | BlockchainKind::Near - | BlockchainKind::Starknet => (), + | BlockchainKind::Near => (), } // The given network does not exist.