mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 01:11:10 +00:00
Apply some clippy lints (#11154)
* Apply some clippy hints * Revert clippy ci changes * Update client/cli/src/commands/generate.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/cli/src/commands/inspect_key.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/db/src/bench.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/db/src/bench.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/service/src/client/block_rules.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/service/src/client/block_rules.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/network/src/transactions.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/network/src/protocol.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Revert due to missing `or_default` function. * Fix compilation and simplify code * Undo change that corrupts benchmark. * fix clippy * Update client/service/test/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/state-db/src/noncanonical.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/state-db/src/noncanonical.rs remove leftovers! * Update client/tracing/src/logging/directives.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update utils/fork-tree/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * added needed ref * Update frame/referenda/src/benchmarking.rs * Simplify byte-vec creation * let's just not overlap the ranges * Correction * cargo fmt * Update utils/frame/benchmarking-cli/src/shared/stats.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update utils/frame/benchmarking-cli/src/pallet/command.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update utils/frame/benchmarking-cli/src/pallet/command.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Giles Cope <gilescope@gmail.com>
This commit is contained in:
committed by
GitHub
parent
a990473cf9
commit
b581604aa7
@@ -39,7 +39,7 @@ impl DataSegmentsSnapshot {
|
||||
.map(|mut segment| {
|
||||
// Just replace contents of the segment since the segments will be discarded later
|
||||
// anyway.
|
||||
let contents = mem::replace(segment.value_mut(), vec![]);
|
||||
let contents = mem::take(segment.value_mut());
|
||||
|
||||
let init_expr = match segment.offset() {
|
||||
Some(offset) => offset.code(),
|
||||
|
||||
@@ -187,9 +187,7 @@ impl RuntimeBlob {
|
||||
}
|
||||
|
||||
/// Returns an iterator of all globals which were exported by [`expose_mutable_globals`].
|
||||
pub(super) fn exported_internal_global_names<'module>(
|
||||
&'module self,
|
||||
) -> impl Iterator<Item = &'module str> {
|
||||
pub(super) fn exported_internal_global_names(&self) -> impl Iterator<Item = &str> {
|
||||
let exports = self.raw_module.export_section().map(|es| es.entries()).unwrap_or(&[]);
|
||||
exports.iter().filter_map(|export| match export.internal() {
|
||||
Internal::Global(_) if export.field().starts_with("exported_internal_global") =>
|
||||
|
||||
@@ -264,8 +264,8 @@ fn decode_environment_definition(
|
||||
let memory_ref = memories
|
||||
.get(memory_idx as usize)
|
||||
.cloned()
|
||||
.ok_or_else(|| InstantiationError::EnvironmentDefinitionCorrupted)?
|
||||
.ok_or_else(|| InstantiationError::EnvironmentDefinitionCorrupted)?;
|
||||
.ok_or(InstantiationError::EnvironmentDefinitionCorrupted)?
|
||||
.ok_or(InstantiationError::EnvironmentDefinitionCorrupted)?;
|
||||
memories_map.insert((module, field), memory_ref);
|
||||
},
|
||||
}
|
||||
@@ -458,7 +458,7 @@ impl<DT: Clone> Store<DT> {
|
||||
};
|
||||
|
||||
let mem_idx = memories.len();
|
||||
memories.push(Some(memory.clone()));
|
||||
memories.push(Some(memory));
|
||||
|
||||
Ok(mem_idx as u32)
|
||||
}
|
||||
@@ -472,7 +472,7 @@ impl<DT: Clone> Store<DT> {
|
||||
pub fn instance(&self, instance_idx: u32) -> Result<Rc<SandboxInstance>> {
|
||||
self.instances
|
||||
.get(instance_idx as usize)
|
||||
.ok_or_else(|| "Trying to access a non-existent instance")?
|
||||
.ok_or("Trying to access a non-existent instance")?
|
||||
.as_ref()
|
||||
.map(|v| v.0.clone())
|
||||
.ok_or_else(|| "Trying to access a torndown instance".into())
|
||||
@@ -488,7 +488,7 @@ impl<DT: Clone> Store<DT> {
|
||||
self.instances
|
||||
.get(instance_idx as usize)
|
||||
.as_ref()
|
||||
.ok_or_else(|| "Trying to access a non-existent instance")?
|
||||
.ok_or("Trying to access a non-existent instance")?
|
||||
.as_ref()
|
||||
.map(|v| v.1.clone())
|
||||
.ok_or_else(|| "Trying to access a torndown instance".into())
|
||||
@@ -504,7 +504,7 @@ impl<DT: Clone> Store<DT> {
|
||||
self.memories
|
||||
.get(memory_idx as usize)
|
||||
.cloned()
|
||||
.ok_or_else(|| "Trying to access a non-existent sandboxed memory")?
|
||||
.ok_or("Trying to access a non-existent sandboxed memory")?
|
||||
.ok_or_else(|| "Trying to access a torndown sandboxed memory".into())
|
||||
}
|
||||
|
||||
@@ -564,7 +564,7 @@ impl<DT: Clone> Store<DT> {
|
||||
|
||||
#[cfg(feature = "wasmer-sandbox")]
|
||||
BackendContext::Wasmer(ref context) =>
|
||||
wasmer_instantiate(&context, wasm, guest_env, state, sandbox_context)?,
|
||||
wasmer_instantiate(context, wasm, guest_env, state, sandbox_context)?,
|
||||
};
|
||||
|
||||
Ok(UnregisteredInstance { sandbox_instance })
|
||||
|
||||
@@ -113,7 +113,7 @@ pub fn instantiate(
|
||||
type Exports = HashMap<String, wasmer::Exports>;
|
||||
let mut exports_map = Exports::new();
|
||||
|
||||
for import in module.imports().into_iter() {
|
||||
for import in module.imports() {
|
||||
match import.ty() {
|
||||
// Nothing to do here
|
||||
wasmer::ExternType::Global(_) | wasmer::ExternType::Table(_) => (),
|
||||
@@ -121,7 +121,7 @@ pub fn instantiate(
|
||||
wasmer::ExternType::Memory(_) => {
|
||||
let exports = exports_map
|
||||
.entry(import.module().to_string())
|
||||
.or_insert(wasmer::Exports::new());
|
||||
.or_insert_with(wasmer::Exports::new);
|
||||
|
||||
let memory = guest_env
|
||||
.imports
|
||||
@@ -173,7 +173,7 @@ pub fn instantiate(
|
||||
|
||||
let exports = exports_map
|
||||
.entry(import.module().to_string())
|
||||
.or_insert(wasmer::Exports::new());
|
||||
.or_insert_with(wasmer::Exports::new);
|
||||
|
||||
exports.insert(import.name(), wasmer::Extern::Function(function));
|
||||
},
|
||||
|
||||
@@ -78,7 +78,7 @@ impl ImportResolver for Imports {
|
||||
// Here we use inner memory reference only to resolve the imports
|
||||
// without accessing the memory contents. All subsequent memory accesses
|
||||
// should happen through the wrapper, that enforces the memory access protocol.
|
||||
let mem = wrapper.0.clone();
|
||||
let mem = wrapper.0;
|
||||
|
||||
Ok(mem)
|
||||
}
|
||||
@@ -247,7 +247,7 @@ impl<'a> wasmi::Externals for GuestExternals<'a> {
|
||||
serialized_result_val_ptr,
|
||||
"Can't deallocate memory for dispatch thunk's result",
|
||||
)
|
||||
.and_then(|_| serialized_result_val)
|
||||
.and(serialized_result_val)
|
||||
.and_then(|serialized_result_val| {
|
||||
let result_val = std::result::Result::<ReturnValue, HostError>::decode(&mut serialized_result_val.as_slice())
|
||||
.map_err(|_| trap("Decoding Result<ReturnValue, HostError> failed!"))?;
|
||||
|
||||
@@ -253,7 +253,7 @@ where
|
||||
wasm_code: &[u8],
|
||||
ext: &mut dyn Externalities,
|
||||
) -> std::result::Result<Vec<u8>, String> {
|
||||
let runtime_blob = RuntimeBlob::uncompress_if_needed(&wasm_code)
|
||||
let runtime_blob = RuntimeBlob::uncompress_if_needed(wasm_code)
|
||||
.map_err(|e| format!("Failed to create runtime blob: {:?}", e))?;
|
||||
|
||||
if let Some(version) = crate::wasm_runtime::read_embedded_version(&runtime_blob)
|
||||
@@ -493,8 +493,7 @@ impl RuntimeSpawn for RuntimeInstanceSpawn {
|
||||
|
||||
fn join(&self, handle: u64) -> Vec<u8> {
|
||||
let receiver = self.tasks.lock().remove(&handle).expect("No task for the handle");
|
||||
let output = receiver.recv().expect("Spawned task panicked for the handle");
|
||||
output
|
||||
receiver.recv().expect("Spawned task panicked for the handle")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -368,7 +368,7 @@ pub fn read_embedded_version(blob: &RuntimeBlob) -> Result<Option<RuntimeVersion
|
||||
.transpose()?
|
||||
.map(Into::into);
|
||||
|
||||
let core_version = apis.as_ref().and_then(|apis| sp_version::core_version_from_apis(apis));
|
||||
let core_version = apis.as_ref().and_then(sp_version::core_version_from_apis);
|
||||
// We do not use `RuntimeVersion::decode` here because that `decode_version` relies on
|
||||
// presence of a special API in the `apis` field to treat the input as a non-legacy version.
|
||||
// However the structure found in the `runtime_version` always contain an empty `apis`
|
||||
@@ -403,7 +403,7 @@ where
|
||||
{
|
||||
// The incoming code may be actually compressed. We decompress it here and then work with
|
||||
// the uncompressed code from now on.
|
||||
let blob = sc_executor_common::runtime_blob::RuntimeBlob::uncompress_if_needed(&code)?;
|
||||
let blob = sc_executor_common::runtime_blob::RuntimeBlob::uncompress_if_needed(code)?;
|
||||
|
||||
// Use the runtime blob to scan if there is any metadata embedded into the wasm binary
|
||||
// pertaining to runtime version. We do it before consuming the runtime blob for creating the
|
||||
|
||||
@@ -103,7 +103,7 @@ impl<'a> sandbox::SandboxContext for SandboxContext<'a> {
|
||||
|
||||
match result {
|
||||
Ok(Some(RuntimeValue::I64(val))) => Ok(val),
|
||||
Ok(_) => return Err("Supervisor function returned unexpected result!".into()),
|
||||
Ok(_) => Err("Supervisor function returned unexpected result!".into()),
|
||||
Err(err) => Err(Error::Sandbox(err.to_string())),
|
||||
}
|
||||
}
|
||||
@@ -161,7 +161,7 @@ impl Sandbox for FunctionExecutor {
|
||||
Ok(buffer) => buffer,
|
||||
};
|
||||
|
||||
if let Err(_) = self.memory.set(buf_ptr.into(), &buffer) {
|
||||
if self.memory.set(buf_ptr.into(), &buffer).is_err() {
|
||||
return Ok(sandbox_env::ERR_OUT_OF_BOUNDS)
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ impl Sandbox for FunctionExecutor {
|
||||
Ok(buffer) => buffer,
|
||||
};
|
||||
|
||||
if let Err(_) = sandboxed_memory.write_from(Pointer::new(offset as u32), &buffer) {
|
||||
if sandboxed_memory.write_from(Pointer::new(offset as u32), &buffer).is_err() {
|
||||
return Ok(sandbox_env::ERR_OUT_OF_BOUNDS)
|
||||
}
|
||||
|
||||
@@ -241,9 +241,9 @@ impl Sandbox for FunctionExecutor {
|
||||
Ok(None) => Ok(sandbox_env::ERR_OK),
|
||||
Ok(Some(val)) => {
|
||||
// Serialize return value and write it back into the memory.
|
||||
sp_wasm_interface::ReturnValue::Value(val.into()).using_encoded(|val| {
|
||||
sp_wasm_interface::ReturnValue::Value(val).using_encoded(|val| {
|
||||
if val.len() > return_val_len as usize {
|
||||
Err("Return value buffer is too small")?;
|
||||
return Err("Return value buffer is too small".into())
|
||||
}
|
||||
self.write_memory(return_val, val).map_err(|_| "Return value buffer is OOB")?;
|
||||
Ok(sandbox_env::ERR_OK)
|
||||
@@ -272,11 +272,11 @@ impl Sandbox for FunctionExecutor {
|
||||
let table = self
|
||||
.table
|
||||
.as_ref()
|
||||
.ok_or_else(|| "Runtime doesn't have a table; sandbox is unavailable")?;
|
||||
.ok_or("Runtime doesn't have a table; sandbox is unavailable")?;
|
||||
table
|
||||
.get(dispatch_thunk_id)
|
||||
.map_err(|_| "dispatch_thunk_idx is out of the table bounds")?
|
||||
.ok_or_else(|| "dispatch_thunk_idx points on an empty table entry")?
|
||||
.ok_or("dispatch_thunk_idx points on an empty table entry")?
|
||||
};
|
||||
|
||||
let guest_env =
|
||||
@@ -458,9 +458,9 @@ impl wasmi::Externals for FunctionExecutor {
|
||||
fn get_mem_instance(module: &ModuleRef) -> Result<MemoryRef, Error> {
|
||||
Ok(module
|
||||
.export_by_name("memory")
|
||||
.ok_or_else(|| Error::InvalidMemoryReference)?
|
||||
.ok_or(Error::InvalidMemoryReference)?
|
||||
.as_memory()
|
||||
.ok_or_else(|| Error::InvalidMemoryReference)?
|
||||
.ok_or(Error::InvalidMemoryReference)?
|
||||
.clone())
|
||||
}
|
||||
|
||||
@@ -469,9 +469,9 @@ fn get_mem_instance(module: &ModuleRef) -> Result<MemoryRef, Error> {
|
||||
fn get_heap_base(module: &ModuleRef) -> Result<u32, Error> {
|
||||
let heap_base_val = module
|
||||
.export_by_name("__heap_base")
|
||||
.ok_or_else(|| Error::HeapBaseNotFoundOrInvalid)?
|
||||
.ok_or(Error::HeapBaseNotFoundOrInvalid)?
|
||||
.as_global()
|
||||
.ok_or_else(|| Error::HeapBaseNotFoundOrInvalid)?
|
||||
.ok_or(Error::HeapBaseNotFoundOrInvalid)?
|
||||
.get();
|
||||
|
||||
match heap_base_val {
|
||||
@@ -564,7 +564,7 @@ fn call_in_wasm_module(
|
||||
match result {
|
||||
Ok(Some(I64(r))) => {
|
||||
let (ptr, length) = unpack_ptr_and_len(r as u64);
|
||||
memory.get(ptr.into(), length as usize).map_err(|_| Error::Runtime)
|
||||
memory.get(ptr, length as usize).map_err(|_| Error::Runtime)
|
||||
},
|
||||
Err(e) => {
|
||||
trace!(
|
||||
@@ -572,7 +572,7 @@ fn call_in_wasm_module(
|
||||
"Failed to execute code with {} pages",
|
||||
memory.current_size().0,
|
||||
);
|
||||
Err(e.into())
|
||||
Err(e)
|
||||
},
|
||||
_ => Err(Error::InvalidReturn),
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ impl<'a> Sandbox for HostContext<'a> {
|
||||
// Serialize return value and write it back into the memory.
|
||||
sp_wasm_interface::ReturnValue::Value(val.into()).using_encoded(|val| {
|
||||
if val.len() > return_val_len as usize {
|
||||
Err("Return value buffer is too small")?;
|
||||
return Err("Return value buffer is too small".into())
|
||||
}
|
||||
<HostContext as FunctionContext>::write_memory(self, return_val, val)
|
||||
.map_err(|_| "can't write return value")?;
|
||||
@@ -273,19 +273,18 @@ impl<'a> Sandbox for HostContext<'a> {
|
||||
.caller
|
||||
.data()
|
||||
.table()
|
||||
.ok_or_else(|| "Runtime doesn't have a table; sandbox is unavailable")?;
|
||||
.ok_or("Runtime doesn't have a table; sandbox is unavailable")?;
|
||||
let table_item = table.get(&mut self.caller, dispatch_thunk_id);
|
||||
|
||||
table_item
|
||||
.ok_or_else(|| "dispatch_thunk_id is out of bounds")?
|
||||
.ok_or("dispatch_thunk_id is out of bounds")?
|
||||
.funcref()
|
||||
.ok_or_else(|| "dispatch_thunk_idx should be a funcref")?
|
||||
.ok_or_else(|| "dispatch_thunk_idx should point to actual func")?
|
||||
.ok_or("dispatch_thunk_idx should be a funcref")?
|
||||
.ok_or("dispatch_thunk_idx should point to actual func")?
|
||||
.clone()
|
||||
};
|
||||
|
||||
let guest_env = match sandbox::GuestEnvironment::decode(&self.sandbox_store(), raw_env_def)
|
||||
{
|
||||
let guest_env = match sandbox::GuestEnvironment::decode(self.sandbox_store(), raw_env_def) {
|
||||
Ok(guest_env) => guest_env,
|
||||
Err(_) => return Ok(sandbox_env::ERR_MODULE as u32),
|
||||
};
|
||||
@@ -304,7 +303,7 @@ impl<'a> Sandbox for HostContext<'a> {
|
||||
wasm,
|
||||
guest_env,
|
||||
state,
|
||||
&mut SandboxContext { host_context: self, dispatch_thunk: dispatch_thunk.clone() },
|
||||
&mut SandboxContext { host_context: self, dispatch_thunk },
|
||||
)
|
||||
}));
|
||||
|
||||
@@ -316,7 +315,7 @@ impl<'a> Sandbox for HostContext<'a> {
|
||||
};
|
||||
|
||||
let instance_idx_or_err_code = match result {
|
||||
Ok(instance) => instance.register(&mut self.sandbox_store_mut(), dispatch_thunk),
|
||||
Ok(instance) => instance.register(self.sandbox_store_mut(), dispatch_thunk),
|
||||
Err(sandbox::InstantiationError::StartTrapped) => sandbox_env::ERR_EXECUTION,
|
||||
Err(_) => sandbox_env::ERR_MODULE,
|
||||
};
|
||||
@@ -366,7 +365,7 @@ impl<'a, 'b> sandbox::SandboxContext for SandboxContext<'a, 'b> {
|
||||
if let Some(ret_val) = ret_vals[0].i64() {
|
||||
Ok(ret_val)
|
||||
} else {
|
||||
return Err("Supervisor function returned unexpected result!".into())
|
||||
Err("Supervisor function returned unexpected result!".into())
|
||||
},
|
||||
Err(err) => Err(err.to_string().into()),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user