@@ -3,7 +3,7 @@ use anyhow::{Context, Error};
33use graph:: blockchain:: client:: ChainClient ;
44use graph:: blockchain:: firehose_block_ingestor:: { FirehoseBlockIngestor , Transforms } ;
55use graph:: blockchain:: {
6- BlockIngestor , BlockTime , BlockchainKind , ChainIdentifier , TriggerFilterWrapper ,
6+ BlockIngestor , BlockPtrExt , BlockTime , BlockchainKind , ChainIdentifier , TriggerFilterWrapper ,
77 TriggersAdapterSelector ,
88} ;
99use graph:: components:: adapter:: ChainId ;
@@ -156,6 +156,7 @@ impl BlockStreamBuilder<Chain> for EthereumStreamBuilder {
156156 unified_api_version : UnifiedMappingApiVersion ,
157157 ) -> Result < Box < dyn BlockStream < Chain > > > {
158158 let requirements = filter. chain_filter . node_capabilities ( ) ;
159+ let is_using_subgraph_composition = !source_subgraph_stores. is_empty ( ) ;
159160 let adapter = TriggersAdapterWrapper :: new (
160161 chain
161162 . triggers_adapter ( & deployment, & requirements, unified_api_version. clone ( ) )
@@ -181,20 +182,26 @@ impl BlockStreamBuilder<Chain> for EthereumStreamBuilder {
181182 // This is ok because Celo blocks are always final. And we _need_ to do this because
182183 // some events appear only in eth_getLogs but not in transaction receipts.
183184 // See also ca0edc58-0ec5-4c89-a7dd-2241797f5e50.
184- let chain_id = match chain. chain_client ( ) . as_ref ( ) {
185+ let reorg_threshold = match chain. chain_client ( ) . as_ref ( ) {
185186 ChainClient :: Rpc ( adapter) => {
186- adapter
187+ let chain_id = adapter
187188 . cheapest ( )
188189 . await
189190 . ok_or ( anyhow ! ( "unable to get eth adapter for chan_id call" ) ) ?
190191 . chain_id ( )
191- . await ?
192+ . await ?;
193+
194+ if CELO_CHAIN_IDS . contains ( & chain_id) {
195+ 0
196+ } else {
197+ chain. reorg_threshold
198+ }
192199 }
193- _ => panic ! ( "expected rpc when using polling blockstream" ) ,
194- } ;
195- let reorg_threshold = match CELO_CHAIN_IDS . contains ( & chain_id ) {
196- false => chain . reorg_threshold ,
197- true => 0 ,
200+ _ if is_using_subgraph_composition => chain . reorg_threshold ,
201+ _ => panic ! (
202+ "expected rpc when using polling blockstream : {}" ,
203+ is_using_subgraph_composition
204+ ) ,
198205 } ;
199206
200207 Ok ( Box :: new ( PollingBlockStream :: new (
@@ -617,6 +624,8 @@ pub enum BlockFinality {
617624
618625 // If a block may still be reorged, we need to work with more local data.
619626 NonFinal ( EthereumBlockWithCalls ) ,
627+
628+ Ptr ( Arc < BlockPtrExt > ) ,
620629}
621630
622631impl Default for BlockFinality {
@@ -630,6 +639,7 @@ impl BlockFinality {
630639 match self {
631640 BlockFinality :: Final ( block) => block,
632641 BlockFinality :: NonFinal ( block) => & block. ethereum_block . block ,
642+ BlockFinality :: Ptr ( _) => unreachable ! ( "light_block called on HeaderOnly" ) ,
633643 }
634644 }
635645}
@@ -639,6 +649,7 @@ impl<'a> From<&'a BlockFinality> for BlockPtr {
639649 match block {
640650 BlockFinality :: Final ( b) => BlockPtr :: from ( & * * b) ,
641651 BlockFinality :: NonFinal ( b) => BlockPtr :: from ( & b. ethereum_block ) ,
652+ BlockFinality :: Ptr ( b) => BlockPtr :: new ( b. hash . clone ( ) , b. number ) ,
642653 }
643654 }
644655}
@@ -648,13 +659,17 @@ impl Block for BlockFinality {
648659 match self {
649660 BlockFinality :: Final ( block) => block. block_ptr ( ) ,
650661 BlockFinality :: NonFinal ( block) => block. ethereum_block . block . block_ptr ( ) ,
662+ BlockFinality :: Ptr ( block) => BlockPtr :: new ( block. hash . clone ( ) , block. number ) ,
651663 }
652664 }
653665
654666 fn parent_ptr ( & self ) -> Option < BlockPtr > {
655667 match self {
656668 BlockFinality :: Final ( block) => block. parent_ptr ( ) ,
657669 BlockFinality :: NonFinal ( block) => block. ethereum_block . block . parent_ptr ( ) ,
670+ BlockFinality :: Ptr ( block) => {
671+ Some ( BlockPtr :: new ( block. parent_hash . clone ( ) , block. number - 1 ) )
672+ }
658673 }
659674 }
660675
@@ -687,13 +702,15 @@ impl Block for BlockFinality {
687702 json:: to_value ( eth_block)
688703 }
689704 BlockFinality :: NonFinal ( block) => json:: to_value ( & block. ethereum_block ) ,
705+ BlockFinality :: Ptr ( _) => Ok ( json:: Value :: Null ) ,
690706 }
691707 }
692708
693709 fn timestamp ( & self ) -> BlockTime {
694710 let ts = match self {
695711 BlockFinality :: Final ( block) => block. timestamp ,
696712 BlockFinality :: NonFinal ( block) => block. ethereum_block . block . timestamp ,
713+ BlockFinality :: Ptr ( block) => block. timestamp ,
697714 } ;
698715 let ts = i64:: try_from ( ts. as_u64 ( ) ) . unwrap ( ) ;
699716 BlockTime :: since_epoch ( ts, 0 )
@@ -735,7 +752,7 @@ impl TriggersAdapterTrait<Chain> for TriggersAdapter {
735752 . await
736753 }
737754
738- async fn load_blocks_by_numbers (
755+ async fn load_block_ptrs_by_numbers (
739756 & self ,
740757 logger : Logger ,
741758 block_numbers : HashSet < BlockNumber > ,
@@ -749,9 +766,9 @@ impl TriggersAdapterTrait<Chain> for TriggersAdapter {
749766 . await ?;
750767
751768 let blocks = adapter
752- . load_blocks_by_numbers ( logger, self . chain_store . clone ( ) , block_numbers)
769+ . load_block_ptrs_by_numbers ( logger, self . chain_store . clone ( ) , block_numbers)
753770 . await
754- . map ( |block| BlockFinality :: Final ( block) )
771+ . map ( |block| BlockFinality :: Ptr ( block) )
755772 . collect ( )
756773 . compat ( )
757774 . await ?;
@@ -812,6 +829,7 @@ impl TriggersAdapterTrait<Chain> for TriggersAdapter {
812829 triggers. append ( & mut parse_block_triggers ( & filter. block , full_block) ) ;
813830 Ok ( BlockWithTriggers :: new ( block, triggers, logger) )
814831 }
832+ BlockFinality :: Ptr ( _) => unreachable ! ( "triggers_in_block called on HeaderOnly" ) ,
815833 }
816834 }
817835
0 commit comments