@@ -14,17 +14,15 @@ use graph::{
1414 } ,
1515 firehose_block_stream:: FirehoseBlockStream ,
1616 polling_block_stream:: PollingBlockStream ,
17- Block , BlockHash , BlockPtr , Blockchain , ChainHeadUpdateListener ,
18- IngestorAdapter as IngestorAdapterTrait , IngestorError , TriggerFilter as _,
17+ Block , BlockPtr , Blockchain , ChainHeadUpdateListener , IngestorError , TriggerFilter as _,
1918 } ,
2019 cheap_clone:: CheapClone ,
2120 components:: store:: DeploymentLocator ,
2221 firehose,
23- log:: factory:: { ComponentLoggerConfig , ElasticComponentLoggerConfig } ,
2422 prelude:: {
25- async_trait, error , lazy_static, o, serde_json as json, web3 :: types :: H256 , BlockNumber ,
26- ChainStore , EthereumBlockWithCalls , Future01CompatExt , Logger , LoggerFactory ,
27- MetricsRegistry , NodeId , SubgraphStore ,
23+ async_trait, lazy_static, o, serde_json as json, BlockNumber , ChainStore ,
24+ EthereumBlockWithCalls , Future01CompatExt , Logger , LoggerFactory , MetricsRegistry , NodeId ,
25+ SubgraphStore ,
2826 } ,
2927} ;
3028use prost:: Message ;
@@ -72,7 +70,6 @@ pub struct Chain {
7270 registry : Arc < dyn MetricsRegistry > ,
7371 firehose_endpoints : Arc < FirehoseEndpoints > ,
7472 eth_adapters : Arc < EthereumNetworkAdapters > ,
75- ancestor_count : BlockNumber ,
7673 chain_store : Arc < dyn ChainStore > ,
7774 call_cache : Arc < dyn EthereumCallCache > ,
7875 subgraph_store : Arc < dyn SubgraphStore > ,
@@ -99,7 +96,6 @@ impl Chain {
9996 firehose_endpoints : FirehoseEndpoints ,
10097 eth_adapters : EthereumNetworkAdapters ,
10198 chain_head_update_listener : Arc < dyn ChainHeadUpdateListener > ,
102- ancestor_count : BlockNumber ,
10399 reorg_threshold : BlockNumber ,
104100 is_ingestible : bool ,
105101 ) -> Self {
@@ -110,7 +106,6 @@ impl Chain {
110106 registry,
111107 firehose_endpoints : Arc :: new ( firehose_endpoints) ,
112108 eth_adapters : Arc :: new ( eth_adapters) ,
113- ancestor_count,
114109 chain_store,
115110 call_cache,
116111 subgraph_store,
@@ -121,6 +116,12 @@ impl Chain {
121116 }
122117}
123118
119+ impl Chain {
120+ pub fn cheapest_adapter ( & self ) -> Arc < EthereumAdapter > {
121+ self . eth_adapters . cheapest ( ) . unwrap ( ) . clone ( )
122+ }
123+ }
124+
124125#[ async_trait]
125126impl Blockchain for Chain {
126127 const KIND : BlockchainKind = BlockchainKind :: Ethereum ;
@@ -145,8 +146,6 @@ impl Blockchain for Chain {
145146
146147 type NodeCapabilities = crate :: capabilities:: NodeCapabilities ;
147148
148- type IngestorAdapter = IngestorAdapter ;
149-
150149 type RuntimeAdapter = RuntimeAdapter ;
151150
152151 fn triggers_adapter (
@@ -299,29 +298,6 @@ impl Blockchain for Chain {
299298 ) ) )
300299 }
301300
302- fn ingestor_adapter ( & self ) -> Arc < Self :: IngestorAdapter > {
303- let eth_adapter = self . eth_adapters . cheapest ( ) . unwrap ( ) . clone ( ) ;
304- let logger = self
305- . logger_factory
306- . component_logger (
307- "BlockIngestor" ,
308- Some ( ComponentLoggerConfig {
309- elastic : Some ( ElasticComponentLoggerConfig {
310- index : String :: from ( "block-ingestor-logs" ) ,
311- } ) ,
312- } ) ,
313- )
314- . new ( o ! ( "provider" => eth_adapter. provider( ) . to_string( ) ) ) ;
315-
316- let adapter = IngestorAdapter {
317- eth_adapter,
318- logger,
319- ancestor_count : self . ancestor_count ,
320- chain_store : self . chain_store . clone ( ) ,
321- } ;
322- Arc :: new ( adapter)
323- }
324-
325301 fn chain_store ( & self ) -> Arc < dyn ChainStore > {
326302 self . chain_store . clone ( )
327303 }
@@ -624,79 +600,3 @@ impl FirehoseMapperTrait<Chain> for FirehoseMapper {
624600 }
625601 }
626602}
627-
628- pub struct IngestorAdapter {
629- logger : Logger ,
630- ancestor_count : i32 ,
631- eth_adapter : Arc < EthereumAdapter > ,
632- chain_store : Arc < dyn ChainStore > ,
633- }
634-
635- #[ async_trait]
636- impl IngestorAdapterTrait < Chain > for IngestorAdapter {
637- fn logger ( & self ) -> & Logger {
638- & self . logger
639- }
640-
641- fn ancestor_count ( & self ) -> BlockNumber {
642- self . ancestor_count
643- }
644-
645- async fn latest_block ( & self ) -> Result < BlockPtr , IngestorError > {
646- self . eth_adapter
647- . latest_block_header ( & self . logger )
648- . compat ( )
649- . await
650- . map ( |block| block. into ( ) )
651- }
652-
653- async fn ingest_block (
654- & self ,
655- block_hash : & BlockHash ,
656- ) -> Result < Option < BlockHash > , IngestorError > {
657- // TODO: H256::from_slice can panic
658- let block_hash = H256 :: from_slice ( block_hash. as_slice ( ) ) ;
659-
660- // Get the fully populated block
661- let block = self
662- . eth_adapter
663- . block_by_hash ( & self . logger , block_hash)
664- . compat ( )
665- . await ?
666- . ok_or_else ( || IngestorError :: BlockUnavailable ( block_hash) ) ?;
667- let ethereum_block = self
668- . eth_adapter
669- . load_full_block ( & self . logger , block)
670- . await ?;
671-
672- // We need something that implements `Block` to store the block; the
673- // store does not care whether the block is final or not
674- let ethereum_block = BlockFinality :: NonFinal ( EthereumBlockWithCalls {
675- ethereum_block,
676- calls : None ,
677- } ) ;
678-
679- // Store it in the database and try to advance the chain head pointer
680- self . chain_store
681- . upsert_block ( Arc :: new ( ethereum_block) )
682- . await ?;
683-
684- self . chain_store
685- . cheap_clone ( )
686- . attempt_chain_head_update ( self . ancestor_count )
687- . await
688- . map ( |missing| missing. map ( |h256| h256. into ( ) ) )
689- . map_err ( |e| {
690- error ! ( self . logger, "failed to update chain head" ) ;
691- IngestorError :: Unknown ( e)
692- } )
693- }
694-
695- fn chain_head_ptr ( & self ) -> Result < Option < BlockPtr > , Error > {
696- self . chain_store . chain_head_ptr ( )
697- }
698-
699- fn cleanup_cached_blocks ( & self ) -> Result < Option < ( i32 , usize ) > , Error > {
700- self . chain_store . cleanup_cached_blocks ( self . ancestor_count )
701- }
702- }
0 commit comments