@@ -81,32 +81,32 @@ where
8181 fn check_override < ' a > (
8282 & ' a self ,
8383 onchain_code : RuntimeCode < ' a > ,
84- id : & BlockId < Block > ,
84+ hash : <Block as BlockT > :: Hash ,
8585 ) -> sp_blockchain:: Result < ( RuntimeCode < ' a > , RuntimeVersion ) >
8686 where
8787 Block : BlockT ,
8888 B : backend:: Backend < Block > ,
8989 {
90- let on_chain_version = self . on_chain_runtime_version ( id ) ?;
90+ let on_chain_version = self . on_chain_runtime_version ( hash ) ?;
9191 let code_and_version = if let Some ( d) = self . wasm_override . as_ref ( ) . as_ref ( ) . and_then ( |o| {
9292 o. get (
9393 & on_chain_version. spec_version ,
9494 onchain_code. heap_pages ,
9595 & on_chain_version. spec_name ,
9696 )
9797 } ) {
98- log:: debug!( target: "wasm_overrides" , "using WASM override for block {}" , id ) ;
98+ log:: debug!( target: "wasm_overrides" , "using WASM override for block {}" , hash ) ;
9999 d
100100 } else if let Some ( s) =
101101 self . wasm_substitutes
102- . get ( on_chain_version. spec_version , onchain_code. heap_pages , id )
102+ . get ( on_chain_version. spec_version , onchain_code. heap_pages , hash )
103103 {
104- log:: debug!( target: "wasm_substitutes" , "Using WASM substitute for block {:?}" , id ) ;
104+ log:: debug!( target: "wasm_substitutes" , "Using WASM substitute for block {:?}" , hash ) ;
105105 s
106106 } else {
107107 log:: debug!(
108108 target: "wasm_overrides" ,
109- "Neither WASM override nor substitute available for block {id }, using onchain code" ,
109+ "Neither WASM override nor substitute available for block {hash }, using onchain code" ,
110110 ) ;
111111 ( onchain_code, on_chain_version)
112112 } ;
@@ -115,14 +115,10 @@ where
115115 }
116116
117117 /// Returns the on chain runtime version.
118- fn on_chain_runtime_version (
119- & self ,
120- id : & BlockId < Block > ,
121- ) -> sp_blockchain:: Result < RuntimeVersion > {
118+ fn on_chain_runtime_version ( & self , hash : Block :: Hash ) -> sp_blockchain:: Result < RuntimeVersion > {
122119 let mut overlay = OverlayedChanges :: default ( ) ;
123120
124- let at_hash = self . backend . blockchain ( ) . expect_block_hash_from_id ( id) ?;
125- let state = self . backend . state_at ( at_hash) ?;
121+ let state = self . backend . state_at ( hash) ?;
126122 let mut cache = StorageTransactionCache :: < Block , B :: State > :: default ( ) ;
127123 let mut ext = Ext :: new ( & mut overlay, & mut cache, & state, None ) ;
128124 let state_runtime_code = sp_state_machine:: backend:: BackendRuntimeCode :: new ( & state) ;
@@ -166,21 +162,21 @@ where
166162
167163 fn call (
168164 & self ,
169- at : & BlockId < Block > ,
165+ at_hash : Block :: Hash ,
170166 method : & str ,
171167 call_data : & [ u8 ] ,
172168 strategy : ExecutionStrategy ,
173169 ) -> sp_blockchain:: Result < Vec < u8 > > {
174170 let mut changes = OverlayedChanges :: default ( ) ;
175- let at_hash = self . backend . blockchain ( ) . expect_block_hash_from_id ( at ) ? ;
176- let at_number = self . backend . blockchain ( ) . expect_block_number_from_id ( at ) ?;
171+ let at_number =
172+ self . backend . blockchain ( ) . expect_block_number_from_id ( & BlockId :: Hash ( at_hash ) ) ?;
177173 let state = self . backend . state_at ( at_hash) ?;
178174
179175 let state_runtime_code = sp_state_machine:: backend:: BackendRuntimeCode :: new ( & state) ;
180176 let runtime_code =
181177 state_runtime_code. runtime_code ( ) . map_err ( sp_blockchain:: Error :: RuntimeCode ) ?;
182178
183- let runtime_code = self . check_override ( runtime_code, at ) ?. 0 ;
179+ let runtime_code = self . check_override ( runtime_code, at_hash ) ?. 0 ;
184180
185181 let extensions = self . execution_extensions . extensions (
186182 at_hash,
@@ -206,7 +202,7 @@ where
206202
207203 fn contextual_call (
208204 & self ,
209- at : & BlockId < Block > ,
205+ at_hash : Block :: Hash ,
210206 method : & str ,
211207 call_data : & [ u8 ] ,
212208 changes : & RefCell < OverlayedChanges > ,
@@ -216,8 +212,8 @@ where
216212 ) -> Result < Vec < u8 > , sp_blockchain:: Error > {
217213 let mut storage_transaction_cache = storage_transaction_cache. map ( |c| c. borrow_mut ( ) ) ;
218214
219- let at_hash = self . backend . blockchain ( ) . expect_block_hash_from_id ( at ) ? ;
220- let at_number = self . backend . blockchain ( ) . expect_block_number_from_id ( at ) ?;
215+ let at_number =
216+ self . backend . blockchain ( ) . expect_block_number_from_id ( & BlockId :: Hash ( at_hash ) ) ?;
221217 let state = self . backend . state_at ( at_hash) ?;
222218
223219 let ( execution_manager, extensions) =
@@ -232,7 +228,7 @@ where
232228
233229 let runtime_code =
234230 state_runtime_code. runtime_code ( ) . map_err ( sp_blockchain:: Error :: RuntimeCode ) ?;
235- let runtime_code = self . check_override ( runtime_code, at ) ?. 0 ;
231+ let runtime_code = self . check_override ( runtime_code, at_hash ) ?. 0 ;
236232
237233 match recorder {
238234 Some ( recorder) => {
@@ -275,32 +271,31 @@ where
275271 . map_err ( Into :: into)
276272 }
277273
278- fn runtime_version ( & self , id : & BlockId < Block > ) -> sp_blockchain:: Result < RuntimeVersion > {
279- let at_hash = self . backend . blockchain ( ) . expect_block_hash_from_id ( id) ?;
274+ fn runtime_version ( & self , at_hash : Block :: Hash ) -> sp_blockchain:: Result < RuntimeVersion > {
280275 let state = self . backend . state_at ( at_hash) ?;
281276 let state_runtime_code = sp_state_machine:: backend:: BackendRuntimeCode :: new ( & state) ;
282277
283278 let runtime_code =
284279 state_runtime_code. runtime_code ( ) . map_err ( sp_blockchain:: Error :: RuntimeCode ) ?;
285- self . check_override ( runtime_code, id ) . map ( |( _, v) | v)
280+ self . check_override ( runtime_code, at_hash ) . map ( |( _, v) | v)
286281 }
287282
288283 fn prove_execution (
289284 & self ,
290- at : & BlockId < Block > ,
285+ at_hash : Block :: Hash ,
291286 method : & str ,
292287 call_data : & [ u8 ] ,
293288 ) -> sp_blockchain:: Result < ( Vec < u8 > , StorageProof ) > {
294- let at_hash = self . backend . blockchain ( ) . expect_block_hash_from_id ( at ) ? ;
295- let at_number = self . backend . blockchain ( ) . expect_block_number_from_id ( at ) ?;
289+ let at_number =
290+ self . backend . blockchain ( ) . expect_block_number_from_id ( & BlockId :: Hash ( at_hash ) ) ?;
296291 let state = self . backend . state_at ( at_hash) ?;
297292
298293 let trie_backend = state. as_trie_backend ( ) ;
299294
300295 let state_runtime_code = sp_state_machine:: backend:: BackendRuntimeCode :: new ( trie_backend) ;
301296 let runtime_code =
302297 state_runtime_code. runtime_code ( ) . map_err ( sp_blockchain:: Error :: RuntimeCode ) ?;
303- let runtime_code = self . check_override ( runtime_code, at ) ?. 0 ;
298+ let runtime_code = self . check_override ( runtime_code, at_hash ) ?. 0 ;
304299
305300 sp_state_machine:: prove_execution_on_trie_backend (
306301 trie_backend,
@@ -340,7 +335,7 @@ where
340335 E : CodeExecutor + RuntimeVersionOf + Clone + ' static ,
341336 Block : BlockT ,
342337{
343- fn runtime_version ( & self , at : & BlockId < Block > ) -> Result < sp_version:: RuntimeVersion , String > {
338+ fn runtime_version ( & self , at : Block :: Hash ) -> Result < sp_version:: RuntimeVersion , String > {
344339 CallExecutor :: runtime_version ( self , at) . map_err ( |e| e. to_string ( ) )
345340 }
346341}
@@ -359,6 +354,7 @@ where
359354#[ cfg( test) ]
360355mod tests {
361356 use super :: * ;
357+ use backend:: Backend ;
362358 use sc_client_api:: in_mem;
363359 use sc_executor:: { NativeElseWasmExecutor , WasmExecutionMethod } ;
364360 use sp_core:: {
@@ -432,7 +428,7 @@ mod tests {
432428 } ;
433429
434430 let check = call_executor
435- . check_override ( onchain_code, & BlockId :: Number ( Default :: default ( ) ) )
431+ . check_override ( onchain_code, backend . blockchain ( ) . info ( ) . genesis_hash )
436432 . expect ( "RuntimeCode override" )
437433 . 0 ;
438434
0 commit comments