@@ -18,7 +18,7 @@ mod client;
18
18
19
19
use serde:: Deserialize ;
20
20
use std:: {
21
- collections:: HashMap ,
21
+ collections:: { BTreeMap , HashMap } ,
22
22
convert:: { TryFrom , TryInto } ,
23
23
path:: PathBuf ,
24
24
str:: FromStr ,
@@ -33,9 +33,7 @@ use sc_executor::{WasmExecutionMethod, WasmExecutor};
33
33
use sc_service:: { ChainSpec , ClientConfig , LocalCallExecutor , TransactionStorageMode } ;
34
34
use sp_api:: ConstructRuntimeApi ;
35
35
use sp_core:: traits:: SpawnNamed ;
36
- use sp_runtime:: traits:: { BlakeTwo256 , Block as BlockT } ;
37
- use sp_wasm_interface:: Function ;
38
- use sp_wasm_interface:: HostFunctions ;
36
+ use sp_runtime:: traits:: { BlakeTwo256 , Block as BlockT , NumberFor } ;
39
37
40
38
pub use self :: client:: { Client , GetMetadata } ;
41
39
use crate :: { database:: ReadOnlyDb , error:: BackendError , read_only_backend:: ReadOnlyBackend , RuntimeApiCollection } ;
@@ -44,7 +42,8 @@ use crate::{database::ReadOnlyDb, error::BackendError, read_only_backend::ReadOn
44
42
pub type TArchiveClient < TBl , TRtApi , D > = Client < TFullCallExecutor < TBl , D > , TBl , TRtApi , D > ;
45
43
46
44
/// Full client call executor type.
47
- type TFullCallExecutor < TBl , D > = LocalCallExecutor < TBl , ReadOnlyBackend < TBl , D > , WasmExecutor > ;
45
+ type TFullCallExecutor < TBl , D > =
46
+ LocalCallExecutor < TBl , ReadOnlyBackend < TBl , D > , WasmExecutor < sp_io:: SubstrateHostFunctions > > ;
48
47
49
48
#[ derive( Copy , Clone , Debug , Deserialize ) ]
50
49
pub enum ExecutionMethod {
@@ -67,6 +66,8 @@ impl From<ExecutionMethod> for WasmExecutionMethod {
67
66
}
68
67
}
69
68
69
+ /// Configuration controls how Archive executes blocks in `execute_block`
70
+ /// (in tasks.rs in `substrate-archive/`).
70
71
#[ derive( Clone , Debug , Deserialize ) ]
71
72
pub struct RuntimeConfig {
72
73
/// How to execute the runtime code: interpreted (default) or JIT compiled.
@@ -85,7 +86,7 @@ pub struct RuntimeConfig {
85
86
/// are included in the chain_spec and primarily for fixing problematic on-chain wasm.
86
87
/// If both are in use, the `wasm_runtime_overrides` takes precedence.
87
88
#[ serde( skip) ]
88
- code_substitutes : HashMap < String , Vec < u8 > > ,
89
+ code_substitutes : BTreeMap < String , Vec < u8 > > ,
89
90
/// Method of storing and retrieving transactions(extrinsics).
90
91
#[ serde( skip, default = "default_storage_mode" ) ]
91
92
pub storage_mode : TransactionStorageMode ,
@@ -123,36 +124,41 @@ const fn default_storage_mode() -> TransactionStorageMode {
123
124
impl < B > TryFrom < RuntimeConfig > for ClientConfig < B >
124
125
where
125
126
B : BlockT ,
126
- B :: Hash : FromStr ,
127
127
{
128
128
type Error = BackendError ;
129
129
fn try_from ( config : RuntimeConfig ) -> Result < ClientConfig < B > , BackendError > {
130
130
let wasm_runtime_substitutes = config
131
131
. code_substitutes
132
132
. into_iter ( )
133
- . map ( |( hash, code) | {
134
- let hash = B :: Hash :: from_str ( & hash) . map_err ( |_| {
135
- BackendError :: Msg ( format ! ( "Failed to parse `{}` as block hash for code substitute." , hash) )
133
+ . map ( |( n, code) | {
134
+ let number = NumberFor :: < B > :: from_str ( & n) . map_err ( |_| {
135
+ BackendError :: Msg ( format ! (
136
+ "Failed to parse `{}` as block number for code substitutes. \
137
+ In an old version the key for code substitute was a block hash. \
138
+ Please update the chain spec to a version that is compatible with your node.",
139
+ n
140
+ ) )
136
141
} ) ?;
137
- Ok ( ( hash , code) )
142
+ Ok ( ( number , code) )
138
143
} )
139
- . collect :: < Result < HashMap < B :: Hash , Vec < u8 > > , BackendError > > ( ) ?;
144
+ . collect :: < Result < HashMap < _ , _ > , BackendError > > ( ) ?;
140
145
141
146
Ok ( ClientConfig {
142
147
offchain_worker_enabled : false ,
143
148
offchain_indexing_api : false ,
144
149
wasm_runtime_overrides : config. wasm_runtime_overrides ,
145
- wasm_runtime_substitutes,
146
150
// we do not support 'no_genesis', so this value is inconsiquential
147
151
no_genesis : false ,
152
+ wasm_runtime_substitutes,
148
153
} )
149
154
}
150
155
}
151
156
157
+ /// Main entry to initialize the substrate-archive backend client, used to
158
+ /// call into the runtime of the network being indexed (e.g to execute blocks).
152
159
pub fn runtime_api < Block , Runtime , D : ReadOnlyDb + ' static > (
153
160
config : RuntimeConfig ,
154
161
backend : Arc < ReadOnlyBackend < Block , D > > ,
155
- host_functions : Option < Vec < & ' static dyn Function > > ,
156
162
task_executor : impl SpawnNamed + ' static ,
157
163
) -> Result < TArchiveClient < Block , Runtime , D > , BackendError >
158
164
where
@@ -165,11 +171,13 @@ where
165
171
+ ' static ,
166
172
<Runtime :: RuntimeApi as sp_api:: ApiExt < Block > >:: StateBackend : sp_api:: StateBackend < BlakeTwo256 > ,
167
173
{
168
- let host_functions =
169
- if let Some ( funcs) = host_functions { funcs } else { sp_io:: SubstrateHostFunctions :: host_functions ( ) } ;
170
-
171
- let executor =
172
- WasmExecutor :: new ( config. exec_method . into ( ) , config. wasm_pages , host_functions, config. block_workers , None ) ;
174
+ let executor = WasmExecutor :: < sp_io:: SubstrateHostFunctions > :: new (
175
+ config. exec_method . into ( ) ,
176
+ config. wasm_pages ,
177
+ config. block_workers ,
178
+ None ,
179
+ 128 ,
180
+ ) ;
173
181
let executor = LocalCallExecutor :: new ( backend. clone ( ) , executor, Box :: new ( task_executor) , config. try_into ( ) ?) ?;
174
182
let client = Client :: new ( backend, executor, ExecutionExtensions :: new ( execution_strategies ( ) , None , None ) ) ?;
175
183
Ok ( client)
0 commit comments