Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
crystalin committed Sep 28, 2023
1 parent cd1f07c commit a9953bd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 32 deletions.
6 changes: 2 additions & 4 deletions substrate/client/chain-spec/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ use std::{marker::PhantomData, sync::Arc};
use sc_client_api::{backend::Backend, BlockImportOperation};
use sc_executor::RuntimeVersionOf;
use sp_core::{
storage::{
well_known_keys, StateVersion, Storage
},
Blake2Hasher
storage::{well_known_keys, StateVersion, Storage},
Blake2Hasher,
};

use sp_runtime::{
Expand Down
13 changes: 7 additions & 6 deletions substrate/client/cli/src/commands/precompile_wasm_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ use crate::{

use clap::Parser;
use sc_client_api::{Backend, HeaderBackend};
use sp_core::traits::RuntimeCode;
use sc_executor::{
precompile_and_serialize_versioned_wasm_runtime, HeapAllocStrategy, DEFAULT_HEAP_ALLOC_PAGES,
};
use sp_runtime::traits::Block as BlockT;
use sc_service::ChainSpec;
use sp_core::traits::RuntimeCode;
use sp_runtime::traits::Block as BlockT;
use sp_state_machine::backend::BackendRuntimeCode;
use std::{fmt::Debug, path::PathBuf, sync::Arc};

Expand Down Expand Up @@ -81,7 +81,7 @@ pub struct PrecompileWasmCmd {

impl PrecompileWasmCmd {
/// Run the precompile-wasm command
pub async fn run<B, BA>(&self, backend: Arc<BA>, spec: Box<dyn ChainSpec>,) -> error::Result<()>
pub async fn run<B, BA>(&self, backend: Arc<BA>, spec: Box<dyn ChainSpec>) -> error::Result<()>
where
B: BlockT,
BA: Backend<B>,
Expand All @@ -92,7 +92,7 @@ impl PrecompileWasmCmd {

if backend.have_state_at(blockchain_info.finalized_hash, blockchain_info.finalized_number) {
let state = backend.state_at(backend.blockchain().info().finalized_hash)?;

precompile_and_serialize_versioned_wasm_runtime(
HeapAllocStrategy::Static { extra_pages: heap_pages },
&BackendRuntimeCode::new(&state).runtime_code()?,
Expand All @@ -107,7 +107,9 @@ impl PrecompileWasmCmd {
let storage = spec.as_storage_builder().build_storage()?;
if let Some(wasm_bytecode) = storage.top.get(sp_storage::well_known_keys::CODE) {
let runtime_code = RuntimeCode {
code_fetcher: &sp_core::traits::WrappedRuntimeCode(wasm_bytecode.as_slice().into()),
code_fetcher: &sp_core::traits::WrappedRuntimeCode(
wasm_bytecode.as_slice().into(),
),
hash: sp_core::blake2_256(&wasm_bytecode).to_vec(),
heap_pages: Some(heap_pages as u64),
};
Expand All @@ -124,7 +126,6 @@ impl PrecompileWasmCmd {
}
}


Ok(())
}
}
Expand Down
41 changes: 19 additions & 22 deletions substrate/client/executor/src/wasm_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,25 +321,22 @@ where
return Err(WasmError::Instantiation(format!(
"--wasmtime-precompiled is not a directory: {}",
wasmtime_precompiled_dir.display()
)))
)));
}
let handle_err = |e: std::io::Error| -> WasmError {
return WasmError::Instantiation(format!(
"Io error when loading wasmtime precompiled folder ({}): {}",
wasmtime_precompiled_dir.display(),
e
))
));
};
let mut maybe_compiled_artifact = None;

let artifact_version = compute_artifact_version(
allow_missing_func_imports,
code_hash,
&semantics,
);

let artifact_version =
compute_artifact_version(allow_missing_func_imports, code_hash, &semantics);
log::debug!(
target: "wasmtime-runtime",
"Searching for wasm hash: {}",
target: "wasmtime-runtime",
"Searching for wasm hash: {}",
artifact_version.clone()
);

Expand All @@ -350,8 +347,8 @@ where
// version and with the same wasm interface version and configuration.
if file_name.contains(&artifact_version.clone()) {
log::info!(
target: "wasmtime-runtime",
"Found precompiled wasm: {}",
target: "wasmtime-runtime",
"Found precompiled wasm: {}",
file_name
);
// We change the version check strategy to make sure that the file
Expand All @@ -367,7 +364,7 @@ where
return Err(WasmError::Instantiation(
"wasmtime precompiled folder contain a file with invalid utf8 name"
.to_owned(),
))
));
}
}

Expand Down Expand Up @@ -427,7 +424,7 @@ pub fn precompile_and_serialize_versioned_wasm_runtime<'c>(
wasmtime_precompiled_path: &Path,
) -> Result<(), WasmError> {
let semantics = match wasm_method {
WasmExecutionMethod::Compiled { instantiation_strategy } =>
WasmExecutionMethod::Compiled { instantiation_strategy } => {
sc_executor_wasmtime::Semantics {
heap_alloc_strategy,
instantiation_strategy,
Expand All @@ -438,16 +435,16 @@ pub fn precompile_and_serialize_versioned_wasm_runtime<'c>(
wasm_bulk_memory: false,
wasm_reference_types: false,
wasm_simd: false,
},
}
},
};

let code_hash = &runtime_code.hash;

let artifact_version =
compute_artifact_version(false, code_hash, &semantics);
let artifact_version = compute_artifact_version(false, code_hash, &semantics);
log::debug!(
target: "wasmtime-runtime",
"Generated precompiled wasm hash: {}",
target: "wasmtime-runtime",
"Generated precompiled wasm hash: {}",
artifact_version.clone()
);

Expand Down Expand Up @@ -488,9 +485,9 @@ fn compute_artifact_version(
semantics: &sc_executor_wasmtime::Semantics,
) -> String {
log::trace!(
target: "wasmtime-runtime",
"Computing wasm runtime hash [allow_missing_func_imports: {}, code_hash: {:?}, semantics: {:?}]",
allow_missing_func_imports, code_hash, semantics
target: "wasmtime-runtime",
"Computing wasm runtime hash [allow_missing_func_imports: {}, code_hash: {}, semantics: {:?}]",
allow_missing_func_imports, sp_core::bytes::to_hex(&code_hash, false), semantics
);
let mut buffer = Vec::new();
buffer.extend_from_slice(code_hash);
Expand Down

0 comments on commit a9953bd

Please sign in to comment.