@@ -14,17 +14,15 @@ use graph::{
14
14
} ,
15
15
firehose_block_stream:: FirehoseBlockStream ,
16
16
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 _,
19
18
} ,
20
19
cheap_clone:: CheapClone ,
21
20
components:: store:: DeploymentLocator ,
22
21
firehose,
23
- log:: factory:: { ComponentLoggerConfig , ElasticComponentLoggerConfig } ,
24
22
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 ,
28
26
} ,
29
27
} ;
30
28
use prost:: Message ;
@@ -72,7 +70,6 @@ pub struct Chain {
72
70
registry : Arc < dyn MetricsRegistry > ,
73
71
firehose_endpoints : Arc < FirehoseEndpoints > ,
74
72
eth_adapters : Arc < EthereumNetworkAdapters > ,
75
- ancestor_count : BlockNumber ,
76
73
chain_store : Arc < dyn ChainStore > ,
77
74
call_cache : Arc < dyn EthereumCallCache > ,
78
75
subgraph_store : Arc < dyn SubgraphStore > ,
@@ -99,7 +96,6 @@ impl Chain {
99
96
firehose_endpoints : FirehoseEndpoints ,
100
97
eth_adapters : EthereumNetworkAdapters ,
101
98
chain_head_update_listener : Arc < dyn ChainHeadUpdateListener > ,
102
- ancestor_count : BlockNumber ,
103
99
reorg_threshold : BlockNumber ,
104
100
is_ingestible : bool ,
105
101
) -> Self {
@@ -110,7 +106,6 @@ impl Chain {
110
106
registry,
111
107
firehose_endpoints : Arc :: new ( firehose_endpoints) ,
112
108
eth_adapters : Arc :: new ( eth_adapters) ,
113
- ancestor_count,
114
109
chain_store,
115
110
call_cache,
116
111
subgraph_store,
@@ -121,6 +116,12 @@ impl Chain {
121
116
}
122
117
}
123
118
119
+ impl Chain {
120
+ pub fn cheapest_adapter ( & self ) -> Arc < EthereumAdapter > {
121
+ self . eth_adapters . cheapest ( ) . unwrap ( ) . clone ( )
122
+ }
123
+ }
124
+
124
125
#[ async_trait]
125
126
impl Blockchain for Chain {
126
127
const KIND : BlockchainKind = BlockchainKind :: Ethereum ;
@@ -145,8 +146,6 @@ impl Blockchain for Chain {
145
146
146
147
type NodeCapabilities = crate :: capabilities:: NodeCapabilities ;
147
148
148
- type IngestorAdapter = IngestorAdapter ;
149
-
150
149
type RuntimeAdapter = RuntimeAdapter ;
151
150
152
151
fn triggers_adapter (
@@ -299,29 +298,6 @@ impl Blockchain for Chain {
299
298
) ) )
300
299
}
301
300
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
-
325
301
fn chain_store ( & self ) -> Arc < dyn ChainStore > {
326
302
self . chain_store . clone ( )
327
303
}
@@ -624,79 +600,3 @@ impl FirehoseMapperTrait<Chain> for FirehoseMapper {
624
600
}
625
601
}
626
602
}
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