1818
1919//! Substrate Client
2020
21- use super :: {
22- block_rules:: { BlockRules , LookupResult as BlockLookupResult } ,
23- genesis:: BuildGenesisBlock ,
24- } ;
21+ use super :: block_rules:: { BlockRules , LookupResult as BlockLookupResult } ;
2522use futures:: { FutureExt , StreamExt } ;
2623use log:: { error, info, trace, warn} ;
2724use parking_lot:: { Mutex , RwLock } ;
2825use prometheus_endpoint:: Registry ;
2926use rand:: Rng ;
3027use sc_block_builder:: { BlockBuilderApi , BlockBuilderProvider , RecordProof } ;
28+ use sc_chain_spec:: { resolve_state_version_from_wasm, BuildGenesisBlock } ;
3129use sc_client_api:: {
3230 backend:: {
3331 self , apply_aux, BlockImportOperation , ClientImportOperation , FinalizeSummary , Finalizer ,
@@ -46,7 +44,7 @@ use sc_client_api::{
4644use sc_consensus:: {
4745 BlockCheckParams , BlockImportParams , ForkChoiceStrategy , ImportResult , StateAction ,
4846} ;
49- use sc_executor:: { RuntimeVersion , RuntimeVersionOf } ;
47+ use sc_executor:: RuntimeVersion ;
5048use sc_telemetry:: { telemetry, TelemetryHandle , SUBSTRATE_INFO } ;
5149use sp_api:: {
5250 ApiExt , ApiRef , CallApiAt , CallApiAtParams , ConstructRuntimeApi , Core as CoreApi ,
@@ -61,8 +59,8 @@ use sp_consensus::{BlockOrigin, BlockStatus, Error as ConsensusError};
6159use sc_utils:: mpsc:: { tracing_unbounded, TracingUnboundedSender } ;
6260use sp_core:: {
6361 storage:: {
64- well_known_keys, ChildInfo , ChildType , PrefixedStorageKey , Storage , StorageChild ,
65- StorageData , StorageKey ,
62+ well_known_keys, ChildInfo , ChildType , PrefixedStorageKey , StorageChild , StorageData ,
63+ StorageKey ,
6664 } ,
6765 traits:: SpawnNamed ,
6866} ;
@@ -84,7 +82,7 @@ use sp_state_machine::{
8482} ;
8583use sp_trie:: { CompactProof , StorageProof } ;
8684use std:: {
87- collections:: { hash_map :: DefaultHasher , HashMap , HashSet } ,
85+ collections:: { HashMap , HashSet } ,
8886 marker:: PhantomData ,
8987 path:: PathBuf ,
9088 sync:: Arc ,
@@ -172,7 +170,7 @@ pub fn new_in_mem<E, Block, G, RA>(
172170 Client < in_mem:: Backend < Block > , LocalCallExecutor < Block , in_mem:: Backend < Block > , E > , Block , RA > ,
173171>
174172where
175- E : CodeExecutor + RuntimeVersionOf ,
173+ E : CodeExecutor + sc_executor :: RuntimeVersionOf ,
176174 Block : BlockT ,
177175 G : BuildGenesisBlock <
178176 Block ,
@@ -233,7 +231,7 @@ pub fn new_with_backend<B, E, Block, G, RA>(
233231 config : ClientConfig < Block > ,
234232) -> sp_blockchain:: Result < Client < B , LocalCallExecutor < Block , B , E > , Block , RA > >
235233where
236- E : CodeExecutor + RuntimeVersionOf ,
234+ E : CodeExecutor + sc_executor :: RuntimeVersionOf ,
237235 G : BuildGenesisBlock <
238236 Block ,
239237 BlockImportOperation = <B as backend:: Backend < Block > >:: BlockImportOperation ,
@@ -1222,38 +1220,6 @@ where
12221220 }
12231221}
12241222
1225- /// Return the genesis state version given the genesis storage and executor.
1226- pub fn resolve_state_version_from_wasm < E > (
1227- storage : & Storage ,
1228- executor : & E ,
1229- ) -> sp_blockchain:: Result < StateVersion >
1230- where
1231- E : RuntimeVersionOf ,
1232- {
1233- if let Some ( wasm) = storage. top . get ( well_known_keys:: CODE ) {
1234- let mut ext = sp_state_machine:: BasicExternalities :: new_empty ( ) ; // just to read runtime version.
1235-
1236- let code_fetcher = sp_core:: traits:: WrappedRuntimeCode ( wasm. as_slice ( ) . into ( ) ) ;
1237- let runtime_code = sp_core:: traits:: RuntimeCode {
1238- code_fetcher : & code_fetcher,
1239- heap_pages : None ,
1240- hash : {
1241- use std:: hash:: { Hash , Hasher } ;
1242- let mut state = DefaultHasher :: new ( ) ;
1243- wasm. hash ( & mut state) ;
1244- state. finish ( ) . to_le_bytes ( ) . to_vec ( )
1245- } ,
1246- } ;
1247- let runtime_version = RuntimeVersionOf :: runtime_version ( executor, & mut ext, & runtime_code)
1248- . map_err ( |e| sp_blockchain:: Error :: VersionInvalid ( e. to_string ( ) ) ) ?;
1249- Ok ( runtime_version. state_version ( ) )
1250- } else {
1251- Err ( sp_blockchain:: Error :: VersionInvalid (
1252- "Runtime missing from initial storage, could not read state version." . to_string ( ) ,
1253- ) )
1254- }
1255- }
1256-
12571223impl < B , E , Block , RA > UsageProvider < Block > for Client < B , E , Block , RA >
12581224where
12591225 B : backend:: Backend < Block > ,
0 commit comments