File tree Expand file tree Collapse file tree 6 files changed +42
-8
lines changed Expand file tree Collapse file tree 6 files changed +42
-8
lines changed Original file line number Diff line number Diff line change @@ -272,7 +272,7 @@ where
272272 data_source : DataSource ,
273273 top_level_templates : Arc < Vec < DataSourceTemplate > > ,
274274 metrics : Arc < HostMetrics > ,
275- ) -> Result < Arc < T :: Host > , anyhow:: Error > {
275+ ) -> Result < Option < Arc < T :: Host > > , anyhow:: Error > {
276276 // Protect against creating more than the allowed maximum number of data sources
277277 if let Some ( max_data_sources) = * MAX_DATA_SOURCES {
278278 if self . hosts . len ( ) >= max_data_sources {
@@ -289,7 +289,12 @@ where
289289 top_level_templates,
290290 metrics. clone ( ) ,
291291 ) ?) ;
292- self . hosts . push ( host. clone ( ) ) ;
293- Ok ( host)
292+
293+ Ok ( if self . hosts . contains ( & host) {
294+ None
295+ } else {
296+ self . hosts . push ( host. clone ( ) ) ;
297+ Some ( host)
298+ } )
294299 }
295300}
Original file line number Diff line number Diff line change @@ -964,8 +964,22 @@ where
964964 host_metrics. clone ( ) ,
965965 ) ?;
966966
967- data_sources. push ( data_source) ;
968- runtime_hosts. push ( host) ;
967+ match host {
968+ Some ( host) => {
969+ data_sources. push ( data_source) ;
970+ runtime_hosts. push ( host) ;
971+ }
972+ None => warn ! (
973+ logger,
974+ "no runtime hosted created, there is already a runtime host instantiated for \
975+ this data source";
976+ "name" => & data_source. name,
977+ "address" => & data_source. source. address
978+ . map( |address| address. to_string( ) )
979+ . unwrap_or( "none" . to_string( ) ) ,
980+ "abi" => & data_source. source. abi
981+ ) ,
982+ }
969983 }
970984
971985 Ok ( ( data_sources, runtime_hosts) )
Original file line number Diff line number Diff line change 1+ use std:: cmp:: PartialEq ;
12use std:: fmt;
23use std:: sync:: Arc ;
34
@@ -145,7 +146,7 @@ impl HostMetrics {
145146}
146147
147148pub trait RuntimeHostBuilder : Clone + Send + Sync + ' static {
148- type Host : RuntimeHost ;
149+ type Host : RuntimeHost + PartialEq ;
149150 type Req : ' static + Send ;
150151
151152 /// Build a new runtime host for a subgraph data source.
Original file line number Diff line number Diff line change @@ -61,5 +61,5 @@ pub trait SubgraphInstance<H: RuntimeHost> {
6161 data_source : DataSource ,
6262 top_level_templates : Arc < Vec < DataSourceTemplate > > ,
6363 metrics : Arc < HostMetrics > ,
64- ) -> Result < Arc < H > , anyhow:: Error > ;
64+ ) -> Result < Option < Arc < H > > , anyhow:: Error > ;
6565}
Original file line number Diff line number Diff line change @@ -488,7 +488,7 @@ impl From<EthereumContractAbiEntity> for UnresolvedMappingABI {
488488 }
489489}
490490
491- #[ derive( Clone , Debug ) ]
491+ #[ derive( Clone , Debug , PartialEq ) ]
492492pub struct MappingABI {
493493 pub name : String ,
494494 pub contract : Contract ,
Original file line number Diff line number Diff line change 1+ use std:: cmp:: PartialEq ;
12use std:: collections:: HashMap ;
23use std:: str:: FromStr ;
34use std:: time:: { Duration , Instant } ;
@@ -719,3 +720,16 @@ impl RuntimeHostTrait for RuntimeHost {
719720 . await
720721 }
721722}
723+
724+ impl PartialEq for RuntimeHost {
725+ fn eq ( & self , other : & Self ) -> bool {
726+ // mapping_request_sender, host_exports and host_metrics are operational structs not needed
727+ // to define uniqueness; each runtime host should be for a unique data source.
728+ self . data_source_name == other. data_source_name
729+ && self . data_source_contract == other. data_source_contract
730+ && self . data_source_contract_abi == other. data_source_contract_abi
731+ && self . data_source_event_handlers == other. data_source_event_handlers
732+ && self . data_source_call_handlers == other. data_source_call_handlers
733+ && self . data_source_block_handlers == other. data_source_block_handlers
734+ }
735+ }
You can’t perform that action at this time.
0 commit comments