@@ -81,32 +81,32 @@ where
81
81
fn check_override < ' a > (
82
82
& ' a self ,
83
83
onchain_code : RuntimeCode < ' a > ,
84
- id : & BlockId < Block > ,
84
+ hash : <Block as BlockT > :: Hash ,
85
85
) -> sp_blockchain:: Result < ( RuntimeCode < ' a > , RuntimeVersion ) >
86
86
where
87
87
Block : BlockT ,
88
88
B : backend:: Backend < Block > ,
89
89
{
90
- let on_chain_version = self . on_chain_runtime_version ( id ) ?;
90
+ let on_chain_version = self . on_chain_runtime_version ( hash ) ?;
91
91
let code_and_version = if let Some ( d) = self . wasm_override . as_ref ( ) . as_ref ( ) . and_then ( |o| {
92
92
o. get (
93
93
& on_chain_version. spec_version ,
94
94
onchain_code. heap_pages ,
95
95
& on_chain_version. spec_name ,
96
96
)
97
97
} ) {
98
- log:: debug!( target: "wasm_overrides" , "using WASM override for block {}" , id ) ;
98
+ log:: debug!( target: "wasm_overrides" , "using WASM override for block {}" , hash ) ;
99
99
d
100
100
} else if let Some ( s) =
101
101
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 )
103
103
{
104
- log:: debug!( target: "wasm_substitutes" , "Using WASM substitute for block {:?}" , id ) ;
104
+ log:: debug!( target: "wasm_substitutes" , "Using WASM substitute for block {:?}" , hash ) ;
105
105
s
106
106
} else {
107
107
log:: debug!(
108
108
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" ,
110
110
) ;
111
111
( onchain_code, on_chain_version)
112
112
} ;
@@ -115,14 +115,10 @@ where
115
115
}
116
116
117
117
/// 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 > {
122
119
let mut overlay = OverlayedChanges :: default ( ) ;
123
120
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) ?;
126
122
let mut cache = StorageTransactionCache :: < Block , B :: State > :: default ( ) ;
127
123
let mut ext = Ext :: new ( & mut overlay, & mut cache, & state, None ) ;
128
124
let state_runtime_code = sp_state_machine:: backend:: BackendRuntimeCode :: new ( & state) ;
@@ -166,21 +162,21 @@ where
166
162
167
163
fn call (
168
164
& self ,
169
- at : & BlockId < Block > ,
165
+ at_hash : Block :: Hash ,
170
166
method : & str ,
171
167
call_data : & [ u8 ] ,
172
168
strategy : ExecutionStrategy ,
173
169
) -> sp_blockchain:: Result < Vec < u8 > > {
174
170
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 ) ) ?;
177
173
let state = self . backend . state_at ( at_hash) ?;
178
174
179
175
let state_runtime_code = sp_state_machine:: backend:: BackendRuntimeCode :: new ( & state) ;
180
176
let runtime_code =
181
177
state_runtime_code. runtime_code ( ) . map_err ( sp_blockchain:: Error :: RuntimeCode ) ?;
182
178
183
- let runtime_code = self . check_override ( runtime_code, at ) ?. 0 ;
179
+ let runtime_code = self . check_override ( runtime_code, at_hash ) ?. 0 ;
184
180
185
181
let extensions = self . execution_extensions . extensions (
186
182
at_hash,
@@ -206,7 +202,7 @@ where
206
202
207
203
fn contextual_call (
208
204
& self ,
209
- at : & BlockId < Block > ,
205
+ at_hash : Block :: Hash ,
210
206
method : & str ,
211
207
call_data : & [ u8 ] ,
212
208
changes : & RefCell < OverlayedChanges > ,
@@ -216,8 +212,8 @@ where
216
212
) -> Result < Vec < u8 > , sp_blockchain:: Error > {
217
213
let mut storage_transaction_cache = storage_transaction_cache. map ( |c| c. borrow_mut ( ) ) ;
218
214
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 ) ) ?;
221
217
let state = self . backend . state_at ( at_hash) ?;
222
218
223
219
let ( execution_manager, extensions) =
@@ -232,7 +228,7 @@ where
232
228
233
229
let runtime_code =
234
230
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 ;
236
232
237
233
match recorder {
238
234
Some ( recorder) => {
@@ -275,32 +271,31 @@ where
275
271
. map_err ( Into :: into)
276
272
}
277
273
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 > {
280
275
let state = self . backend . state_at ( at_hash) ?;
281
276
let state_runtime_code = sp_state_machine:: backend:: BackendRuntimeCode :: new ( & state) ;
282
277
283
278
let runtime_code =
284
279
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)
286
281
}
287
282
288
283
fn prove_execution (
289
284
& self ,
290
- at : & BlockId < Block > ,
285
+ at_hash : Block :: Hash ,
291
286
method : & str ,
292
287
call_data : & [ u8 ] ,
293
288
) -> 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 ) ) ?;
296
291
let state = self . backend . state_at ( at_hash) ?;
297
292
298
293
let trie_backend = state. as_trie_backend ( ) ;
299
294
300
295
let state_runtime_code = sp_state_machine:: backend:: BackendRuntimeCode :: new ( trie_backend) ;
301
296
let runtime_code =
302
297
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 ;
304
299
305
300
sp_state_machine:: prove_execution_on_trie_backend (
306
301
trie_backend,
@@ -340,7 +335,7 @@ where
340
335
E : CodeExecutor + RuntimeVersionOf + Clone + ' static ,
341
336
Block : BlockT ,
342
337
{
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 > {
344
339
CallExecutor :: runtime_version ( self , at) . map_err ( |e| e. to_string ( ) )
345
340
}
346
341
}
@@ -359,6 +354,7 @@ where
359
354
#[ cfg( test) ]
360
355
mod tests {
361
356
use super :: * ;
357
+ use backend:: Backend ;
362
358
use sc_client_api:: in_mem;
363
359
use sc_executor:: { NativeElseWasmExecutor , WasmExecutionMethod } ;
364
360
use sp_core:: {
@@ -432,7 +428,7 @@ mod tests {
432
428
} ;
433
429
434
430
let check = call_executor
435
- . check_override ( onchain_code, & BlockId :: Number ( Default :: default ( ) ) )
431
+ . check_override ( onchain_code, backend . blockchain ( ) . info ( ) . genesis_hash )
436
432
. expect ( "RuntimeCode override" )
437
433
. 0 ;
438
434
0 commit comments