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:
Falco Hirschenberger
2022-04-30 23:28:27 +02:00
committed by GitHub
parent a990473cf9
commit b581604aa7
368 changed files with 1927 additions and 2236 deletions
@@ -277,15 +277,14 @@ where
}
module
};
let limits = module
let limits = *module
.import_section()
.unwrap()
.entries()
.iter()
.find_map(|e| if let External::Memory(mem) = e.external() { Some(mem) } else { None })
.unwrap()
.limits()
.clone();
.limits();
let code = module.to_bytes().unwrap();
let hash = T::Hashing::hash(&code);
let memory =
@@ -512,16 +511,10 @@ pub mod body {
DynInstr::RandomI32(low, high) => {
vec![Instruction::I32Const(rng.gen_range(*low..*high))]
},
DynInstr::RandomI32Repeated(num) => (&mut rng)
.sample_iter(Standard)
.take(*num)
.map(|val| Instruction::I32Const(val))
.collect(),
DynInstr::RandomI64Repeated(num) => (&mut rng)
.sample_iter(Standard)
.take(*num)
.map(|val| Instruction::I64Const(val))
.collect(),
DynInstr::RandomI32Repeated(num) =>
(&mut rng).sample_iter(Standard).take(*num).map(Instruction::I32Const).collect(),
DynInstr::RandomI64Repeated(num) =>
(&mut rng).sample_iter(Standard).take(*num).map(Instruction::I64Const).collect(),
DynInstr::RandomGetLocal(low, high) => {
vec![Instruction::GetLocal(rng.gen_range(*low..*high))]
},
@@ -138,7 +138,7 @@ where
Storage::<T>::write(&info.trie_id, &item.0, Some(item.1.clone()), None, false)
.map_err(|_| "Failed to write storage to restoration dest")?;
}
<ContractInfoOf<T>>::insert(&self.account_id, info.clone());
<ContractInfoOf<T>>::insert(&self.account_id, info);
Ok(())
}
@@ -253,7 +253,7 @@ benchmarks! {
)?;
let value = T::Currency::minimum_balance();
let origin = RawOrigin::Signed(instance.caller.clone());
let callee = instance.addr.clone();
let callee = instance.addr;
}: call(origin, callee, value, Weight::MAX, None, vec![])
// This constructs a contract that is maximal expensive to instrument.
@@ -1067,7 +1067,7 @@ benchmarks! {
)
.map_err(|_| "Failed to write to storage during setup.")?;
}
<ContractInfoOf<T>>::insert(&instance.account_id, info.clone());
<ContractInfoOf<T>>::insert(&instance.account_id, info);
let origin = RawOrigin::Signed(instance.caller.clone());
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
@@ -1164,7 +1164,7 @@ benchmarks! {
)
.map_err(|_| "Failed to write to storage during setup.")?;
}
<ContractInfoOf<T>>::insert(&instance.account_id, info.clone());
<ContractInfoOf<T>>::insert(&instance.account_id, info);
let origin = RawOrigin::Signed(instance.caller.clone());
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
@@ -1216,7 +1216,7 @@ benchmarks! {
)
.map_err(|_| "Failed to write to storage during setup.")?;
}
<ContractInfoOf<T>>::insert(&instance.account_id, info.clone());
<ContractInfoOf<T>>::insert(&instance.account_id, info);
let origin = RawOrigin::Signed(instance.caller.clone());
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
@@ -1263,7 +1263,7 @@ benchmarks! {
)
.map_err(|_| "Failed to write to storage during setup.")?;
}
<ContractInfoOf<T>>::insert(&instance.account_id, info.clone());
<ContractInfoOf<T>>::insert(&instance.account_id, info);
let origin = RawOrigin::Signed(instance.caller.clone());
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
@@ -1308,7 +1308,7 @@ benchmarks! {
)
.map_err(|_| "Failed to write to storage during setup.")?;
}
<ContractInfoOf<T>>::insert(&instance.account_id, info.clone());
<ContractInfoOf<T>>::insert(&instance.account_id, info);
let origin = RawOrigin::Signed(instance.caller.clone());
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
@@ -1360,7 +1360,7 @@ benchmarks! {
)
.map_err(|_| "Failed to write to storage during setup.")?;
}
<ContractInfoOf<T>>::insert(&instance.account_id, info.clone());
<ContractInfoOf<T>>::insert(&instance.account_id, info);
let origin = RawOrigin::Signed(instance.caller.clone());
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
@@ -1412,7 +1412,7 @@ benchmarks! {
)
.map_err(|_| "Failed to write to storage during setup.")?;
}
<ContractInfoOf<T>>::insert(&instance.account_id, info.clone());
<ContractInfoOf<T>>::insert(&instance.account_id, info);
let origin = RawOrigin::Signed(instance.caller.clone());
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
@@ -1577,7 +1577,7 @@ benchmarks! {
});
let instance = Contract::<T>::new(code, vec![])?;
let callee = instance.addr.clone();
let origin = RawOrigin::Signed(instance.caller.clone());
let origin = RawOrigin::Signed(instance.caller);
}: call(origin, callee, 0u32.into(), Weight::MAX, None, vec![])
seal_call_per_transfer_clone_kb {
@@ -1739,7 +1739,7 @@ benchmarks! {
.collect::<Vec<_>>();
for addr in &addresses {
if let Some(_) = ContractInfoOf::<T>::get(&addr) {
if ContractInfoOf::<T>::get(&addr).is_some() {
return Err("Expected that contract does not exist at this point.".into());
}
}
@@ -1747,7 +1747,7 @@ benchmarks! {
verify {
for addr in &addresses {
ContractInfoOf::<T>::get(&addr)
.ok_or_else(|| "Contract should have been instantiated")?;
.ok_or("Contract should have been instantiated")?;
}
}
@@ -1755,7 +1755,7 @@ benchmarks! {
let t in 0 .. 1;
let s in 0 .. (code::max_pages::<T>() - 1) * 64;
let callee_code = WasmModule::<T>::dummy();
let hash = callee_code.hash.clone();
let hash = callee_code.hash;
let hash_bytes = callee_code.hash.encode();
let hash_len = hash_bytes.len();
Contracts::<T>::store_code_raw(callee_code.code, whitelisted_caller())?;
+13 -16
View File
@@ -610,7 +610,7 @@ where
debug_message: Option<&'a mut Vec<u8>>,
) -> Result<(Self, E), ExecError> {
let (first_frame, executable, nonce) =
Self::new_frame(args, value, gas_meter, storage_meter, 0, &schedule)?;
Self::new_frame(args, value, gas_meter, storage_meter, 0, schedule)?;
let stack = Self {
origin,
schedule,
@@ -660,13 +660,10 @@ where
},
FrameArgs::Instantiate { sender, nonce, executable, salt } => {
let account_id =
<Contracts<T>>::contract_address(&sender, executable.code_hash(), &salt);
<Contracts<T>>::contract_address(&sender, executable.code_hash(), salt);
let trie_id = Storage::<T>::generate_trie_id(&account_id, nonce);
let contract = Storage::<T>::new_contract(
&account_id,
trie_id,
executable.code_hash().clone(),
)?;
let contract =
Storage::<T>::new_contract(&account_id, trie_id, *executable.code_hash())?;
(
account_id,
contract,
@@ -742,7 +739,7 @@ where
top_frame.nested_storage.charge_instantiate(
&self.origin,
&top_frame.account_id,
&mut top_frame.contract_info.get(&top_frame.account_id),
top_frame.contract_info.get(&top_frame.account_id),
)?;
}
@@ -1020,11 +1017,11 @@ where
code_hash: CodeHash<Self::T>,
input_data: Vec<u8>,
) -> Result<ExecReturnValue, ExecError> {
let executable = E::from_storage(code_hash, &self.schedule, self.gas_meter())?;
let executable = E::from_storage(code_hash, self.schedule, self.gas_meter())?;
let top_frame = self.top_frame_mut();
let contract_info = top_frame.contract_info().clone();
let account_id = top_frame.account_id.clone();
let value = top_frame.value_transferred.clone();
let value = top_frame.value_transferred;
let executable = self.push_frame(
FrameArgs::Call {
dest: account_id,
@@ -1045,7 +1042,7 @@ where
input_data: Vec<u8>,
salt: &[u8],
) -> Result<(AccountIdOf<T>, ExecReturnValue), ExecError> {
let executable = E::from_storage(code_hash, &self.schedule, self.gas_meter())?;
let executable = E::from_storage(code_hash, self.schedule, self.gas_meter())?;
let nonce = self.next_nonce();
let executable = self.push_frame(
FrameArgs::Instantiate {
@@ -1118,7 +1115,7 @@ where
fn caller(&self) -> &T::AccountId {
if let Some(caller) = &self.top_frame().delegate_caller {
&caller
caller
} else {
self.frames().nth(1).map(|f| &f.account_id).unwrap_or(&self.origin)
}
@@ -1180,7 +1177,7 @@ where
}
fn schedule(&self) -> &Schedule<Self::T> {
&self.schedule
self.schedule
}
fn gas_meter(&mut self) -> &mut GasMeter<Self::T> {
@@ -1205,7 +1202,7 @@ where
}
fn ecdsa_recover(&self, signature: &[u8; 65], message_hash: &[u8; 32]) -> Result<[u8; 33], ()> {
secp256k1_ecdsa_recover_compressed(&signature, &message_hash).map_err(|_| ())
secp256k1_ecdsa_recover_compressed(signature, message_hash).map_err(|_| ())
}
fn ecdsa_to_eth_address(&self, pk: &[u8; 33]) -> Result<[u8; 20], ()> {
@@ -1220,8 +1217,8 @@ where
fn set_code_hash(&mut self, hash: CodeHash<Self::T>) -> Result<(), DispatchError> {
E::add_user(hash)?;
let top_frame = self.top_frame_mut();
let prev_hash = top_frame.contract_info().code_hash.clone();
E::remove_user(prev_hash.clone());
let prev_hash = top_frame.contract_info().code_hash;
E::remove_user(prev_hash);
top_frame.contract_info().code_hash = hash;
Contracts::<Self::T>::deposit_event(Event::ContractCodeUpdated {
contract: top_frame.account_id.clone(),
+1 -1
View File
@@ -114,7 +114,7 @@ where
if self.gas_left < amount {
Err(<Error<T>>::OutOfGas.into())
} else {
self.gas_left = self.gas_left - amount;
self.gas_left -= amount;
Ok(GasMeter::new(amount))
}
}
+1 -1
View File
@@ -670,7 +670,7 @@ struct ScheduleRules<'a, T: Config> {
impl<T: Config> Schedule<T> {
pub(crate) fn rules(&self, module: &elements::Module) -> impl gas_metering::Rules + '_ {
ScheduleRules {
schedule: &self,
schedule: self,
params: module
.type_section()
.iter()
+4 -4
View File
@@ -154,10 +154,10 @@ where
let hashed_key = blake2_256(key);
let child_trie_info = &child_trie_info(trie_id);
let (old_len, old_value) = if take {
let val = child::get_raw(&child_trie_info, &hashed_key);
let val = child::get_raw(child_trie_info, &hashed_key);
(val.as_ref().map(|v| v.len() as u32), val)
} else {
(child::len(&child_trie_info, &hashed_key), None)
(child::len(child_trie_info, &hashed_key), None)
};
if let Some(storage_meter) = storage_meter {
@@ -183,8 +183,8 @@ where
}
match &new_value {
Some(new_value) => child::put_raw(&child_trie_info, &hashed_key, new_value),
None => child::kill(&child_trie_info, &hashed_key),
Some(new_value) => child::put_raw(child_trie_info, &hashed_key, new_value),
None => child::kill(child_trie_info, &hashed_key),
}
Ok(match (old_len, old_value) {
@@ -230,7 +230,7 @@ where
self.total_deposit = self.total_deposit.saturating_add(&absorbed.total_deposit);
if !absorbed.own_deposit.is_zero() {
E::charge(origin, &contract, &absorbed.own_deposit, absorbed.terminated);
E::charge(origin, contract, &absorbed.own_deposit, absorbed.terminated);
}
}
@@ -255,7 +255,7 @@ where
limit: Option<BalanceOf<T>>,
min_leftover: BalanceOf<T>,
) -> Result<Self, DispatchError> {
let limit = E::check_limit(&origin, limit, min_leftover)?;
let limit = E::check_limit(origin, limit, min_leftover)?;
Ok(Self { limit, ..Default::default() })
}
@@ -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;
+14 -20
View File
@@ -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)?;
+19 -19
View File
@@ -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)? {