7272 // we use the same order here as in the subgraph manifest to make the
7373 // event processing behavior predictable
7474 for ds in manifest. data_sources {
75+ let runtime = ds. runtime ( ) ;
76+ let module_bytes = match runtime {
77+ None => continue ,
78+ Some ( ref module_bytes) => module_bytes,
79+ } ;
80+
7581 let host = this. new_host (
7682 logger. cheap_clone ( ) ,
7783 ds,
84+ module_bytes,
7885 templates. cheap_clone ( ) ,
7986 host_metrics. cheap_clone ( ) ,
8087 ) ?;
@@ -84,21 +91,23 @@ where
8491 Ok ( this)
8592 }
8693
94+ // module_bytes is the same as data_source.runtime().unwrap(), this is to ensure that this
95+ // function is only called for data_sources for which data_source.runtime().is_some() is true.
8796 fn new_host (
8897 & mut self ,
8998 logger : Logger ,
9099 data_source : C :: DataSource ,
100+ module_bytes : & Arc < Vec < u8 > > ,
91101 templates : Arc < Vec < C :: DataSourceTemplate > > ,
92102 host_metrics : Arc < HostMetrics > ,
93103 ) -> Result < T :: Host , Error > {
94104 let mapping_request_sender = {
95- let module_bytes = data_source. runtime ( ) ;
96- let module_hash = tiny_keccak:: keccak256 ( module_bytes) ;
105+ let module_hash = tiny_keccak:: keccak256 ( module_bytes. as_ref ( ) ) ;
97106 if let Some ( sender) = self . module_cache . get ( & module_hash) {
98107 sender. clone ( )
99108 } else {
100109 let sender = T :: spawn_mapping (
101- module_bytes. to_owned ( ) ,
110+ module_bytes. as_ref ( ) ,
102111 logger,
103112 self . subgraph_id . clone ( ) ,
104113 host_metrics. clone ( ) ,
@@ -167,7 +176,18 @@ where
167176 <= data_source. creation_block( )
168177 ) ;
169178
170- let host = Arc :: new ( self . new_host ( logger. clone ( ) , data_source, templates, metrics) ?) ;
179+ let module_bytes = match & data_source. runtime ( ) {
180+ None => return Ok ( None ) ,
181+ Some ( ref module_bytes) => module_bytes. cheap_clone ( ) ,
182+ } ;
183+
184+ let host = Arc :: new ( self . new_host (
185+ logger. clone ( ) ,
186+ data_source,
187+ & module_bytes,
188+ templates,
189+ metrics,
190+ ) ?) ;
171191
172192 Ok ( if self . hosts . contains ( & host) {
173193 None
0 commit comments