mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 10:31:03 +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
@@ -165,8 +165,7 @@ where
|
||||
{
|
||||
let charged = gas_meter.charge(CodeToken::Load(schedule.limits.code_len))?;
|
||||
|
||||
let mut prefab_module =
|
||||
<CodeStorage<T>>::get(code_hash).ok_or_else(|| Error::<T>::CodeNotFound)?;
|
||||
let mut prefab_module = <CodeStorage<T>>::get(code_hash).ok_or(Error::<T>::CodeNotFound)?;
|
||||
gas_meter.adjust_gas(charged, CodeToken::Load(prefab_module.code.len() as u32));
|
||||
prefab_module.code_hash = code_hash;
|
||||
|
||||
@@ -189,7 +188,7 @@ pub fn reinstrument<T: Config>(
|
||||
schedule: &Schedule<T>,
|
||||
) -> Result<u32, DispatchError> {
|
||||
let original_code =
|
||||
<PristineCode<T>>::get(&prefab_module.code_hash).ok_or_else(|| Error::<T>::CodeNotFound)?;
|
||||
<PristineCode<T>>::get(&prefab_module.code_hash).ok_or(Error::<T>::CodeNotFound)?;
|
||||
let original_code_len = original_code.len();
|
||||
prefab_module.code = prepare::reinstrument_contract::<T>(original_code, schedule)?;
|
||||
prefab_module.instruction_weights_version = schedule.instruction_weights.version;
|
||||
|
||||
@@ -225,10 +225,7 @@ impl<'a, T: Config> ContractModule<'a, T> {
|
||||
.map(|is| is.entries())
|
||||
.unwrap_or(&[])
|
||||
.iter()
|
||||
.filter(|entry| match *entry.external() {
|
||||
External::Function(_) => true,
|
||||
_ => false,
|
||||
})
|
||||
.filter(|entry| matches!(*entry.external(), External::Function(_)))
|
||||
.count();
|
||||
|
||||
for export in export_entries {
|
||||
@@ -259,11 +256,10 @@ impl<'a, T: Config> ContractModule<'a, T> {
|
||||
// We still support () -> (i32) for backwards compatibility.
|
||||
let func_ty_idx = func_entries
|
||||
.get(fn_idx as usize)
|
||||
.ok_or_else(|| "export refers to non-existent function")?
|
||||
.ok_or("export refers to non-existent function")?
|
||||
.type_ref();
|
||||
let Type::Function(ref func_ty) = types
|
||||
.get(func_ty_idx as usize)
|
||||
.ok_or_else(|| "function has a non-existent type")?;
|
||||
let Type::Function(ref func_ty) =
|
||||
types.get(func_ty_idx as usize).ok_or("function has a non-existent type")?;
|
||||
if !(func_ty.params().is_empty() &&
|
||||
(func_ty.results().is_empty() || func_ty.results() == [ValueType::I32]))
|
||||
{
|
||||
@@ -300,11 +296,11 @@ impl<'a, T: Config> ContractModule<'a, T> {
|
||||
let mut imported_mem_type = None;
|
||||
|
||||
for import in import_entries {
|
||||
let type_idx = match import.external() {
|
||||
&External::Table(_) => return Err("Cannot import tables"),
|
||||
&External::Global(_) => return Err("Cannot import globals"),
|
||||
&External::Function(ref type_idx) => type_idx,
|
||||
&External::Memory(ref memory_type) => {
|
||||
let type_idx = match *import.external() {
|
||||
External::Table(_) => return Err("Cannot import tables"),
|
||||
External::Global(_) => return Err("Cannot import globals"),
|
||||
External::Function(ref type_idx) => type_idx,
|
||||
External::Memory(ref memory_type) => {
|
||||
if import.module() != IMPORT_MODULE_MEMORY {
|
||||
return Err("Invalid module for imported memory")
|
||||
}
|
||||
@@ -321,7 +317,7 @@ impl<'a, T: Config> ContractModule<'a, T> {
|
||||
|
||||
let Type::Function(ref func_ty) = types
|
||||
.get(*type_idx as usize)
|
||||
.ok_or_else(|| "validation: import entry points to a non-existent type")?;
|
||||
.ok_or("validation: import entry points to a non-existent type")?;
|
||||
|
||||
if !T::ChainExtension::enabled() &&
|
||||
import.field().as_bytes() == b"seal_call_chain_extension"
|
||||
@@ -352,17 +348,15 @@ fn get_memory_limits<T: Config>(
|
||||
let limits = memory_type.limits();
|
||||
match (limits.initial(), limits.maximum()) {
|
||||
(initial, Some(maximum)) if initial > maximum =>
|
||||
return Err(
|
||||
"Requested initial number of pages should not exceed the requested maximum",
|
||||
),
|
||||
Err("Requested initial number of pages should not exceed the requested maximum"),
|
||||
(_, Some(maximum)) if maximum > schedule.limits.memory_pages =>
|
||||
return Err("Maximum number of pages should not exceed the configured maximum."),
|
||||
Err("Maximum number of pages should not exceed the configured maximum."),
|
||||
(initial, Some(maximum)) => Ok((initial, maximum)),
|
||||
(_, None) => {
|
||||
// Maximum number of pages should be always declared.
|
||||
// This isn't a hard requirement and can be treated as a maximum set
|
||||
// to configured maximum.
|
||||
return Err("Maximum number of pages should be always declared.")
|
||||
Err("Maximum number of pages should be always declared.")
|
||||
},
|
||||
}
|
||||
} else {
|
||||
@@ -377,7 +371,7 @@ fn check_and_instrument<C: ImportSatisfyCheck, T: Config>(
|
||||
schedule: &Schedule<T>,
|
||||
) -> Result<(Vec<u8>, (u32, u32)), &'static str> {
|
||||
let result = (|| {
|
||||
let contract_module = ContractModule::new(&original_code, schedule)?;
|
||||
let contract_module = ContractModule::new(original_code, schedule)?;
|
||||
contract_module.scan_exports()?;
|
||||
contract_module.ensure_no_internal_memory()?;
|
||||
contract_module.ensure_table_size_limit(schedule.limits.table_size)?;
|
||||
|
||||
@@ -460,13 +460,13 @@ where
|
||||
return match trap_reason {
|
||||
// The trap was the result of the execution `return` host function.
|
||||
TrapReason::Return(ReturnData { flags, data }) => {
|
||||
let flags = ReturnFlags::from_bits(flags)
|
||||
.ok_or_else(|| Error::<E::T>::InvalidCallFlags)?;
|
||||
let flags =
|
||||
ReturnFlags::from_bits(flags).ok_or(Error::<E::T>::InvalidCallFlags)?;
|
||||
Ok(ExecReturnValue { flags, data: Bytes(data) })
|
||||
},
|
||||
TrapReason::Termination =>
|
||||
Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: Bytes(Vec::new()) }),
|
||||
TrapReason::SupervisorError(error) => Err(error)?,
|
||||
TrapReason::SupervisorError(error) => return Err(error.into()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -480,10 +480,10 @@ where
|
||||
//
|
||||
// Because panics are really undesirable in the runtime code, we treat this as
|
||||
// a trap for now. Eventually, we might want to revisit this.
|
||||
Err(sp_sandbox::Error::Module) => Err("validation error")?,
|
||||
Err(sp_sandbox::Error::Module) => return Err("validation error".into()),
|
||||
// Any other kind of a trap should result in a failure.
|
||||
Err(sp_sandbox::Error::Execution) | Err(sp_sandbox::Error::OutOfBounds) =>
|
||||
Err(Error::<E::T>::ContractTrapped)?,
|
||||
return Err(Error::<E::T>::ContractTrapped.into()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -620,7 +620,7 @@ where
|
||||
let len: u32 = self.read_sandbox_memory_as(out_len_ptr)?;
|
||||
|
||||
if len < buf_len {
|
||||
Err(Error::<E::T>::OutputBufferTooSmall)?
|
||||
return Err(Error::<E::T>::OutputBufferTooSmall.into())
|
||||
}
|
||||
|
||||
if let Some(costs) = create_token(buf_len) {
|
||||
@@ -717,7 +717,7 @@ where
|
||||
let charged = self
|
||||
.charge_gas(RuntimeCosts::SetStorage { new_bytes: value_len, old_bytes: max_size })?;
|
||||
if value_len > max_size {
|
||||
Err(Error::<E::T>::ValueTooLarge)?;
|
||||
return Err(Error::<E::T>::ValueTooLarge.into())
|
||||
}
|
||||
let mut key: StorageKey = [0; 32];
|
||||
self.read_sandbox_memory_into_buf(key_ptr, &mut key)?;
|
||||
@@ -750,11 +750,11 @@ where
|
||||
) -> Result<ReturnCode, TrapReason> {
|
||||
self.charge_gas(call_type.cost())?;
|
||||
let input_data = if flags.contains(CallFlags::CLONE_INPUT) {
|
||||
let input = self.input_data.as_ref().ok_or_else(|| Error::<E::T>::InputForwarded)?;
|
||||
let input = self.input_data.as_ref().ok_or(Error::<E::T>::InputForwarded)?;
|
||||
charge_gas!(self, RuntimeCosts::CallInputCloned(input.len() as u32))?;
|
||||
input.clone()
|
||||
} else if flags.contains(CallFlags::FORWARD_INPUT) {
|
||||
self.input_data.take().ok_or_else(|| Error::<E::T>::InputForwarded)?
|
||||
self.input_data.take().ok_or(Error::<E::T>::InputForwarded)?
|
||||
} else {
|
||||
self.charge_gas(RuntimeCosts::CopyFromContract(input_data_len))?;
|
||||
self.read_sandbox_memory(input_data_ptr, input_data_len)?
|
||||
@@ -1108,7 +1108,7 @@ define_env!(Env, <E: Ext>,
|
||||
output_len_ptr: u32
|
||||
) -> ReturnCode => {
|
||||
ctx.call(
|
||||
CallFlags::from_bits(flags).ok_or_else(|| Error::<E::T>::InvalidCallFlags)?,
|
||||
CallFlags::from_bits(flags).ok_or(Error::<E::T>::InvalidCallFlags)?,
|
||||
CallType::Call{callee_ptr, value_ptr, gas},
|
||||
input_data_ptr,
|
||||
input_data_len,
|
||||
@@ -1151,7 +1151,7 @@ define_env!(Env, <E: Ext>,
|
||||
output_len_ptr: u32
|
||||
) -> ReturnCode => {
|
||||
ctx.call(
|
||||
CallFlags::from_bits(flags).ok_or_else(|| Error::<E::T>::InvalidCallFlags)?,
|
||||
CallFlags::from_bits(flags).ok_or(Error::<E::T>::InvalidCallFlags)?,
|
||||
CallType::DelegateCall{code_hash_ptr},
|
||||
input_data_ptr,
|
||||
input_data_len,
|
||||
@@ -1486,7 +1486,7 @@ define_env!(Env, <E: Ext>,
|
||||
ctx.charge_gas(RuntimeCosts::GasLeft)?;
|
||||
let gas_left = &ctx.ext.gas_meter().gas_left().encode();
|
||||
Ok(ctx.write_sandbox_output(
|
||||
out_ptr, out_len_ptr, &gas_left, false, already_charged,
|
||||
out_ptr, out_len_ptr, gas_left, false, already_charged,
|
||||
)?)
|
||||
},
|
||||
|
||||
@@ -1535,7 +1535,7 @@ define_env!(Env, <E: Ext>,
|
||||
[seal0] seal_random(ctx, subject_ptr: u32, subject_len: u32, out_ptr: u32, out_len_ptr: u32) => {
|
||||
ctx.charge_gas(RuntimeCosts::Random)?;
|
||||
if subject_len > ctx.ext.schedule().limits.subject_len {
|
||||
Err(Error::<E::T>::RandomSubjectTooLong)?;
|
||||
return Err(Error::<E::T>::RandomSubjectTooLong.into());
|
||||
}
|
||||
let subject_buf = ctx.read_sandbox_memory(subject_ptr, subject_len)?;
|
||||
Ok(ctx.write_sandbox_output(
|
||||
@@ -1567,7 +1567,7 @@ define_env!(Env, <E: Ext>,
|
||||
[seal1] seal_random(ctx, subject_ptr: u32, subject_len: u32, out_ptr: u32, out_len_ptr: u32) => {
|
||||
ctx.charge_gas(RuntimeCosts::Random)?;
|
||||
if subject_len > ctx.ext.schedule().limits.subject_len {
|
||||
Err(Error::<E::T>::RandomSubjectTooLong)?;
|
||||
return Err(Error::<E::T>::RandomSubjectTooLong.into());
|
||||
}
|
||||
let subject_buf = ctx.read_sandbox_memory(subject_ptr, subject_len)?;
|
||||
Ok(ctx.write_sandbox_output(
|
||||
@@ -1685,13 +1685,13 @@ define_env!(Env, <E: Ext>,
|
||||
|
||||
let num_topic = topics_len
|
||||
.checked_div(sp_std::mem::size_of::<TopicOf<E::T>>() as u32)
|
||||
.ok_or_else(|| "Zero sized topics are not allowed")?;
|
||||
.ok_or("Zero sized topics are not allowed")?;
|
||||
ctx.charge_gas(RuntimeCosts::DepositEvent {
|
||||
num_topic,
|
||||
len: data_len,
|
||||
})?;
|
||||
if data_len > ctx.ext.max_value_size() {
|
||||
Err(Error::<E::T>::ValueTooLarge)?;
|
||||
return Err(Error::<E::T>::ValueTooLarge.into());
|
||||
}
|
||||
|
||||
let mut topics: Vec::<TopicOf<<E as Ext>::T>> = match topics_len {
|
||||
@@ -1701,14 +1701,14 @@ define_env!(Env, <E: Ext>,
|
||||
|
||||
// If there are more than `event_topics`, then trap.
|
||||
if topics.len() > ctx.ext.schedule().limits.event_topics as usize {
|
||||
Err(Error::<E::T>::TooManyTopics)?;
|
||||
return Err(Error::<E::T>::TooManyTopics.into());
|
||||
}
|
||||
|
||||
// Check for duplicate topics. If there are any, then trap.
|
||||
// Complexity O(n * log(n)) and no additional allocations.
|
||||
// This also sorts the topics.
|
||||
if has_duplicates(&mut topics) {
|
||||
Err(Error::<E::T>::DuplicateTopics)?;
|
||||
return Err(Error::<E::T>::DuplicateTopics.into());
|
||||
}
|
||||
|
||||
let event_data = ctx.read_sandbox_memory(data_ptr, data_len)?;
|
||||
@@ -1888,7 +1888,7 @@ define_env!(Env, <E: Ext>,
|
||||
) -> u32 => {
|
||||
use crate::chain_extension::{ChainExtension, Environment, RetVal};
|
||||
if !<E::T as Config>::ChainExtension::enabled() {
|
||||
Err(Error::<E::T>::NoChainExtension)?;
|
||||
return Err(Error::<E::T>::NoChainExtension.into());
|
||||
}
|
||||
let env = Environment::new(ctx, input_ptr, input_len, output_ptr, output_len_ptr);
|
||||
match <E::T as Config>::ChainExtension::call(func_id, env)? {
|
||||
|
||||
Reference in New Issue
Block a user